Skip to content

Commit

Permalink
Simplify PrefService initialization (issue chromiumembedded#1947)
Browse files Browse the repository at this point in the history
  • Loading branch information
magreenblatt committed Sep 25, 2017
1 parent 157ad1d commit 264fa66
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 35 deletions.
11 changes: 3 additions & 8 deletions libcef/browser/browser_context_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -265,17 +265,12 @@ void CefBrowserContextImpl::Initialize() {
CefString(&CefContext::Get()->settings().accept_language_list);
}

// Initialize a temporary PrefService object that may be referenced during
// BrowserContextServices initialization.
pref_service_ =
browser_prefs::CreatePrefService(this, base::FilePath(), false, true);
// Initialize the PrefService object.
pref_service_ = browser_prefs::CreatePrefService(
this, cache_path_, !!settings_.persist_user_preferences);

CefBrowserContext::Initialize();

// Initialize the real PrefService object.
pref_service_ = browser_prefs::CreatePrefService(
this, cache_path_, !!settings_.persist_user_preferences, false);

// Initialize visited links management.
base::FilePath visited_link_path;
if (!cache_path_.empty())
Expand Down
39 changes: 17 additions & 22 deletions libcef/browser/prefs/browser_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ const char kUserPrefsFileName[] = "UserPrefs.json";

std::unique_ptr<PrefService> CreatePrefService(Profile* profile,
const base::FilePath& cache_path,
bool persist_user_preferences,
bool is_pre_initialization) {
bool persist_user_preferences) {
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();

Expand All @@ -115,8 +114,7 @@ std::unique_ptr<PrefService> CreatePrefService(Profile* profile,
factory.set_command_line_prefs(command_line_pref_store);

// True if preferences will be stored on disk.
const bool store_on_disk =
!cache_path.empty() && persist_user_preferences && !is_pre_initialization;
const bool store_on_disk = !cache_path.empty() && persist_user_preferences;

scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner;
if (store_on_disk) {
Expand All @@ -142,26 +140,23 @@ std::unique_ptr<PrefService> CreatePrefService(Profile* profile,
}

#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
// Don't access factories during pre-initialization.
if (!is_pre_initialization) {
// Used to store supervised user preferences.
SupervisedUserSettingsService* supervised_user_settings =
SupervisedUserSettingsServiceFactory::GetForProfile(profile);

if (store_on_disk) {
supervised_user_settings->Init(cache_path, sequenced_task_runner.get(),
true);
} else {
scoped_refptr<CefPrefStore> cef_pref_store = new CefPrefStore();
cef_pref_store->SetInitializationCompleted();
supervised_user_settings->Init(cef_pref_store);
}
// Used to store supervised user preferences.
SupervisedUserSettingsService* supervised_user_settings =
SupervisedUserSettingsServiceFactory::GetForProfile(profile);

scoped_refptr<PrefStore> supervised_user_prefs = make_scoped_refptr(
new SupervisedUserPrefStore(supervised_user_settings));
DCHECK(supervised_user_prefs->IsInitializationComplete());
factory.set_supervised_user_prefs(supervised_user_prefs);
if (store_on_disk) {
supervised_user_settings->Init(cache_path, sequenced_task_runner.get(),
true);
} else {
scoped_refptr<CefPrefStore> cef_pref_store = new CefPrefStore();
cef_pref_store->SetInitializationCompleted();
supervised_user_settings->Init(cef_pref_store);
}

scoped_refptr<PrefStore> supervised_user_prefs =
make_scoped_refptr(new SupervisedUserPrefStore(supervised_user_settings));
DCHECK(supervised_user_prefs->IsInitializationComplete());
factory.set_supervised_user_prefs(supervised_user_prefs);
#endif // BUILDFLAG(ENABLE_SUPERVISED_USERS)

// Registry that will be populated with all known preferences. Preferences
Expand Down
7 changes: 2 additions & 5 deletions libcef/browser/prefs/browser_prefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@ namespace browser_prefs {
// Name for the user prefs JSON file.
extern const char kUserPrefsFileName[];

// Create the PrefService used to manage pref registration and storage. If
// |is_pre_initialization| is true a non-persistent PrefService will be created
// for temporary usage during BrowserContextServices initialization.
// Create the PrefService used to manage pref registration and storage.
std::unique_ptr<PrefService> CreatePrefService(Profile* profile,
const base::FilePath& cache_path,
bool persist_user_preferences,
bool is_pre_initialization);
bool persist_user_preferences);

} // namespace browser_prefs

Expand Down

0 comments on commit 264fa66

Please sign in to comment.