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/predictor.h" | 49 #include "chrome/browser/net/predictor.h" |
50 #include "chrome/browser/net/pref_proxy_config_tracker.h" | 50 #include "chrome/browser/net/pref_proxy_config_tracker.h" |
51 #include "chrome/browser/net/proxy_service_factory.h" | 51 #include "chrome/browser/net/proxy_service_factory.h" |
52 #include "chrome/browser/net/ssl_config_service_manager.h" | 52 #include "chrome/browser/net/ssl_config_service_manager.h" |
53 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" | 53 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" |
54 #include "chrome/browser/plugins/plugin_prefs.h" | 54 #include "chrome/browser/plugins/plugin_prefs.h" |
55 #include "chrome/browser/policy/profile_policy_connector.h" | 55 #include "chrome/browser/policy/profile_policy_connector.h" |
56 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 56 #include "chrome/browser/policy/profile_policy_connector_factory.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_hash_store_impl.h" | |
60 #include "chrome/browser/prefs/pref_service_syncable.h" | 59 #include "chrome/browser/prefs/pref_service_syncable.h" |
61 #include "chrome/browser/prerender/prerender_manager_factory.h" | 60 #include "chrome/browser/prerender/prerender_manager_factory.h" |
62 #include "chrome/browser/profiles/bookmark_model_loaded_observer.h" | 61 #include "chrome/browser/profiles/bookmark_model_loaded_observer.h" |
63 #include "chrome/browser/profiles/chrome_version_service.h" | 62 #include "chrome/browser/profiles/chrome_version_service.h" |
64 #include "chrome/browser/profiles/gaia_info_update_service_factory.h" | 63 #include "chrome/browser/profiles/gaia_info_update_service_factory.h" |
65 #include "chrome/browser/profiles/profile_destroyer.h" | 64 #include "chrome/browser/profiles/profile_destroyer.h" |
66 #include "chrome/browser/profiles/profile_info_cache.h" | 65 #include "chrome/browser/profiles/profile_info_cache.h" |
67 #include "chrome/browser/profiles/profile_manager.h" | 66 #include "chrome/browser/profiles/profile_manager.h" |
68 #include "chrome/browser/profiles/profile_metrics.h" | 67 #include "chrome/browser/profiles/profile_metrics.h" |
69 #include "chrome/browser/search_engines/template_url_fetcher.h" | 68 #include "chrome/browser/search_engines/template_url_fetcher.h" |
(...skipping 17 matching lines...) Expand all Loading... |
87 #include "content/public/browser/host_zoom_map.h" | 86 #include "content/public/browser/host_zoom_map.h" |
88 #include "content/public/browser/notification_service.h" | 87 #include "content/public/browser/notification_service.h" |
89 #include "content/public/browser/render_process_host.h" | 88 #include "content/public/browser/render_process_host.h" |
90 #include "content/public/browser/storage_partition.h" | 89 #include "content/public/browser/storage_partition.h" |
91 #include "content/public/browser/user_metrics.h" | 90 #include "content/public/browser/user_metrics.h" |
92 #include "content/public/common/content_constants.h" | 91 #include "content/public/common/content_constants.h" |
93 #include "extensions/browser/extension_pref_store.h" | 92 #include "extensions/browser/extension_pref_store.h" |
94 #include "extensions/browser/extension_pref_value_map.h" | 93 #include "extensions/browser/extension_pref_value_map.h" |
95 #include "extensions/browser/extension_pref_value_map_factory.h" | 94 #include "extensions/browser/extension_pref_value_map_factory.h" |
96 #include "extensions/browser/extension_system.h" | 95 #include "extensions/browser/extension_system.h" |
97 #include "grit/browser_resources.h" | |
98 #include "grit/chromium_strings.h" | 96 #include "grit/chromium_strings.h" |
99 #include "grit/generated_resources.h" | 97 #include "grit/generated_resources.h" |
100 #include "ui/base/l10n/l10n_util.h" | 98 #include "ui/base/l10n/l10n_util.h" |
101 | 99 |
102 #if defined(OS_ANDROID) | 100 #if defined(OS_ANDROID) |
103 #include "chrome/browser/media/protected_media_identifier_permission_context.h" | 101 #include "chrome/browser/media/protected_media_identifier_permission_context.h" |
104 #include "chrome/browser/media/protected_media_identifier_permission_context_fac
tory.h" | 102 #include "chrome/browser/media/protected_media_identifier_permission_context_fac
tory.h" |
105 #endif // defined(OS_ANDROID) | 103 #endif // defined(OS_ANDROID) |
106 | 104 |
107 #if defined(ENABLE_CONFIGURATION_POLICY) | 105 #if defined(ENABLE_CONFIGURATION_POLICY) |
108 #include "chrome/browser/policy/schema_registry_service.h" | 106 #include "chrome/browser/policy/schema_registry_service.h" |
109 #include "chrome/browser/policy/schema_registry_service_factory.h" | 107 #include "chrome/browser/policy/schema_registry_service_factory.h" |
110 #include "components/policy/core/browser/browser_policy_connector.h" | 108 #include "components/policy/core/browser/browser_policy_connector.h" |
111 #if defined(OS_CHROMEOS) | 109 #if defined(OS_CHROMEOS) |
112 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" | 110 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" |
113 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom
eos.h" | 111 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom
eos.h" |
114 #else | 112 #else |
115 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" | 113 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" |
116 #include "components/policy/core/common/cloud/user_cloud_policy_manager.h" | 114 #include "components/policy/core/common/cloud/user_cloud_policy_manager.h" |
117 #endif | 115 #endif |
118 #endif | 116 #endif |
119 | 117 |
120 #if defined(ENABLE_MANAGED_USERS) | 118 #if defined(ENABLE_MANAGED_USERS) |
121 #include "chrome/browser/managed_mode/managed_user_settings_service.h" | 119 #include "chrome/browser/managed_mode/managed_user_settings_service.h" |
122 #include "chrome/browser/managed_mode/managed_user_settings_service_factory.h" | 120 #include "chrome/browser/managed_mode/managed_user_settings_service_factory.h" |
123 #endif | 121 #endif |
124 | 122 |
125 #if defined(OS_WIN) | |
126 #include "chrome/browser/profiles/file_path_verifier_win.h" | |
127 #include "chrome/installer/util/install_util.h" | |
128 #if defined(ENABLE_RLZ) | |
129 #include "rlz/lib/machine_id.h" | |
130 #endif | |
131 #endif | |
132 | |
133 #if defined(OS_CHROMEOS) | 123 #if defined(OS_CHROMEOS) |
134 #include "chrome/browser/chromeos/locale_change_guard.h" | 124 #include "chrome/browser/chromeos/locale_change_guard.h" |
135 #include "chrome/browser/chromeos/login/user_manager.h" | 125 #include "chrome/browser/chromeos/login/user_manager.h" |
136 #include "chrome/browser/chromeos/preferences.h" | 126 #include "chrome/browser/chromeos/preferences.h" |
137 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 127 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
138 #endif | 128 #endif |
139 | 129 |
140 using base::Time; | 130 using base::Time; |
141 using base::TimeDelta; | 131 using base::TimeDelta; |
142 using base::UserMetricsAction; | 132 using base::UserMetricsAction; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 return ProfileImpl::kPrefExitTypeNormal; | 239 return ProfileImpl::kPrefExitTypeNormal; |
250 case Profile::EXIT_SESSION_ENDED: | 240 case Profile::EXIT_SESSION_ENDED: |
251 return kPrefExitTypeSessionEnded; | 241 return kPrefExitTypeSessionEnded; |
252 case Profile::EXIT_CRASHED: | 242 case Profile::EXIT_CRASHED: |
253 return kPrefExitTypeCrashed; | 243 return kPrefExitTypeCrashed; |
254 } | 244 } |
255 NOTREACHED(); | 245 NOTREACHED(); |
256 return std::string(); | 246 return std::string(); |
257 } | 247 } |
258 | 248 |
259 void SchedulePrefsFileVerification(const base::FilePath& prefs_file) { | |
260 #if defined(OS_WIN) | |
261 // Only do prefs file verification on Windows. | |
262 const int kVerifyPrefsFileDelaySeconds = 60; | |
263 BrowserThread::GetBlockingPool()->PostDelayedTask( | |
264 FROM_HERE, | |
265 base::Bind(&VerifyPreferencesFile, prefs_file), | |
266 base::TimeDelta::FromSeconds(kVerifyPrefsFileDelaySeconds)); | |
267 #endif | |
268 } | |
269 | |
270 scoped_ptr<PrefHashStoreImpl> GetPrefHashStore( | |
271 const base::FilePath& profile_path) { | |
272 // TODO(erikwright): Enable this on Android when race condition is sorted out. | |
273 #if defined(OS_ANDROID) | |
274 return scoped_ptr<PrefHashStoreImpl>(); | |
275 #else | |
276 std::string seed = ResourceBundle::GetSharedInstance().GetRawDataResource( | |
277 IDR_PREF_HASH_SEED_BIN).as_string(); | |
278 std::string device_id; | |
279 | |
280 #if defined(OS_WIN) && defined(ENABLE_RLZ) | |
281 // This is used by | |
282 // chrome/browser/extensions/api/music_manager_private/device_id_win.cc | |
283 // but that API is private (http://crbug.com/276485) and other platforms are | |
284 // not available synchronously. | |
285 // As part of improving pref metrics on other platforms we may want to find | |
286 // ways to defer preference loading until the device ID can be used. | |
287 rlz_lib::GetMachineId(&device_id); | |
288 #endif | |
289 | |
290 return make_scoped_ptr(new PrefHashStoreImpl( | |
291 profile_path.AsUTF8Unsafe(), | |
292 seed, | |
293 device_id, | |
294 g_browser_process->local_state())); | |
295 #endif | |
296 } | |
297 | |
298 base::FilePath GetPrefFilePathFromProfilePath( | |
299 const base::FilePath& profile_path) { | |
300 return profile_path.Append(chrome::kPreferencesFilename); | |
301 } | |
302 | |
303 } // namespace | 249 } // namespace |
304 | 250 |
305 // static | 251 // static |
306 Profile* Profile::CreateProfile(const base::FilePath& path, | 252 Profile* Profile::CreateProfile(const base::FilePath& path, |
307 Delegate* delegate, | 253 Delegate* delegate, |
308 CreateMode create_mode) { | 254 CreateMode create_mode) { |
309 TRACE_EVENT0("browser", "Profile::CreateProfile") | 255 TRACE_EVENT0("browser", "Profile::CreateProfile") |
310 // Get sequenced task runner for making sure that file operations of | 256 // Get sequenced task runner for making sure that file operations of |
311 // this profile (defined by |path|) are executed in expected order | 257 // this profile (defined by |path|) are executed in expected order |
312 // (what was previously assured by the FILE thread). | 258 // (what was previously assured by the FILE thread). |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 0, | 353 0, |
408 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 354 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
409 | 355 |
410 // Deprecated. Kept around for migration. | 356 // Deprecated. Kept around for migration. |
411 registry->RegisterBooleanPref( | 357 registry->RegisterBooleanPref( |
412 prefs::kClearSiteDataOnExit, | 358 prefs::kClearSiteDataOnExit, |
413 false, | 359 false, |
414 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 360 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
415 } | 361 } |
416 | 362 |
417 // static | |
418 void ProfileImpl::InitializePrefHashStoreIfRequired( | |
419 const base::FilePath& profile_path) { | |
420 scoped_ptr<PrefHashStoreImpl> pref_hash_store(GetPrefHashStore(profile_path)); | |
421 if (pref_hash_store && !pref_hash_store->IsInitialized()) { | |
422 chrome_prefs::InitializeHashStoreForPrefFile( | |
423 GetPrefFilePathFromProfilePath(profile_path), | |
424 JsonPrefStore::GetTaskRunnerForFile( | |
425 profile_path, BrowserThread::GetBlockingPool()), | |
426 pref_hash_store.PassAs<PrefHashStore>()); | |
427 } | |
428 } | |
429 | |
430 // static | |
431 void ProfileImpl::ResetPrefHashStore(const base::FilePath& profile_path) { | |
432 GetPrefHashStore(profile_path)->Reset(); | |
433 } | |
434 | |
435 ProfileImpl::ProfileImpl( | 363 ProfileImpl::ProfileImpl( |
436 const base::FilePath& path, | 364 const base::FilePath& path, |
437 Delegate* delegate, | 365 Delegate* delegate, |
438 CreateMode create_mode, | 366 CreateMode create_mode, |
439 base::SequencedTaskRunner* sequenced_task_runner) | 367 base::SequencedTaskRunner* sequenced_task_runner) |
440 : path_(path), | 368 : path_(path), |
441 pref_registry_(new user_prefs::PrefRegistrySyncable), | 369 pref_registry_(new user_prefs::PrefRegistrySyncable), |
442 io_data_(this), | 370 io_data_(this), |
443 host_content_settings_map_(NULL), | 371 host_content_settings_map_(NULL), |
444 last_session_exit_type_(EXIT_NORMAL), | 372 last_session_exit_type_(EXIT_NORMAL), |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 managed_user_settings->Init( | 438 managed_user_settings->Init( |
511 path_, sequenced_task_runner, create_mode == CREATE_MODE_SYNCHRONOUS); | 439 path_, sequenced_task_runner, create_mode == CREATE_MODE_SYNCHRONOUS); |
512 #endif | 440 #endif |
513 | 441 |
514 { | 442 { |
515 // On startup, preference loading is always synchronous so a scoped timer | 443 // On startup, preference loading is always synchronous so a scoped timer |
516 // will work here. | 444 // will work here. |
517 startup_metric_utils::ScopedSlowStartupUMA | 445 startup_metric_utils::ScopedSlowStartupUMA |
518 scoped_timer("Startup.SlowStartupPreferenceLoading"); | 446 scoped_timer("Startup.SlowStartupPreferenceLoading"); |
519 prefs_ = chrome_prefs::CreateProfilePrefs( | 447 prefs_ = chrome_prefs::CreateProfilePrefs( |
520 GetPrefFilePath(), | 448 path_, |
521 sequenced_task_runner, | 449 sequenced_task_runner, |
522 profile_policy_connector_->policy_service(), | 450 profile_policy_connector_->policy_service(), |
523 managed_user_settings, | 451 managed_user_settings, |
524 GetPrefHashStore(path_).PassAs<PrefHashStore>(), | |
525 new ExtensionPrefStore( | 452 new ExtensionPrefStore( |
526 ExtensionPrefValueMapFactory::GetForBrowserContext(this), false), | 453 ExtensionPrefValueMapFactory::GetForBrowserContext(this), false), |
527 pref_registry_, | 454 pref_registry_, |
528 async_prefs).Pass(); | 455 async_prefs).Pass(); |
529 // Register on BrowserContext. | 456 // Register on BrowserContext. |
530 user_prefs::UserPrefs::Set(this, prefs_.get()); | 457 user_prefs::UserPrefs::Set(this, prefs_.get()); |
531 } | 458 } |
532 | 459 |
533 startup_metric_utils::ScopedSlowStartupUMA | 460 startup_metric_utils::ScopedSlowStartupUMA |
534 scoped_timer("Startup.SlowStartupFinalProfileInit"); | 461 scoped_timer("Startup.SlowStartupFinalProfileInit"); |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 | 798 |
872 DCHECK(!net_pref_observer_); | 799 DCHECK(!net_pref_observer_); |
873 { | 800 { |
874 TRACE_EVENT0("browser", "ProfileImpl::OnPrefsLoaded:NetPrefObserver") | 801 TRACE_EVENT0("browser", "ProfileImpl::OnPrefsLoaded:NetPrefObserver") |
875 net_pref_observer_.reset(new NetPrefObserver( | 802 net_pref_observer_.reset(new NetPrefObserver( |
876 prefs_.get(), | 803 prefs_.get(), |
877 prerender::PrerenderManagerFactory::GetForProfile(this), | 804 prerender::PrerenderManagerFactory::GetForProfile(this), |
878 predictor_)); | 805 predictor_)); |
879 } | 806 } |
880 | 807 |
881 SchedulePrefsFileVerification(GetPrefFilePath()); | 808 chrome_prefs::SchedulePrefsFilePathVerification(path_); |
882 | 809 |
883 ChromeVersionService::OnProfileLoaded(prefs_.get(), IsNewProfile()); | 810 ChromeVersionService::OnProfileLoaded(prefs_.get(), IsNewProfile()); |
884 DoFinalInit(); | 811 DoFinalInit(); |
885 } | 812 } |
886 | 813 |
887 bool ProfileImpl::WasCreatedByVersionOrLater(const std::string& version) { | 814 bool ProfileImpl::WasCreatedByVersionOrLater(const std::string& version) { |
888 Version profile_version(ChromeVersionService::GetVersion(prefs_.get())); | 815 Version profile_version(ChromeVersionService::GetVersion(prefs_.get())); |
889 Version arg_version(version); | 816 Version arg_version(version); |
890 return (profile_version.CompareTo(arg_version) >= 0); | 817 return (profile_version.CompareTo(arg_version) >= 0); |
891 } | 818 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 if (!otr_prefs_) { | 856 if (!otr_prefs_) { |
930 // The new ExtensionPrefStore is ref_counted and the new PrefService | 857 // The new ExtensionPrefStore is ref_counted and the new PrefService |
931 // stores a reference so that we do not leak memory here. | 858 // stores a reference so that we do not leak memory here. |
932 otr_prefs_.reset(prefs_->CreateIncognitoPrefService( | 859 otr_prefs_.reset(prefs_->CreateIncognitoPrefService( |
933 new ExtensionPrefStore( | 860 new ExtensionPrefStore( |
934 ExtensionPrefValueMapFactory::GetForBrowserContext(this), true))); | 861 ExtensionPrefValueMapFactory::GetForBrowserContext(this), true))); |
935 } | 862 } |
936 return otr_prefs_.get(); | 863 return otr_prefs_.get(); |
937 } | 864 } |
938 | 865 |
939 base::FilePath ProfileImpl::GetPrefFilePath() { | |
940 return GetPrefFilePathFromProfilePath(path_); | |
941 } | |
942 | |
943 net::URLRequestContextGetter* ProfileImpl::CreateRequestContext( | 866 net::URLRequestContextGetter* ProfileImpl::CreateRequestContext( |
944 content::ProtocolHandlerMap* protocol_handlers) { | 867 content::ProtocolHandlerMap* protocol_handlers) { |
945 return io_data_ | 868 return io_data_ |
946 .CreateMainRequestContextGetter(protocol_handlers, | 869 .CreateMainRequestContextGetter(protocol_handlers, |
947 g_browser_process->local_state(), | 870 g_browser_process->local_state(), |
948 g_browser_process->io_thread()).get(); | 871 g_browser_process->io_thread()).get(); |
949 } | 872 } |
950 | 873 |
951 net::URLRequestContextGetter* ProfileImpl::GetRequestContext() { | 874 net::URLRequestContextGetter* ProfileImpl::GetRequestContext() { |
952 return GetDefaultStoragePartition(this)->GetURLRequestContext(); | 875 return GetDefaultStoragePartition(this)->GetURLRequestContext(); |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1346 PrefProxyConfigTracker* ProfileImpl::CreateProxyConfigTracker() { | 1269 PrefProxyConfigTracker* ProfileImpl::CreateProxyConfigTracker() { |
1347 #if defined(OS_CHROMEOS) | 1270 #if defined(OS_CHROMEOS) |
1348 if (chromeos::ProfileHelper::IsSigninProfile(this)) { | 1271 if (chromeos::ProfileHelper::IsSigninProfile(this)) { |
1349 return ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState( | 1272 return ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState( |
1350 g_browser_process->local_state()); | 1273 g_browser_process->local_state()); |
1351 } | 1274 } |
1352 #endif // defined(OS_CHROMEOS) | 1275 #endif // defined(OS_CHROMEOS) |
1353 return ProxyServiceFactory::CreatePrefProxyConfigTrackerOfProfile( | 1276 return ProxyServiceFactory::CreatePrefProxyConfigTrackerOfProfile( |
1354 GetPrefs(), g_browser_process->local_state()); | 1277 GetPrefs(), g_browser_process->local_state()); |
1355 } | 1278 } |
OLD | NEW |