| 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_io_data.h" | 5 #include "chrome/browser/profiles/profile_io_data.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 26 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 27 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" | 27 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" |
| 28 #include "chrome/browser/download/download_service.h" | 28 #include "chrome/browser/download/download_service.h" |
| 29 #include "chrome/browser/download/download_service_factory.h" | 29 #include "chrome/browser/download/download_service_factory.h" |
| 30 #include "chrome/browser/extensions/extension_info_map.h" | 30 #include "chrome/browser/extensions/extension_info_map.h" |
| 31 #include "chrome/browser/extensions/extension_protocols.h" | 31 #include "chrome/browser/extensions/extension_protocols.h" |
| 32 #include "chrome/browser/extensions/extension_resource_protocols.h" | 32 #include "chrome/browser/extensions/extension_resource_protocols.h" |
| 33 #include "chrome/browser/extensions/extension_system.h" | 33 #include "chrome/browser/extensions/extension_system.h" |
| 34 #include "chrome/browser/io_thread.h" | 34 #include "chrome/browser/io_thread.h" |
| 35 #include "chrome/browser/net/about_protocol_handler.h" | 35 #include "chrome/browser/net/about_protocol_handler.h" |
| 36 #include "chrome/browser/net/chrome_cookie_notification_details.h" | |
| 37 #include "chrome/browser/net/chrome_fraudulent_certificate_reporter.h" | 36 #include "chrome/browser/net/chrome_fraudulent_certificate_reporter.h" |
| 38 #include "chrome/browser/net/chrome_http_user_agent_settings.h" | 37 #include "chrome/browser/net/chrome_http_user_agent_settings.h" |
| 39 #include "chrome/browser/net/chrome_net_log.h" | 38 #include "chrome/browser/net/chrome_net_log.h" |
| 40 #include "chrome/browser/net/chrome_network_delegate.h" | 39 #include "chrome/browser/net/chrome_network_delegate.h" |
| 41 #include "chrome/browser/net/evicted_domain_cookie_counter.h" | 40 #include "chrome/browser/net/evicted_domain_cookie_counter.h" |
| 42 #include "chrome/browser/net/load_time_stats.h" | 41 #include "chrome/browser/net/load_time_stats.h" |
| 43 #include "chrome/browser/net/proxy_service_factory.h" | 42 #include "chrome/browser/net/proxy_service_factory.h" |
| 44 #include "chrome/browser/net/resource_prefetch_predictor_observer.h" | 43 #include "chrome/browser/net/resource_prefetch_predictor_observer.h" |
| 45 #include "chrome/browser/net/transport_security_persister.h" | 44 #include "chrome/browser/net/transport_security_persister.h" |
| 46 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 45 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 47 #include "chrome/browser/policy/url_blacklist_manager.h" | 46 #include "chrome/browser/policy/url_blacklist_manager.h" |
| 48 #include "chrome/browser/predictors/resource_prefetch_predictor.h" | 47 #include "chrome/browser/predictors/resource_prefetch_predictor.h" |
| 49 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h" | 48 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h" |
| 50 #include "chrome/browser/profiles/profile.h" | 49 #include "chrome/browser/profiles/profile.h" |
| 51 #include "chrome/browser/profiles/profile_manager.h" | 50 #include "chrome/browser/profiles/profile_manager.h" |
| 52 #include "chrome/browser/signin/signin_names_io_thread.h" | 51 #include "chrome/browser/signin/signin_names_io_thread.h" |
| 53 #include "chrome/common/chrome_paths.h" | 52 #include "chrome/common/chrome_paths.h" |
| 54 #include "chrome/common/chrome_switches.h" | 53 #include "chrome/common/chrome_switches.h" |
| 55 #include "chrome/common/pref_names.h" | 54 #include "chrome/common/pref_names.h" |
| 56 #include "chrome/common/startup_metric_utils.h" | 55 #include "chrome/common/startup_metric_utils.h" |
| 57 #include "chrome/common/url_constants.h" | 56 #include "chrome/common/url_constants.h" |
| 58 #include "content/public/browser/browser_thread.h" | 57 #include "content/public/browser/browser_thread.h" |
| 59 #include "content/public/browser/host_zoom_map.h" | 58 #include "content/public/browser/host_zoom_map.h" |
| 60 #include "content/public/browser/notification_service.h" | 59 #include "content/public/browser/notification_service.h" |
| 61 #include "content/public/browser/resource_context.h" | 60 #include "content/public/browser/resource_context.h" |
| 62 #include "extensions/common/constants.h" | 61 #include "extensions/common/constants.h" |
| 63 #include "net/cert/cert_verifier.h" | 62 #include "net/cert/cert_verifier.h" |
| 64 #include "net/cookies/canonical_cookie.h" | 63 #include "net/cookies/canonical_cookie.h" |
| 65 #include "net/cookies/cookie_monster.h" | |
| 66 #include "net/http/http_transaction_factory.h" | 64 #include "net/http/http_transaction_factory.h" |
| 67 #include "net/http/http_util.h" | 65 #include "net/http/http_util.h" |
| 68 #include "net/proxy/proxy_config_service_fixed.h" | 66 #include "net/proxy/proxy_config_service_fixed.h" |
| 69 #include "net/proxy/proxy_script_fetcher_impl.h" | 67 #include "net/proxy/proxy_script_fetcher_impl.h" |
| 70 #include "net/proxy/proxy_service.h" | 68 #include "net/proxy/proxy_service.h" |
| 71 #include "net/ssl/server_bound_cert_service.h" | 69 #include "net/ssl/server_bound_cert_service.h" |
| 72 #include "net/url_request/data_protocol_handler.h" | 70 #include "net/url_request/data_protocol_handler.h" |
| 73 #include "net/url_request/file_protocol_handler.h" | 71 #include "net/url_request/file_protocol_handler.h" |
| 74 #include "net/url_request/ftp_protocol_handler.h" | 72 #include "net/url_request/ftp_protocol_handler.h" |
| 75 #include "net/url_request/protocol_intercept_job_factory.h" | 73 #include "net/url_request/protocol_intercept_job_factory.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 90 #include "chrome/browser/chromeos/settings/cros_settings_names.h" | 88 #include "chrome/browser/chromeos/settings/cros_settings_names.h" |
| 91 #include "chrome/browser/policy/browser_policy_connector.h" | 89 #include "chrome/browser/policy/browser_policy_connector.h" |
| 92 #endif // defined(OS_CHROMEOS) | 90 #endif // defined(OS_CHROMEOS) |
| 93 | 91 |
| 94 using content::BrowserContext; | 92 using content::BrowserContext; |
| 95 using content::BrowserThread; | 93 using content::BrowserThread; |
| 96 using content::ResourceContext; | 94 using content::ResourceContext; |
| 97 | 95 |
| 98 namespace { | 96 namespace { |
| 99 | 97 |
| 100 // ---------------------------------------------------------------------------- | |
| 101 // CookieMonster::Delegate implementation | |
| 102 // ---------------------------------------------------------------------------- | |
| 103 class ChromeCookieMonsterDelegate : public net::CookieMonster::Delegate { | |
| 104 public: | |
| 105 explicit ChromeCookieMonsterDelegate( | |
| 106 const base::Callback<Profile*(void)>& profile_getter) | |
| 107 : profile_getter_(profile_getter) { | |
| 108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 109 } | |
| 110 | |
| 111 // net::CookieMonster::Delegate implementation. | |
| 112 virtual void OnCookieChanged( | |
| 113 const net::CanonicalCookie& cookie, | |
| 114 bool removed, | |
| 115 net::CookieMonster::Delegate::ChangeCause cause) OVERRIDE { | |
| 116 BrowserThread::PostTask( | |
| 117 BrowserThread::UI, FROM_HERE, | |
| 118 base::Bind(&ChromeCookieMonsterDelegate::OnCookieChangedAsyncHelper, | |
| 119 this, cookie, removed, cause)); | |
| 120 } | |
| 121 | |
| 122 private: | |
| 123 virtual ~ChromeCookieMonsterDelegate() {} | |
| 124 | |
| 125 void OnCookieChangedAsyncHelper( | |
| 126 const net::CanonicalCookie& cookie, | |
| 127 bool removed, | |
| 128 net::CookieMonster::Delegate::ChangeCause cause) { | |
| 129 Profile* profile = profile_getter_.Run(); | |
| 130 if (profile) { | |
| 131 ChromeCookieDetails cookie_details(&cookie, removed, cause); | |
| 132 content::NotificationService::current()->Notify( | |
| 133 chrome::NOTIFICATION_COOKIE_CHANGED, | |
| 134 content::Source<Profile>(profile), | |
| 135 content::Details<ChromeCookieDetails>(&cookie_details)); | |
| 136 } | |
| 137 } | |
| 138 | |
| 139 const base::Callback<Profile*(void)> profile_getter_; | |
| 140 }; | |
| 141 | |
| 142 Profile* GetProfileOnUI(ProfileManager* profile_manager, Profile* profile) { | |
| 143 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 144 DCHECK(profile); | |
| 145 if (profile_manager->IsValidProfile(profile)) | |
| 146 return profile; | |
| 147 return NULL; | |
| 148 } | |
| 149 | |
| 150 #if defined(DEBUG_DEVTOOLS) | 98 #if defined(DEBUG_DEVTOOLS) |
| 151 bool IsSupportedDevToolsURL(const GURL& url, base::FilePath* path) { | 99 bool IsSupportedDevToolsURL(const GURL& url, base::FilePath* path) { |
| 152 std::string bundled_path_prefix(chrome::kChromeUIDevToolsBundledPath); | 100 std::string bundled_path_prefix(chrome::kChromeUIDevToolsBundledPath); |
| 153 bundled_path_prefix = "/" + bundled_path_prefix + "/"; | 101 bundled_path_prefix = "/" + bundled_path_prefix + "/"; |
| 154 | 102 |
| 155 if (!url.SchemeIs(chrome::kChromeDevToolsScheme) || | 103 if (!url.SchemeIs(chrome::kChromeDevToolsScheme) || |
| 156 url.host() != chrome::kChromeUIDevToolsHost || | 104 url.host() != chrome::kChromeUIDevToolsHost || |
| 157 !StartsWithASCII(url.path(), bundled_path_prefix, false)) { | 105 !StartsWithASCII(url.path(), bundled_path_prefix, false)) { |
| 158 return false; | 106 return false; |
| 159 } | 107 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 PrefService* local_state_pref_service = g_browser_process->local_state(); | 171 PrefService* local_state_pref_service = g_browser_process->local_state(); |
| 224 | 172 |
| 225 scoped_ptr<ProfileParams> params(new ProfileParams); | 173 scoped_ptr<ProfileParams> params(new ProfileParams); |
| 226 params->path = profile->GetPath(); | 174 params->path = profile->GetPath(); |
| 227 | 175 |
| 228 params->io_thread = g_browser_process->io_thread(); | 176 params->io_thread = g_browser_process->io_thread(); |
| 229 | 177 |
| 230 params->cookie_settings = CookieSettings::Factory::GetForProfile(profile); | 178 params->cookie_settings = CookieSettings::Factory::GetForProfile(profile); |
| 231 params->host_content_settings_map = profile->GetHostContentSettingsMap(); | 179 params->host_content_settings_map = profile->GetHostContentSettingsMap(); |
| 232 params->ssl_config_service = profile->GetSSLConfigService(); | 180 params->ssl_config_service = profile->GetSSLConfigService(); |
| 233 base::Callback<Profile*(void)> profile_getter = | |
| 234 base::Bind(&GetProfileOnUI, g_browser_process->profile_manager(), | |
| 235 profile); | |
| 236 params->cookie_monster_delegate = | |
| 237 new chrome_browser_net::EvictedDomainCookieCounter( | |
| 238 new ChromeCookieMonsterDelegate(profile_getter)); | |
| 239 params->extension_info_map = | 181 params->extension_info_map = |
| 240 extensions::ExtensionSystem::Get(profile)->info_map(); | 182 extensions::ExtensionSystem::Get(profile)->info_map(); |
| 241 | 183 |
| 242 if (predictors::ResourcePrefetchPredictor* predictor = | 184 if (predictors::ResourcePrefetchPredictor* predictor = |
| 243 predictors::ResourcePrefetchPredictorFactory::GetForProfile( | 185 predictors::ResourcePrefetchPredictorFactory::GetForProfile( |
| 244 profile)) { | 186 profile)) { |
| 245 resource_prefetch_predictor_observer_.reset( | 187 resource_prefetch_predictor_observer_.reset( |
| 246 new chrome_browser_net::ResourcePrefetchPredictorObserver(predictor)); | 188 new chrome_browser_net::ResourcePrefetchPredictorObserver(predictor)); |
| 247 } | 189 } |
| 248 | 190 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 } | 294 } |
| 353 | 295 |
| 354 ProfileIOData::MediaRequestContext::~MediaRequestContext() {} | 296 ProfileIOData::MediaRequestContext::~MediaRequestContext() {} |
| 355 | 297 |
| 356 ProfileIOData::AppRequestContext::AppRequestContext( | 298 ProfileIOData::AppRequestContext::AppRequestContext( |
| 357 chrome_browser_net::LoadTimeStats* load_time_stats) | 299 chrome_browser_net::LoadTimeStats* load_time_stats) |
| 358 : ChromeURLRequestContext(ChromeURLRequestContext::CONTEXT_TYPE_APP, | 300 : ChromeURLRequestContext(ChromeURLRequestContext::CONTEXT_TYPE_APP, |
| 359 load_time_stats) { | 301 load_time_stats) { |
| 360 } | 302 } |
| 361 | 303 |
| 362 void ProfileIOData::AppRequestContext::SetCookieStore( | |
| 363 net::CookieStore* cookie_store) { | |
| 364 cookie_store_ = cookie_store; | |
| 365 set_cookie_store(cookie_store); | |
| 366 } | |
| 367 | |
| 368 void ProfileIOData::AppRequestContext::SetHttpTransactionFactory( | 304 void ProfileIOData::AppRequestContext::SetHttpTransactionFactory( |
| 369 scoped_ptr<net::HttpTransactionFactory> http_factory) { | 305 scoped_ptr<net::HttpTransactionFactory> http_factory) { |
| 370 http_factory_ = http_factory.Pass(); | 306 http_factory_ = http_factory.Pass(); |
| 371 set_http_transaction_factory(http_factory_.get()); | 307 set_http_transaction_factory(http_factory_.get()); |
| 372 } | 308 } |
| 373 | 309 |
| 374 void ProfileIOData::AppRequestContext::SetJobFactory( | 310 void ProfileIOData::AppRequestContext::SetJobFactory( |
| 375 scoped_ptr<net::URLRequestJobFactory> job_factory) { | 311 scoped_ptr<net::URLRequestJobFactory> job_factory) { |
| 376 job_factory_ = job_factory.Pass(); | 312 job_factory_ = job_factory.Pass(); |
| 377 set_job_factory(job_factory_.get()); | 313 set_job_factory(job_factory_.get()); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 ++it, ++current_context) { | 383 ++it, ++current_context) { |
| 448 media_context_cache[current_context] = it->second; | 384 media_context_cache[current_context] = it->second; |
| 449 memcpy(&media_context_vtable_cache[current_context], | 385 memcpy(&media_context_vtable_cache[current_context], |
| 450 static_cast<void*>(it->second), sizeof(void*)); | 386 static_cast<void*>(it->second), sizeof(void*)); |
| 451 } | 387 } |
| 452 | 388 |
| 453 // TODO(ajwong): These AssertNoURLRequests() calls are unnecessary since they | 389 // TODO(ajwong): These AssertNoURLRequests() calls are unnecessary since they |
| 454 // are already done in the URLRequestContext destructor. | 390 // are already done in the URLRequestContext destructor. |
| 455 if (main_request_context_) | 391 if (main_request_context_) |
| 456 main_request_context_->AssertNoURLRequests(); | 392 main_request_context_->AssertNoURLRequests(); |
| 457 if (extensions_request_context_) | |
| 458 extensions_request_context_->AssertNoURLRequests(); | |
| 459 | 393 |
| 460 current_context = 0; | 394 current_context = 0; |
| 461 for (URLRequestContextMap::iterator it = app_request_context_map_.begin(); | 395 for (URLRequestContextMap::iterator it = app_request_context_map_.begin(); |
| 462 it != app_request_context_map_.end(); ++it) { | 396 it != app_request_context_map_.end(); ++it) { |
| 463 if (current_context < kMaxCachedContexts) { | 397 if (current_context < kMaxCachedContexts) { |
| 464 CHECK_EQ(app_context_cache[current_context], it->second); | 398 CHECK_EQ(app_context_cache[current_context], it->second); |
| 465 memcpy(&tmp_vtable, static_cast<void*>(it->second), sizeof(void*)); | 399 memcpy(&tmp_vtable, static_cast<void*>(it->second), sizeof(void*)); |
| 466 CHECK_EQ(app_context_vtable_cache[current_context], tmp_vtable); | 400 CHECK_EQ(app_context_vtable_cache[current_context], tmp_vtable); |
| 467 } | 401 } |
| 468 it->second->AssertNoURLRequests(); | 402 it->second->AssertNoURLRequests(); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 return main_request_context_.get(); | 487 return main_request_context_.get(); |
| 554 } | 488 } |
| 555 | 489 |
| 556 ChromeURLRequestContext* ProfileIOData::GetMediaRequestContext() const { | 490 ChromeURLRequestContext* ProfileIOData::GetMediaRequestContext() const { |
| 557 DCHECK(initialized_); | 491 DCHECK(initialized_); |
| 558 ChromeURLRequestContext* context = AcquireMediaRequestContext(); | 492 ChromeURLRequestContext* context = AcquireMediaRequestContext(); |
| 559 DCHECK(context); | 493 DCHECK(context); |
| 560 return context; | 494 return context; |
| 561 } | 495 } |
| 562 | 496 |
| 563 ChromeURLRequestContext* ProfileIOData::GetExtensionsRequestContext() const { | |
| 564 DCHECK(initialized_); | |
| 565 return extensions_request_context_.get(); | |
| 566 } | |
| 567 | |
| 568 ChromeURLRequestContext* ProfileIOData::GetIsolatedAppRequestContext( | 497 ChromeURLRequestContext* ProfileIOData::GetIsolatedAppRequestContext( |
| 569 ChromeURLRequestContext* main_context, | 498 ChromeURLRequestContext* main_context, |
| 570 const StoragePartitionDescriptor& partition_descriptor, | 499 const StoragePartitionDescriptor& partition_descriptor, |
| 571 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> | 500 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
| 572 protocol_handler_interceptor, | 501 protocol_handler_interceptor, |
| 573 content::ProtocolHandlerMap* protocol_handlers) const { | 502 content::ProtocolHandlerMap* protocol_handlers) const { |
| 574 DCHECK(initialized_); | 503 DCHECK(initialized_); |
| 575 ChromeURLRequestContext* context = NULL; | 504 ChromeURLRequestContext* context = NULL; |
| 576 if (ContainsKey(app_request_context_map_, partition_descriptor)) { | 505 if (ContainsKey(app_request_context_map_, partition_descriptor)) { |
| 577 context = app_request_context_map_[partition_descriptor]; | 506 context = app_request_context_map_[partition_descriptor]; |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 | 649 |
| 721 IOThread* const io_thread = profile_params_->io_thread; | 650 IOThread* const io_thread = profile_params_->io_thread; |
| 722 IOThread::Globals* const io_thread_globals = io_thread->globals(); | 651 IOThread::Globals* const io_thread_globals = io_thread->globals(); |
| 723 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 652 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 724 load_time_stats_ = GetLoadTimeStats(io_thread_globals); | 653 load_time_stats_ = GetLoadTimeStats(io_thread_globals); |
| 725 | 654 |
| 726 // Create the common request contexts. | 655 // Create the common request contexts. |
| 727 main_request_context_.reset( | 656 main_request_context_.reset( |
| 728 new ChromeURLRequestContext(ChromeURLRequestContext::CONTEXT_TYPE_MAIN, | 657 new ChromeURLRequestContext(ChromeURLRequestContext::CONTEXT_TYPE_MAIN, |
| 729 load_time_stats_)); | 658 load_time_stats_)); |
| 730 extensions_request_context_.reset( | |
| 731 new ChromeURLRequestContext( | |
| 732 ChromeURLRequestContext::CONTEXT_TYPE_EXTENSIONS, | |
| 733 load_time_stats_)); | |
| 734 | 659 |
| 735 ChromeNetworkDelegate* network_delegate = | 660 ChromeNetworkDelegate* network_delegate = |
| 736 new ChromeNetworkDelegate( | 661 new ChromeNetworkDelegate( |
| 737 io_thread_globals->extension_event_router_forwarder.get(), | 662 io_thread_globals->extension_event_router_forwarder.get(), |
| 738 &enable_referrers_); | 663 &enable_referrers_); |
| 739 network_delegate->set_extension_info_map( | 664 network_delegate->set_extension_info_map( |
| 740 profile_params_->extension_info_map.get()); | 665 profile_params_->extension_info_map.get()); |
| 741 network_delegate->set_url_blacklist_manager(url_blacklist_manager_.get()); | 666 network_delegate->set_url_blacklist_manager(url_blacklist_manager_.get()); |
| 742 network_delegate->set_profile(profile_params_->profile); | 667 network_delegate->set_profile(profile_params_->profile); |
| 743 network_delegate->set_cookie_settings(profile_params_->cookie_settings.get()); | 668 network_delegate->set_cookie_settings(profile_params_->cookie_settings.get()); |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 936 void ProfileIOData::SetCookieSettingsForTesting( | 861 void ProfileIOData::SetCookieSettingsForTesting( |
| 937 CookieSettings* cookie_settings) { | 862 CookieSettings* cookie_settings) { |
| 938 DCHECK(!cookie_settings_.get()); | 863 DCHECK(!cookie_settings_.get()); |
| 939 cookie_settings_ = cookie_settings; | 864 cookie_settings_ = cookie_settings; |
| 940 } | 865 } |
| 941 | 866 |
| 942 void ProfileIOData::set_signin_names_for_testing( | 867 void ProfileIOData::set_signin_names_for_testing( |
| 943 SigninNamesOnIOThread* signin_names) { | 868 SigninNamesOnIOThread* signin_names) { |
| 944 signin_names_.reset(signin_names); | 869 signin_names_.reset(signin_names); |
| 945 } | 870 } |
| OLD | NEW |