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/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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 } | 239 } |
240 | 240 |
241 ProfileImpl::ProfileImpl(const FilePath& path, | 241 ProfileImpl::ProfileImpl(const FilePath& path, |
242 Profile::Delegate* delegate) | 242 Profile::Delegate* delegate) |
243 : path_(path), | 243 : path_(path), |
244 ALLOW_THIS_IN_INITIALIZER_LIST(visited_link_event_listener_( | 244 ALLOW_THIS_IN_INITIALIZER_LIST(visited_link_event_listener_( |
245 new VisitedLinkEventListener(this))), | 245 new VisitedLinkEventListener(this))), |
246 ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)), | 246 ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)), |
247 extension_devtools_manager_(NULL), | 247 extension_devtools_manager_(NULL), |
248 host_content_settings_map_(NULL), | 248 host_content_settings_map_(NULL), |
249 host_zoom_map_(NULL), | |
250 history_service_created_(false), | 249 history_service_created_(false), |
251 favicon_service_created_(false), | 250 favicon_service_created_(false), |
252 created_web_data_service_(false), | 251 created_web_data_service_(false), |
253 created_password_store_(false), | 252 created_password_store_(false), |
254 start_time_(Time::Now()), | 253 start_time_(Time::Now()), |
255 #if defined(OS_WIN) | 254 #if defined(OS_WIN) |
256 checked_instant_promo_(false), | 255 checked_instant_promo_(false), |
257 #endif | 256 #endif |
258 delegate_(delegate), | 257 delegate_(delegate), |
259 predictor_(NULL), | 258 predictor_(NULL), |
(...skipping 24 matching lines...) Expand all Loading... |
284 registrar_.Add(this, chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED, | 283 registrar_.Add(this, chrome::NOTIFICATION_PREF_INITIALIZATION_COMPLETED, |
285 content::Source<PrefService>(prefs_.get())); | 284 content::Source<PrefService>(prefs_.get())); |
286 } else { | 285 } else { |
287 // Load prefs synchronously. | 286 // Load prefs synchronously. |
288 prefs_.reset(PrefService::CreatePrefService( | 287 prefs_.reset(PrefService::CreatePrefService( |
289 GetPrefFilePath(), | 288 GetPrefFilePath(), |
290 new ExtensionPrefStore(GetExtensionPrefValueMap(), false), | 289 new ExtensionPrefStore(GetExtensionPrefValueMap(), false), |
291 false)); | 290 false)); |
292 OnPrefsLoaded(true); | 291 OnPrefsLoaded(true); |
293 } | 292 } |
| 293 |
| 294 HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this); |
| 295 host_zoom_map->SetDefaultZoomLevel( |
| 296 GetPrefs()->GetDouble(prefs::kDefaultZoomLevel)); |
| 297 |
| 298 const DictionaryValue* host_zoom_dictionary = |
| 299 prefs_->GetDictionary(prefs::kPerHostZoomLevels); |
| 300 // Careful: The returned value could be NULL if the pref has never been set. |
| 301 if (host_zoom_dictionary != NULL) { |
| 302 for (DictionaryValue::key_iterator i(host_zoom_dictionary->begin_keys()); |
| 303 i != host_zoom_dictionary->end_keys(); ++i) { |
| 304 const std::string& host(*i); |
| 305 double zoom_level = 0; |
| 306 |
| 307 bool success = host_zoom_dictionary->GetDoubleWithoutPathExpansion( |
| 308 host, &zoom_level); |
| 309 DCHECK(success); |
| 310 host_zoom_map->SetZoomLevel(host, zoom_level); |
| 311 } |
| 312 } |
| 313 |
| 314 registrar_.Add(this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED, |
| 315 content::Source<HostZoomMap>(host_zoom_map)); |
294 } | 316 } |
295 | 317 |
296 void ProfileImpl::DoFinalInit() { | 318 void ProfileImpl::DoFinalInit() { |
297 PrefService* prefs = GetPrefs(); | 319 PrefService* prefs = GetPrefs(); |
298 pref_change_registrar_.Init(prefs); | 320 pref_change_registrar_.Init(prefs); |
299 pref_change_registrar_.Add(prefs::kSpeechInputFilterProfanities, this); | 321 pref_change_registrar_.Add(prefs::kSpeechInputFilterProfanities, this); |
300 pref_change_registrar_.Add(prefs::kClearSiteDataOnExit, this); | 322 pref_change_registrar_.Add(prefs::kClearSiteDataOnExit, this); |
301 pref_change_registrar_.Add(prefs::kGoogleServicesUsername, this); | 323 pref_change_registrar_.Add(prefs::kGoogleServicesUsername, this); |
302 pref_change_registrar_.Add(prefs::kDefaultZoomLevel, this); | 324 pref_change_registrar_.Add(prefs::kDefaultZoomLevel, this); |
303 pref_change_registrar_.Add(prefs::kProfileAvatarIndex, this); | 325 pref_change_registrar_.Add(prefs::kProfileAvatarIndex, this); |
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
865 } | 887 } |
866 | 888 |
867 HostContentSettingsMap* ProfileImpl::GetHostContentSettingsMap() { | 889 HostContentSettingsMap* ProfileImpl::GetHostContentSettingsMap() { |
868 if (!host_content_settings_map_.get()) { | 890 if (!host_content_settings_map_.get()) { |
869 host_content_settings_map_ = new HostContentSettingsMap( | 891 host_content_settings_map_ = new HostContentSettingsMap( |
870 GetPrefs(), GetExtensionService(), false); | 892 GetPrefs(), GetExtensionService(), false); |
871 } | 893 } |
872 return host_content_settings_map_.get(); | 894 return host_content_settings_map_.get(); |
873 } | 895 } |
874 | 896 |
875 HostZoomMap* ProfileImpl::GetHostZoomMap() { | |
876 if (!host_zoom_map_) { | |
877 host_zoom_map_ = HostZoomMap::Create(); | |
878 host_zoom_map_->SetDefaultZoomLevel( | |
879 GetPrefs()->GetDouble(prefs::kDefaultZoomLevel)); | |
880 | |
881 const DictionaryValue* host_zoom_dictionary = | |
882 prefs_->GetDictionary(prefs::kPerHostZoomLevels); | |
883 // Careful: The returned value could be NULL if the pref has never been set. | |
884 if (host_zoom_dictionary != NULL) { | |
885 for (DictionaryValue::key_iterator i(host_zoom_dictionary->begin_keys()); | |
886 i != host_zoom_dictionary->end_keys(); ++i) { | |
887 const std::string& host(*i); | |
888 double zoom_level = 0; | |
889 | |
890 bool success = host_zoom_dictionary->GetDoubleWithoutPathExpansion( | |
891 host, &zoom_level); | |
892 DCHECK(success); | |
893 host_zoom_map_->SetZoomLevel(host, zoom_level); | |
894 } | |
895 } | |
896 | |
897 registrar_.Add(this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED, | |
898 content::Source<HostZoomMap>(host_zoom_map_)); | |
899 } | |
900 return host_zoom_map_.get(); | |
901 } | |
902 | |
903 content::GeolocationPermissionContext* | 897 content::GeolocationPermissionContext* |
904 ProfileImpl::GetGeolocationPermissionContext() { | 898 ProfileImpl::GetGeolocationPermissionContext() { |
905 if (!geolocation_permission_context_.get()) { | 899 if (!geolocation_permission_context_.get()) { |
906 geolocation_permission_context_ = | 900 geolocation_permission_context_ = |
907 new ChromeGeolocationPermissionContext(this); | 901 new ChromeGeolocationPermissionContext(this); |
908 } | 902 } |
909 return geolocation_permission_context_.get(); | 903 return geolocation_permission_context_.get(); |
910 } | 904 } |
911 | 905 |
912 content::SpeechInputPreferences* ProfileImpl::GetSpeechInputPreferences() { | 906 content::SpeechInputPreferences* ProfileImpl::GetSpeechInputPreferences() { |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1204 } else if (*pref_name_in == prefs::kClearSiteDataOnExit) { | 1198 } else if (*pref_name_in == prefs::kClearSiteDataOnExit) { |
1205 clear_local_state_on_exit_ = | 1199 clear_local_state_on_exit_ = |
1206 prefs->GetBoolean(prefs::kClearSiteDataOnExit); | 1200 prefs->GetBoolean(prefs::kClearSiteDataOnExit); |
1207 } else if (*pref_name_in == prefs::kGoogleServicesUsername) { | 1201 } else if (*pref_name_in == prefs::kGoogleServicesUsername) { |
1208 UpdateProfileUserNameCache(); | 1202 UpdateProfileUserNameCache(); |
1209 } else if (*pref_name_in == prefs::kProfileAvatarIndex) { | 1203 } else if (*pref_name_in == prefs::kProfileAvatarIndex) { |
1210 UpdateProfileAvatarCache(); | 1204 UpdateProfileAvatarCache(); |
1211 } else if (*pref_name_in == prefs::kProfileName) { | 1205 } else if (*pref_name_in == prefs::kProfileName) { |
1212 UpdateProfileNameCache(); | 1206 UpdateProfileNameCache(); |
1213 } else if (*pref_name_in == prefs::kDefaultZoomLevel) { | 1207 } else if (*pref_name_in == prefs::kDefaultZoomLevel) { |
1214 GetHostZoomMap()->SetDefaultZoomLevel( | 1208 HostZoomMap::GetForBrowserContext(this)->SetDefaultZoomLevel( |
1215 prefs->GetDouble(prefs::kDefaultZoomLevel)); | 1209 prefs->GetDouble(prefs::kDefaultZoomLevel)); |
1216 } | 1210 } |
1217 break; | 1211 break; |
1218 } | 1212 } |
1219 case chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED: | 1213 case chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED: |
1220 // Causes lazy-load if sync is enabled. | 1214 // Causes lazy-load if sync is enabled. |
1221 ProfileSyncServiceFactory::GetInstance()->GetForProfile(this); | 1215 ProfileSyncServiceFactory::GetInstance()->GetForProfile(this); |
1222 registrar_.Remove(this, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, | 1216 registrar_.Remove(this, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, |
1223 content::Source<Profile>(this)); | 1217 content::Source<Profile>(this)); |
1224 break; | 1218 break; |
1225 case content::NOTIFICATION_ZOOM_LEVEL_CHANGED: { | 1219 case content::NOTIFICATION_ZOOM_LEVEL_CHANGED: { |
1226 const std::string& host = | 1220 const std::string& host = |
1227 *(content::Details<const std::string>(details).ptr()); | 1221 *(content::Details<const std::string>(details).ptr()); |
1228 if (!host.empty()) { | 1222 if (!host.empty()) { |
1229 double level = host_zoom_map_->GetZoomLevel(host); | 1223 HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this); |
| 1224 double level = host_zoom_map->GetZoomLevel(host); |
1230 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels); | 1225 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels); |
1231 DictionaryValue* host_zoom_dictionary = update.Get(); | 1226 DictionaryValue* host_zoom_dictionary = update.Get(); |
1232 if (level == host_zoom_map_->GetDefaultZoomLevel()) { | 1227 if (level == host_zoom_map->GetDefaultZoomLevel()) { |
1233 host_zoom_dictionary->RemoveWithoutPathExpansion(host, NULL); | 1228 host_zoom_dictionary->RemoveWithoutPathExpansion(host, NULL); |
1234 } else { | 1229 } else { |
1235 host_zoom_dictionary->SetWithoutPathExpansion( | 1230 host_zoom_dictionary->SetWithoutPathExpansion( |
1236 host, Value::CreateDoubleValue(level)); | 1231 host, Value::CreateDoubleValue(level)); |
1237 } | 1232 } |
1238 } | 1233 } |
1239 break; | 1234 break; |
1240 } | 1235 } |
1241 default: | 1236 default: |
1242 NOTREACHED(); | 1237 NOTREACHED(); |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1483 FilePath* cache_path, | 1478 FilePath* cache_path, |
1484 int* max_size) { | 1479 int* max_size) { |
1485 DCHECK(cache_path); | 1480 DCHECK(cache_path); |
1486 DCHECK(max_size); | 1481 DCHECK(max_size); |
1487 FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir)); | 1482 FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir)); |
1488 if (!path.empty()) | 1483 if (!path.empty()) |
1489 *cache_path = path; | 1484 *cache_path = path; |
1490 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : | 1485 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : |
1491 prefs_->GetInteger(prefs::kDiskCacheSize); | 1486 prefs_->GetInteger(prefs::kDiskCacheSize); |
1492 } | 1487 } |
OLD | NEW |