Chromium Code Reviews| Index: chrome/browser/extensions/external_pref_loader.cc |
| diff --git a/chrome/browser/extensions/external_pref_loader.cc b/chrome/browser/extensions/external_pref_loader.cc |
| index 9a32ac34426b0a623573cd45e60c32fe043eccbf..0bfb82a14918e7aa5d617ccaf974dea76d6b8325 100644 |
| --- a/chrome/browser/extensions/external_pref_loader.cc |
| +++ b/chrome/browser/extensions/external_pref_loader.cc |
| @@ -15,6 +15,7 @@ |
| #include "base/path_service.h" |
| #include "base/strings/string_util.h" |
| #include "base/strings/utf_string_conversions.h" |
| +#include "chrome/browser/prefs/pref_service_syncable.h" |
| #include "chrome/common/chrome_paths.h" |
| #include "content/public/browser/browser_thread.h" |
| @@ -90,11 +91,22 @@ base::DictionaryValue* ExtractExtensionPrefs(base::ValueSerializer* serializer, |
| namespace extensions { |
| -ExternalPrefLoader::ExternalPrefLoader(int base_path_id, Options options) |
| - : base_path_id_(base_path_id), options_(options) { |
| +ExternalPrefLoader::ExternalPrefLoader(int base_path_id, |
| + Options options, |
| + Profile* profile) |
| + : base_path_id_(base_path_id), options_(options), |
|
Nikita (slow)
2014/10/27 09:44:49
nit: one initialization per line now that they all
Dmitry Polukhin
2014/10/27 14:48:48
Done.
|
| + profile_(profile), pref_observer_added_(false) { |
| CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| } |
| +ExternalPrefLoader::~ExternalPrefLoader() { |
| + if (pref_observer_added_) { |
| + PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); |
| + DCHECK(prefs); |
| + prefs->RemoveObserver(this); |
| + } |
| +} |
| + |
| const base::FilePath ExternalPrefLoader::GetBaseCrxFilePath() { |
| CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| @@ -104,9 +116,40 @@ const base::FilePath ExternalPrefLoader::GetBaseCrxFilePath() { |
| void ExternalPrefLoader::StartLoading() { |
| CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| - BrowserThread::PostTask( |
| - BrowserThread::FILE, FROM_HERE, |
| - base::Bind(&ExternalPrefLoader::LoadOnFileThread, this)); |
| + if (options_ & DELAY_LOAD_UNTIL_PRIORITY_SYNC) { |
| + if (!PostLoadIfPrioritySyncReady()) { |
| + PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); |
|
Nikita (slow)
2014/10/27 09:44:49
nit: DCHECK(profile_);
Dmitry Polukhin
2014/10/27 14:48:48
Done.
|
| + DCHECK(prefs); |
| + prefs->AddObserver(this); |
| + pref_observer_added_ = true; |
| + } |
| + } else { |
| + BrowserThread::PostTask( |
| + BrowserThread::FILE, FROM_HERE, |
|
Nikita (slow)
2014/10/27 09:44:49
nit: As a follow up change you can get rid of FILE
|
| + base::Bind(&ExternalPrefLoader::LoadOnFileThread, this)); |
| + } |
| +} |
| + |
| +void ExternalPrefLoader::OnIsSyncingChanged() { |
| + PostLoadIfPrioritySyncReady(); |
| +} |
| + |
| +bool ExternalPrefLoader::PostLoadIfPrioritySyncReady() { |
| + DCHECK(options_ & DELAY_LOAD_UNTIL_PRIORITY_SYNC); |
| + DCHECK(profile_); |
| + |
| + PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); |
| + DCHECK(prefs); |
| + if (prefs->IsPrioritySyncing()) { |
| + BrowserThread::PostTask( |
| + BrowserThread::FILE, FROM_HERE, |
| + base::Bind(&ExternalPrefLoader::LoadOnFileThread, this)); |
| + prefs->RemoveObserver(this); |
| + pref_observer_added_ = false; |
| + return true; |
| + } |
| + |
| + return false; |
| } |
| void ExternalPrefLoader::LoadOnFileThread() { |