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

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

Issue 10969017: Create a new URLRequestJobFactory for isolated request contexts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix ordering Created 8 years, 3 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 | Annotate | Revision Log
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_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"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/stl_util.h" 15 #include "base/stl_util.h"
16 #include "base/string_number_conversions.h" 16 #include "base/string_number_conversions.h"
17 #include "base/string_util.h" 17 #include "base/string_util.h"
18 #include "base/stringprintf.h" 18 #include "base/stringprintf.h"
19 #include "chrome/browser/browser_process.h" 19 #include "chrome/browser/browser_process.h"
20 #include "chrome/browser/net/about_protocol_handler.h"
20 #include "chrome/browser/content_settings/cookie_settings.h" 21 #include "chrome/browser/content_settings/cookie_settings.h"
21 #include "chrome/browser/content_settings/host_content_settings_map.h" 22 #include "chrome/browser/content_settings/host_content_settings_map.h"
22 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" 23 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
23 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" 24 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
24 #include "chrome/browser/download/download_service.h" 25 #include "chrome/browser/download/download_service.h"
25 #include "chrome/browser/download/download_service_factory.h" 26 #include "chrome/browser/download/download_service_factory.h"
26 #include "chrome/browser/extensions/extension_info_map.h" 27 #include "chrome/browser/extensions/extension_info_map.h"
27 #include "chrome/browser/extensions/extension_protocols.h" 28 #include "chrome/browser/extensions/extension_protocols.h"
28 #include "chrome/browser/extensions/extension_resource_protocols.h" 29 #include "chrome/browser/extensions/extension_resource_protocols.h"
29 #include "chrome/browser/extensions/extension_system.h" 30 #include "chrome/browser/extensions/extension_system.h"
(...skipping 25 matching lines...) Expand all
55 #include "content/public/browser/resource_context.h" 56 #include "content/public/browser/resource_context.h"
56 #include "net/base/server_bound_cert_service.h" 57 #include "net/base/server_bound_cert_service.h"
57 #include "net/cookies/canonical_cookie.h" 58 #include "net/cookies/canonical_cookie.h"
58 #include "net/cookies/cookie_monster.h" 59 #include "net/cookies/cookie_monster.h"
59 #include "net/http/http_transaction_factory.h" 60 #include "net/http/http_transaction_factory.h"
60 #include "net/http/http_util.h" 61 #include "net/http/http_util.h"
61 #include "net/proxy/proxy_config_service_fixed.h" 62 #include "net/proxy/proxy_config_service_fixed.h"
62 #include "net/proxy/proxy_script_fetcher_impl.h" 63 #include "net/proxy/proxy_script_fetcher_impl.h"
63 #include "net/proxy/proxy_service.h" 64 #include "net/proxy/proxy_service.h"
64 #include "net/url_request/data_protocol_handler.h" 65 #include "net/url_request/data_protocol_handler.h"
66 #include "net/url_request/file_protocol_handler.h"
67 #include "net/url_request/ftp_protocol_handler.h"
65 #include "net/url_request/url_request.h" 68 #include "net/url_request/url_request.h"
66 69
67 #if !defined(OS_ANDROID) 70 #if !defined(OS_ANDROID)
68 #include "chrome/browser/managed_mode.h" 71 #include "chrome/browser/managed_mode.h"
69 #endif 72 #endif
70 73
71 #if defined(OS_CHROMEOS) 74 #if defined(OS_CHROMEOS)
72 #include "chrome/browser/chromeos/gdata/drive_protocol_handler.h" 75 #include "chrome/browser/chromeos/gdata/drive_protocol_handler.h"
73 #include "chrome/browser/chromeos/gview_request_interceptor.h" 76 #include "chrome/browser/chromeos/gview_request_interceptor.h"
74 #include "chrome/browser/chromeos/proxy_config_service_impl.h" 77 #include "chrome/browser/chromeos/proxy_config_service_impl.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 186
184 #if defined(ENABLE_NOTIFICATIONS) 187 #if defined(ENABLE_NOTIFICATIONS)
185 params->notification_service = 188 params->notification_service =
186 DesktopNotificationServiceFactory::GetForProfile(profile); 189 DesktopNotificationServiceFactory::GetForProfile(profile);
187 #endif 190 #endif
188 191
189 ProtocolHandlerRegistry* protocol_handler_registry = 192 ProtocolHandlerRegistry* protocol_handler_registry =
190 ProtocolHandlerRegistryFactory::GetForProfile(profile); 193 ProtocolHandlerRegistryFactory::GetForProfile(profile);
191 DCHECK(protocol_handler_registry); 194 DCHECK(protocol_handler_registry);
192 195
193 // the profile instance is only available here in the InitializeOnUIThread 196 // The profile instance is only available here in the InitializeOnUIThread
194 // method, so we create the url interceptor here, then save it for 197 // method, so we create the url interceptor here, then save it for
195 // later delivery to the job factory in LazyInitialize 198 // later delivery to the job factory in LazyInitialize.
196 params->protocol_handler_url_interceptor.reset( 199 params->protocol_handler_interceptor.reset(
197 protocol_handler_registry->CreateURLInterceptor()); 200 protocol_handler_registry->CreateURLInterceptor());
198 201
199 ChromeProxyConfigService* proxy_config_service = 202 ChromeProxyConfigService* proxy_config_service =
200 ProxyServiceFactory::CreateProxyConfigService(true); 203 ProxyServiceFactory::CreateProxyConfigService(true);
201 params->proxy_config_service.reset(proxy_config_service); 204 params->proxy_config_service.reset(proxy_config_service);
202 profile->GetProxyConfigTracker()->SetChromeProxyConfigService( 205 profile->GetProxyConfigTracker()->SetChromeProxyConfigService(
203 proxy_config_service); 206 proxy_config_service);
204 params->profile = profile; 207 params->profile = profile;
205 profile_params_.reset(params.release()); 208 profile_params_.reset(params.release());
206 209
(...skipping 24 matching lines...) Expand all
231 BrowserContext::EnsureResourceContextInitialized(profile); 234 BrowserContext::EnsureResourceContextInitialized(profile);
232 } 235 }
233 236
234 ProfileIOData::MediaRequestContext::MediaRequestContext( 237 ProfileIOData::MediaRequestContext::MediaRequestContext(
235 chrome_browser_net::LoadTimeStats* load_time_stats) 238 chrome_browser_net::LoadTimeStats* load_time_stats)
236 : ChromeURLRequestContext(ChromeURLRequestContext::CONTEXT_TYPE_MEDIA, 239 : ChromeURLRequestContext(ChromeURLRequestContext::CONTEXT_TYPE_MEDIA,
237 load_time_stats) { 240 load_time_stats) {
238 } 241 }
239 242
240 void ProfileIOData::MediaRequestContext::SetHttpTransactionFactory( 243 void ProfileIOData::MediaRequestContext::SetHttpTransactionFactory(
241 net::HttpTransactionFactory* http_factory) { 244 scoped_ptr<net::HttpTransactionFactory> http_factory) {
242 http_factory_.reset(http_factory); 245 http_factory_ = http_factory.Pass();
243 set_http_transaction_factory(http_factory); 246 set_http_transaction_factory(http_factory_.get());
244 } 247 }
245 248
246 ProfileIOData::MediaRequestContext::~MediaRequestContext() {} 249 ProfileIOData::MediaRequestContext::~MediaRequestContext() {}
247 250
248 ProfileIOData::AppRequestContext::AppRequestContext( 251 ProfileIOData::AppRequestContext::AppRequestContext(
249 chrome_browser_net::LoadTimeStats* load_time_stats) 252 chrome_browser_net::LoadTimeStats* load_time_stats)
250 : ChromeURLRequestContext(ChromeURLRequestContext::CONTEXT_TYPE_APP, 253 : ChromeURLRequestContext(ChromeURLRequestContext::CONTEXT_TYPE_APP,
251 load_time_stats) { 254 load_time_stats) {
252 } 255 }
253 256
254 void ProfileIOData::AppRequestContext::SetCookieStore( 257 void ProfileIOData::AppRequestContext::SetCookieStore(
255 net::CookieStore* cookie_store) { 258 net::CookieStore* cookie_store) {
256 cookie_store_ = cookie_store; 259 cookie_store_ = cookie_store;
257 set_cookie_store(cookie_store); 260 set_cookie_store(cookie_store);
258 } 261 }
259 262
260 void ProfileIOData::AppRequestContext::SetHttpTransactionFactory( 263 void ProfileIOData::AppRequestContext::SetHttpTransactionFactory(
261 net::HttpTransactionFactory* http_factory) { 264 scoped_ptr<net::HttpTransactionFactory> http_factory) {
262 http_factory_.reset(http_factory); 265 http_factory_ = http_factory.Pass();
263 set_http_transaction_factory(http_factory); 266 set_http_transaction_factory(http_factory_.get());
267 }
268
269 void ProfileIOData::AppRequestContext::SetJobFactory(
270 scoped_ptr<net::URLRequestJobFactory> job_factory) {
271 job_factory_ = job_factory.Pass();
272 set_job_factory(job_factory_.get());
264 } 273 }
265 274
266 ProfileIOData::AppRequestContext::~AppRequestContext() {} 275 ProfileIOData::AppRequestContext::~AppRequestContext() {}
267 276
268 ProfileIOData::ProfileParams::ProfileParams() 277 ProfileIOData::ProfileParams::ProfileParams()
269 : io_thread(NULL), 278 : io_thread(NULL),
270 #if defined(ENABLE_NOTIFICATIONS) 279 #if defined(ENABLE_NOTIFICATIONS)
271 notification_service(NULL), 280 notification_service(NULL),
272 #endif 281 #endif
273 profile(NULL) { 282 profile(NULL) {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 378
370 ChromeURLRequestContext* 379 ChromeURLRequestContext*
371 ProfileIOData::GetExtensionsRequestContext() const { 380 ProfileIOData::GetExtensionsRequestContext() const {
372 LazyInitialize(); 381 LazyInitialize();
373 return extensions_request_context_.get(); 382 return extensions_request_context_.get();
374 } 383 }
375 384
376 ChromeURLRequestContext* 385 ChromeURLRequestContext*
377 ProfileIOData::GetIsolatedAppRequestContext( 386 ProfileIOData::GetIsolatedAppRequestContext(
378 ChromeURLRequestContext* main_context, 387 ChromeURLRequestContext* main_context,
379 const std::string& app_id) const { 388 const std::string& app_id,
389 scoped_ptr<net::URLRequestJobFactory::Interceptor>
390 protocol_handler_interceptor) const {
380 LazyInitialize(); 391 LazyInitialize();
381 ChromeURLRequestContext* context = NULL; 392 ChromeURLRequestContext* context = NULL;
382 if (ContainsKey(app_request_context_map_, app_id)) { 393 if (ContainsKey(app_request_context_map_, app_id)) {
383 context = app_request_context_map_[app_id]; 394 context = app_request_context_map_[app_id];
384 } else { 395 } else {
385 context = AcquireIsolatedAppRequestContext(main_context, app_id); 396 context = AcquireIsolatedAppRequestContext(
397 main_context, app_id, protocol_handler_interceptor.Pass());
386 app_request_context_map_[app_id] = context; 398 app_request_context_map_[app_id] = context;
387 } 399 }
388 DCHECK(context); 400 DCHECK(context);
389 return context; 401 return context;
390 } 402 }
391 403
392 ChromeURLRequestContext* 404 ChromeURLRequestContext*
393 ProfileIOData::GetIsolatedMediaRequestContext( 405 ProfileIOData::GetIsolatedMediaRequestContext(
394 ChromeURLRequestContext* main_context, 406 ChromeURLRequestContext* app_context,
395 const std::string& app_id) const { 407 const std::string& app_id) const {
396 LazyInitialize(); 408 LazyInitialize();
397 ChromeURLRequestContext* context = NULL; 409 ChromeURLRequestContext* context = NULL;
398 if (ContainsKey(isolated_media_request_context_map_, app_id)) { 410 if (ContainsKey(isolated_media_request_context_map_, app_id)) {
399 context = isolated_media_request_context_map_[app_id]; 411 context = isolated_media_request_context_map_[app_id];
400 } else { 412 } else {
401 // Get the app context as the starting point for the media context,
402 // so that it uses the app's cookie store.
403 ChromeURLRequestContext* app_context = GetIsolatedAppRequestContext(
404 main_context, app_id);
405 context = AcquireIsolatedMediaRequestContext(app_context, app_id); 413 context = AcquireIsolatedMediaRequestContext(app_context, app_id);
406 isolated_media_request_context_map_[app_id] = context; 414 isolated_media_request_context_map_[app_id] = context;
407 } 415 }
408 DCHECK(context); 416 DCHECK(context);
409 return context; 417 return context;
410 } 418 }
411 419
412 ExtensionInfoMap* ProfileIOData::GetExtensionInfoMap() const { 420 ExtensionInfoMap* ProfileIOData::GetExtensionInfoMap() const {
413 DCHECK(extension_info_map_) << "ExtensionSystem not initialized"; 421 DCHECK(extension_info_map_) << "ExtensionSystem not initialized";
414 return extension_info_map_; 422 return extension_info_map_;
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 void ProfileIOData::ApplyProfileParamsToContext( 592 void ProfileIOData::ApplyProfileParamsToContext(
585 ChromeURLRequestContext* context) const { 593 ChromeURLRequestContext* context) const {
586 context->set_is_incognito(is_incognito()); 594 context->set_is_incognito(is_incognito());
587 context->set_accept_language(profile_params_->accept_language); 595 context->set_accept_language(profile_params_->accept_language);
588 context->set_accept_charset(profile_params_->accept_charset); 596 context->set_accept_charset(profile_params_->accept_charset);
589 context->set_referrer_charset(profile_params_->referrer_charset); 597 context->set_referrer_charset(profile_params_->referrer_charset);
590 context->set_ssl_config_service(profile_params_->ssl_config_service); 598 context->set_ssl_config_service(profile_params_->ssl_config_service);
591 } 599 }
592 600
593 void ProfileIOData::SetUpJobFactoryDefaults( 601 void ProfileIOData::SetUpJobFactoryDefaults(
594 net::URLRequestJobFactory* job_factory) const { 602 net::URLRequestJobFactory* job_factory,
603 scoped_ptr<net::URLRequestJobFactory::Interceptor>
604 protocol_handler_interceptor,
605 net::NetworkDelegate* network_delegate,
606 net::FtpTransactionFactory* ftp_transaction_factory,
607 net::FtpAuthCache* ftp_auth_cache) const {
595 // NOTE(willchan): Keep these protocol handlers in sync with 608 // NOTE(willchan): Keep these protocol handlers in sync with
596 // ProfileIOData::IsHandledProtocol(). 609 // ProfileIOData::IsHandledProtocol().
610 bool set_protocol = job_factory->SetProtocolHandler(
611 chrome::kFileScheme, new net::FileProtocolHandler());
612 DCHECK(set_protocol);
597 613
598 if (profile_params_->protocol_handler_url_interceptor.get()) { 614 set_protocol = job_factory->SetProtocolHandler(
599 job_factory->AddInterceptor( 615 chrome::kChromeDevToolsScheme,
600 profile_params_->protocol_handler_url_interceptor.release()); 616 CreateDevToolsProtocolHandler(chrome_url_data_manager_backend(),
617 network_delegate));
618 DCHECK(set_protocol);
619
620 if (protocol_handler_interceptor.get()) {
621 job_factory->AddInterceptor(protocol_handler_interceptor.release());
601 } 622 }
602 623
603 bool set_protocol = job_factory->SetProtocolHandler( 624 set_protocol = job_factory->SetProtocolHandler(
604 chrome::kExtensionScheme, 625 chrome::kExtensionScheme,
605 CreateExtensionProtocolHandler(is_incognito(), 626 CreateExtensionProtocolHandler(is_incognito(), GetExtensionInfoMap()));
606 profile_params_->extension_info_map));
607 DCHECK(set_protocol); 627 DCHECK(set_protocol);
608 set_protocol = job_factory->SetProtocolHandler( 628 set_protocol = job_factory->SetProtocolHandler(
609 chrome::kExtensionResourceScheme, 629 chrome::kExtensionResourceScheme,
610 CreateExtensionResourceProtocolHandler()); 630 CreateExtensionResourceProtocolHandler());
611 DCHECK(set_protocol); 631 DCHECK(set_protocol);
612 set_protocol = job_factory->SetProtocolHandler( 632 set_protocol = job_factory->SetProtocolHandler(
613 chrome::kChromeUIScheme, 633 chrome::kChromeUIScheme,
614 ChromeURLDataManagerBackend::CreateProtocolHandler( 634 ChromeURLDataManagerBackend::CreateProtocolHandler(
615 chrome_url_data_manager_backend_.get())); 635 chrome_url_data_manager_backend_.get()));
616 DCHECK(set_protocol); 636 DCHECK(set_protocol);
617 set_protocol = job_factory->SetProtocolHandler( 637 set_protocol = job_factory->SetProtocolHandler(
618 chrome::kDataScheme, new net::DataProtocolHandler()); 638 chrome::kDataScheme, new net::DataProtocolHandler());
619 DCHECK(set_protocol); 639 DCHECK(set_protocol);
620 #if defined(OS_CHROMEOS) 640 #if defined(OS_CHROMEOS)
621 if (!is_incognito()) { 641 if (!is_incognito()) {
622 set_protocol = job_factory->SetProtocolHandler( 642 set_protocol = job_factory->SetProtocolHandler(
623 chrome::kDriveScheme, new gdata::DriveProtocolHandler()); 643 chrome::kDriveScheme, new gdata::DriveProtocolHandler());
624 DCHECK(set_protocol); 644 DCHECK(set_protocol);
625 } 645 }
626 #if !defined(GOOGLE_CHROME_BUILD) 646 #if !defined(GOOGLE_CHROME_BUILD)
627 // Install the GView request interceptor that will redirect requests 647 // Install the GView request interceptor that will redirect requests
628 // of compatible documents (PDF, etc) to the GView document viewer. 648 // of compatible documents (PDF, etc) to the GView document viewer.
629 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); 649 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
630 if (parsed_command_line.HasSwitch(switches::kEnableGView)) 650 if (parsed_command_line.HasSwitch(switches::kEnableGView))
631 job_factory->AddInterceptor(new chromeos::GViewRequestInterceptor); 651 job_factory->AddInterceptor(new chromeos::GViewRequestInterceptor);
632 #endif // !defined(GOOGLE_CHROME_BUILD) 652 #endif // !defined(GOOGLE_CHROME_BUILD)
633 #endif // defined(OS_CHROMEOS) 653 #endif // defined(OS_CHROMEOS)
654
655 job_factory->SetProtocolHandler(chrome::kAboutScheme,
656 new net::AboutProtocolHandler());
657 #if !defined(DISABLE_FTP_SUPPORT)
658 DCHECK(ftp_transaction_factory);
659 job_factory->SetProtocolHandler(
660 chrome::kFtpScheme,
661 new net::FtpProtocolHandler(ftp_transaction_factory,
662 ftp_auth_cache));
663 #endif // !defined(DISABLE_FTP_SUPPORT)
634 } 664 }
635 665
636 void ProfileIOData::ShutdownOnUIThread() { 666 void ProfileIOData::ShutdownOnUIThread() {
637 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 667 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
638 enable_referrers_.Destroy(); 668 enable_referrers_.Destroy();
639 enable_do_not_track_.Destroy(); 669 enable_do_not_track_.Destroy();
640 #if !defined(OS_CHROMEOS) 670 #if !defined(OS_CHROMEOS)
641 enable_metrics_.Destroy(); 671 enable_metrics_.Destroy();
642 #endif 672 #endif
643 safe_browsing_enabled_.Destroy(); 673 safe_browsing_enabled_.Destroy();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 params->http_pipelining_enabled = globals->http_pipelining_enabled; 716 params->http_pipelining_enabled = globals->http_pipelining_enabled;
687 params->testing_fixed_http_port = globals->testing_fixed_http_port; 717 params->testing_fixed_http_port = globals->testing_fixed_http_port;
688 params->testing_fixed_https_port = globals->testing_fixed_https_port; 718 params->testing_fixed_https_port = globals->testing_fixed_https_port;
689 719
690 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 720 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
691 if (command_line.HasSwitch(switches::kTrustedSpdyProxy)) { 721 if (command_line.HasSwitch(switches::kTrustedSpdyProxy)) {
692 params->trusted_spdy_proxy = command_line.GetSwitchValueASCII( 722 params->trusted_spdy_proxy = command_line.GetSwitchValueASCII(
693 switches::kTrustedSpdyProxy); 723 switches::kTrustedSpdyProxy);
694 } 724 }
695 } 725 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_io_data.h ('k') | chrome/test/data/extensions/api_test/xhr_persistent_fs/bg.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698