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/io_thread.h" | 5 #include "chrome/browser/io_thread.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 20 matching lines...) Expand all Loading... | |
31 #include "chrome/browser/net/proxy_service_factory.h" | 31 #include "chrome/browser/net/proxy_service_factory.h" |
32 #include "chrome/browser/net/sdch_dictionary_fetcher.h" | 32 #include "chrome/browser/net/sdch_dictionary_fetcher.h" |
33 #include "chrome/browser/prefs/pref_service.h" | 33 #include "chrome/browser/prefs/pref_service.h" |
34 #include "chrome/common/chrome_switches.h" | 34 #include "chrome/common/chrome_switches.h" |
35 #include "chrome/common/pref_names.h" | 35 #include "chrome/common/pref_names.h" |
36 #include "content/public/browser/browser_thread.h" | 36 #include "content/public/browser/browser_thread.h" |
37 #include "content/public/common/content_client.h" | 37 #include "content/public/common/content_client.h" |
38 #include "net/base/cert_verifier.h" | 38 #include "net/base/cert_verifier.h" |
39 #include "net/base/default_server_bound_cert_store.h" | 39 #include "net/base/default_server_bound_cert_store.h" |
40 #include "net/base/host_cache.h" | 40 #include "net/base/host_cache.h" |
41 #include "net/base/host_mapping_rules.h" | |
41 #include "net/base/host_resolver.h" | 42 #include "net/base/host_resolver.h" |
42 #include "net/base/mapped_host_resolver.h" | 43 #include "net/base/mapped_host_resolver.h" |
43 #include "net/base/net_util.h" | 44 #include "net/base/net_util.h" |
44 #include "net/base/sdch_manager.h" | 45 #include "net/base/sdch_manager.h" |
45 #include "net/base/server_bound_cert_service.h" | 46 #include "net/base/server_bound_cert_service.h" |
46 #include "net/cookies/cookie_monster.h" | 47 #include "net/cookies/cookie_monster.h" |
47 #include "net/ftp/ftp_network_layer.h" | 48 #include "net/ftp/ftp_network_layer.h" |
48 #include "net/http/http_auth_filter.h" | 49 #include "net/http/http_auth_filter.h" |
49 #include "net/http/http_auth_handler_factory.h" | 50 #include "net/http/http_auth_handler_factory.h" |
50 #include "net/http/http_network_layer.h" | 51 #include "net/http/http_network_layer.h" |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 } | 301 } |
301 | 302 |
302 IOThread::Globals:: | 303 IOThread::Globals:: |
303 SystemRequestContextLeakChecker::~SystemRequestContextLeakChecker() { | 304 SystemRequestContextLeakChecker::~SystemRequestContextLeakChecker() { |
304 if (globals_->system_request_context.get()) | 305 if (globals_->system_request_context.get()) |
305 globals_->system_request_context->AssertNoURLRequests(); | 306 globals_->system_request_context->AssertNoURLRequests(); |
306 } | 307 } |
307 | 308 |
308 IOThread::Globals::Globals() | 309 IOThread::Globals::Globals() |
309 : ALLOW_THIS_IN_INITIALIZER_LIST( | 310 : ALLOW_THIS_IN_INITIALIZER_LIST( |
310 system_request_context_leak_checker(this)) {} | 311 system_request_context_leak_checker(this)), |
312 ignore_certificate_errors(false), | |
313 http_pipelining_enabled(false), | |
314 testing_fixed_http_port(0), | |
315 testing_fixed_https_port(0) {} | |
316 | |
311 IOThread::Globals::~Globals() {} | 317 IOThread::Globals::~Globals() {} |
312 | 318 |
313 // |local_state| is passed in explicitly in order to (1) reduce implicit | 319 // |local_state| is passed in explicitly in order to (1) reduce implicit |
314 // dependencies and (2) make IOThread more flexible for testing. | 320 // dependencies and (2) make IOThread more flexible for testing. |
315 IOThread::IOThread( | 321 IOThread::IOThread( |
316 PrefService* local_state, | 322 PrefService* local_state, |
317 ChromeNetLog* net_log, | 323 ChromeNetLog* net_log, |
318 extensions::EventRouterForwarder* extension_event_router_forwarder) | 324 extensions::EventRouterForwarder* extension_event_router_forwarder) |
319 : net_log_(net_log), | 325 : net_log_(net_log), |
320 extension_event_router_forwarder_(extension_event_router_forwarder), | 326 extension_event_router_forwarder_(extension_event_router_forwarder), |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
379 return system_url_request_context_getter_; | 385 return system_url_request_context_getter_; |
380 } | 386 } |
381 | 387 |
382 void IOThread::Init() { | 388 void IOThread::Init() { |
383 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 389 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
384 | 390 |
385 #if defined(USE_NSS) | 391 #if defined(USE_NSS) |
386 net::SetMessageLoopForNSSHttpIO(); | 392 net::SetMessageLoopForNSSHttpIO(); |
387 #endif // defined(USE_NSS) | 393 #endif // defined(USE_NSS) |
388 | 394 |
395 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
396 | |
389 DCHECK(!globals_); | 397 DCHECK(!globals_); |
390 globals_ = new Globals; | 398 globals_ = new Globals; |
391 | 399 |
392 // Add an observer that will emit network change events to the ChromeNetLog. | 400 // Add an observer that will emit network change events to the ChromeNetLog. |
393 // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be | 401 // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be |
394 // logging the network change before other IO thread consumers respond to it. | 402 // logging the network change before other IO thread consumers respond to it. |
395 network_change_observer_.reset( | 403 network_change_observer_.reset( |
396 new LoggingNetworkChangeObserver(net_log_)); | 404 new LoggingNetworkChangeObserver(net_log_)); |
397 | 405 |
398 // Setup the HistogramWatcher to run on the IO thread. | 406 // Setup the HistogramWatcher to run on the IO thread. |
399 net::NetworkChangeNotifier::InitHistogramWatcher(); | 407 net::NetworkChangeNotifier::InitHistogramWatcher(); |
400 | 408 |
401 globals_->extension_event_router_forwarder = | 409 globals_->extension_event_router_forwarder = |
402 extension_event_router_forwarder_; | 410 extension_event_router_forwarder_; |
403 ChromeNetworkDelegate* network_delegate = new ChromeNetworkDelegate( | 411 ChromeNetworkDelegate* network_delegate = new ChromeNetworkDelegate( |
404 extension_event_router_forwarder_, | 412 extension_event_router_forwarder_, |
405 NULL, | 413 NULL, |
406 NULL, | 414 NULL, |
407 NULL, | 415 NULL, |
408 NULL, | 416 NULL, |
409 NULL, | 417 NULL, |
410 &system_enable_referrers_, | 418 &system_enable_referrers_, |
411 NULL); | 419 NULL); |
412 if (CommandLine::ForCurrentProcess()->HasSwitch( | 420 if (command_line.HasSwitch(switches::kDisableExtensionsHttpThrottling)) |
413 switches::kDisableExtensionsHttpThrottling)) { | |
414 network_delegate->NeverThrottleRequests(); | 421 network_delegate->NeverThrottleRequests(); |
415 } | |
416 globals_->system_network_delegate.reset(network_delegate); | 422 globals_->system_network_delegate.reset(network_delegate); |
417 globals_->host_resolver.reset( | 423 globals_->host_resolver.reset( |
418 CreateGlobalHostResolver(net_log_)); | 424 CreateGlobalHostResolver(net_log_)); |
419 globals_->cert_verifier.reset(net::CertVerifier::CreateDefault()); | 425 globals_->cert_verifier.reset(net::CertVerifier::CreateDefault()); |
420 globals_->transport_security_state.reset(new net::TransportSecurityState()); | 426 globals_->transport_security_state.reset(new net::TransportSecurityState()); |
421 globals_->ssl_config_service = GetSSLConfigService(); | 427 globals_->ssl_config_service = GetSSLConfigService(); |
422 globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory( | 428 globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory( |
423 globals_->host_resolver.get())); | 429 globals_->host_resolver.get())); |
424 globals_->http_server_properties.reset(new net::HttpServerPropertiesImpl); | 430 globals_->http_server_properties.reset(new net::HttpServerPropertiesImpl); |
425 // For the ProxyScriptFetcher, we use a direct ProxyService. | 431 // For the ProxyScriptFetcher, we use a direct ProxyService. |
426 globals_->proxy_script_fetcher_proxy_service.reset( | 432 globals_->proxy_script_fetcher_proxy_service.reset( |
427 net::ProxyService::CreateDirectWithNetLog(net_log_)); | 433 net::ProxyService::CreateDirectWithNetLog(net_log_)); |
428 // In-memory cookie store. | 434 // In-memory cookie store. |
429 globals_->system_cookie_store = new net::CookieMonster(NULL, NULL); | 435 globals_->system_cookie_store = new net::CookieMonster(NULL, NULL); |
430 // In-memory server bound cert store. | 436 // In-memory server bound cert store. |
431 globals_->system_server_bound_cert_service.reset( | 437 globals_->system_server_bound_cert_service.reset( |
432 new net::ServerBoundCertService( | 438 new net::ServerBoundCertService( |
433 new net::DefaultServerBoundCertStore(NULL), | 439 new net::DefaultServerBoundCertStore(NULL), |
434 base::WorkerPool::GetTaskRunner(true))); | 440 base::WorkerPool::GetTaskRunner(true))); |
435 globals_->load_time_stats.reset(new chrome_browser_net::LoadTimeStats()); | 441 globals_->load_time_stats.reset(new chrome_browser_net::LoadTimeStats()); |
442 globals_->host_mapping_rules.reset(new net::HostMappingRules()); | |
443 if (command_line.HasSwitch(switches::kHostRules)) | |
444 globals_->host_mapping_rules->SetRulesFromString( | |
445 command_line.GetSwitchValueASCII(switches::kHostRules)); | |
mmenke
2012/08/23 18:11:28
nit: Use braces when the body of an if statement
| |
446 if (command_line.HasSwitch(switches::kIgnoreCertificateErrors)) | |
447 globals_->ignore_certificate_errors = true; | |
448 if (command_line.HasSwitch(switches::kEnableHttpPipelining)) | |
449 globals_->http_pipelining_enabled = true; | |
450 if (command_line.HasSwitch(switches::kTestingFixedHttpPort)) { | |
451 int value; | |
452 base::StringToInt( | |
453 command_line.GetSwitchValueASCII( | |
454 switches::kTestingFixedHttpPort), | |
455 &value); | |
456 globals_->testing_fixed_http_port = value; | |
457 } | |
458 if (command_line.HasSwitch(switches::kTestingFixedHttpsPort)) { | |
459 int value; | |
460 base::StringToInt( | |
461 command_line.GetSwitchValueASCII( | |
462 switches::kTestingFixedHttpsPort), | |
463 &value); | |
464 globals_->testing_fixed_https_port = value; | |
465 } | |
466 | |
436 net::HttpNetworkSession::Params session_params; | 467 net::HttpNetworkSession::Params session_params; |
437 session_params.host_resolver = globals_->host_resolver.get(); | 468 session_params.host_resolver = globals_->host_resolver.get(); |
438 session_params.cert_verifier = globals_->cert_verifier.get(); | 469 session_params.cert_verifier = globals_->cert_verifier.get(); |
439 session_params.server_bound_cert_service = | 470 session_params.server_bound_cert_service = |
440 globals_->system_server_bound_cert_service.get(); | 471 globals_->system_server_bound_cert_service.get(); |
441 session_params.transport_security_state = | 472 session_params.transport_security_state = |
442 globals_->transport_security_state.get(); | 473 globals_->transport_security_state.get(); |
443 session_params.proxy_service = | 474 session_params.proxy_service = |
444 globals_->proxy_script_fetcher_proxy_service.get(); | 475 globals_->proxy_script_fetcher_proxy_service.get(); |
476 session_params.ssl_config_service = globals_->ssl_config_service.get(); | |
445 session_params.http_auth_handler_factory = | 477 session_params.http_auth_handler_factory = |
446 globals_->http_auth_handler_factory.get(); | 478 globals_->http_auth_handler_factory.get(); |
479 session_params.http_server_properties = | |
480 globals_->http_server_properties.get(); | |
447 session_params.network_delegate = globals_->system_network_delegate.get(); | 481 session_params.network_delegate = globals_->system_network_delegate.get(); |
448 // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the | 482 // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the |
449 // system URLRequestContext too. There's no reason this should be tied to a | 483 // system URLRequestContext too. There's no reason this should be tied to a |
450 // profile. | 484 // profile. |
451 session_params.http_server_properties = | |
452 globals_->http_server_properties.get(); | |
453 session_params.net_log = net_log_; | 485 session_params.net_log = net_log_; |
454 session_params.ssl_config_service = globals_->ssl_config_service; | 486 session_params.ignore_certificate_errors = |
487 globals_->ignore_certificate_errors; | |
488 session_params.host_mapping_rules = globals_->host_mapping_rules.get(); | |
mmenke
2012/08/23 18:11:28
nit: This should go before ignore_certificate_err
| |
489 session_params.http_pipelining_enabled = globals_->http_pipelining_enabled; | |
490 session_params.testing_fixed_http_port = globals_->testing_fixed_http_port; | |
491 session_params.testing_fixed_https_port = globals_->http_pipelining_enabled; | |
492 | |
455 scoped_refptr<net::HttpNetworkSession> network_session( | 493 scoped_refptr<net::HttpNetworkSession> network_session( |
456 new net::HttpNetworkSession(session_params)); | 494 new net::HttpNetworkSession(session_params)); |
457 globals_->proxy_script_fetcher_http_transaction_factory.reset( | 495 globals_->proxy_script_fetcher_http_transaction_factory.reset( |
458 new net::HttpNetworkLayer(network_session)); | 496 new net::HttpNetworkLayer(network_session)); |
459 globals_->proxy_script_fetcher_ftp_transaction_factory.reset( | 497 globals_->proxy_script_fetcher_ftp_transaction_factory.reset( |
460 new net::FtpNetworkLayer(globals_->host_resolver.get())); | 498 new net::FtpNetworkLayer(globals_->host_resolver.get())); |
461 | 499 |
462 globals_->throttler_manager.reset(new net::URLRequestThrottlerManager()); | 500 globals_->throttler_manager.reset(new net::URLRequestThrottlerManager()); |
463 globals_->throttler_manager->set_net_log(net_log_); | 501 globals_->throttler_manager->set_net_log(net_log_); |
464 // Always done in production, disabled only for unit tests. | 502 // Always done in production, disabled only for unit tests. |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
606 DCHECK(!globals_->system_proxy_service.get()); | 644 DCHECK(!globals_->system_proxy_service.get()); |
607 DCHECK(system_proxy_config_service_.get()); | 645 DCHECK(system_proxy_config_service_.get()); |
608 | 646 |
609 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 647 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
610 globals_->system_proxy_service.reset( | 648 globals_->system_proxy_service.reset( |
611 ProxyServiceFactory::CreateProxyService( | 649 ProxyServiceFactory::CreateProxyService( |
612 net_log_, | 650 net_log_, |
613 globals_->proxy_script_fetcher_context.get(), | 651 globals_->proxy_script_fetcher_context.get(), |
614 system_proxy_config_service_.release(), | 652 system_proxy_config_service_.release(), |
615 command_line)); | 653 command_line)); |
654 | |
616 net::HttpNetworkSession::Params system_params; | 655 net::HttpNetworkSession::Params system_params; |
617 system_params.host_resolver = globals_->host_resolver.get(); | 656 system_params.host_resolver = globals_->host_resolver.get(); |
618 system_params.cert_verifier = globals_->cert_verifier.get(); | 657 system_params.cert_verifier = globals_->cert_verifier.get(); |
619 system_params.server_bound_cert_service = | 658 system_params.server_bound_cert_service = |
620 globals_->system_server_bound_cert_service.get(); | 659 globals_->system_server_bound_cert_service.get(); |
621 system_params.transport_security_state = | 660 system_params.transport_security_state = |
622 globals_->transport_security_state.get(); | 661 globals_->transport_security_state.get(); |
623 system_params.proxy_service = globals_->system_proxy_service.get(); | 662 system_params.proxy_service = globals_->system_proxy_service.get(); |
624 system_params.ssl_config_service = globals_->ssl_config_service.get(); | 663 system_params.ssl_config_service = globals_->ssl_config_service.get(); |
625 system_params.http_auth_handler_factory = | 664 system_params.http_auth_handler_factory = |
626 globals_->http_auth_handler_factory.get(); | 665 globals_->http_auth_handler_factory.get(); |
627 system_params.http_server_properties = globals_->http_server_properties.get(); | 666 system_params.http_server_properties = globals_->http_server_properties.get(); |
628 system_params.network_delegate = globals_->system_network_delegate.get(); | 667 system_params.network_delegate = globals_->system_network_delegate.get(); |
629 system_params.net_log = net_log_; | 668 system_params.net_log = net_log_; |
669 system_params.ignore_certificate_errors = globals_->ignore_certificate_errors; | |
670 system_params.host_mapping_rules = globals_->host_mapping_rules.get(); | |
mmenke
2012/08/23 18:11:28
nit: Move host_mapping_rules up, as above.
| |
671 system_params.http_pipelining_enabled = globals_->http_pipelining_enabled; | |
672 system_params.testing_fixed_http_port = globals_->testing_fixed_http_port; | |
673 system_params.testing_fixed_https_port = globals_->testing_fixed_https_port; | |
674 | |
630 globals_->system_http_transaction_factory.reset( | 675 globals_->system_http_transaction_factory.reset( |
631 new net::HttpNetworkLayer( | 676 new net::HttpNetworkLayer( |
632 new net::HttpNetworkSession(system_params))); | 677 new net::HttpNetworkSession(system_params))); |
633 globals_->system_ftp_transaction_factory.reset( | 678 globals_->system_ftp_transaction_factory.reset( |
634 new net::FtpNetworkLayer(globals_->host_resolver.get())); | 679 new net::FtpNetworkLayer(globals_->host_resolver.get())); |
635 globals_->system_request_context.reset( | 680 globals_->system_request_context.reset( |
636 ConstructSystemRequestContext(globals_, net_log_)); | 681 ConstructSystemRequestContext(globals_, net_log_)); |
637 | 682 |
638 sdch_manager_->set_sdch_fetcher( | 683 sdch_manager_->set_sdch_fetcher( |
639 new SdchDictionaryFetcher(system_url_request_context_getter_.get())); | 684 new SdchDictionaryFetcher(system_url_request_context_getter_.get())); |
640 } | 685 } |
OLD | NEW |