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

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

Issue 11345008: Remove content::NotificationObserver dependency from most Prefs code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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/profiles/profile_impl.cc
diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc
index 31cc17b854824e4012c227e776014fe64bc5d47a..ae76eece14bd13a3a7e7c76ab7aeb79dafe5a7d9 100644
--- a/chrome/browser/profiles/profile_impl.cc
+++ b/chrome/browser/profiles/profile_impl.cc
@@ -331,8 +331,7 @@ ProfileImpl::ProfileImpl(const FilePath& path,
true));
// Wait for the notification that prefs has been loaded (successfully or
// not).
- registrar_.Add(this, chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED,
- content::Source<PrefService>(prefs_.get()));
+ prefs_->AddPrefInitObserver(this);
} else if (create_mode == CREATE_MODE_SYNCHRONOUS) {
// Load prefs synchronously.
prefs_.reset(PrefService::CreatePrefService(
@@ -902,32 +901,6 @@ void ProfileImpl::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
switch (type) {
- case chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED: {
- bool* succeeded = content::Details<bool>(details).ptr();
- PrefService *prefs = content::Source<PrefService>(source).ptr();
- DCHECK(prefs == prefs_.get());
- registrar_.Remove(this,
- chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED,
- content::Source<PrefService>(prefs));
- OnPrefsLoaded(*succeeded);
- break;
- }
- case chrome::NOTIFICATION_PREF_CHANGED: {
- std::string* pref_name_in = content::Details<std::string>(details).ptr();
- PrefService* prefs = content::Source<PrefService>(source).ptr();
- DCHECK(pref_name_in && prefs);
- if (*pref_name_in == prefs::kGoogleServicesUsername) {
- UpdateProfileUserNameCache();
- } else if (*pref_name_in == prefs::kProfileAvatarIndex) {
- UpdateProfileAvatarCache();
- } else if (*pref_name_in == prefs::kProfileName) {
- UpdateProfileNameCache();
- } else if (*pref_name_in == prefs::kDefaultZoomLevel) {
- HostZoomMap::GetForBrowserContext(this)->SetDefaultZoomLevel(
- prefs->GetDouble(prefs::kDefaultZoomLevel));
- }
- break;
- }
case chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED:
// Causes lazy-load if sync is enabled.
ProfileSyncServiceFactory::GetInstance()->GetForProfile(this);
@@ -956,6 +929,28 @@ void ProfileImpl::Observe(int type,
}
}
+void ProfileImpl::OnPreferenceChanged(PrefServiceBase* prefs,
+ const std::string& pref_name_in) {
+ DCHECK(prefs);
+ if (pref_name_in == prefs::kGoogleServicesUsername) {
+ UpdateProfileUserNameCache();
+ } else if (pref_name_in == prefs::kProfileAvatarIndex) {
+ UpdateProfileAvatarCache();
+ } else if (pref_name_in == prefs::kProfileName) {
+ UpdateProfileNameCache();
+ } else if (pref_name_in == prefs::kDefaultZoomLevel) {
+ HostZoomMap::GetForBrowserContext(this)->SetDefaultZoomLevel(
+ prefs->GetDouble(prefs::kDefaultZoomLevel));
+ }
+}
+
+void ProfileImpl::OnInitializationCompleted(PrefServiceBase* pref_service,
+ bool succeeded) {
+ DCHECK(pref_service == prefs_.get());
+ prefs_->RemovePrefInitObserver(this);
+ OnPrefsLoaded(succeeded);
+}
+
#if defined(ENABLE_SESSION_SERVICE)
void ProfileImpl::StopCreateSessionServiceTimer() {
create_session_service_timer_.Stop();

Powered by Google App Engine
This is Rietveld 408576698