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/callback.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 #include "chrome/browser/net/chrome_url_request_context.h" | 49 #include "chrome/browser/net/chrome_url_request_context.h" |
50 #include "chrome/browser/net/net_pref_observer.h" | 50 #include "chrome/browser/net/net_pref_observer.h" |
51 #include "chrome/browser/net/predictor.h" | 51 #include "chrome/browser/net/predictor.h" |
52 #include "chrome/browser/net/proxy_service_factory.h" | 52 #include "chrome/browser/net/proxy_service_factory.h" |
53 #include "chrome/browser/net/ssl_config_service_manager.h" | 53 #include "chrome/browser/net/ssl_config_service_manager.h" |
54 #include "chrome/browser/net/url_fixer_upper.h" | 54 #include "chrome/browser/net/url_fixer_upper.h" |
55 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" | 55 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" |
56 #include "chrome/browser/plugins/plugin_prefs.h" | 56 #include "chrome/browser/plugins/plugin_prefs.h" |
57 #include "chrome/browser/prefs/browser_prefs.h" | 57 #include "chrome/browser/prefs/browser_prefs.h" |
58 #include "chrome/browser/prefs/chrome_pref_service_factory.h" | 58 #include "chrome/browser/prefs/chrome_pref_service_factory.h" |
| 59 #include "chrome/browser/prefs/pref_registry_syncable.h" |
| 60 #include "chrome/browser/prefs/pref_service_syncable.h" |
59 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 61 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
60 #include "chrome/browser/prerender/prerender_manager_factory.h" | 62 #include "chrome/browser/prerender/prerender_manager_factory.h" |
61 #include "chrome/browser/profiles/chrome_version_service.h" | 63 #include "chrome/browser/profiles/chrome_version_service.h" |
62 #include "chrome/browser/profiles/gaia_info_update_service_factory.h" | 64 #include "chrome/browser/profiles/gaia_info_update_service_factory.h" |
63 #include "chrome/browser/profiles/profile_dependency_manager.h" | 65 #include "chrome/browser/profiles/profile_dependency_manager.h" |
64 #include "chrome/browser/profiles/profile_destroyer.h" | 66 #include "chrome/browser/profiles/profile_destroyer.h" |
65 #include "chrome/browser/profiles/profile_info_cache.h" | 67 #include "chrome/browser/profiles/profile_info_cache.h" |
66 #include "chrome/browser/profiles/profile_manager.h" | 68 #include "chrome/browser/profiles/profile_manager.h" |
67 #include "chrome/browser/search_engines/template_url_fetcher.h" | 69 #include "chrome/browser/search_engines/template_url_fetcher.h" |
68 #include "chrome/browser/sessions/session_service_factory.h" | 70 #include "chrome/browser/sessions/session_service_factory.h" |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 return new ProfileImpl(path, delegate, create_mode, sequenced_task_runner); | 294 return new ProfileImpl(path, delegate, create_mode, sequenced_task_runner); |
293 } | 295 } |
294 | 296 |
295 // static | 297 // static |
296 int ProfileImpl::create_readme_delay_ms = 60000; | 298 int ProfileImpl::create_readme_delay_ms = 60000; |
297 | 299 |
298 // static | 300 // static |
299 const char* const ProfileImpl::kPrefExitTypeNormal = "Normal"; | 301 const char* const ProfileImpl::kPrefExitTypeNormal = "Normal"; |
300 | 302 |
301 // static | 303 // static |
302 void ProfileImpl::RegisterUserPrefs(PrefServiceSyncable* prefs) { | 304 void ProfileImpl::RegisterUserPrefs(PrefRegistrySyncable* registry) { |
303 prefs->RegisterBooleanPref(prefs::kSavingBrowserHistoryDisabled, | 305 registry->RegisterBooleanPref(prefs::kSavingBrowserHistoryDisabled, |
304 false, | 306 false, |
305 PrefServiceSyncable::UNSYNCABLE_PREF); | 307 PrefRegistrySyncable::UNSYNCABLE_PREF); |
306 prefs->RegisterBooleanPref(prefs::kForceSafeSearch, | 308 registry->RegisterBooleanPref(prefs::kForceSafeSearch, |
307 false, | 309 false, |
308 PrefServiceSyncable::UNSYNCABLE_PREF); | 310 PrefRegistrySyncable::UNSYNCABLE_PREF); |
309 prefs->RegisterIntegerPref(prefs::kProfileAvatarIndex, | 311 registry->RegisterIntegerPref(prefs::kProfileAvatarIndex, |
310 -1, | 312 -1, |
311 PrefServiceSyncable::SYNCABLE_PREF); | 313 PrefRegistrySyncable::SYNCABLE_PREF); |
312 prefs->RegisterStringPref(prefs::kProfileName, | 314 registry->RegisterStringPref(prefs::kProfileName, |
313 "", | 315 "", |
314 PrefServiceSyncable::SYNCABLE_PREF); | 316 PrefRegistrySyncable::SYNCABLE_PREF); |
315 prefs->RegisterBooleanPref(prefs::kProfileIsManaged, | 317 registry->RegisterBooleanPref(prefs::kProfileIsManaged, |
316 false, | 318 false, |
317 PrefServiceSyncable::SYNCABLE_PREF); | 319 PrefRegistrySyncable::SYNCABLE_PREF); |
318 prefs->RegisterStringPref(prefs::kHomePage, | 320 registry->RegisterStringPref(prefs::kHomePage, |
319 std::string(), | 321 std::string(), |
320 PrefServiceSyncable::SYNCABLE_PREF); | 322 PrefRegistrySyncable::SYNCABLE_PREF); |
321 #if defined(ENABLE_PRINTING) | 323 #if defined(ENABLE_PRINTING) |
322 prefs->RegisterBooleanPref(prefs::kPrintingEnabled, | 324 registry->RegisterBooleanPref(prefs::kPrintingEnabled, |
323 true, | 325 true, |
324 PrefServiceSyncable::UNSYNCABLE_PREF); | 326 PrefRegistrySyncable::UNSYNCABLE_PREF); |
325 #endif | 327 #endif |
326 prefs->RegisterBooleanPref(prefs::kPrintPreviewDisabled, | 328 registry->RegisterBooleanPref(prefs::kPrintPreviewDisabled, |
327 #if defined(GOOGLE_CHROME_BUILD) | 329 #if defined(GOOGLE_CHROME_BUILD) |
328 false, | 330 false, |
329 #else | 331 #else |
330 true, | 332 true, |
331 #endif | 333 #endif |
332 PrefServiceSyncable::UNSYNCABLE_PREF); | 334 PrefRegistrySyncable::UNSYNCABLE_PREF); |
333 | 335 |
334 // Initialize the cache prefs. | 336 // Initialize the cache prefs. |
335 prefs->RegisterFilePathPref(prefs::kDiskCacheDir, | 337 registry->RegisterFilePathPref(prefs::kDiskCacheDir, |
336 FilePath(), | 338 FilePath(), |
337 PrefServiceSyncable::UNSYNCABLE_PREF); | 339 PrefRegistrySyncable::UNSYNCABLE_PREF); |
338 prefs->RegisterIntegerPref(prefs::kDiskCacheSize, | 340 registry->RegisterIntegerPref(prefs::kDiskCacheSize, |
339 0, | 341 0, |
340 PrefServiceSyncable::UNSYNCABLE_PREF); | 342 PrefRegistrySyncable::UNSYNCABLE_PREF); |
341 prefs->RegisterIntegerPref(prefs::kMediaCacheSize, | 343 registry->RegisterIntegerPref(prefs::kMediaCacheSize, |
342 0, | 344 0, |
343 PrefServiceSyncable::UNSYNCABLE_PREF); | 345 PrefRegistrySyncable::UNSYNCABLE_PREF); |
344 | 346 |
345 // Deprecated. Kept around for migration. | 347 // Deprecated. Kept around for migration. |
346 prefs->RegisterBooleanPref(prefs::kClearSiteDataOnExit, | 348 registry->RegisterBooleanPref(prefs::kClearSiteDataOnExit, |
347 false, | 349 false, |
348 PrefServiceSyncable::SYNCABLE_PREF); | 350 PrefRegistrySyncable::SYNCABLE_PREF); |
349 } | 351 } |
350 | 352 |
351 ProfileImpl::ProfileImpl( | 353 ProfileImpl::ProfileImpl( |
352 const FilePath& path, | 354 const FilePath& path, |
353 Delegate* delegate, | 355 Delegate* delegate, |
354 CreateMode create_mode, | 356 CreateMode create_mode, |
355 base::SequencedTaskRunner* sequenced_task_runner) | 357 base::SequencedTaskRunner* sequenced_task_runner) |
356 : path_(path), | 358 : path_(path), |
| 359 pref_registry_(new PrefRegistrySyncable), |
357 ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)), | 360 ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)), |
358 host_content_settings_map_(NULL), | 361 host_content_settings_map_(NULL), |
359 last_session_exit_type_(EXIT_NORMAL), | 362 last_session_exit_type_(EXIT_NORMAL), |
360 start_time_(Time::Now()), | 363 start_time_(Time::Now()), |
361 delegate_(delegate), | 364 delegate_(delegate), |
362 predictor_(NULL) { | 365 predictor_(NULL) { |
363 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << | 366 DCHECK(!path.empty()) << "Using an empty path will attempt to write " << |
364 "profile files to the root directory!"; | 367 "profile files to the root directory!"; |
365 | 368 |
366 #if defined(ENABLE_SESSION_SERVICE) | 369 #if defined(ENABLE_SESSION_SERVICE) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 policy_service_ = | 405 policy_service_ = |
403 g_browser_process->browser_policy_connector()->CreatePolicyService(this); | 406 g_browser_process->browser_policy_connector()->CreatePolicyService(this); |
404 #else | 407 #else |
405 policy_service_.reset(new policy::PolicyServiceStub()); | 408 policy_service_.reset(new policy::PolicyServiceStub()); |
406 #endif | 409 #endif |
407 | 410 |
408 DCHECK(create_mode == CREATE_MODE_ASYNCHRONOUS || | 411 DCHECK(create_mode == CREATE_MODE_ASYNCHRONOUS || |
409 create_mode == CREATE_MODE_SYNCHRONOUS); | 412 create_mode == CREATE_MODE_SYNCHRONOUS); |
410 bool async_prefs = create_mode == CREATE_MODE_ASYNCHRONOUS; | 413 bool async_prefs = create_mode == CREATE_MODE_ASYNCHRONOUS; |
411 | 414 |
| 415 Profile::RegisterUserPrefs(pref_registry_); |
| 416 |
412 { | 417 { |
413 // On startup, preference loading is always synchronous so a scoped timer | 418 // On startup, preference loading is always synchronous so a scoped timer |
414 // will work here. | 419 // will work here. |
415 startup_metric_utils::ScopedSlowStartupUMA | 420 startup_metric_utils::ScopedSlowStartupUMA |
416 scoped_timer("Startup.SlowStartupPreferenceLoading"); | 421 scoped_timer("Startup.SlowStartupPreferenceLoading"); |
417 prefs_.reset(chrome_prefs::CreateProfilePrefs( | 422 prefs_.reset(chrome_prefs::CreateProfilePrefs( |
418 GetPrefFilePath(), | 423 GetPrefFilePath(), |
419 sequenced_task_runner, | 424 sequenced_task_runner, |
420 policy_service_.get(), | 425 policy_service_.get(), |
421 new ExtensionPrefStore( | 426 new ExtensionPrefStore( |
422 ExtensionPrefValueMapFactory::GetForProfile(this), false), | 427 ExtensionPrefValueMapFactory::GetForProfile(this), false), |
| 428 pref_registry_, |
423 async_prefs)); | 429 async_prefs)); |
424 } | 430 } |
425 | 431 |
426 startup_metric_utils::ScopedSlowStartupUMA | 432 startup_metric_utils::ScopedSlowStartupUMA |
427 scoped_timer("Startup.SlowStartupFinalProfileInit"); | 433 scoped_timer("Startup.SlowStartupFinalProfileInit"); |
428 if (async_prefs) { | 434 if (async_prefs) { |
429 // Wait for the notification that prefs has been loaded | 435 // Wait for the notification that prefs has been loaded |
430 // (successfully or not). Note that we can use base::Unretained | 436 // (successfully or not). Note that we can use base::Unretained |
431 // because the PrefService is owned by this class and lives on | 437 // because the PrefService is owned by this class and lives on |
432 // the same thread. | 438 // the same thread. |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 return extension_special_storage_policy_.get(); | 721 return extension_special_storage_policy_.get(); |
716 } | 722 } |
717 | 723 |
718 void ProfileImpl::OnPrefsLoaded(bool success) { | 724 void ProfileImpl::OnPrefsLoaded(bool success) { |
719 if (!success) { | 725 if (!success) { |
720 if (delegate_) | 726 if (delegate_) |
721 delegate_->OnProfileCreated(this, false, false); | 727 delegate_->OnProfileCreated(this, false, false); |
722 return; | 728 return; |
723 } | 729 } |
724 | 730 |
725 // The Profile class and ProfileManager class may read some prefs so | 731 // TODO(joi): Registration can move to the constructor once it |
726 // register known prefs as soon as possible. | 732 // doesn't need the PrefService parameter. |
727 Profile::RegisterUserPrefs(prefs_.get()); | 733 chrome::RegisterUserPrefs(prefs_.get(), pref_registry_); |
728 chrome::RegisterUserPrefs(prefs_.get()); | 734 |
729 // TODO(mirandac): remove migration code after 6 months (crbug.com/69995). | 735 // TODO(mirandac): remove migration code after 6 months (crbug.com/69995). |
730 if (g_browser_process->local_state()) | 736 if (g_browser_process->local_state()) |
731 chrome::MigrateBrowserPrefs(this, g_browser_process->local_state()); | 737 chrome::MigrateBrowserPrefs(this, g_browser_process->local_state()); |
732 // TODO(ivankr): remove cleanup code eventually (crbug.com/165672). | 738 // TODO(ivankr): remove cleanup code eventually (crbug.com/165672). |
733 chrome::MigrateUserPrefs(this); | 739 chrome::MigrateUserPrefs(this); |
734 | 740 |
735 // |kSessionExitType| was added after |kSessionExitedCleanly|. If the pref | 741 // |kSessionExitType| was added after |kSessionExitedCleanly|. If the pref |
736 // value is empty fallback to checking for |kSessionExitedCleanly|. | 742 // value is empty fallback to checking for |kSessionExitedCleanly|. |
737 const std::string exit_type_pref_value( | 743 const std::string exit_type_pref_value( |
738 prefs_->GetString(prefs::kSessionExitType)); | 744 prefs_->GetString(prefs::kSessionExitType)); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
801 #else | 807 #else |
802 return NULL; | 808 return NULL; |
803 #endif | 809 #endif |
804 } | 810 } |
805 | 811 |
806 policy::PolicyService* ProfileImpl::GetPolicyService() { | 812 policy::PolicyService* ProfileImpl::GetPolicyService() { |
807 DCHECK(policy_service_.get()); // Should explicitly be initialized. | 813 DCHECK(policy_service_.get()); // Should explicitly be initialized. |
808 return policy_service_.get(); | 814 return policy_service_.get(); |
809 } | 815 } |
810 | 816 |
811 PrefServiceSyncable* ProfileImpl::GetPrefs() { | 817 PrefService* ProfileImpl::GetPrefs() { |
812 DCHECK(prefs_.get()); // Should explicitly be initialized. | 818 DCHECK(prefs_.get()); // Should explicitly be initialized. |
813 return prefs_.get(); | 819 return prefs_.get(); |
814 } | 820 } |
815 | 821 |
816 PrefServiceSyncable* ProfileImpl::GetOffTheRecordPrefs() { | 822 PrefService* ProfileImpl::GetOffTheRecordPrefs() { |
| 823 DCHECK(prefs_.get()); |
817 if (!otr_prefs_.get()) { | 824 if (!otr_prefs_.get()) { |
818 // The new ExtensionPrefStore is ref_counted and the new PrefService | 825 // The new ExtensionPrefStore is ref_counted and the new PrefService |
819 // stores a reference so that we do not leak memory here. | 826 // stores a reference so that we do not leak memory here. |
820 otr_prefs_.reset(GetPrefs()->CreateIncognitoPrefService( | 827 otr_prefs_.reset(prefs_->CreateIncognitoPrefService( |
821 new ExtensionPrefStore( | 828 new ExtensionPrefStore( |
822 ExtensionPrefValueMapFactory::GetForProfile(this), true))); | 829 ExtensionPrefValueMapFactory::GetForProfile(this), true))); |
823 } | 830 } |
824 return otr_prefs_.get(); | 831 return otr_prefs_.get(); |
825 } | 832 } |
826 | 833 |
827 FilePath ProfileImpl::GetPrefFilePath() { | 834 FilePath ProfileImpl::GetPrefFilePath() { |
828 FilePath pref_file_path = path_; | 835 FilePath pref_file_path = path_; |
829 pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename); | 836 pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename); |
830 return pref_file_path; | 837 return pref_file_path; |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1075 } | 1082 } |
1076 | 1083 |
1077 void ProfileImpl::SetupChromeOSEnterpriseExtensionObserver() { | 1084 void ProfileImpl::SetupChromeOSEnterpriseExtensionObserver() { |
1078 DCHECK(!chromeos_enterprise_extension_observer_.get()); | 1085 DCHECK(!chromeos_enterprise_extension_observer_.get()); |
1079 chromeos_enterprise_extension_observer_.reset( | 1086 chromeos_enterprise_extension_observer_.reset( |
1080 new chromeos::EnterpriseExtensionObserver(this)); | 1087 new chromeos::EnterpriseExtensionObserver(this)); |
1081 } | 1088 } |
1082 | 1089 |
1083 void ProfileImpl::InitChromeOSPreferences() { | 1090 void ProfileImpl::InitChromeOSPreferences() { |
1084 chromeos_preferences_.reset(new chromeos::Preferences()); | 1091 chromeos_preferences_.reset(new chromeos::Preferences()); |
1085 chromeos_preferences_->Init(GetPrefs()); | 1092 chromeos_preferences_->Init(PrefServiceSyncable::FromProfile(this)); |
1086 } | 1093 } |
1087 #endif // defined(OS_CHROMEOS) | 1094 #endif // defined(OS_CHROMEOS) |
1088 | 1095 |
1089 PrefProxyConfigTracker* ProfileImpl::GetProxyConfigTracker() { | 1096 PrefProxyConfigTracker* ProfileImpl::GetProxyConfigTracker() { |
1090 if (!pref_proxy_config_tracker_.get()) { | 1097 if (!pref_proxy_config_tracker_.get()) { |
1091 pref_proxy_config_tracker_.reset( | 1098 pref_proxy_config_tracker_.reset( |
1092 ProxyServiceFactory::CreatePrefProxyConfigTracker(GetPrefs())); | 1099 ProxyServiceFactory::CreatePrefProxyConfigTracker(GetPrefs())); |
1093 } | 1100 } |
1094 return pref_proxy_config_tracker_.get(); | 1101 return pref_proxy_config_tracker_.get(); |
1095 } | 1102 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1172 FilePath* cache_path, | 1179 FilePath* cache_path, |
1173 int* max_size) { | 1180 int* max_size) { |
1174 DCHECK(cache_path); | 1181 DCHECK(cache_path); |
1175 DCHECK(max_size); | 1182 DCHECK(max_size); |
1176 FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir)); | 1183 FilePath path(prefs_->GetFilePath(prefs::kDiskCacheDir)); |
1177 if (!path.empty()) | 1184 if (!path.empty()) |
1178 *cache_path = path; | 1185 *cache_path = path; |
1179 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : | 1186 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : |
1180 prefs_->GetInteger(prefs::kDiskCacheSize); | 1187 prefs_->GetInteger(prefs::kDiskCacheSize); |
1181 } | 1188 } |
OLD | NEW |