mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-03-16 12:00:13 +01:00
Simplify PrefService initialization (issue #1947)
This commit is contained in:
parent
f372e90025
commit
3006329678
@ -265,17 +265,12 @@ void CefBrowserContextImpl::Initialize() {
|
|||||||
CefString(&CefContext::Get()->settings().accept_language_list);
|
CefString(&CefContext::Get()->settings().accept_language_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize a temporary PrefService object that may be referenced during
|
// Initialize the PrefService object.
|
||||||
// BrowserContextServices initialization.
|
pref_service_ = browser_prefs::CreatePrefService(
|
||||||
pref_service_ =
|
this, cache_path_, !!settings_.persist_user_preferences);
|
||||||
browser_prefs::CreatePrefService(this, base::FilePath(), false, true);
|
|
||||||
|
|
||||||
CefBrowserContext::Initialize();
|
CefBrowserContext::Initialize();
|
||||||
|
|
||||||
// Initialize the real PrefService object.
|
|
||||||
pref_service_ = browser_prefs::CreatePrefService(
|
|
||||||
this, cache_path_, !!settings_.persist_user_preferences, false);
|
|
||||||
|
|
||||||
// Initialize visited links management.
|
// Initialize visited links management.
|
||||||
base::FilePath visited_link_path;
|
base::FilePath visited_link_path;
|
||||||
if (!cache_path_.empty())
|
if (!cache_path_.empty())
|
||||||
|
@ -97,8 +97,7 @@ const char kUserPrefsFileName[] = "UserPrefs.json";
|
|||||||
|
|
||||||
std::unique_ptr<PrefService> CreatePrefService(Profile* profile,
|
std::unique_ptr<PrefService> CreatePrefService(Profile* profile,
|
||||||
const base::FilePath& cache_path,
|
const base::FilePath& cache_path,
|
||||||
bool persist_user_preferences,
|
bool persist_user_preferences) {
|
||||||
bool is_pre_initialization) {
|
|
||||||
const base::CommandLine* command_line =
|
const base::CommandLine* command_line =
|
||||||
base::CommandLine::ForCurrentProcess();
|
base::CommandLine::ForCurrentProcess();
|
||||||
|
|
||||||
@ -115,8 +114,7 @@ std::unique_ptr<PrefService> CreatePrefService(Profile* profile,
|
|||||||
factory.set_command_line_prefs(command_line_pref_store);
|
factory.set_command_line_prefs(command_line_pref_store);
|
||||||
|
|
||||||
// True if preferences will be stored on disk.
|
// True if preferences will be stored on disk.
|
||||||
const bool store_on_disk =
|
const bool store_on_disk = !cache_path.empty() && persist_user_preferences;
|
||||||
!cache_path.empty() && persist_user_preferences && !is_pre_initialization;
|
|
||||||
|
|
||||||
scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner;
|
scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner;
|
||||||
if (store_on_disk) {
|
if (store_on_disk) {
|
||||||
@ -142,26 +140,23 @@ std::unique_ptr<PrefService> CreatePrefService(Profile* profile,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
|
#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
|
||||||
// Don't access factories during pre-initialization.
|
// Used to store supervised user preferences.
|
||||||
if (!is_pre_initialization) {
|
SupervisedUserSettingsService* supervised_user_settings =
|
||||||
// Used to store supervised user preferences.
|
SupervisedUserSettingsServiceFactory::GetForProfile(profile);
|
||||||
SupervisedUserSettingsService* supervised_user_settings =
|
|
||||||
SupervisedUserSettingsServiceFactory::GetForProfile(profile);
|
|
||||||
|
|
||||||
if (store_on_disk) {
|
if (store_on_disk) {
|
||||||
supervised_user_settings->Init(cache_path, sequenced_task_runner.get(),
|
supervised_user_settings->Init(cache_path, sequenced_task_runner.get(),
|
||||||
true);
|
true);
|
||||||
} else {
|
} else {
|
||||||
scoped_refptr<CefPrefStore> cef_pref_store = new CefPrefStore();
|
scoped_refptr<CefPrefStore> cef_pref_store = new CefPrefStore();
|
||||||
cef_pref_store->SetInitializationCompleted();
|
cef_pref_store->SetInitializationCompleted();
|
||||||
supervised_user_settings->Init(cef_pref_store);
|
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
#endif // BUILDFLAG(ENABLE_SUPERVISED_USERS)
|
||||||
|
|
||||||
// Registry that will be populated with all known preferences. Preferences
|
// Registry that will be populated with all known preferences. Preferences
|
||||||
|
@ -19,13 +19,10 @@ namespace browser_prefs {
|
|||||||
// Name for the user prefs JSON file.
|
// Name for the user prefs JSON file.
|
||||||
extern const char kUserPrefsFileName[];
|
extern const char kUserPrefsFileName[];
|
||||||
|
|
||||||
// Create the PrefService used to manage pref registration and storage. If
|
// Create the PrefService used to manage pref registration and storage.
|
||||||
// |is_pre_initialization| is true a non-persistent PrefService will be created
|
|
||||||
// for temporary usage during BrowserContextServices initialization.
|
|
||||||
std::unique_ptr<PrefService> CreatePrefService(Profile* profile,
|
std::unique_ptr<PrefService> CreatePrefService(Profile* profile,
|
||||||
const base::FilePath& cache_path,
|
const base::FilePath& cache_path,
|
||||||
bool persist_user_preferences,
|
bool persist_user_preferences);
|
||||||
bool is_pre_initialization);
|
|
||||||
|
|
||||||
} // namespace browser_prefs
|
} // namespace browser_prefs
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user