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

Unified Diff: chrome/browser/profiles/profile_impl.cc

Issue 6894020: Adds async interface method to PersistentPrefStore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use Notifications. Created 9 years, 8 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/profiles/profile_impl.cc
diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc
index 9540a394521a5049217751cfc5cecf089f5cfd67..f6541f6100ecd2a2993c8af6e87d740274d6a961 100644
--- a/chrome/browser/profiles/profile_impl.cc
+++ b/chrome/browser/profiles/profile_impl.cc
@@ -287,18 +287,25 @@ ProfileImpl::ProfileImpl(const FilePath& path,
&ProfileImpl::EnsureSessionServiceCreated);
if (delegate_) {
- prefs_.reset(PrefService::CreatePrefServiceAsync(
+ // Wait for the notifcation that prefs has been loaded (successfully or
+ // not).
+ registrar_.Add(this, NotificationType::PREF_INITIALIZATION_COMPLETED,
+ Source<Profile>(this));
+ registrar_.Add(this, NotificationType::PREF_INITIALIZATION_FAILED,
+ Source<Profile>(this));
+ prefs_.reset(PrefService::CreatePrefService(
GetPrefFilePath(),
new ExtensionPrefStore(GetExtensionPrefValueMap(), false),
GetOriginalProfile(),
- this)); // Ask to notify us in the end.
+ true));
} else {
// Load prefs synchronously.
prefs_.reset(PrefService::CreatePrefService(
GetPrefFilePath(),
new ExtensionPrefStore(GetExtensionPrefValueMap(), false),
- GetOriginalProfile()));
- OnPrefsLoaded(prefs_.get(), true);
+ GetOriginalProfile(),
+ false));
+ OnPrefsLoaded(true);
}
}
@@ -797,9 +804,7 @@ net::TransportSecurityState*
return transport_security_state_.get();
}
-void ProfileImpl::OnPrefsLoaded(PrefService* prefs, bool success) {
- DCHECK(prefs == prefs_.get());
-
+void ProfileImpl::OnPrefsLoaded(bool success) {
if (!success) {
DCHECK(delegate_);
delegate_->OnProfileCreated(this, false);
@@ -1317,33 +1322,50 @@ void ProfileImpl::MarkAsCleanShutdown() {
void ProfileImpl::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
- if (NotificationType::PREF_CHANGED == type) {
- std::string* pref_name_in = Details<std::string>(details).ptr();
- PrefService* prefs = Source<PrefService>(source).ptr();
- DCHECK(pref_name_in && prefs);
- if (*pref_name_in == prefs::kSpellCheckDictionary ||
- *pref_name_in == prefs::kEnableSpellCheck) {
- ReinitializeSpellCheckHost(true);
- } else if (*pref_name_in == prefs::kEnableAutoSpellCorrect) {
- NotificationService::current()->Notify(
- NotificationType::SPELLCHECK_AUTOSPELL_TOGGLED,
- Source<Profile>(this), NotificationService::NoDetails());
- } else if (*pref_name_in == prefs::kClearSiteDataOnExit) {
- clear_local_state_on_exit_ =
- prefs->GetBoolean(prefs::kClearSiteDataOnExit);
- if (webkit_context_) {
- webkit_context_->set_clear_local_state_on_exit(
- clear_local_state_on_exit_);
- }
- if (appcache_service_) {
- appcache_service_->SetClearLocalStateOnExit(
- clear_local_state_on_exit_);
+ bool initialization_succeeded = true;
+ switch (type.value) {
+ case NotificationType::PREF_INITIALIZATION_FAILED:
+ initialization_succeeded = false;
+ // Fall through.
+ case NotificationType::PREF_INITIALIZATION_COMPLETED:
+ registrar_.Remove(this, NotificationType::PREF_INITIALIZATION_COMPLETED,
+ Source<Profile>(this));
+ registrar_.Remove(this, NotificationType::PREF_INITIALIZATION_FAILED,
+ Source<Profile>(this));
+ OnPrefsLoaded(initialization_succeeded);
+ break;
+ case NotificationType::PREF_CHANGED: {
+ std::string* pref_name_in = Details<std::string>(details).ptr();
+ PrefService* prefs = Source<PrefService>(source).ptr();
+ DCHECK(pref_name_in && prefs);
+ if (*pref_name_in == prefs::kSpellCheckDictionary ||
+ *pref_name_in == prefs::kEnableSpellCheck) {
+ ReinitializeSpellCheckHost(true);
+ } else if (*pref_name_in == prefs::kEnableAutoSpellCorrect) {
+ NotificationService::current()->Notify(
+ NotificationType::SPELLCHECK_AUTOSPELL_TOGGLED,
+ Source<Profile>(this), NotificationService::NoDetails());
+ } else if (*pref_name_in == prefs::kClearSiteDataOnExit) {
+ clear_local_state_on_exit_ =
+ prefs->GetBoolean(prefs::kClearSiteDataOnExit);
+ if (webkit_context_) {
+ webkit_context_->set_clear_local_state_on_exit(
+ clear_local_state_on_exit_);
+ }
+ if (appcache_service_) {
+ appcache_service_->SetClearLocalStateOnExit(
+ clear_local_state_on_exit_);
+ }
}
+ break;
}
- } else if (NotificationType::BOOKMARK_MODEL_LOADED == type) {
- GetProfileSyncService(); // Causes lazy-load if sync is enabled.
- registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED,
- Source<Profile>(this));
+ case NotificationType::BOOKMARK_MODEL_LOADED:
+ GetProfileSyncService(); // Causes lazy-load if sync is enabled.
+ registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED,
+ Source<Profile>(this));
+ break;
+ default:
+ NOTREACHED();
}
}

Powered by Google App Engine
This is Rietveld 408576698