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