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/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" | 
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" | 
| 12 #include "base/file_util.h" | 12 #include "base/file_util.h" | 
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" | 
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" | 
| 15 #include "base/string_tokenizer.h" | 15 #include "base/string_tokenizer.h" | 
| 16 #include "base/string_util.h" | 16 #include "base/string_util.h" | 
| 17 #include "base/stringprintf.h" | 17 #include "base/stringprintf.h" | 
| 18 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" | 
| 19 #include "base/version.h" | 19 #include "base/version.h" | 
| 20 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 20 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 
| 21 #include "chrome/browser/background/background_contents_service_factory.h" | 21 #include "chrome/browser/background/background_contents_service_factory.h" | 
| 22 #include "chrome/browser/background/background_mode_manager.h" | 22 #include "chrome/browser/background/background_mode_manager.h" | 
| 23 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 23 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 
| 24 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" | 
| 25 #include "chrome/browser/chrome_plugin_service_filter.h" | 25 #include "chrome/browser/chrome_plugin_service_filter.h" | 
| 26 #include "chrome/browser/content_settings/cookie_settings.h" | 26 #include "chrome/browser/content_settings/cookie_settings.h" | 
| 27 #include "chrome/browser/content_settings/host_content_settings_map.h" | 27 #include "chrome/browser/content_settings/host_content_settings_map.h" | 
| 28 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 28 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 
| 29 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" | |
| 29 #include "chrome/browser/download/download_service.h" | 30 #include "chrome/browser/download/download_service.h" | 
| 30 #include "chrome/browser/download/download_service_factory.h" | 31 #include "chrome/browser/download/download_service_factory.h" | 
| 31 #include "chrome/browser/extensions/extension_event_router.h" | 32 #include "chrome/browser/extensions/extension_event_router.h" | 
| 32 #include "chrome/browser/extensions/extension_pref_store.h" | 33 #include "chrome/browser/extensions/extension_pref_store.h" | 
| 33 #include "chrome/browser/extensions/extension_pref_value_map.h" | 34 #include "chrome/browser/extensions/extension_pref_value_map.h" | 
| 34 #include "chrome/browser/extensions/extension_pref_value_map_factory.h" | 35 #include "chrome/browser/extensions/extension_pref_value_map_factory.h" | 
| 35 #include "chrome/browser/extensions/extension_process_manager.h" | 36 #include "chrome/browser/extensions/extension_process_manager.h" | 
| 36 #include "chrome/browser/extensions/extension_service.h" | 37 #include "chrome/browser/extensions/extension_service.h" | 
| 37 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 38 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 
| 38 #include "chrome/browser/extensions/extension_system.h" | 39 #include "chrome/browser/extensions/extension_system.h" | 
| 39 #include "chrome/browser/extensions/user_script_master.h" | 40 #include "chrome/browser/extensions/user_script_master.h" | 
| 40 #include "chrome/browser/favicon/favicon_service.h" | 41 #include "chrome/browser/favicon/favicon_service.h" | 
| 41 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" | 42 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" | 
| 42 #include "chrome/browser/history/history.h" | 43 #include "chrome/browser/history/history.h" | 
| 43 #include "chrome/browser/history/history_service_factory.h" | 44 #include "chrome/browser/history/history_service_factory.h" | 
| 44 #include "chrome/browser/history/shortcuts_backend.h" | 45 #include "chrome/browser/history/shortcuts_backend.h" | 
| 45 #include "chrome/browser/history/top_sites.h" | 46 #include "chrome/browser/history/top_sites.h" | 
| 46 #include "chrome/browser/instant/instant_controller.h" | 47 #include "chrome/browser/instant/instant_controller.h" | 
| 48 #include "chrome/browser/intents/web_intents_registry.h" | |
| 49 #include "chrome/browser/intents/web_intents_registry_factory.h" | |
| 47 #include "chrome/browser/metrics/metrics_service.h" | 50 #include "chrome/browser/metrics/metrics_service.h" | 
| 48 #include "chrome/browser/net/chrome_url_request_context.h" | 51 #include "chrome/browser/net/chrome_url_request_context.h" | 
| 49 #include "chrome/browser/net/net_pref_observer.h" | 52 #include "chrome/browser/net/net_pref_observer.h" | 
| 50 #include "chrome/browser/net/predictor.h" | 53 #include "chrome/browser/net/predictor.h" | 
| 51 #include "chrome/browser/net/proxy_service_factory.h" | 54 #include "chrome/browser/net/proxy_service_factory.h" | 
| 52 #include "chrome/browser/net/ssl_config_service_manager.h" | 55 #include "chrome/browser/net/ssl_config_service_manager.h" | 
| 53 #include "chrome/browser/net/url_fixer_upper.h" | 56 #include "chrome/browser/net/url_fixer_upper.h" | 
| 54 #include "chrome/browser/plugin_prefs.h" | 57 #include "chrome/browser/plugin_prefs.h" | 
| 55 #include "chrome/browser/policy/policy_service.h" | 58 #include "chrome/browser/policy/policy_service.h" | 
| 56 #include "chrome/browser/prefs/browser_prefs.h" | 59 #include "chrome/browser/prefs/browser_prefs.h" | 
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 329 bool init_background_mode_manager = true; | 332 bool init_background_mode_manager = true; | 
| 330 #if defined(OS_CHROMEOS) | 333 #if defined(OS_CHROMEOS) | 
| 331 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kKeepAliveForTest)) | 334 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kKeepAliveForTest)) | 
| 332 init_background_mode_manager = false; | 335 init_background_mode_manager = false; | 
| 333 #endif | 336 #endif | 
| 334 if (init_background_mode_manager) { | 337 if (init_background_mode_manager) { | 
| 335 if (g_browser_process->background_mode_manager()) | 338 if (g_browser_process->background_mode_manager()) | 
| 336 g_browser_process->background_mode_manager()->RegisterProfile(this); | 339 g_browser_process->background_mode_manager()->RegisterProfile(this); | 
| 337 } | 340 } | 
| 338 | 341 | 
| 339 InitRegisteredProtocolHandlers(); | |
| 
 
Steve McKay
2012/06/14 04:05:04
I've been trying to figure out if we need to prese
 
 | |
| 340 | |
| 341 InstantController::RecordMetrics(this); | 342 InstantController::RecordMetrics(this); | 
| 342 | 343 | 
| 343 FilePath cookie_path = GetPath(); | 344 FilePath cookie_path = GetPath(); | 
| 344 cookie_path = cookie_path.Append(chrome::kCookieFilename); | 345 cookie_path = cookie_path.Append(chrome::kCookieFilename); | 
| 345 FilePath server_bound_cert_path = GetPath(); | 346 FilePath server_bound_cert_path = GetPath(); | 
| 346 server_bound_cert_path = | 347 server_bound_cert_path = | 
| 347 server_bound_cert_path.Append(chrome::kOBCertFilename); | 348 server_bound_cert_path.Append(chrome::kOBCertFilename); | 
| 348 FilePath cache_path = base_cache_path_; | 349 FilePath cache_path = base_cache_path_; | 
| 349 int cache_max_size; | 350 int cache_max_size; | 
| 350 GetCacheParameters(false, &cache_path, &cache_max_size); | 351 GetCacheParameters(false, &cache_path, &cache_max_size); | 
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 435 void ProfileImpl::InitPromoResources() { | 436 void ProfileImpl::InitPromoResources() { | 
| 436 #if defined(ENABLE_PROMO_RESOURCE_SERVICE) | 437 #if defined(ENABLE_PROMO_RESOURCE_SERVICE) | 
| 437 if (promo_resource_service_) | 438 if (promo_resource_service_) | 
| 438 return; | 439 return; | 
| 439 | 440 | 
| 440 promo_resource_service_ = new PromoResourceService(this); | 441 promo_resource_service_ = new PromoResourceService(this); | 
| 441 promo_resource_service_->StartAfterDelay(); | 442 promo_resource_service_->StartAfterDelay(); | 
| 442 #endif | 443 #endif | 
| 443 } | 444 } | 
| 444 | 445 | 
| 445 void ProfileImpl::InitRegisteredProtocolHandlers() { | |
| 446 if (protocol_handler_registry_) | |
| 447 return; | |
| 448 protocol_handler_registry_ = new ProtocolHandlerRegistry(this, | |
| 449 new ProtocolHandlerRegistry::Delegate()); | |
| 450 | |
| 451 // Install predefined protocol handlers. | |
| 452 InstallDefaultProtocolHandlers(); | |
| 453 | |
| 454 protocol_handler_registry_->Load(); | |
| 455 } | |
| 456 | |
| 457 void ProfileImpl::InstallDefaultProtocolHandlers() { | |
| 458 #if defined(OS_CHROMEOS) | |
| 459 protocol_handler_registry_->AddPredefinedHandler( | |
| 460 ProtocolHandler::CreateProtocolHandler( | |
| 461 "mailto", | |
| 462 GURL(l10n_util::GetStringUTF8(IDS_GOOGLE_MAILTO_HANDLER_URL)), | |
| 463 l10n_util::GetStringUTF16(IDS_GOOGLE_MAILTO_HANDLER_NAME))); | |
| 464 protocol_handler_registry_->AddPredefinedHandler( | |
| 465 ProtocolHandler::CreateProtocolHandler( | |
| 466 "webcal", | |
| 467 GURL(l10n_util::GetStringUTF8(IDS_GOOGLE_WEBCAL_HANDLER_URL)), | |
| 468 l10n_util::GetStringUTF16(IDS_GOOGLE_WEBCAL_HANDLER_NAME))); | |
| 469 #endif | |
| 470 } | |
| 471 | |
| 472 FilePath ProfileImpl::last_selected_directory() { | 446 FilePath ProfileImpl::last_selected_directory() { | 
| 473 return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory); | 447 return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory); | 
| 474 } | 448 } | 
| 475 | 449 | 
| 476 void ProfileImpl::set_last_selected_directory(const FilePath& path) { | 450 void ProfileImpl::set_last_selected_directory(const FilePath& path) { | 
| 477 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path); | 451 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path); | 
| 478 } | 452 } | 
| 479 | 453 | 
| 480 ProfileImpl::~ProfileImpl() { | 454 ProfileImpl::~ProfileImpl() { | 
| 481 content::NotificationService::current()->Notify( | 455 content::NotificationService::current()->Notify( | 
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 515 if (top_sites_.get()) | 489 if (top_sites_.get()) | 
| 516 top_sites_->Shutdown(); | 490 top_sites_->Shutdown(); | 
| 517 | 491 | 
| 518 // FaviconService depends on HistoryServce so make sure we delete | 492 // FaviconService depends on HistoryServce so make sure we delete | 
| 519 // HistoryService first. | 493 // HistoryService first. | 
| 520 favicon_service_.reset(); | 494 favicon_service_.reset(); | 
| 521 | 495 | 
| 522 if (pref_proxy_config_tracker_.get()) | 496 if (pref_proxy_config_tracker_.get()) | 
| 523 pref_proxy_config_tracker_->DetachFromPrefService(); | 497 pref_proxy_config_tracker_->DetachFromPrefService(); | 
| 524 | 498 | 
| 525 if (protocol_handler_registry_) | |
| 526 protocol_handler_registry_->Finalize(); | |
| 527 | |
| 528 if (host_content_settings_map_) | 499 if (host_content_settings_map_) | 
| 529 host_content_settings_map_->ShutdownOnUIThread(); | 500 host_content_settings_map_->ShutdownOnUIThread(); | 
| 530 | 501 | 
| 531 // This causes the Preferences file to be written to disk. | 502 // This causes the Preferences file to be written to disk. | 
| 532 if (prefs_loaded) | 503 if (prefs_loaded) | 
| 533 MarkAsCleanShutdown(); | 504 MarkAsCleanShutdown(); | 
| 534 } | 505 } | 
| 535 | 506 | 
| 536 std::string ProfileImpl::GetProfileName() { | 507 std::string ProfileImpl::GetProfileName() { | 
| 537 return GetPrefs()->GetString(prefs::kGoogleServicesUsername); | 508 return GetPrefs()->GetString(prefs::kGoogleServicesUsername); | 
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 805 | 776 | 
| 806 quota::SpecialStoragePolicy* ProfileImpl::GetSpecialStoragePolicy() { | 777 quota::SpecialStoragePolicy* ProfileImpl::GetSpecialStoragePolicy() { | 
| 807 return GetExtensionSpecialStoragePolicy(); | 778 return GetExtensionSpecialStoragePolicy(); | 
| 808 } | 779 } | 
| 809 | 780 | 
| 810 BookmarkModel* ProfileImpl::GetBookmarkModel() { | 781 BookmarkModel* ProfileImpl::GetBookmarkModel() { | 
| 811 return BookmarkModelFactory::GetForProfile(this); | 782 return BookmarkModelFactory::GetForProfile(this); | 
| 812 } | 783 } | 
| 813 | 784 | 
| 814 ProtocolHandlerRegistry* ProfileImpl::GetProtocolHandlerRegistry() { | 785 ProtocolHandlerRegistry* ProfileImpl::GetProtocolHandlerRegistry() { | 
| 815 return protocol_handler_registry_.get(); | 786 // TODO(smckay): Update all existing callers to use | 
| 787 // ProtocolHandlerRegistryFactory. Once that's done, this method | |
| 788 // can be nuked from Profile and ProfileImpl. | |
| 789 return ProtocolHandlerRegistryFactory::GetForProfile(this); | |
| 816 } | 790 } | 
| 817 | 791 | 
| 818 bool ProfileImpl::IsSameProfile(Profile* profile) { | 792 bool ProfileImpl::IsSameProfile(Profile* profile) { | 
| 819 if (profile == static_cast<Profile*>(this)) | 793 if (profile == static_cast<Profile*>(this)) | 
| 820 return true; | 794 return true; | 
| 821 Profile* otr_profile = off_the_record_profile_.get(); | 795 Profile* otr_profile = off_the_record_profile_.get(); | 
| 822 return otr_profile && profile == otr_profile; | 796 return otr_profile && profile == otr_profile; | 
| 823 } | 797 } | 
| 824 | 798 | 
| 825 Time ProfileImpl::GetStartTime() const { | 799 Time ProfileImpl::GetStartTime() const { | 
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1101 if (!path.empty()) | 1075 if (!path.empty()) | 
| 1102 *cache_path = path; | 1076 *cache_path = path; | 
| 1103 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : | 1077 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : | 
| 1104 prefs_->GetInteger(prefs::kDiskCacheSize); | 1078 prefs_->GetInteger(prefs::kDiskCacheSize); | 
| 1105 } | 1079 } | 
| 1106 | 1080 | 
| 1107 base::Callback<ChromeURLDataManagerBackend*(void)> | 1081 base::Callback<ChromeURLDataManagerBackend*(void)> | 
| 1108 ProfileImpl::GetChromeURLDataManagerBackendGetter() const { | 1082 ProfileImpl::GetChromeURLDataManagerBackendGetter() const { | 
| 1109 return io_data_.GetChromeURLDataManagerBackendGetter(); | 1083 return io_data_.GetChromeURLDataManagerBackendGetter(); | 
| 1110 } | 1084 } | 
| OLD | NEW |