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