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

Side by Side 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, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/profiles/profile_impl.h" 5 #include "chrome/browser/profiles/profile_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/environment.h" 10 #include "base/environment.h"
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 324
325 if (create_mode == CREATE_MODE_ASYNCHRONOUS) { 325 if (create_mode == CREATE_MODE_ASYNCHRONOUS) {
326 prefs_.reset(PrefService::CreatePrefService( 326 prefs_.reset(PrefService::CreatePrefService(
327 GetPrefFilePath(), 327 GetPrefFilePath(),
328 policy_service_.get(), 328 policy_service_.get(),
329 new ExtensionPrefStore( 329 new ExtensionPrefStore(
330 ExtensionPrefValueMapFactory::GetForProfile(this), false), 330 ExtensionPrefValueMapFactory::GetForProfile(this), false),
331 true)); 331 true));
332 // Wait for the notification that prefs has been loaded (successfully or 332 // Wait for the notification that prefs has been loaded (successfully or
333 // not). 333 // not).
334 registrar_.Add(this, chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED, 334 prefs_->AddPrefInitObserver(this);
335 content::Source<PrefService>(prefs_.get()));
336 } else if (create_mode == CREATE_MODE_SYNCHRONOUS) { 335 } else if (create_mode == CREATE_MODE_SYNCHRONOUS) {
337 // Load prefs synchronously. 336 // Load prefs synchronously.
338 prefs_.reset(PrefService::CreatePrefService( 337 prefs_.reset(PrefService::CreatePrefService(
339 GetPrefFilePath(), 338 GetPrefFilePath(),
340 policy_service_.get(), 339 policy_service_.get(),
341 new ExtensionPrefStore( 340 new ExtensionPrefStore(
342 ExtensionPrefValueMapFactory::GetForProfile(this), false), 341 ExtensionPrefValueMapFactory::GetForProfile(this), false),
343 false)); 342 false));
344 OnPrefsLoaded(true); 343 OnPrefsLoaded(true);
345 } else { 344 } else {
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 } 894 }
896 895
897 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() { 896 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() {
898 return top_sites_; 897 return top_sites_;
899 } 898 }
900 899
901 void ProfileImpl::Observe(int type, 900 void ProfileImpl::Observe(int type,
902 const content::NotificationSource& source, 901 const content::NotificationSource& source,
903 const content::NotificationDetails& details) { 902 const content::NotificationDetails& details) {
904 switch (type) { 903 switch (type) {
905 case chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED: {
906 bool* succeeded = content::Details<bool>(details).ptr();
907 PrefService *prefs = content::Source<PrefService>(source).ptr();
908 DCHECK(prefs == prefs_.get());
909 registrar_.Remove(this,
910 chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED,
911 content::Source<PrefService>(prefs));
912 OnPrefsLoaded(*succeeded);
913 break;
914 }
915 case chrome::NOTIFICATION_PREF_CHANGED: {
916 std::string* pref_name_in = content::Details<std::string>(details).ptr();
917 PrefService* prefs = content::Source<PrefService>(source).ptr();
918 DCHECK(pref_name_in && prefs);
919 if (*pref_name_in == prefs::kGoogleServicesUsername) {
920 UpdateProfileUserNameCache();
921 } else if (*pref_name_in == prefs::kProfileAvatarIndex) {
922 UpdateProfileAvatarCache();
923 } else if (*pref_name_in == prefs::kProfileName) {
924 UpdateProfileNameCache();
925 } else if (*pref_name_in == prefs::kDefaultZoomLevel) {
926 HostZoomMap::GetForBrowserContext(this)->SetDefaultZoomLevel(
927 prefs->GetDouble(prefs::kDefaultZoomLevel));
928 }
929 break;
930 }
931 case chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED: 904 case chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED:
932 // Causes lazy-load if sync is enabled. 905 // Causes lazy-load if sync is enabled.
933 ProfileSyncServiceFactory::GetInstance()->GetForProfile(this); 906 ProfileSyncServiceFactory::GetInstance()->GetForProfile(this);
934 registrar_.Remove(this, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, 907 registrar_.Remove(this, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED,
935 content::Source<Profile>(this)); 908 content::Source<Profile>(this));
936 break; 909 break;
937 case content::NOTIFICATION_ZOOM_LEVEL_CHANGED: { 910 case content::NOTIFICATION_ZOOM_LEVEL_CHANGED: {
938 const std::string& host = 911 const std::string& host =
939 *(content::Details<const std::string>(details).ptr()); 912 *(content::Details<const std::string>(details).ptr());
940 if (!host.empty()) { 913 if (!host.empty()) {
941 HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this); 914 HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this);
942 double level = host_zoom_map->GetZoomLevel(host); 915 double level = host_zoom_map->GetZoomLevel(host);
943 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels); 916 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels);
944 DictionaryValue* host_zoom_dictionary = update.Get(); 917 DictionaryValue* host_zoom_dictionary = update.Get();
945 if (level == host_zoom_map->GetDefaultZoomLevel()) { 918 if (level == host_zoom_map->GetDefaultZoomLevel()) {
946 host_zoom_dictionary->RemoveWithoutPathExpansion(host, NULL); 919 host_zoom_dictionary->RemoveWithoutPathExpansion(host, NULL);
947 } else { 920 } else {
948 host_zoom_dictionary->SetWithoutPathExpansion( 921 host_zoom_dictionary->SetWithoutPathExpansion(
949 host, Value::CreateDoubleValue(level)); 922 host, Value::CreateDoubleValue(level));
950 } 923 }
951 } 924 }
952 break; 925 break;
953 } 926 }
954 default: 927 default:
955 NOTREACHED(); 928 NOTREACHED();
956 } 929 }
957 } 930 }
958 931
932 void ProfileImpl::OnPreferenceChanged(PrefServiceBase* prefs,
933 const std::string& pref_name_in) {
934 DCHECK(prefs);
935 if (pref_name_in == prefs::kGoogleServicesUsername) {
936 UpdateProfileUserNameCache();
937 } else if (pref_name_in == prefs::kProfileAvatarIndex) {
938 UpdateProfileAvatarCache();
939 } else if (pref_name_in == prefs::kProfileName) {
940 UpdateProfileNameCache();
941 } else if (pref_name_in == prefs::kDefaultZoomLevel) {
942 HostZoomMap::GetForBrowserContext(this)->SetDefaultZoomLevel(
943 prefs->GetDouble(prefs::kDefaultZoomLevel));
944 }
945 }
946
947 void ProfileImpl::OnInitializationCompleted(PrefServiceBase* pref_service,
948 bool succeeded) {
949 DCHECK(pref_service == prefs_.get());
950 prefs_->RemovePrefInitObserver(this);
951 OnPrefsLoaded(succeeded);
952 }
953
959 #if defined(ENABLE_SESSION_SERVICE) 954 #if defined(ENABLE_SESSION_SERVICE)
960 void ProfileImpl::StopCreateSessionServiceTimer() { 955 void ProfileImpl::StopCreateSessionServiceTimer() {
961 create_session_service_timer_.Stop(); 956 create_session_service_timer_.Stop();
962 } 957 }
963 958
964 void ProfileImpl::EnsureSessionServiceCreated() { 959 void ProfileImpl::EnsureSessionServiceCreated() {
965 SessionServiceFactory::GetForProfile(this); 960 SessionServiceFactory::GetForProfile(this);
966 } 961 }
967 #endif 962 #endif
968 963
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 if (!path.empty()) 1145 if (!path.empty())
1151 *cache_path = path; 1146 *cache_path = path;
1152 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : 1147 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) :
1153 prefs_->GetInteger(prefs::kDiskCacheSize); 1148 prefs_->GetInteger(prefs::kDiskCacheSize);
1154 } 1149 }
1155 1150
1156 base::Callback<ChromeURLDataManagerBackend*(void)> 1151 base::Callback<ChromeURLDataManagerBackend*(void)>
1157 ProfileImpl::GetChromeURLDataManagerBackendGetter() const { 1152 ProfileImpl::GetChromeURLDataManagerBackendGetter() const {
1158 return io_data_.GetChromeURLDataManagerBackendGetter(); 1153 return io_data_.GetChromeURLDataManagerBackendGetter();
1159 } 1154 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698