From 4e089766a5d1f5ff6572531fb1198c02c06f38bd Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Fri, 26 Apr 2019 17:17:24 -0400 Subject: [PATCH] Fix NetworkService startup assertion with multi-threaded message loop (see issue #2622). When using multi-threaded message loop mode the PrefService needs to be created on the UI thread. To test: Run `cefclient --enable-network-service --multi-threaded-message-loop`. The application should start successfully. --- libcef/browser/chrome_browser_process_stub.cc | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/libcef/browser/chrome_browser_process_stub.cc b/libcef/browser/chrome_browser_process_stub.cc index a0d7fdf28..93ddad66d 100644 --- a/libcef/browser/chrome_browser_process_stub.cc +++ b/libcef/browser/chrome_browser_process_stub.cc @@ -45,14 +45,6 @@ void ChromeBrowserProcessStub::Initialize() { // Initialize this early before any code tries to check feature flags. content::SetUpFieldTrialsAndFeatureList(); - const CefSettings& settings = CefContext::Get()->settings(); - const base::FilePath& cache_path = - base::FilePath(CefString(&settings.cache_path)); - - // Used for very early NetworkService initialization. - local_state_ = browser_prefs::CreatePrefService( - nullptr, cache_path, !!settings.persist_user_preferences); - initialized_ = true; } @@ -160,6 +152,15 @@ ProfileManager* ChromeBrowserProcessStub::profile_manager() { PrefService* ChromeBrowserProcessStub::local_state() { DCHECK(initialized_); + if (!local_state_) { + const CefSettings& settings = CefContext::Get()->settings(); + const base::FilePath& cache_path = + base::FilePath(CefString(&settings.cache_path)); + + // Used for very early NetworkService initialization. + local_state_ = browser_prefs::CreatePrefService( + nullptr, cache_path, !!settings.persist_user_preferences); + } return local_state_.get(); }