From 043377523a166c6a5444f22ed9bb4e9add404230 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Sun, 12 Apr 2026 10:15:05 -0500 Subject: [PATCH] fix: preference initialization with `app.setPath('sessionData')` (#50908) fix: preference initialization with app.setPath('sessionData') Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Niklas Wenzel --- shell/browser/browser_process_impl.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/shell/browser/browser_process_impl.cc b/shell/browser/browser_process_impl.cc index 3a33345589..1b56858ad3 100644 --- a/shell/browser/browser_process_impl.cc +++ b/shell/browser/browser_process_impl.cc @@ -10,6 +10,7 @@ #include "base/command_line.h" #include "base/files/file_path.h" +#include "base/files/file_util.h" #include "base/functional/bind.h" #include "base/notimplemented.h" #include "base/path_service.h" @@ -20,7 +21,6 @@ #include "components/os_crypt/sync/os_crypt.h" #include "components/prefs/in_memory_pref_store.h" #include "components/prefs/json_pref_store.h" -#include "components/prefs/overlay_user_pref_store.h" #include "components/prefs/pref_registry.h" #include "components/prefs/pref_registry_simple.h" #include "components/prefs/pref_service.h" @@ -153,16 +153,19 @@ void BrowserProcessImpl::PostEarlyInitialization() { ApplyProxyModeFromCommandLine(in_memory_pref_store()); prefs_factory.set_command_line_prefs(in_memory_pref_store()); - // Only use a persistent prefs store when cookie encryption is enabled as that - // is the only key that needs it base::FilePath prefs_path; CHECK(base::PathService::Get(electron::DIR_SESSION_DATA, &prefs_path)); + if (!base::DirectoryExists(prefs_path)) + base::CreateDirectory(prefs_path); prefs_path = prefs_path.Append(FILE_PATH_LITERAL("Local State")); + electron::ScopedAllowBlockingForElectron allow_blocking; scoped_refptr user_pref_store = base::MakeRefCounted(prefs_path); user_pref_store->ReadPrefs(); prefs_factory.set_user_prefs(user_pref_store); + DCHECK(user_pref_store->IsInitializationComplete()); + local_state_ = prefs_factory.Create(std::move(pref_registry)); }