| 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 18 matching lines...) Expand all Loading... |
| 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/custom_handlers/protocol_handler_registry_factory.h" |
| 31 #include "chrome/browser/download/download_service.h" | 31 #include "chrome/browser/download/download_service.h" |
| 32 #include "chrome/browser/download/download_service_factory.h" | 32 #include "chrome/browser/download/download_service_factory.h" |
| 33 #include "chrome/browser/extensions/extension_info_map.h" | 33 #include "chrome/browser/extensions/extension_info_map.h" |
| 34 #include "chrome/browser/extensions/extension_protocols.h" | 34 #include "chrome/browser/extensions/extension_protocols.h" |
| 35 #include "chrome/browser/extensions/extension_resource_protocols.h" | 35 #include "chrome/browser/extensions/extension_resource_protocols.h" |
| 36 #include "chrome/browser/extensions/extension_system.h" | 36 #include "chrome/browser/extensions/extension_system.h" |
| 37 #include "chrome/browser/io_thread.h" | 37 #include "chrome/browser/io_thread.h" |
| 38 #include "chrome/browser/net/about_protocol_handler.h" | 38 #include "chrome/browser/net/about_protocol_handler.h" |
| 39 #include "chrome/browser/net/chrome_cookie_notification_details.h" | |
| 40 #include "chrome/browser/net/chrome_fraudulent_certificate_reporter.h" | 39 #include "chrome/browser/net/chrome_fraudulent_certificate_reporter.h" |
| 41 #include "chrome/browser/net/chrome_http_user_agent_settings.h" | 40 #include "chrome/browser/net/chrome_http_user_agent_settings.h" |
| 42 #include "chrome/browser/net/chrome_net_log.h" | 41 #include "chrome/browser/net/chrome_net_log.h" |
| 43 #include "chrome/browser/net/chrome_network_delegate.h" | 42 #include "chrome/browser/net/chrome_network_delegate.h" |
| 44 #include "chrome/browser/net/evicted_domain_cookie_counter.h" | 43 #include "chrome/browser/net/evicted_domain_cookie_counter.h" |
| 45 #include "chrome/browser/net/load_time_stats.h" | 44 #include "chrome/browser/net/load_time_stats.h" |
| 46 #include "chrome/browser/net/proxy_service_factory.h" | 45 #include "chrome/browser/net/proxy_service_factory.h" |
| 47 #include "chrome/browser/net/resource_prefetch_predictor_observer.h" | 46 #include "chrome/browser/net/resource_prefetch_predictor_observer.h" |
| 48 #include "chrome/browser/net/transport_security_persister.h" | 47 #include "chrome/browser/net/transport_security_persister.h" |
| 49 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 48 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 50 #include "chrome/browser/policy/url_blacklist_manager.h" | 49 #include "chrome/browser/policy/url_blacklist_manager.h" |
| 51 #include "chrome/browser/predictors/resource_prefetch_predictor.h" | 50 #include "chrome/browser/predictors/resource_prefetch_predictor.h" |
| 52 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h" | 51 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h" |
| 53 #include "chrome/browser/profiles/profile.h" | 52 #include "chrome/browser/profiles/profile.h" |
| 54 #include "chrome/browser/profiles/profile_manager.h" | 53 #include "chrome/browser/profiles/profile_manager.h" |
| 55 #include "chrome/browser/signin/signin_names_io_thread.h" | 54 #include "chrome/browser/signin/signin_names_io_thread.h" |
| 56 #include "chrome/common/chrome_paths.h" | 55 #include "chrome/common/chrome_paths.h" |
| 57 #include "chrome/common/chrome_switches.h" | 56 #include "chrome/common/chrome_switches.h" |
| 58 #include "chrome/common/pref_names.h" | 57 #include "chrome/common/pref_names.h" |
| 59 #include "chrome/common/startup_metric_utils.h" | 58 #include "chrome/common/startup_metric_utils.h" |
| 60 #include "chrome/common/url_constants.h" | 59 #include "chrome/common/url_constants.h" |
| 61 #include "content/public/browser/browser_thread.h" | 60 #include "content/public/browser/browser_thread.h" |
| 62 #include "content/public/browser/host_zoom_map.h" | 61 #include "content/public/browser/host_zoom_map.h" |
| 63 #include "content/public/browser/notification_service.h" | 62 #include "content/public/browser/notification_service.h" |
| 64 #include "content/public/browser/resource_context.h" | 63 #include "content/public/browser/resource_context.h" |
| 65 #include "extensions/common/constants.h" | 64 #include "extensions/common/constants.h" |
| 66 #include "net/cert/cert_verifier.h" | 65 #include "net/cert/cert_verifier.h" |
| 67 #include "net/cookies/canonical_cookie.h" | 66 #include "net/cookies/canonical_cookie.h" |
| 68 #include "net/cookies/cookie_monster.h" | |
| 69 #include "net/http/http_transaction_factory.h" | 67 #include "net/http/http_transaction_factory.h" |
| 70 #include "net/http/http_util.h" | 68 #include "net/http/http_util.h" |
| 71 #include "net/proxy/proxy_config_service_fixed.h" | 69 #include "net/proxy/proxy_config_service_fixed.h" |
| 72 #include "net/proxy/proxy_script_fetcher_impl.h" | 70 #include "net/proxy/proxy_script_fetcher_impl.h" |
| 73 #include "net/proxy/proxy_service.h" | 71 #include "net/proxy/proxy_service.h" |
| 74 #include "net/ssl/server_bound_cert_service.h" | 72 #include "net/ssl/server_bound_cert_service.h" |
| 75 #include "net/url_request/data_protocol_handler.h" | 73 #include "net/url_request/data_protocol_handler.h" |
| 76 #include "net/url_request/file_protocol_handler.h" | 74 #include "net/url_request/file_protocol_handler.h" |
| 77 #include "net/url_request/ftp_protocol_handler.h" | 75 #include "net/url_request/ftp_protocol_handler.h" |
| 78 #include "net/url_request/protocol_intercept_job_factory.h" | 76 #include "net/url_request/protocol_intercept_job_factory.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 94 #include "chrome/browser/policy/profile_policy_connector.h" | 92 #include "chrome/browser/policy/profile_policy_connector.h" |
| 95 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 93 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| 96 #endif // defined(OS_CHROMEOS) | 94 #endif // defined(OS_CHROMEOS) |
| 97 | 95 |
| 98 using content::BrowserContext; | 96 using content::BrowserContext; |
| 99 using content::BrowserThread; | 97 using content::BrowserThread; |
| 100 using content::ResourceContext; | 98 using content::ResourceContext; |
| 101 | 99 |
| 102 namespace { | 100 namespace { |
| 103 | 101 |
| 104 // ---------------------------------------------------------------------------- | |
| 105 // CookieMonster::Delegate implementation | |
| 106 // ---------------------------------------------------------------------------- | |
| 107 class ChromeCookieMonsterDelegate : public net::CookieMonster::Delegate { | |
| 108 public: | |
| 109 explicit ChromeCookieMonsterDelegate( | |
| 110 const base::Callback<Profile*(void)>& profile_getter) | |
| 111 : profile_getter_(profile_getter) { | |
| 112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 113 } | |
| 114 | |
| 115 // net::CookieMonster::Delegate implementation. | |
| 116 virtual void OnCookieChanged( | |
| 117 const net::CanonicalCookie& cookie, | |
| 118 bool removed, | |
| 119 net::CookieMonster::Delegate::ChangeCause cause) OVERRIDE { | |
| 120 BrowserThread::PostTask( | |
| 121 BrowserThread::UI, FROM_HERE, | |
| 122 base::Bind(&ChromeCookieMonsterDelegate::OnCookieChangedAsyncHelper, | |
| 123 this, cookie, removed, cause)); | |
| 124 } | |
| 125 | |
| 126 private: | |
| 127 virtual ~ChromeCookieMonsterDelegate() {} | |
| 128 | |
| 129 void OnCookieChangedAsyncHelper( | |
| 130 const net::CanonicalCookie& cookie, | |
| 131 bool removed, | |
| 132 net::CookieMonster::Delegate::ChangeCause cause) { | |
| 133 Profile* profile = profile_getter_.Run(); | |
| 134 if (profile) { | |
| 135 ChromeCookieDetails cookie_details(&cookie, removed, cause); | |
| 136 content::NotificationService::current()->Notify( | |
| 137 chrome::NOTIFICATION_COOKIE_CHANGED, | |
| 138 content::Source<Profile>(profile), | |
| 139 content::Details<ChromeCookieDetails>(&cookie_details)); | |
| 140 } | |
| 141 } | |
| 142 | |
| 143 const base::Callback<Profile*(void)> profile_getter_; | |
| 144 }; | |
| 145 | |
| 146 Profile* GetProfileOnUI(ProfileManager* profile_manager, Profile* profile) { | |
| 147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 148 DCHECK(profile); | |
| 149 if (profile_manager->IsValidProfile(profile)) | |
| 150 return profile; | |
| 151 return NULL; | |
| 152 } | |
| 153 | |
| 154 #if defined(DEBUG_DEVTOOLS) | 102 #if defined(DEBUG_DEVTOOLS) |
| 155 bool IsSupportedDevToolsURL(const GURL& url, base::FilePath* path) { | 103 bool IsSupportedDevToolsURL(const GURL& url, base::FilePath* path) { |
| 156 std::string bundled_path_prefix(chrome::kChromeUIDevToolsBundledPath); | 104 std::string bundled_path_prefix(chrome::kChromeUIDevToolsBundledPath); |
| 157 bundled_path_prefix = "/" + bundled_path_prefix + "/"; | 105 bundled_path_prefix = "/" + bundled_path_prefix + "/"; |
| 158 | 106 |
| 159 if (!url.SchemeIs(chrome::kChromeDevToolsScheme) || | 107 if (!url.SchemeIs(chrome::kChromeDevToolsScheme) || |
| 160 url.host() != chrome::kChromeUIDevToolsHost || | 108 url.host() != chrome::kChromeUIDevToolsHost || |
| 161 !StartsWithASCII(url.path(), bundled_path_prefix, false)) { | 109 !StartsWithASCII(url.path(), bundled_path_prefix, false)) { |
| 162 return false; | 110 return false; |
| 163 } | 111 } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 PrefService* local_state_pref_service = g_browser_process->local_state(); | 195 PrefService* local_state_pref_service = g_browser_process->local_state(); |
| 248 | 196 |
| 249 scoped_ptr<ProfileParams> params(new ProfileParams); | 197 scoped_ptr<ProfileParams> params(new ProfileParams); |
| 250 params->path = profile->GetPath(); | 198 params->path = profile->GetPath(); |
| 251 | 199 |
| 252 params->io_thread = g_browser_process->io_thread(); | 200 params->io_thread = g_browser_process->io_thread(); |
| 253 | 201 |
| 254 params->cookie_settings = CookieSettings::Factory::GetForProfile(profile); | 202 params->cookie_settings = CookieSettings::Factory::GetForProfile(profile); |
| 255 params->host_content_settings_map = profile->GetHostContentSettingsMap(); | 203 params->host_content_settings_map = profile->GetHostContentSettingsMap(); |
| 256 params->ssl_config_service = profile->GetSSLConfigService(); | 204 params->ssl_config_service = profile->GetSSLConfigService(); |
| 257 base::Callback<Profile*(void)> profile_getter = | |
| 258 base::Bind(&GetProfileOnUI, g_browser_process->profile_manager(), | |
| 259 profile); | |
| 260 params->cookie_monster_delegate = | |
| 261 new chrome_browser_net::EvictedDomainCookieCounter( | |
| 262 new ChromeCookieMonsterDelegate(profile_getter)); | |
| 263 params->extension_info_map = | 205 params->extension_info_map = |
| 264 extensions::ExtensionSystem::Get(profile)->info_map(); | 206 extensions::ExtensionSystem::Get(profile)->info_map(); |
| 265 | 207 |
| 266 if (predictors::ResourcePrefetchPredictor* predictor = | 208 if (predictors::ResourcePrefetchPredictor* predictor = |
| 267 predictors::ResourcePrefetchPredictorFactory::GetForProfile( | 209 predictors::ResourcePrefetchPredictorFactory::GetForProfile( |
| 268 profile)) { | 210 profile)) { |
| 269 resource_prefetch_predictor_observer_.reset( | 211 resource_prefetch_predictor_observer_.reset( |
| 270 new chrome_browser_net::ResourcePrefetchPredictorObserver(predictor)); | 212 new chrome_browser_net::ResourcePrefetchPredictorObserver(predictor)); |
| 271 } | 213 } |
| 272 | 214 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 } | 316 } |
| 375 | 317 |
| 376 ProfileIOData::MediaRequestContext::~MediaRequestContext() {} | 318 ProfileIOData::MediaRequestContext::~MediaRequestContext() {} |
| 377 | 319 |
| 378 ProfileIOData::AppRequestContext::AppRequestContext( | 320 ProfileIOData::AppRequestContext::AppRequestContext( |
| 379 chrome_browser_net::LoadTimeStats* load_time_stats) | 321 chrome_browser_net::LoadTimeStats* load_time_stats) |
| 380 : ChromeURLRequestContext(ChromeURLRequestContext::CONTEXT_TYPE_APP, | 322 : ChromeURLRequestContext(ChromeURLRequestContext::CONTEXT_TYPE_APP, |
| 381 load_time_stats) { | 323 load_time_stats) { |
| 382 } | 324 } |
| 383 | 325 |
| 384 void ProfileIOData::AppRequestContext::SetCookieStore( | |
| 385 net::CookieStore* cookie_store) { | |
| 386 cookie_store_ = cookie_store; | |
| 387 set_cookie_store(cookie_store); | |
| 388 } | |
| 389 | |
| 390 void ProfileIOData::AppRequestContext::SetHttpTransactionFactory( | 326 void ProfileIOData::AppRequestContext::SetHttpTransactionFactory( |
| 391 scoped_ptr<net::HttpTransactionFactory> http_factory) { | 327 scoped_ptr<net::HttpTransactionFactory> http_factory) { |
| 392 http_factory_ = http_factory.Pass(); | 328 http_factory_ = http_factory.Pass(); |
| 393 set_http_transaction_factory(http_factory_.get()); | 329 set_http_transaction_factory(http_factory_.get()); |
| 394 } | 330 } |
| 395 | 331 |
| 396 void ProfileIOData::AppRequestContext::SetJobFactory( | 332 void ProfileIOData::AppRequestContext::SetJobFactory( |
| 397 scoped_ptr<net::URLRequestJobFactory> job_factory) { | 333 scoped_ptr<net::URLRequestJobFactory> job_factory) { |
| 398 job_factory_ = job_factory.Pass(); | 334 job_factory_ = job_factory.Pass(); |
| 399 set_job_factory(job_factory_.get()); | 335 set_job_factory(job_factory_.get()); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 ++it, ++current_context) { | 402 ++it, ++current_context) { |
| 467 media_context_cache[current_context] = it->second; | 403 media_context_cache[current_context] = it->second; |
| 468 memcpy(&media_context_vtable_cache[current_context], | 404 memcpy(&media_context_vtable_cache[current_context], |
| 469 static_cast<void*>(it->second), sizeof(void*)); | 405 static_cast<void*>(it->second), sizeof(void*)); |
| 470 } | 406 } |
| 471 | 407 |
| 472 // TODO(ajwong): These AssertNoURLRequests() calls are unnecessary since they | 408 // TODO(ajwong): These AssertNoURLRequests() calls are unnecessary since they |
| 473 // are already done in the URLRequestContext destructor. | 409 // are already done in the URLRequestContext destructor. |
| 474 if (main_request_context_) | 410 if (main_request_context_) |
| 475 main_request_context_->AssertNoURLRequests(); | 411 main_request_context_->AssertNoURLRequests(); |
| 476 if (extensions_request_context_) | |
| 477 extensions_request_context_->AssertNoURLRequests(); | |
| 478 | 412 |
| 479 current_context = 0; | 413 current_context = 0; |
| 480 for (URLRequestContextMap::iterator it = app_request_context_map_.begin(); | 414 for (URLRequestContextMap::iterator it = app_request_context_map_.begin(); |
| 481 it != app_request_context_map_.end(); ++it) { | 415 it != app_request_context_map_.end(); ++it) { |
| 482 if (current_context < kMaxCachedContexts) { | 416 if (current_context < kMaxCachedContexts) { |
| 483 CHECK_EQ(app_context_cache[current_context], it->second); | 417 CHECK_EQ(app_context_cache[current_context], it->second); |
| 484 memcpy(&tmp_vtable, static_cast<void*>(it->second), sizeof(void*)); | 418 memcpy(&tmp_vtable, static_cast<void*>(it->second), sizeof(void*)); |
| 485 CHECK_EQ(app_context_vtable_cache[current_context], tmp_vtable); | 419 CHECK_EQ(app_context_vtable_cache[current_context], tmp_vtable); |
| 486 } | 420 } |
| 487 it->second->AssertNoURLRequests(); | 421 it->second->AssertNoURLRequests(); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 return main_request_context_.get(); | 506 return main_request_context_.get(); |
| 573 } | 507 } |
| 574 | 508 |
| 575 ChromeURLRequestContext* ProfileIOData::GetMediaRequestContext() const { | 509 ChromeURLRequestContext* ProfileIOData::GetMediaRequestContext() const { |
| 576 DCHECK(initialized_); | 510 DCHECK(initialized_); |
| 577 ChromeURLRequestContext* context = AcquireMediaRequestContext(); | 511 ChromeURLRequestContext* context = AcquireMediaRequestContext(); |
| 578 DCHECK(context); | 512 DCHECK(context); |
| 579 return context; | 513 return context; |
| 580 } | 514 } |
| 581 | 515 |
| 582 ChromeURLRequestContext* ProfileIOData::GetExtensionsRequestContext() const { | |
| 583 DCHECK(initialized_); | |
| 584 return extensions_request_context_.get(); | |
| 585 } | |
| 586 | |
| 587 ChromeURLRequestContext* ProfileIOData::GetIsolatedAppRequestContext( | 516 ChromeURLRequestContext* ProfileIOData::GetIsolatedAppRequestContext( |
| 588 ChromeURLRequestContext* main_context, | 517 ChromeURLRequestContext* main_context, |
| 589 const StoragePartitionDescriptor& partition_descriptor, | 518 const StoragePartitionDescriptor& partition_descriptor, |
| 590 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> | 519 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
| 591 protocol_handler_interceptor, | 520 protocol_handler_interceptor, |
| 592 content::ProtocolHandlerMap* protocol_handlers) const { | 521 content::ProtocolHandlerMap* protocol_handlers) const { |
| 593 DCHECK(initialized_); | 522 DCHECK(initialized_); |
| 594 ChromeURLRequestContext* context = NULL; | 523 ChromeURLRequestContext* context = NULL; |
| 595 if (ContainsKey(app_request_context_map_, partition_descriptor)) { | 524 if (ContainsKey(app_request_context_map_, partition_descriptor)) { |
| 596 context = app_request_context_map_[partition_descriptor]; | 525 context = app_request_context_map_[partition_descriptor]; |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 | 685 |
| 757 IOThread* const io_thread = profile_params_->io_thread; | 686 IOThread* const io_thread = profile_params_->io_thread; |
| 758 IOThread::Globals* const io_thread_globals = io_thread->globals(); | 687 IOThread::Globals* const io_thread_globals = io_thread->globals(); |
| 759 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 688 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 760 load_time_stats_ = GetLoadTimeStats(io_thread_globals); | 689 load_time_stats_ = GetLoadTimeStats(io_thread_globals); |
| 761 | 690 |
| 762 // Create the common request contexts. | 691 // Create the common request contexts. |
| 763 main_request_context_.reset( | 692 main_request_context_.reset( |
| 764 new ChromeURLRequestContext(ChromeURLRequestContext::CONTEXT_TYPE_MAIN, | 693 new ChromeURLRequestContext(ChromeURLRequestContext::CONTEXT_TYPE_MAIN, |
| 765 load_time_stats_)); | 694 load_time_stats_)); |
| 766 extensions_request_context_.reset( | |
| 767 new ChromeURLRequestContext( | |
| 768 ChromeURLRequestContext::CONTEXT_TYPE_EXTENSIONS, | |
| 769 load_time_stats_)); | |
| 770 | 695 |
| 771 ChromeNetworkDelegate* network_delegate = | 696 ChromeNetworkDelegate* network_delegate = |
| 772 new ChromeNetworkDelegate( | 697 new ChromeNetworkDelegate( |
| 773 io_thread_globals->extension_event_router_forwarder.get(), | 698 io_thread_globals->extension_event_router_forwarder.get(), |
| 774 &enable_referrers_); | 699 &enable_referrers_); |
| 775 network_delegate->set_extension_info_map( | 700 network_delegate->set_extension_info_map( |
| 776 profile_params_->extension_info_map.get()); | 701 profile_params_->extension_info_map.get()); |
| 777 network_delegate->set_url_blacklist_manager(url_blacklist_manager_.get()); | 702 network_delegate->set_url_blacklist_manager(url_blacklist_manager_.get()); |
| 778 network_delegate->set_profile(profile_params_->profile); | 703 network_delegate->set_profile(profile_params_->profile); |
| 779 network_delegate->set_cookie_settings(profile_params_->cookie_settings.get()); | 704 network_delegate->set_cookie_settings(profile_params_->cookie_settings.get()); |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 976 void ProfileIOData::SetCookieSettingsForTesting( | 901 void ProfileIOData::SetCookieSettingsForTesting( |
| 977 CookieSettings* cookie_settings) { | 902 CookieSettings* cookie_settings) { |
| 978 DCHECK(!cookie_settings_.get()); | 903 DCHECK(!cookie_settings_.get()); |
| 979 cookie_settings_ = cookie_settings; | 904 cookie_settings_ = cookie_settings; |
| 980 } | 905 } |
| 981 | 906 |
| 982 void ProfileIOData::set_signin_names_for_testing( | 907 void ProfileIOData::set_signin_names_for_testing( |
| 983 SigninNamesOnIOThread* signin_names) { | 908 SigninNamesOnIOThread* signin_names) { |
| 984 signin_names_.reset(signin_names); | 909 signin_names_.reset(signin_names); |
| 985 } | 910 } |
| OLD | NEW |