Simplify PrefService initialization (issue #1947)

This commit is contained in:
Marshall Greenblatt 2017-09-25 15:11:17 +02:00
parent f372e90025
commit 3006329678
3 changed files with 22 additions and 35 deletions

View File

@ -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())

View File

@ -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();
@ -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) {
@ -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);
// 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);
}
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

View File

@ -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