OLD | NEW |
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/callback.h" |
8 #include "base/command_line.h" | 9 #include "base/command_line.h" |
9 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
10 #include "base/environment.h" | 11 #include "base/environment.h" |
11 #include "base/file_path.h" | 12 #include "base/file_path.h" |
12 #include "base/file_util.h" | 13 #include "base/file_util.h" |
13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
14 #include "base/path_service.h" | 15 #include "base/path_service.h" |
15 #include "base/string_number_conversions.h" | 16 #include "base/string_number_conversions.h" |
16 #include "base/string_tokenizer.h" | 17 #include "base/string_tokenizer.h" |
17 #include "base/string_util.h" | 18 #include "base/string_util.h" |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 policy_service_.reset(new policy::PolicyServiceStub()); | 315 policy_service_.reset(new policy::PolicyServiceStub()); |
315 #endif | 316 #endif |
316 | 317 |
317 if (create_mode == CREATE_MODE_ASYNCHRONOUS) { | 318 if (create_mode == CREATE_MODE_ASYNCHRONOUS) { |
318 prefs_.reset(PrefService::CreatePrefService( | 319 prefs_.reset(PrefService::CreatePrefService( |
319 GetPrefFilePath(), | 320 GetPrefFilePath(), |
320 policy_service_.get(), | 321 policy_service_.get(), |
321 new ExtensionPrefStore( | 322 new ExtensionPrefStore( |
322 ExtensionPrefValueMapFactory::GetForProfile(this), false), | 323 ExtensionPrefValueMapFactory::GetForProfile(this), false), |
323 true)); | 324 true)); |
324 // Wait for the notification that prefs has been loaded (successfully or | 325 // Wait for the notification that prefs has been loaded |
325 // not). | 326 // (successfully or not). Note that we can use base::Unretained |
326 registrar_.Add(this, chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED, | 327 // because the prefs service is owned by this class and lives on |
327 content::Source<PrefService>(prefs_.get())); | 328 // the same thread. |
| 329 prefs_->AddPrefInitObserver(base::Bind(&ProfileImpl::OnPrefsLoaded, |
| 330 base::Unretained(this))); |
328 } else if (create_mode == CREATE_MODE_SYNCHRONOUS) { | 331 } else if (create_mode == CREATE_MODE_SYNCHRONOUS) { |
329 // Load prefs synchronously. | 332 // Load prefs synchronously. |
330 prefs_.reset(PrefService::CreatePrefService( | 333 prefs_.reset(PrefService::CreatePrefService( |
331 GetPrefFilePath(), | 334 GetPrefFilePath(), |
332 policy_service_.get(), | 335 policy_service_.get(), |
333 new ExtensionPrefStore( | 336 new ExtensionPrefStore( |
334 ExtensionPrefValueMapFactory::GetForProfile(this), false), | 337 ExtensionPrefValueMapFactory::GetForProfile(this), false), |
335 false)); | 338 false)); |
336 OnPrefsLoaded(true); | 339 OnPrefsLoaded(true); |
337 } else { | 340 } else { |
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
884 } | 887 } |
885 | 888 |
886 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() { | 889 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() { |
887 return top_sites_; | 890 return top_sites_; |
888 } | 891 } |
889 | 892 |
890 void ProfileImpl::Observe(int type, | 893 void ProfileImpl::Observe(int type, |
891 const content::NotificationSource& source, | 894 const content::NotificationSource& source, |
892 const content::NotificationDetails& details) { | 895 const content::NotificationDetails& details) { |
893 switch (type) { | 896 switch (type) { |
894 case chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED: { | |
895 bool* succeeded = content::Details<bool>(details).ptr(); | |
896 PrefService *prefs = content::Source<PrefService>(source).ptr(); | |
897 DCHECK(prefs == prefs_.get()); | |
898 registrar_.Remove(this, | |
899 chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED, | |
900 content::Source<PrefService>(prefs)); | |
901 OnPrefsLoaded(*succeeded); | |
902 break; | |
903 } | |
904 case chrome::NOTIFICATION_PREF_CHANGED: { | |
905 std::string* pref_name_in = content::Details<std::string>(details).ptr(); | |
906 PrefService* prefs = content::Source<PrefService>(source).ptr(); | |
907 DCHECK(pref_name_in && prefs); | |
908 if (*pref_name_in == prefs::kGoogleServicesUsername) { | |
909 UpdateProfileUserNameCache(); | |
910 } else if (*pref_name_in == prefs::kProfileAvatarIndex) { | |
911 UpdateProfileAvatarCache(); | |
912 } else if (*pref_name_in == prefs::kProfileName) { | |
913 UpdateProfileNameCache(); | |
914 } else if (*pref_name_in == prefs::kDefaultZoomLevel) { | |
915 HostZoomMap::GetForBrowserContext(this)->SetDefaultZoomLevel( | |
916 prefs->GetDouble(prefs::kDefaultZoomLevel)); | |
917 } | |
918 break; | |
919 } | |
920 case chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED: | 897 case chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED: |
921 // Causes lazy-load if sync is enabled. | 898 // Causes lazy-load if sync is enabled. |
922 ProfileSyncServiceFactory::GetInstance()->GetForProfile(this); | 899 ProfileSyncServiceFactory::GetInstance()->GetForProfile(this); |
923 registrar_.Remove(this, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, | 900 registrar_.Remove(this, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, |
924 content::Source<Profile>(this)); | 901 content::Source<Profile>(this)); |
925 break; | 902 break; |
926 case content::NOTIFICATION_ZOOM_LEVEL_CHANGED: { | 903 case content::NOTIFICATION_ZOOM_LEVEL_CHANGED: { |
927 const std::string& host = | 904 const std::string& host = |
928 *(content::Details<const std::string>(details).ptr()); | 905 *(content::Details<const std::string>(details).ptr()); |
929 if (!host.empty()) { | 906 if (!host.empty()) { |
930 HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this); | 907 HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this); |
931 double level = host_zoom_map->GetZoomLevel(host); | 908 double level = host_zoom_map->GetZoomLevel(host); |
932 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels); | 909 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels); |
933 DictionaryValue* host_zoom_dictionary = update.Get(); | 910 DictionaryValue* host_zoom_dictionary = update.Get(); |
934 if (level == host_zoom_map->GetDefaultZoomLevel()) { | 911 if (level == host_zoom_map->GetDefaultZoomLevel()) { |
935 host_zoom_dictionary->RemoveWithoutPathExpansion(host, NULL); | 912 host_zoom_dictionary->RemoveWithoutPathExpansion(host, NULL); |
936 } else { | 913 } else { |
937 host_zoom_dictionary->SetWithoutPathExpansion( | 914 host_zoom_dictionary->SetWithoutPathExpansion( |
938 host, Value::CreateDoubleValue(level)); | 915 host, Value::CreateDoubleValue(level)); |
939 } | 916 } |
940 } | 917 } |
941 break; | 918 break; |
942 } | 919 } |
943 default: | 920 default: |
944 NOTREACHED(); | 921 NOTREACHED(); |
945 } | 922 } |
946 } | 923 } |
947 | 924 |
| 925 void ProfileImpl::OnPreferenceChanged(PrefServiceBase* prefs, |
| 926 const std::string& pref_name_in) { |
| 927 DCHECK(prefs); |
| 928 if (pref_name_in == prefs::kGoogleServicesUsername) { |
| 929 UpdateProfileUserNameCache(); |
| 930 } else if (pref_name_in == prefs::kProfileAvatarIndex) { |
| 931 UpdateProfileAvatarCache(); |
| 932 } else if (pref_name_in == prefs::kProfileName) { |
| 933 UpdateProfileNameCache(); |
| 934 } else if (pref_name_in == prefs::kDefaultZoomLevel) { |
| 935 HostZoomMap::GetForBrowserContext(this)->SetDefaultZoomLevel( |
| 936 prefs->GetDouble(prefs::kDefaultZoomLevel)); |
| 937 } |
| 938 } |
| 939 |
948 #if defined(ENABLE_SESSION_SERVICE) | 940 #if defined(ENABLE_SESSION_SERVICE) |
949 void ProfileImpl::StopCreateSessionServiceTimer() { | 941 void ProfileImpl::StopCreateSessionServiceTimer() { |
950 create_session_service_timer_.Stop(); | 942 create_session_service_timer_.Stop(); |
951 } | 943 } |
952 | 944 |
953 void ProfileImpl::EnsureSessionServiceCreated() { | 945 void ProfileImpl::EnsureSessionServiceCreated() { |
954 SessionServiceFactory::GetForProfile(this); | 946 SessionServiceFactory::GetForProfile(this); |
955 } | 947 } |
956 #endif | 948 #endif |
957 | 949 |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1139 if (!path.empty()) | 1131 if (!path.empty()) |
1140 *cache_path = path; | 1132 *cache_path = path; |
1141 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : | 1133 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : |
1142 prefs_->GetInteger(prefs::kDiskCacheSize); | 1134 prefs_->GetInteger(prefs::kDiskCacheSize); |
1143 } | 1135 } |
1144 | 1136 |
1145 base::Callback<ChromeURLDataManagerBackend*(void)> | 1137 base::Callback<ChromeURLDataManagerBackend*(void)> |
1146 ProfileImpl::GetChromeURLDataManagerBackendGetter() const { | 1138 ProfileImpl::GetChromeURLDataManagerBackendGetter() const { |
1147 return io_data_.GetChromeURLDataManagerBackendGetter(); | 1139 return io_data_.GetChromeURLDataManagerBackendGetter(); |
1148 } | 1140 } |
OLD | NEW |