| 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_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
| 16 #include "base/string_tokenizer.h" | 16 #include "base/string_tokenizer.h" |
| 17 #include "base/string_util.h" | 17 #include "base/string_util.h" |
| 18 #include "base/stringprintf.h" | 18 #include "base/stringprintf.h" |
| 19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
| 20 #include "base/version.h" | 20 #include "base/version.h" |
| 21 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 21 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
| 22 #include "chrome/browser/background/background_contents_service_factory.h" | 22 #include "chrome/browser/background/background_contents_service_factory.h" |
| 23 #include "chrome/browser/background/background_mode_manager.h" | 23 #include "chrome/browser/background/background_mode_manager.h" |
| 24 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 24 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 25 #include "chrome/browser/browser_process.h" | 25 #include "chrome/browser/browser_process.h" |
| 26 #include "chrome/browser/chrome_plugin_service_filter.h" | 26 #include "chrome/browser/chrome_plugin_service_filter.h" |
| 27 #include "chrome/browser/content_settings/cookie_settings.h" | 27 #include "chrome/browser/content_settings/cookie_settings.h" |
| 28 #include "chrome/browser/content_settings/host_content_settings_map.h" | 28 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 29 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 29 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 30 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" |
| 30 #include "chrome/browser/download/download_service.h" | 31 #include "chrome/browser/download/download_service.h" |
| 31 #include "chrome/browser/download/download_service_factory.h" | 32 #include "chrome/browser/download/download_service_factory.h" |
| 32 #include "chrome/browser/extensions/extension_event_router.h" | 33 #include "chrome/browser/extensions/extension_event_router.h" |
| 33 #include "chrome/browser/extensions/extension_pref_store.h" | 34 #include "chrome/browser/extensions/extension_pref_store.h" |
| 34 #include "chrome/browser/extensions/extension_pref_value_map.h" | 35 #include "chrome/browser/extensions/extension_pref_value_map.h" |
| 35 #include "chrome/browser/extensions/extension_pref_value_map_factory.h" | 36 #include "chrome/browser/extensions/extension_pref_value_map_factory.h" |
| 36 #include "chrome/browser/extensions/extension_process_manager.h" | 37 #include "chrome/browser/extensions/extension_process_manager.h" |
| 37 #include "chrome/browser/extensions/extension_service.h" | 38 #include "chrome/browser/extensions/extension_service.h" |
| 38 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 39 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
| 39 #include "chrome/browser/extensions/extension_system.h" | 40 #include "chrome/browser/extensions/extension_system.h" |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 bool init_background_mode_manager = true; | 347 bool init_background_mode_manager = true; |
| 347 #if defined(OS_CHROMEOS) | 348 #if defined(OS_CHROMEOS) |
| 348 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kKeepAliveForTest)) | 349 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kKeepAliveForTest)) |
| 349 init_background_mode_manager = false; | 350 init_background_mode_manager = false; |
| 350 #endif | 351 #endif |
| 351 if (init_background_mode_manager) { | 352 if (init_background_mode_manager) { |
| 352 if (g_browser_process->background_mode_manager()) | 353 if (g_browser_process->background_mode_manager()) |
| 353 g_browser_process->background_mode_manager()->RegisterProfile(this); | 354 g_browser_process->background_mode_manager()->RegisterProfile(this); |
| 354 } | 355 } |
| 355 | 356 |
| 356 InitRegisteredProtocolHandlers(); | |
| 357 | |
| 358 InstantController::RecordMetrics(this); | 357 InstantController::RecordMetrics(this); |
| 359 | 358 |
| 360 FilePath cookie_path = GetPath(); | 359 FilePath cookie_path = GetPath(); |
| 361 cookie_path = cookie_path.Append(chrome::kCookieFilename); | 360 cookie_path = cookie_path.Append(chrome::kCookieFilename); |
| 362 FilePath server_bound_cert_path = GetPath(); | 361 FilePath server_bound_cert_path = GetPath(); |
| 363 server_bound_cert_path = | 362 server_bound_cert_path = |
| 364 server_bound_cert_path.Append(chrome::kOBCertFilename); | 363 server_bound_cert_path.Append(chrome::kOBCertFilename); |
| 365 FilePath cache_path = base_cache_path_; | 364 FilePath cache_path = base_cache_path_; |
| 366 int cache_max_size; | 365 int cache_max_size; |
| 367 GetCacheParameters(false, &cache_path, &cache_max_size); | 366 GetCacheParameters(false, &cache_path, &cache_max_size); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 void ProfileImpl::InitPromoResources() { | 451 void ProfileImpl::InitPromoResources() { |
| 453 #if defined(ENABLE_PROMO_RESOURCE_SERVICE) | 452 #if defined(ENABLE_PROMO_RESOURCE_SERVICE) |
| 454 if (promo_resource_service_) | 453 if (promo_resource_service_) |
| 455 return; | 454 return; |
| 456 | 455 |
| 457 promo_resource_service_ = new PromoResourceService(this); | 456 promo_resource_service_ = new PromoResourceService(this); |
| 458 promo_resource_service_->StartAfterDelay(); | 457 promo_resource_service_->StartAfterDelay(); |
| 459 #endif | 458 #endif |
| 460 } | 459 } |
| 461 | 460 |
| 462 void ProfileImpl::InitRegisteredProtocolHandlers() { | |
| 463 if (protocol_handler_registry_) | |
| 464 return; | |
| 465 protocol_handler_registry_ = new ProtocolHandlerRegistry(this, | |
| 466 new ProtocolHandlerRegistry::Delegate()); | |
| 467 | |
| 468 // Install predefined protocol handlers. | |
| 469 InstallDefaultProtocolHandlers(); | |
| 470 | |
| 471 protocol_handler_registry_->Load(); | |
| 472 } | |
| 473 | |
| 474 void ProfileImpl::InstallDefaultProtocolHandlers() { | |
| 475 #if defined(OS_CHROMEOS) | |
| 476 protocol_handler_registry_->AddPredefinedHandler( | |
| 477 ProtocolHandler::CreateProtocolHandler( | |
| 478 "mailto", | |
| 479 GURL(l10n_util::GetStringUTF8(IDS_GOOGLE_MAILTO_HANDLER_URL)), | |
| 480 l10n_util::GetStringUTF16(IDS_GOOGLE_MAILTO_HANDLER_NAME))); | |
| 481 protocol_handler_registry_->AddPredefinedHandler( | |
| 482 ProtocolHandler::CreateProtocolHandler( | |
| 483 "webcal", | |
| 484 GURL(l10n_util::GetStringUTF8(IDS_GOOGLE_WEBCAL_HANDLER_URL)), | |
| 485 l10n_util::GetStringUTF16(IDS_GOOGLE_WEBCAL_HANDLER_NAME))); | |
| 486 #endif | |
| 487 } | |
| 488 | |
| 489 FilePath ProfileImpl::last_selected_directory() { | 461 FilePath ProfileImpl::last_selected_directory() { |
| 490 return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory); | 462 return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory); |
| 491 } | 463 } |
| 492 | 464 |
| 493 void ProfileImpl::set_last_selected_directory(const FilePath& path) { | 465 void ProfileImpl::set_last_selected_directory(const FilePath& path) { |
| 494 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path); | 466 GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path); |
| 495 } | 467 } |
| 496 | 468 |
| 497 ProfileImpl::~ProfileImpl() { | 469 ProfileImpl::~ProfileImpl() { |
| 498 content::NotificationService::current()->Notify( | 470 content::NotificationService::current()->Notify( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 if (top_sites_.get()) | 505 if (top_sites_.get()) |
| 534 top_sites_->Shutdown(); | 506 top_sites_->Shutdown(); |
| 535 | 507 |
| 536 // FaviconService depends on HistoryServce so make sure we delete | 508 // FaviconService depends on HistoryServce so make sure we delete |
| 537 // HistoryService first. | 509 // HistoryService first. |
| 538 favicon_service_.reset(); | 510 favicon_service_.reset(); |
| 539 | 511 |
| 540 if (pref_proxy_config_tracker_.get()) | 512 if (pref_proxy_config_tracker_.get()) |
| 541 pref_proxy_config_tracker_->DetachFromPrefService(); | 513 pref_proxy_config_tracker_->DetachFromPrefService(); |
| 542 | 514 |
| 543 if (protocol_handler_registry_) | |
| 544 protocol_handler_registry_->Finalize(); | |
| 545 | |
| 546 if (host_content_settings_map_) | 515 if (host_content_settings_map_) |
| 547 host_content_settings_map_->ShutdownOnUIThread(); | 516 host_content_settings_map_->ShutdownOnUIThread(); |
| 548 | 517 |
| 549 // This causes the Preferences file to be written to disk. | 518 // This causes the Preferences file to be written to disk. |
| 550 if (prefs_loaded) | 519 if (prefs_loaded) |
| 551 MarkAsCleanShutdown(); | 520 MarkAsCleanShutdown(); |
| 552 } | 521 } |
| 553 | 522 |
| 554 std::string ProfileImpl::GetProfileName() { | 523 std::string ProfileImpl::GetProfileName() { |
| 555 return GetPrefs()->GetString(prefs::kGoogleServicesUsername); | 524 return GetPrefs()->GetString(prefs::kGoogleServicesUsername); |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 | 780 |
| 812 quota::SpecialStoragePolicy* ProfileImpl::GetSpecialStoragePolicy() { | 781 quota::SpecialStoragePolicy* ProfileImpl::GetSpecialStoragePolicy() { |
| 813 return GetExtensionSpecialStoragePolicy(); | 782 return GetExtensionSpecialStoragePolicy(); |
| 814 } | 783 } |
| 815 | 784 |
| 816 BookmarkModel* ProfileImpl::GetBookmarkModel() { | 785 BookmarkModel* ProfileImpl::GetBookmarkModel() { |
| 817 return BookmarkModelFactory::GetForProfile(this); | 786 return BookmarkModelFactory::GetForProfile(this); |
| 818 } | 787 } |
| 819 | 788 |
| 820 ProtocolHandlerRegistry* ProfileImpl::GetProtocolHandlerRegistry() { | 789 ProtocolHandlerRegistry* ProfileImpl::GetProtocolHandlerRegistry() { |
| 821 return protocol_handler_registry_.get(); | 790 // TODO(smckay): Update all existing callers to use |
| 791 // ProtocolHandlerRegistryFactory. Once that's done, this method |
| 792 // can be nuked from Profile and ProfileImpl. |
| 793 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 794 return ProtocolHandlerRegistryFactory::GetForProfile(this); |
| 822 } | 795 } |
| 823 | 796 |
| 824 bool ProfileImpl::IsSameProfile(Profile* profile) { | 797 bool ProfileImpl::IsSameProfile(Profile* profile) { |
| 825 if (profile == static_cast<Profile*>(this)) | 798 if (profile == static_cast<Profile*>(this)) |
| 826 return true; | 799 return true; |
| 827 Profile* otr_profile = off_the_record_profile_.get(); | 800 Profile* otr_profile = off_the_record_profile_.get(); |
| 828 return otr_profile && profile == otr_profile; | 801 return otr_profile && profile == otr_profile; |
| 829 } | 802 } |
| 830 | 803 |
| 831 Time ProfileImpl::GetStartTime() const { | 804 Time ProfileImpl::GetStartTime() const { |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1107 if (!path.empty()) | 1080 if (!path.empty()) |
| 1108 *cache_path = path; | 1081 *cache_path = path; |
| 1109 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : | 1082 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : |
| 1110 prefs_->GetInteger(prefs::kDiskCacheSize); | 1083 prefs_->GetInteger(prefs::kDiskCacheSize); |
| 1111 } | 1084 } |
| 1112 | 1085 |
| 1113 base::Callback<ChromeURLDataManagerBackend*(void)> | 1086 base::Callback<ChromeURLDataManagerBackend*(void)> |
| 1114 ProfileImpl::GetChromeURLDataManagerBackendGetter() const { | 1087 ProfileImpl::GetChromeURLDataManagerBackendGetter() const { |
| 1115 return io_data_.GetChromeURLDataManagerBackendGetter(); | 1088 return io_data_.GetChromeURLDataManagerBackendGetter(); |
| 1116 } | 1089 } |
| OLD | NEW |