Chromium Code Reviews| 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/prefs/json_pref_store.h" | 16 #include "base/prefs/json_pref_store.h" |
| 16 #include "base/string_number_conversions.h" | 17 #include "base/string_number_conversions.h" |
| 17 #include "base/string_tokenizer.h" | 18 #include "base/string_tokenizer.h" |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 354 #endif | 355 #endif |
| 355 | 356 |
| 356 if (create_mode == CREATE_MODE_ASYNCHRONOUS) { | 357 if (create_mode == CREATE_MODE_ASYNCHRONOUS) { |
| 357 prefs_.reset(PrefService::CreatePrefService( | 358 prefs_.reset(PrefService::CreatePrefService( |
| 358 GetPrefFilePath(), | 359 GetPrefFilePath(), |
| 359 sequenced_task_runner, | 360 sequenced_task_runner, |
| 360 policy_service_.get(), | 361 policy_service_.get(), |
| 361 new ExtensionPrefStore( | 362 new ExtensionPrefStore( |
| 362 ExtensionPrefValueMapFactory::GetForProfile(this), false), | 363 ExtensionPrefValueMapFactory::GetForProfile(this), false), |
| 363 true)); | 364 true)); |
| 364 // Wait for the notification that prefs has been loaded (successfully or | 365 // Wait for the notification that prefs has been loaded |
| 365 // not). | 366 // (successfully or not). Note that we can use base::Unretained |
| 366 registrar_.Add(this, chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED, | 367 // because the prefs service is owned by this class and lives on |
|
Mattias Nissler (ping if slow)
2012/10/31 13:29:36
nit: s/prefs service/PrefService/
Jói
2012/10/31 14:56:26
Done.
| |
| 367 content::Source<PrefService>(prefs_.get())); | 368 // the same thread. |
| 369 prefs_->AddPrefInitObserver(base::Bind(&ProfileImpl::OnPrefsLoaded, | |
| 370 base::Unretained(this))); | |
| 368 } else if (create_mode == CREATE_MODE_SYNCHRONOUS) { | 371 } else if (create_mode == CREATE_MODE_SYNCHRONOUS) { |
| 369 // Load prefs synchronously. | 372 // Load prefs synchronously. |
| 370 prefs_.reset(PrefService::CreatePrefService( | 373 prefs_.reset(PrefService::CreatePrefService( |
| 371 GetPrefFilePath(), | 374 GetPrefFilePath(), |
| 372 sequenced_task_runner, | 375 sequenced_task_runner, |
| 373 policy_service_.get(), | 376 policy_service_.get(), |
| 374 new ExtensionPrefStore( | 377 new ExtensionPrefStore( |
| 375 ExtensionPrefValueMapFactory::GetForProfile(this), false), | 378 ExtensionPrefValueMapFactory::GetForProfile(this), false), |
| 376 false)); | 379 false)); |
| 377 OnPrefsLoaded(true); | 380 OnPrefsLoaded(true); |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 908 } | 911 } |
| 909 | 912 |
| 910 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() { | 913 history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() { |
| 911 return top_sites_; | 914 return top_sites_; |
| 912 } | 915 } |
| 913 | 916 |
| 914 void ProfileImpl::Observe(int type, | 917 void ProfileImpl::Observe(int type, |
| 915 const content::NotificationSource& source, | 918 const content::NotificationSource& source, |
| 916 const content::NotificationDetails& details) { | 919 const content::NotificationDetails& details) { |
| 917 switch (type) { | 920 switch (type) { |
| 918 case chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED: { | |
| 919 bool* succeeded = content::Details<bool>(details).ptr(); | |
| 920 PrefService *prefs = content::Source<PrefService>(source).ptr(); | |
| 921 DCHECK(prefs == prefs_.get()); | |
| 922 registrar_.Remove(this, | |
| 923 chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED, | |
| 924 content::Source<PrefService>(prefs)); | |
| 925 OnPrefsLoaded(*succeeded); | |
| 926 break; | |
| 927 } | |
| 928 case chrome::NOTIFICATION_PREF_CHANGED: { | |
| 929 std::string* pref_name_in = content::Details<std::string>(details).ptr(); | |
| 930 PrefService* prefs = content::Source<PrefService>(source).ptr(); | |
| 931 DCHECK(pref_name_in && prefs); | |
| 932 if (*pref_name_in == prefs::kGoogleServicesUsername) { | |
| 933 UpdateProfileUserNameCache(); | |
| 934 } else if (*pref_name_in == prefs::kProfileAvatarIndex) { | |
| 935 UpdateProfileAvatarCache(); | |
| 936 } else if (*pref_name_in == prefs::kProfileName) { | |
| 937 UpdateProfileNameCache(); | |
| 938 } else if (*pref_name_in == prefs::kDefaultZoomLevel) { | |
| 939 HostZoomMap::GetForBrowserContext(this)->SetDefaultZoomLevel( | |
| 940 prefs->GetDouble(prefs::kDefaultZoomLevel)); | |
| 941 } | |
| 942 break; | |
| 943 } | |
| 944 case chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED: | 921 case chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED: |
| 945 // Causes lazy-load if sync is enabled. | 922 // Causes lazy-load if sync is enabled. |
| 946 ProfileSyncServiceFactory::GetInstance()->GetForProfile(this); | 923 ProfileSyncServiceFactory::GetInstance()->GetForProfile(this); |
| 947 registrar_.Remove(this, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, | 924 registrar_.Remove(this, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, |
| 948 content::Source<Profile>(this)); | 925 content::Source<Profile>(this)); |
| 949 break; | 926 break; |
| 950 case content::NOTIFICATION_ZOOM_LEVEL_CHANGED: { | 927 case content::NOTIFICATION_ZOOM_LEVEL_CHANGED: { |
| 951 const std::string& host = | 928 const std::string& host = |
| 952 *(content::Details<const std::string>(details).ptr()); | 929 *(content::Details<const std::string>(details).ptr()); |
| 953 if (!host.empty()) { | 930 if (!host.empty()) { |
| 954 HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this); | 931 HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this); |
| 955 double level = host_zoom_map->GetZoomLevel(host); | 932 double level = host_zoom_map->GetZoomLevel(host); |
| 956 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels); | 933 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels); |
| 957 DictionaryValue* host_zoom_dictionary = update.Get(); | 934 DictionaryValue* host_zoom_dictionary = update.Get(); |
| 958 if (level == host_zoom_map->GetDefaultZoomLevel()) { | 935 if (level == host_zoom_map->GetDefaultZoomLevel()) { |
| 959 host_zoom_dictionary->RemoveWithoutPathExpansion(host, NULL); | 936 host_zoom_dictionary->RemoveWithoutPathExpansion(host, NULL); |
| 960 } else { | 937 } else { |
| 961 host_zoom_dictionary->SetWithoutPathExpansion( | 938 host_zoom_dictionary->SetWithoutPathExpansion( |
| 962 host, Value::CreateDoubleValue(level)); | 939 host, Value::CreateDoubleValue(level)); |
| 963 } | 940 } |
| 964 } | 941 } |
| 965 break; | 942 break; |
| 966 } | 943 } |
| 967 default: | 944 default: |
| 968 NOTREACHED(); | 945 NOTREACHED(); |
| 969 } | 946 } |
| 970 } | 947 } |
| 971 | 948 |
| 949 void ProfileImpl::OnPreferenceChanged(PrefServiceBase* prefs, | |
| 950 const std::string& pref_name_in) { | |
| 951 DCHECK(prefs); | |
| 952 if (pref_name_in == prefs::kGoogleServicesUsername) { | |
| 953 UpdateProfileUserNameCache(); | |
| 954 } else if (pref_name_in == prefs::kProfileAvatarIndex) { | |
| 955 UpdateProfileAvatarCache(); | |
| 956 } else if (pref_name_in == prefs::kProfileName) { | |
| 957 UpdateProfileNameCache(); | |
| 958 } else if (pref_name_in == prefs::kDefaultZoomLevel) { | |
| 959 HostZoomMap::GetForBrowserContext(this)->SetDefaultZoomLevel( | |
| 960 prefs->GetDouble(prefs::kDefaultZoomLevel)); | |
| 961 } | |
| 962 } | |
| 963 | |
| 972 #if defined(ENABLE_SESSION_SERVICE) | 964 #if defined(ENABLE_SESSION_SERVICE) |
| 973 void ProfileImpl::StopCreateSessionServiceTimer() { | 965 void ProfileImpl::StopCreateSessionServiceTimer() { |
| 974 create_session_service_timer_.Stop(); | 966 create_session_service_timer_.Stop(); |
| 975 } | 967 } |
| 976 | 968 |
| 977 void ProfileImpl::EnsureSessionServiceCreated() { | 969 void ProfileImpl::EnsureSessionServiceCreated() { |
| 978 SessionServiceFactory::GetForProfile(this); | 970 SessionServiceFactory::GetForProfile(this); |
| 979 } | 971 } |
| 980 #endif | 972 #endif |
| 981 | 973 |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1163 if (!path.empty()) | 1155 if (!path.empty()) |
| 1164 *cache_path = path; | 1156 *cache_path = path; |
| 1165 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : | 1157 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : |
| 1166 prefs_->GetInteger(prefs::kDiskCacheSize); | 1158 prefs_->GetInteger(prefs::kDiskCacheSize); |
| 1167 } | 1159 } |
| 1168 | 1160 |
| 1169 base::Callback<ChromeURLDataManagerBackend*(void)> | 1161 base::Callback<ChromeURLDataManagerBackend*(void)> |
| 1170 ProfileImpl::GetChromeURLDataManagerBackendGetter() const { | 1162 ProfileImpl::GetChromeURLDataManagerBackendGetter() const { |
| 1171 return io_data_.GetChromeURLDataManagerBackendGetter(); | 1163 return io_data_.GetChromeURLDataManagerBackendGetter(); |
| 1172 } | 1164 } |
| OLD | NEW |