Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Unified Diff: chrome/browser/extensions/external_pref_loader.cc

Issue 650763003: Delay default apps installation on Chrome OS for first time sign-in (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed ExternalProviderImplTest.InAppPayments Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..a248eb5fcc896ffbbc56087781abf9ade9363c01 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,24 @@ 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),
+ 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 +118,41 @@ 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()) {
+ DCHECK(profile_);
+ PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_);
+ DCHECK(prefs);
+ prefs->AddObserver(this);
+ pref_observer_added_ = true;
+ }
+ } else {
+ BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
+ 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() {

Powered by Google App Engine
This is Rietveld 408576698