summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSzabolcs David <davidsz@inf.u-szeged.hu>2023-07-18 15:20:22 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-08-03 21:46:36 +0000
commit925efb3a8b741cc483b8afda8b450d32e6c83180 (patch)
treec9c8587f076f6f30a27e76020f3d8fcb54bd7e76
parent6396aca64364cd98d56bfe12a01dae21fdccaec4 (diff)
Fix crashing PDF viewer after changing the storage path
Changing the storage path (and recreating PrefService) caused a crash in the extension system, because the pointer of the old PrefService was dangling in ExtensionPrefs. Recreating it as well seems to be the nicest way to update its dangling part. Task-number: QTBUG-115188 Change-Id: I46321b1737432c7d1cd6ec41c76e7803e69f2011 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> (cherry picked from commit 7af3d247a930baa3262654082c441f8a015889b6) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/core/profile_qt.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/core/profile_qt.cpp b/src/core/profile_qt.cpp
index 410340fb8..c912c9898 100644
--- a/src/core/profile_qt.cpp
+++ b/src/core/profile_qt.cpp
@@ -46,7 +46,12 @@
#endif
#if BUILDFLAG(ENABLE_EXTENSIONS)
+#include "base/command_line.h"
#include "components/guest_view/browser/guest_view_manager.h"
+#include "extensions/browser/extension_pref_value_map_factory.h"
+#include "extensions/browser/extension_prefs.h"
+#include "extensions/browser/extension_prefs_factory.h"
+#include "extensions/browser/extensions_browser_client.h"
#include "extensions/browser/pref_names.h"
#include "extensions/browser/process_manager.h"
#include "extensions/common/constants.h"
@@ -246,6 +251,7 @@ content::FileSystemAccessPermissionContext *ProfileQt::GetFileSystemAccessPermis
void ProfileQt::setupPrefService()
{
+ const bool recreation = m_prefServiceAdapter.prefService() != nullptr;
profile_metrics::SetBrowserProfileType(this,
IsOffTheRecord()
? profile_metrics::BrowserProfileType::kIncognito
@@ -253,12 +259,28 @@ void ProfileQt::setupPrefService()
// Remove previous handler before we set a new one or we will assert
// TODO: Remove in Qt6
- if (m_prefServiceAdapter.prefService() != nullptr) {
+ if (recreation) {
user_prefs::UserPrefs::Remove(this);
m_prefServiceAdapter.commit();
}
m_prefServiceAdapter.setup(*m_profileAdapter);
user_prefs::UserPrefs::Set(this, m_prefServiceAdapter.prefService());
+
+#if BUILDFLAG(ENABLE_EXTENSIONS)
+ if (recreation) {
+ // Recreate ExtensionPrefs to update its pointer to the new PrefService
+ extensions::ExtensionsBrowserClient *client = extensions::ExtensionsBrowserClient::Get();
+ std::vector<extensions::EarlyExtensionPrefsObserver *> prefsObservers;
+ client->GetEarlyExtensionPrefsObservers(this, &prefsObservers);
+ extensions::ExtensionPrefs *extensionPrefs = extensions::ExtensionPrefs::Create(
+ this, client->GetPrefServiceForContext(this),
+ this->GetPath().AppendASCII(extensions::kInstallDirectoryName),
+ ExtensionPrefValueMapFactory::GetForBrowserContext(this),
+ client->AreExtensionsDisabled(*base::CommandLine::ForCurrentProcess(), this),
+ prefsObservers);
+ extensions::ExtensionPrefsFactory::GetInstance()->SetInstanceForTesting(this, base::WrapUnique(extensionPrefs));
+ }
+#endif
}
PrefServiceAdapter &ProfileQt::prefServiceAdapter()