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