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/base64.h" | 9 #include "base/base64.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 #include "net/cert/ct_verifier.h" | 68 #include "net/cert/ct_verifier.h" |
69 #include "net/cert/multi_log_ct_verifier.h" | 69 #include "net/cert/multi_log_ct_verifier.h" |
70 #include "net/cert/multi_threaded_cert_verifier.h" | 70 #include "net/cert/multi_threaded_cert_verifier.h" |
71 #include "net/cookies/cookie_store.h" | 71 #include "net/cookies/cookie_store.h" |
72 #include "net/dns/host_cache.h" | 72 #include "net/dns/host_cache.h" |
73 #include "net/dns/host_resolver.h" | 73 #include "net/dns/host_resolver.h" |
74 #include "net/dns/mapped_host_resolver.h" | 74 #include "net/dns/mapped_host_resolver.h" |
75 #include "net/ftp/ftp_network_layer.h" | 75 #include "net/ftp/ftp_network_layer.h" |
76 #include "net/http/http_auth_filter.h" | 76 #include "net/http/http_auth_filter.h" |
77 #include "net/http/http_auth_handler_factory.h" | 77 #include "net/http/http_auth_handler_factory.h" |
| 78 #include "net/http/http_auth_preferences.h" |
78 #include "net/http/http_network_layer.h" | 79 #include "net/http/http_network_layer.h" |
79 #include "net/http/http_network_session.h" | 80 #include "net/http/http_network_session.h" |
80 #include "net/http/http_server_properties_impl.h" | 81 #include "net/http/http_server_properties_impl.h" |
81 #include "net/proxy/proxy_config_service.h" | 82 #include "net/proxy/proxy_config_service.h" |
82 #include "net/proxy/proxy_script_fetcher_impl.h" | 83 #include "net/proxy/proxy_script_fetcher_impl.h" |
83 #include "net/proxy/proxy_service.h" | 84 #include "net/proxy/proxy_service.h" |
84 #include "net/quic/crypto/crypto_protocol.h" | 85 #include "net/quic/crypto/crypto_protocol.h" |
85 #include "net/quic/quic_protocol.h" | 86 #include "net/quic/quic_protocol.h" |
86 #include "net/quic/quic_utils.h" | 87 #include "net/quic/quic_utils.h" |
87 #include "net/socket/ssl_client_socket.h" | 88 #include "net/socket/ssl_client_socket.h" |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 extensions::EventRouterForwarder* extension_event_router_forwarder) | 460 extensions::EventRouterForwarder* extension_event_router_forwarder) |
460 : net_log_(net_log), | 461 : net_log_(net_log), |
461 #if defined(ENABLE_EXTENSIONS) | 462 #if defined(ENABLE_EXTENSIONS) |
462 extension_event_router_forwarder_(extension_event_router_forwarder), | 463 extension_event_router_forwarder_(extension_event_router_forwarder), |
463 #endif | 464 #endif |
464 globals_(NULL), | 465 globals_(NULL), |
465 is_spdy_disabled_by_policy_(false), | 466 is_spdy_disabled_by_policy_(false), |
466 is_quic_allowed_by_policy_(true), | 467 is_quic_allowed_by_policy_(true), |
467 creation_time_(base::TimeTicks::Now()), | 468 creation_time_(base::TimeTicks::Now()), |
468 weak_factory_(this) { | 469 weak_factory_(this) { |
| 470 scoped_refptr<base::SingleThreadTaskRunner> io_thread_proxy = |
| 471 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
469 auth_schemes_ = local_state->GetString(prefs::kAuthSchemes); | 472 auth_schemes_ = local_state->GetString(prefs::kAuthSchemes); |
470 negotiate_disable_cname_lookup_ = local_state->GetBoolean( | 473 negotiate_disable_cname_lookup_.Init( |
471 prefs::kDisableAuthNegotiateCnameLookup); | 474 prefs::kDisableAuthNegotiateCnameLookup, local_state, |
472 negotiate_enable_port_ = local_state->GetBoolean( | 475 base::Bind(&IOThread::UpdateNegotiateDisableCnameLookup, |
473 prefs::kEnableAuthNegotiatePort); | 476 base::Unretained(this))); |
474 auth_server_whitelist_ = local_state->GetString(prefs::kAuthServerWhitelist); | 477 negotiate_disable_cname_lookup_.MoveToThread(io_thread_proxy); |
475 auth_delegate_whitelist_ = local_state->GetString( | 478 negotiate_enable_port_.Init( |
476 prefs::kAuthNegotiateDelegateWhitelist); | 479 prefs::kEnableAuthNegotiatePort, local_state, |
| 480 base::Bind(&IOThread::UpdateNegotiateEnablePort, base::Unretained(this))); |
| 481 negotiate_enable_port_.MoveToThread(io_thread_proxy); |
| 482 auth_server_whitelist_.Init( |
| 483 prefs::kAuthServerWhitelist, local_state, |
| 484 base::Bind(&IOThread::UpdateServerWhitelist, base::Unretained(this))); |
| 485 auth_server_whitelist_.MoveToThread(io_thread_proxy); |
| 486 auth_delegate_whitelist_.Init( |
| 487 prefs::kAuthNegotiateDelegateWhitelist, local_state, |
| 488 base::Bind(&IOThread::UpdateDelegateWhitelist, base::Unretained(this))); |
| 489 auth_delegate_whitelist_.MoveToThread(io_thread_proxy); |
| 490 #if defined(OS_ANDROID) |
| 491 auth_android_negotiate_account_type_.Init( |
| 492 prefs::kAuthAndroidNegotiateAccountType, local_state, |
| 493 base::Bind(&IOThread::UpdateAndroidAuthNegotiateAccountType, |
| 494 base::Unretained(this))); |
| 495 auth_android_negotiate_account_type_.MoveToThread(io_thread_proxy); |
| 496 #endif |
| 497 #if defined(OS_POSIX) && !defined(OS_ANDROID) |
477 gssapi_library_name_ = local_state->GetString(prefs::kGSSAPILibraryName); | 498 gssapi_library_name_ = local_state->GetString(prefs::kGSSAPILibraryName); |
478 auth_android_negotiate_account_type_ = | 499 #endif |
479 local_state->GetString(prefs::kAuthAndroidNegotiateAccountType); | |
480 pref_proxy_config_tracker_.reset( | 500 pref_proxy_config_tracker_.reset( |
481 ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState( | 501 ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState( |
482 local_state)); | 502 local_state)); |
483 ChromeNetworkDelegate::InitializePrefsOnUIThread( | 503 ChromeNetworkDelegate::InitializePrefsOnUIThread( |
484 &system_enable_referrers_, | 504 &system_enable_referrers_, |
485 NULL, | 505 NULL, |
486 NULL, | 506 NULL, |
487 NULL, | 507 NULL, |
488 local_state); | 508 local_state); |
489 ssl_config_service_manager_.reset( | 509 ssl_config_service_manager_.reset( |
490 ssl_config::SSLConfigServiceManager::CreateDefaultManager( | 510 ssl_config::SSLConfigServiceManager::CreateDefaultManager( |
491 local_state, | 511 local_state, |
492 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); | 512 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); |
493 | 513 |
494 base::Value* dns_client_enabled_default = new base::FundamentalValue( | 514 base::Value* dns_client_enabled_default = new base::FundamentalValue( |
495 chrome_browser_net::ConfigureAsyncDnsFieldTrial()); | 515 chrome_browser_net::ConfigureAsyncDnsFieldTrial()); |
496 local_state->SetDefaultPrefValue(prefs::kBuiltInDnsClientEnabled, | 516 local_state->SetDefaultPrefValue(prefs::kBuiltInDnsClientEnabled, |
497 dns_client_enabled_default); | 517 dns_client_enabled_default); |
498 chrome_browser_net::LogAsyncDnsPrefSource( | 518 chrome_browser_net::LogAsyncDnsPrefSource( |
499 local_state->FindPreference(prefs::kBuiltInDnsClientEnabled)); | 519 local_state->FindPreference(prefs::kBuiltInDnsClientEnabled)); |
500 | 520 |
501 dns_client_enabled_.Init(prefs::kBuiltInDnsClientEnabled, | 521 dns_client_enabled_.Init(prefs::kBuiltInDnsClientEnabled, |
502 local_state, | 522 local_state, |
503 base::Bind(&IOThread::UpdateDnsClientEnabled, | 523 base::Bind(&IOThread::UpdateDnsClientEnabled, |
504 base::Unretained(this))); | 524 base::Unretained(this))); |
505 dns_client_enabled_.MoveToThread( | 525 dns_client_enabled_.MoveToThread(io_thread_proxy); |
506 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); | |
507 | 526 |
508 quick_check_enabled_.Init(prefs::kQuickCheckEnabled, | 527 quick_check_enabled_.Init(prefs::kQuickCheckEnabled, |
509 local_state); | 528 local_state); |
510 quick_check_enabled_.MoveToThread( | 529 quick_check_enabled_.MoveToThread(io_thread_proxy); |
511 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); | |
512 | 530 |
513 #if defined(ENABLE_CONFIGURATION_POLICY) | 531 #if defined(ENABLE_CONFIGURATION_POLICY) |
514 is_spdy_disabled_by_policy_ = policy_service->GetPolicies( | 532 is_spdy_disabled_by_policy_ = policy_service->GetPolicies( |
515 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, std::string())).Get( | 533 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, std::string())).Get( |
516 policy::key::kDisableSpdy) != NULL; | 534 policy::key::kDisableSpdy) != NULL; |
517 | 535 |
518 const base::Value* value = policy_service->GetPolicies( | 536 const base::Value* value = policy_service->GetPolicies( |
519 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, | 537 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, |
520 std::string())).GetValue(policy::key::kQuicAllowed); | 538 std::string())).GetValue(policy::key::kQuicAllowed); |
521 if (value) | 539 if (value) |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 | 754 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 |
737 // is fixed. | 755 // is fixed. |
738 tracked_objects::ScopedTracker tracking_profile10( | 756 tracked_objects::ScopedTracker tracking_profile10( |
739 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 757 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
740 "466432 IOThread::InitAsync::CertPolicyEnforcer")); | 758 "466432 IOThread::InitAsync::CertPolicyEnforcer")); |
741 net::CertPolicyEnforcer* policy_enforcer = new net::CertPolicyEnforcer; | 759 net::CertPolicyEnforcer* policy_enforcer = new net::CertPolicyEnforcer; |
742 globals_->cert_policy_enforcer.reset(policy_enforcer); | 760 globals_->cert_policy_enforcer.reset(policy_enforcer); |
743 | 761 |
744 globals_->ssl_config_service = GetSSLConfigService(); | 762 globals_->ssl_config_service = GetSSLConfigService(); |
745 | 763 |
746 globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory( | 764 CreateDefaultAuthHandlerFactory(); |
747 globals_->host_resolver.get())); | |
748 globals_->http_server_properties.reset(new net::HttpServerPropertiesImpl()); | 765 globals_->http_server_properties.reset(new net::HttpServerPropertiesImpl()); |
749 // For the ProxyScriptFetcher, we use a direct ProxyService. | 766 // For the ProxyScriptFetcher, we use a direct ProxyService. |
750 globals_->proxy_script_fetcher_proxy_service = | 767 globals_->proxy_script_fetcher_proxy_service = |
751 net::ProxyService::CreateDirectWithNetLog(net_log_); | 768 net::ProxyService::CreateDirectWithNetLog(net_log_); |
752 // In-memory cookie store. | 769 // In-memory cookie store. |
753 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 | 770 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 |
754 // is fixed. | 771 // is fixed. |
755 tracked_objects::ScopedTracker tracking_profile11( | 772 tracked_objects::ScopedTracker tracking_profile11( |
756 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 773 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
757 "466432 IOThread::InitAsync::CreateCookieStore::Start")); | 774 "466432 IOThread::InitAsync::CreateCookieStore::Start")); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 // Release objects that the net::URLRequestContext could have been pointing | 892 // Release objects that the net::URLRequestContext could have been pointing |
876 // to. | 893 // to. |
877 | 894 |
878 // Shutdown the HistogramWatcher on the IO thread. | 895 // Shutdown the HistogramWatcher on the IO thread. |
879 net::NetworkChangeNotifier::ShutdownHistogramWatcher(); | 896 net::NetworkChangeNotifier::ShutdownHistogramWatcher(); |
880 | 897 |
881 // This must be reset before the ChromeNetLog is destroyed. | 898 // This must be reset before the ChromeNetLog is destroyed. |
882 network_change_observer_.reset(); | 899 network_change_observer_.reset(); |
883 | 900 |
884 system_proxy_config_service_.reset(); | 901 system_proxy_config_service_.reset(); |
885 | |
886 delete globals_; | 902 delete globals_; |
887 globals_ = NULL; | 903 globals_ = NULL; |
888 | 904 |
889 base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks(); | 905 base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks(); |
890 } | 906 } |
891 | 907 |
892 void IOThread::InitializeNetworkOptions(const base::CommandLine& command_line) { | 908 void IOThread::InitializeNetworkOptions(const base::CommandLine& command_line) { |
893 // Only handle use-spdy command line flags if "spdy.disabled" preference is | 909 // Only handle use-spdy command line flags if "spdy.disabled" preference is |
894 // not disabled via policy. | 910 // not disabled via policy. |
895 if (is_spdy_disabled_by_policy_) { | 911 if (is_spdy_disabled_by_policy_) { |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1011 std::string()); | 1027 std::string()); |
1012 registry->RegisterStringPref(prefs::kGSSAPILibraryName, std::string()); | 1028 registry->RegisterStringPref(prefs::kGSSAPILibraryName, std::string()); |
1013 registry->RegisterStringPref(prefs::kAuthAndroidNegotiateAccountType, | 1029 registry->RegisterStringPref(prefs::kAuthAndroidNegotiateAccountType, |
1014 std::string()); | 1030 std::string()); |
1015 registry->RegisterBooleanPref(prefs::kEnableReferrers, true); | 1031 registry->RegisterBooleanPref(prefs::kEnableReferrers, true); |
1016 data_reduction_proxy::RegisterPrefs(registry); | 1032 data_reduction_proxy::RegisterPrefs(registry); |
1017 registry->RegisterBooleanPref(prefs::kBuiltInDnsClientEnabled, true); | 1033 registry->RegisterBooleanPref(prefs::kBuiltInDnsClientEnabled, true); |
1018 registry->RegisterBooleanPref(prefs::kQuickCheckEnabled, true); | 1034 registry->RegisterBooleanPref(prefs::kQuickCheckEnabled, true); |
1019 } | 1035 } |
1020 | 1036 |
1021 net::HttpAuthHandlerFactory* IOThread::CreateDefaultAuthHandlerFactory( | 1037 void IOThread::UpdateServerWhitelist() { |
1022 net::HostResolver* resolver) { | 1038 globals_->http_auth_preferences->set_server_whitelist( |
1023 net::HttpAuthFilterWhitelist* auth_filter_default_credentials = NULL; | 1039 auth_server_whitelist_.GetValue()); |
1024 if (!auth_server_whitelist_.empty()) { | 1040 } |
1025 auth_filter_default_credentials = | 1041 |
1026 new net::HttpAuthFilterWhitelist(auth_server_whitelist_); | 1042 void IOThread::UpdateDelegateWhitelist() { |
1027 } | 1043 globals_->http_auth_preferences->set_delegate_whitelist( |
1028 net::HttpAuthFilterWhitelist* auth_filter_delegate = NULL; | 1044 auth_delegate_whitelist_.GetValue()); |
1029 if (!auth_delegate_whitelist_.empty()) { | 1045 } |
1030 auth_filter_delegate = | 1046 |
1031 new net::HttpAuthFilterWhitelist(auth_delegate_whitelist_); | 1047 #if defined(OS_ANDROID) |
1032 } | 1048 void IOThread::UpdateAndroidAuthNegotiateAccountType() { |
1033 globals_->url_security_manager.reset( | 1049 globals_->http_auth_preferences->set_auth_android_negotiate_account_type( |
1034 net::URLSecurityManager::Create(auth_filter_default_credentials, | 1050 auth_android_negotiate_account_type_.GetValue()); |
1035 auth_filter_delegate)); | 1051 } |
| 1052 #endif |
| 1053 |
| 1054 void IOThread::UpdateNegotiateDisableCnameLookup() { |
| 1055 globals_->http_auth_preferences->set_negotiate_disable_cname_lookup( |
| 1056 negotiate_disable_cname_lookup_.GetValue()); |
| 1057 } |
| 1058 |
| 1059 void IOThread::UpdateNegotiateEnablePort() { |
| 1060 globals_->http_auth_preferences->set_negotiate_enable_port( |
| 1061 negotiate_enable_port_.GetValue()); |
| 1062 } |
| 1063 |
| 1064 void IOThread::CreateDefaultAuthHandlerFactory() { |
1036 std::vector<std::string> supported_schemes = base::SplitString( | 1065 std::vector<std::string> supported_schemes = base::SplitString( |
1037 auth_schemes_, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 1066 auth_schemes_, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
1038 | 1067 globals_->http_auth_preferences.reset(new net::HttpAuthPreferences( |
1039 scoped_ptr<net::HttpAuthHandlerRegistryFactory> registry_factory( | 1068 supported_schemes |
| 1069 #if defined(OS_POSIX) && !defined(OS_ANDROID) |
| 1070 , |
| 1071 gssapi_library_name_ |
| 1072 #endif |
| 1073 )); |
| 1074 UpdateServerWhitelist(); |
| 1075 UpdateDelegateWhitelist(); |
| 1076 UpdateNegotiateDisableCnameLookup(); |
| 1077 UpdateNegotiateEnablePort(); |
| 1078 #if defined(OS_ANDROID) |
| 1079 UpdateAndroidAuthNegotiateAccountType(); |
| 1080 #endif |
| 1081 globals_->http_auth_handler_factory = |
1040 net::HttpAuthHandlerRegistryFactory::Create( | 1082 net::HttpAuthHandlerRegistryFactory::Create( |
1041 supported_schemes, globals_->url_security_manager.get(), resolver, | 1083 globals_->http_auth_preferences.get(), globals_->host_resolver.get()) |
1042 gssapi_library_name_, auth_android_negotiate_account_type_, | 1084 .Pass(); |
1043 negotiate_disable_cname_lookup_, negotiate_enable_port_)); | |
1044 return registry_factory.release(); | |
1045 } | 1085 } |
1046 | 1086 |
1047 void IOThread::ClearHostCache() { | 1087 void IOThread::ClearHostCache() { |
1048 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1088 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1049 | 1089 |
1050 net::HostCache* host_cache = globals_->host_resolver->GetHostCache(); | 1090 net::HostCache* host_cache = globals_->host_resolver->GetHostCache(); |
1051 if (host_cache) | 1091 if (host_cache) |
1052 host_cache->clear(); | 1092 host_cache->clear(); |
1053 } | 1093 } |
1054 | 1094 |
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1663 globals->proxy_script_fetcher_url_request_job_factory = job_factory.Pass(); | 1703 globals->proxy_script_fetcher_url_request_job_factory = job_factory.Pass(); |
1664 | 1704 |
1665 context->set_job_factory( | 1705 context->set_job_factory( |
1666 globals->proxy_script_fetcher_url_request_job_factory.get()); | 1706 globals->proxy_script_fetcher_url_request_job_factory.get()); |
1667 | 1707 |
1668 // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the | 1708 // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the |
1669 // system URLRequestContext too. There's no reason this should be tied to a | 1709 // system URLRequestContext too. There's no reason this should be tied to a |
1670 // profile. | 1710 // profile. |
1671 return context; | 1711 return context; |
1672 } | 1712 } |
OLD | NEW |