Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(900)

Side by Side Diff: chrome/browser/profiles/profile_impl.cc

Issue 10546083: Convert ProtocolHandlerRegistry to be a ProfileKeyedService. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Respond to Will's comments. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
benwells 2012/06/22 23:31:27 Why are these includes needed?
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
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();
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
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
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 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 769
799 quota::SpecialStoragePolicy* ProfileImpl::GetSpecialStoragePolicy() { 770 quota::SpecialStoragePolicy* ProfileImpl::GetSpecialStoragePolicy() {
800 return GetExtensionSpecialStoragePolicy(); 771 return GetExtensionSpecialStoragePolicy();
801 } 772 }
802 773
803 BookmarkModel* ProfileImpl::GetBookmarkModel() { 774 BookmarkModel* ProfileImpl::GetBookmarkModel() {
804 return BookmarkModelFactory::GetForProfile(this); 775 return BookmarkModelFactory::GetForProfile(this);
805 } 776 }
806 777
807 ProtocolHandlerRegistry* ProfileImpl::GetProtocolHandlerRegistry() { 778 ProtocolHandlerRegistry* ProfileImpl::GetProtocolHandlerRegistry() {
808 return protocol_handler_registry_.get(); 779 // TODO(smckay): Update all existing callers to use
780 // ProtocolHandlerRegistryFactory. Once that's done, this method
781 // can be nuked from Profile and ProfileImpl.
782 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
783 return ProtocolHandlerRegistryFactory::GetForProfile(this);
809 } 784 }
810 785
811 bool ProfileImpl::IsSameProfile(Profile* profile) { 786 bool ProfileImpl::IsSameProfile(Profile* profile) {
812 if (profile == static_cast<Profile*>(this)) 787 if (profile == static_cast<Profile*>(this))
813 return true; 788 return true;
814 Profile* otr_profile = off_the_record_profile_.get(); 789 Profile* otr_profile = off_the_record_profile_.get();
815 return otr_profile && profile == otr_profile; 790 return otr_profile && profile == otr_profile;
816 } 791 }
817 792
818 Time ProfileImpl::GetStartTime() const { 793 Time ProfileImpl::GetStartTime() const {
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 if (!path.empty()) 1069 if (!path.empty())
1095 *cache_path = path; 1070 *cache_path = path;
1096 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) : 1071 *max_size = is_media_context ? prefs_->GetInteger(prefs::kMediaCacheSize) :
1097 prefs_->GetInteger(prefs::kDiskCacheSize); 1072 prefs_->GetInteger(prefs::kDiskCacheSize);
1098 } 1073 }
1099 1074
1100 base::Callback<ChromeURLDataManagerBackend*(void)> 1075 base::Callback<ChromeURLDataManagerBackend*(void)>
1101 ProfileImpl::GetChromeURLDataManagerBackendGetter() const { 1076 ProfileImpl::GetChromeURLDataManagerBackendGetter() const {
1102 return io_data_.GetChromeURLDataManagerBackendGetter(); 1077 return io_data_.GetChromeURLDataManagerBackendGetter();
1103 } 1078 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698