[email protected] | d24fc3a0 | 2012-02-11 02:08:34 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/io_thread.h" |
[email protected] | e83326f | 2010-07-31 17:29:25 | [diff] [blame] | 6 | |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 7 | #include <vector> |
| 8 | |
[email protected] | 21ee224e | 2011-11-21 02:17:53 | [diff] [blame] | 9 | #include "base/bind.h" |
| 10 | #include "base/bind_helpers.h" |
[email protected] | aa84a7e | 2012-03-15 21:29:06 | [diff] [blame] | 11 | #include "base/command_line.h" |
[email protected] | c93123fa | 2012-04-19 02:49:48 | [diff] [blame] | 12 | #include "base/compiler_specific.h" |
[email protected] | 5858035 | 2010-10-26 04:07:50 | [diff] [blame] | 13 | #include "base/debug/leak_tracker.h" |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 14 | #include "base/logging.h" |
[email protected] | 7286e3fc | 2011-07-19 22:13:24 | [diff] [blame] | 15 | #include "base/stl_util.h" |
[email protected] | e83326f | 2010-07-31 17:29:25 | [diff] [blame] | 16 | #include "base/string_number_conversions.h" |
[email protected] | 4e5ae20f | 2010-09-24 04:52:11 | [diff] [blame] | 17 | #include "base/string_split.h" |
[email protected] | f1d8192 | 2010-07-31 17:47:09 | [diff] [blame] | 18 | #include "base/string_util.h" |
[email protected] | 3fc40c14 | 2011-12-01 13:09:04 | [diff] [blame] | 19 | #include "base/threading/thread.h" |
[email protected] | 5bab49ec | 2012-05-04 21:13:19 | [diff] [blame] | 20 | #include "base/threading/worker_pool.h" |
[email protected] | addb324 | 2011-06-13 21:39:16 | [diff] [blame] | 21 | #include "build/build_config.h" |
[email protected] | df2840d | 2011-02-20 16:32:32 | [diff] [blame] | 22 | #include "chrome/browser/browser_process.h" |
[email protected] | 5a38dfd | 2012-07-23 23:22:10 | [diff] [blame] | 23 | #include "chrome/browser/extensions/event_router_forwarder.h" |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 24 | #include "chrome/browser/net/chrome_net_log.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 25 | #include "chrome/browser/net/chrome_network_delegate.h" |
[email protected] | 0ee7a3b | 2010-11-09 06:13:40 | [diff] [blame] | 26 | #include "chrome/browser/net/chrome_url_request_context.h" |
[email protected] | 1889dc1b | 2010-10-14 22:03:13 | [diff] [blame] | 27 | #include "chrome/browser/net/connect_interceptor.h" |
[email protected] | 7613faae | 2012-04-18 01:01:19 | [diff] [blame] | 28 | #include "chrome/browser/net/http_pipelining_compatibility_client.h" |
[email protected] | a9e0d141 | 2012-08-20 22:13:01 | [diff] [blame^] | 29 | #include "chrome/browser/net/load_time_stats.h" |
[email protected] | 6f96cbcb | 2011-11-04 02:26:07 | [diff] [blame] | 30 | #include "chrome/browser/net/pref_proxy_config_tracker.h" |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 31 | #include "chrome/browser/net/proxy_service_factory.h" |
[email protected] | 3b543ab | 2011-09-17 21:47:00 | [diff] [blame] | 32 | #include "chrome/browser/net/sdch_dictionary_fetcher.h" |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 33 | #include "chrome/browser/prefs/pref_service.h" |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 34 | #include "chrome/common/chrome_switches.h" |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 35 | #include "chrome/common/pref_names.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 36 | #include "content/public/browser/browser_thread.h" |
[email protected] | 5d1fa24 | 2011-10-18 23:35:38 | [diff] [blame] | 37 | #include "content/public/common/content_client.h" |
[email protected] | 822581d | 2010-12-16 17:27:15 | [diff] [blame] | 38 | #include "net/base/cert_verifier.h" |
[email protected] | 32cb7fb | 2012-03-22 22:41:11 | [diff] [blame] | 39 | #include "net/base/default_server_bound_cert_store.h" |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 40 | #include "net/base/host_cache.h" |
| 41 | #include "net/base/host_resolver.h" |
[email protected] | 8693361 | 2010-10-16 23:10:33 | [diff] [blame] | 42 | #include "net/base/mapped_host_resolver.h" |
[email protected] | 32eaa33 | 2010-02-08 22:15:54 | [diff] [blame] | 43 | #include "net/base/net_util.h" |
[email protected] | 3b543ab | 2011-09-17 21:47:00 | [diff] [blame] | 44 | #include "net/base/sdch_manager.h" |
[email protected] | 32cb7fb | 2012-03-22 22:41:11 | [diff] [blame] | 45 | #include "net/base/server_bound_cert_service.h" |
[email protected] | aa84a7e | 2012-03-15 21:29:06 | [diff] [blame] | 46 | #include "net/cookies/cookie_monster.h" |
[email protected] | 933bc5c6 | 2011-04-12 19:08:02 | [diff] [blame] | 47 | #include "net/ftp/ftp_network_layer.h" |
[email protected] | eb3cac7 | 2010-02-26 21:07:45 | [diff] [blame] | 48 | #include "net/http/http_auth_filter.h" |
[email protected] | fa55e19 | 2010-02-15 14:25:50 | [diff] [blame] | 49 | #include "net/http/http_auth_handler_factory.h" |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 50 | #include "net/http/http_network_layer.h" |
[email protected] | 57cb0f7 | 2011-01-28 06:33:58 | [diff] [blame] | 51 | #include "net/http/http_network_session.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 52 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 53 | #include "net/proxy/proxy_config_service.h" |
[email protected] | 8693361 | 2010-10-16 23:10:33 | [diff] [blame] | 54 | #include "net/proxy/proxy_script_fetcher_impl.h" |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 55 | #include "net/proxy/proxy_service.h" |
[email protected] | 3dc1bc4 | 2012-06-19 08:20:53 | [diff] [blame] | 56 | #include "net/url_request/url_fetcher.h" |
[email protected] | a73a280 | 2012-05-02 19:20:15 | [diff] [blame] | 57 | #include "net/url_request/url_request_throttler_manager.h" |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 58 | |
[email protected] | 77feb46 | 2011-05-16 23:37:25 | [diff] [blame] | 59 | #if defined(USE_NSS) |
| 60 | #include "net/ocsp/nss_ocsp.h" |
| 61 | #endif // defined(USE_NSS) |
| 62 | |
[email protected] | 6f96cbcb | 2011-11-04 02:26:07 | [diff] [blame] | 63 | #if defined(OS_CHROMEOS) |
| 64 | #include "chrome/browser/chromeos/proxy_config_service_impl.h" |
| 65 | #endif // defined(OS_CHROMEOS) |
| 66 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 67 | using content::BrowserThread; |
| 68 | |
[email protected] | 075c032 | 2012-02-14 00:56:44 | [diff] [blame] | 69 | class SafeBrowsingURLRequestContext; |
| 70 | |
[email protected] | 21ee224e | 2011-11-21 02:17:53 | [diff] [blame] | 71 | // The IOThread object must outlive any tasks posted to the IO thread before the |
| 72 | // Quit task, so base::Bind() calls are not refcounted. |
| 73 | |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 74 | namespace { |
| 75 | |
[email protected] | bd0875e | 2011-03-25 05:13:35 | [diff] [blame] | 76 | // Custom URLRequestContext used by requests which aren't associated with a |
| 77 | // particular profile. We need to use a subclass of URLRequestContext in order |
| 78 | // to provide the correct User-Agent. |
| 79 | class URLRequestContextWithUserAgent : public net::URLRequestContext { |
| 80 | public: |
| 81 | virtual const std::string& GetUserAgent( |
| 82 | const GURL& url) const OVERRIDE { |
[email protected] | b7552023 | 2011-10-12 23:45:25 | [diff] [blame] | 83 | return content::GetUserAgent(url); |
[email protected] | bd0875e | 2011-03-25 05:13:35 | [diff] [blame] | 84 | } |
[email protected] | 649d1c0 | 2012-04-27 02:56:21 | [diff] [blame] | 85 | |
| 86 | protected: |
| 87 | virtual ~URLRequestContextWithUserAgent() {} |
[email protected] | bd0875e | 2011-03-25 05:13:35 | [diff] [blame] | 88 | }; |
| 89 | |
[email protected] | 77feb46 | 2011-05-16 23:37:25 | [diff] [blame] | 90 | // Used for the "system" URLRequestContext. If this grows more complicated, then |
| 91 | // consider inheriting directly from URLRequestContext rather than using |
| 92 | // implementation inheritance. |
| 93 | class SystemURLRequestContext : public URLRequestContextWithUserAgent { |
| 94 | public: |
| 95 | SystemURLRequestContext() { |
| 96 | #if defined(USE_NSS) |
[email protected] | 8c434cbc | 2012-03-14 14:25:09 | [diff] [blame] | 97 | net::SetURLRequestContextForNSSHttpIO(this); |
[email protected] | 77feb46 | 2011-05-16 23:37:25 | [diff] [blame] | 98 | #endif // defined(USE_NSS) |
| 99 | } |
| 100 | |
| 101 | private: |
| 102 | virtual ~SystemURLRequestContext() { |
| 103 | #if defined(USE_NSS) |
[email protected] | 8c434cbc | 2012-03-14 14:25:09 | [diff] [blame] | 104 | net::SetURLRequestContextForNSSHttpIO(NULL); |
[email protected] | 77feb46 | 2011-05-16 23:37:25 | [diff] [blame] | 105 | #endif // defined(USE_NSS) |
| 106 | } |
| 107 | }; |
| 108 | |
[email protected] | ee094b8 | 2010-08-24 15:55:51 | [diff] [blame] | 109 | net::HostResolver* CreateGlobalHostResolver(net::NetLog* net_log) { |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 110 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | 962b9821 | 2010-07-17 03:37:51 | [diff] [blame] | 111 | |
| 112 | size_t parallelism = net::HostResolver::kDefaultParallelism; |
| 113 | |
| 114 | // Use the concurrency override from the command-line, if any. |
| 115 | if (command_line.HasSwitch(switches::kHostResolverParallelism)) { |
| 116 | std::string s = |
| 117 | command_line.GetSwitchValueASCII(switches::kHostResolverParallelism); |
| 118 | |
| 119 | // Parse the switch (it should be a positive integer formatted as decimal). |
| 120 | int n; |
[email protected] | e83326f | 2010-07-31 17:29:25 | [diff] [blame] | 121 | if (base::StringToInt(s, &n) && n > 0) { |
[email protected] | 962b9821 | 2010-07-17 03:37:51 | [diff] [blame] | 122 | parallelism = static_cast<size_t>(n); |
| 123 | } else { |
| 124 | LOG(ERROR) << "Invalid switch for host resolver parallelism: " << s; |
| 125 | } |
| 126 | } |
| 127 | |
[email protected] | 06ef6d9 | 2011-05-19 04:24:58 | [diff] [blame] | 128 | size_t retry_attempts = net::HostResolver::kDefaultRetryAttempts; |
| 129 | |
| 130 | // Use the retry attempts override from the command-line, if any. |
| 131 | if (command_line.HasSwitch(switches::kHostResolverRetryAttempts)) { |
| 132 | std::string s = |
| 133 | command_line.GetSwitchValueASCII(switches::kHostResolverRetryAttempts); |
| 134 | // Parse the switch (it should be a non-negative integer). |
| 135 | int n; |
| 136 | if (base::StringToInt(s, &n) && n >= 0) { |
| 137 | retry_attempts = static_cast<size_t>(n); |
| 138 | } else { |
| 139 | LOG(ERROR) << "Invalid switch for host resolver retry attempts: " << s; |
| 140 | } |
| 141 | } |
| 142 | |
[email protected] | d987cca | 2011-07-21 12:54:37 | [diff] [blame] | 143 | net::HostResolver* global_host_resolver = NULL; |
[email protected] | b3601bc2 | 2012-02-21 21:23:20 | [diff] [blame] | 144 | if (command_line.HasSwitch(switches::kEnableAsyncDns)) { |
| 145 | global_host_resolver = |
| 146 | net::CreateAsyncHostResolver(parallelism, retry_attempts, net_log); |
[email protected] | d987cca | 2011-07-21 12:54:37 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | if (!global_host_resolver) { |
| 150 | global_host_resolver = |
[email protected] | 06ef6d9 | 2011-05-19 04:24:58 | [diff] [blame] | 151 | net::CreateSystemHostResolver(parallelism, retry_attempts, net_log); |
[email protected] | d987cca | 2011-07-21 12:54:37 | [diff] [blame] | 152 | } |
[email protected] | 9087aa3 | 2010-02-18 08:03:38 | [diff] [blame] | 153 | |
[email protected] | 0f8f1b43 | 2010-03-16 19:06:03 | [diff] [blame] | 154 | // Determine if we should disable IPv6 support. |
[email protected] | 9087aa3 | 2010-02-18 08:03:38 | [diff] [blame] | 155 | if (!command_line.HasSwitch(switches::kEnableIPv6)) { |
[email protected] | 0f8f1b43 | 2010-03-16 19:06:03 | [diff] [blame] | 156 | if (command_line.HasSwitch(switches::kDisableIPv6)) { |
[email protected] | 46f6e20 | 2010-02-26 06:07:25 | [diff] [blame] | 157 | global_host_resolver->SetDefaultAddressFamily(net::ADDRESS_FAMILY_IPV4); |
[email protected] | 0f8f1b43 | 2010-03-16 19:06:03 | [diff] [blame] | 158 | } else { |
[email protected] | a78f427 | 2011-10-21 19:16:33 | [diff] [blame] | 159 | global_host_resolver->ProbeIPv6Support(); |
[email protected] | 0f8f1b43 | 2010-03-16 19:06:03 | [diff] [blame] | 160 | } |
[email protected] | 9087aa3 | 2010-02-18 08:03:38 | [diff] [blame] | 161 | } |
| 162 | |
[email protected] | 9087aa3 | 2010-02-18 08:03:38 | [diff] [blame] | 163 | // If hostname remappings were specified on the command-line, layer these |
| 164 | // rules on top of the real host resolver. This allows forwarding all requests |
| 165 | // through a designated test server. |
[email protected] | 0f8f1b43 | 2010-03-16 19:06:03 | [diff] [blame] | 166 | if (!command_line.HasSwitch(switches::kHostResolverRules)) |
| 167 | return global_host_resolver; |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 168 | |
[email protected] | 0f8f1b43 | 2010-03-16 19:06:03 | [diff] [blame] | 169 | net::MappedHostResolver* remapped_resolver = |
| 170 | new net::MappedHostResolver(global_host_resolver); |
| 171 | remapped_resolver->SetRulesFromString( |
| 172 | command_line.GetSwitchValueASCII(switches::kHostResolverRules)); |
| 173 | return remapped_resolver; |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 174 | } |
| 175 | |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 176 | // TODO(willchan): Remove proxy script fetcher context since it's not necessary |
| 177 | // now that I got rid of refcounting URLRequestContexts. |
[email protected] | 77feb46 | 2011-05-16 23:37:25 | [diff] [blame] | 178 | // See IOThread::Globals for details. |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 179 | net::URLRequestContext* |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 180 | ConstructProxyScriptFetcherContext(IOThread::Globals* globals, |
| 181 | net::NetLog* net_log) { |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 182 | net::URLRequestContext* context = new URLRequestContextWithUserAgent; |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 183 | context->set_net_log(net_log); |
| 184 | context->set_host_resolver(globals->host_resolver.get()); |
| 185 | context->set_cert_verifier(globals->cert_verifier.get()); |
[email protected] | a2a4197 | 2011-12-07 17:47:27 | [diff] [blame] | 186 | context->set_transport_security_state( |
| 187 | globals->transport_security_state.get()); |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 188 | context->set_http_auth_handler_factory( |
| 189 | globals->http_auth_handler_factory.get()); |
| 190 | context->set_proxy_service(globals->proxy_script_fetcher_proxy_service.get()); |
| 191 | context->set_http_transaction_factory( |
[email protected] | 52617df | 2010-12-24 07:30:01 | [diff] [blame] | 192 | globals->proxy_script_fetcher_http_transaction_factory.get()); |
[email protected] | 933bc5c6 | 2011-04-12 19:08:02 | [diff] [blame] | 193 | context->set_ftp_transaction_factory( |
| 194 | globals->proxy_script_fetcher_ftp_transaction_factory.get()); |
[email protected] | 273e37d | 2011-08-11 01:49:12 | [diff] [blame] | 195 | context->set_cookie_store(globals->system_cookie_store.get()); |
[email protected] | 9c4eff2 | 2012-03-20 22:42:29 | [diff] [blame] | 196 | context->set_server_bound_cert_service( |
| 197 | globals->system_server_bound_cert_service.get()); |
[email protected] | 3ce0241 | 2011-03-01 12:01:15 | [diff] [blame] | 198 | context->set_network_delegate(globals->system_network_delegate.get()); |
[email protected] | db96a88 | 2011-10-09 02:01:54 | [diff] [blame] | 199 | // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the |
| 200 | // system URLRequestContext too. There's no reason this should be tied to a |
| 201 | // profile. |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 202 | return context; |
| 203 | } |
| 204 | |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 205 | net::URLRequestContext* |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 206 | ConstructSystemRequestContext(IOThread::Globals* globals, |
| 207 | net::NetLog* net_log) { |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 208 | net::URLRequestContext* context = new SystemURLRequestContext; |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 209 | context->set_net_log(net_log); |
| 210 | context->set_host_resolver(globals->host_resolver.get()); |
| 211 | context->set_cert_verifier(globals->cert_verifier.get()); |
[email protected] | a2a4197 | 2011-12-07 17:47:27 | [diff] [blame] | 212 | context->set_transport_security_state( |
| 213 | globals->transport_security_state.get()); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 214 | context->set_http_auth_handler_factory( |
| 215 | globals->http_auth_handler_factory.get()); |
| 216 | context->set_proxy_service(globals->system_proxy_service.get()); |
| 217 | context->set_http_transaction_factory( |
| 218 | globals->system_http_transaction_factory.get()); |
[email protected] | 933bc5c6 | 2011-04-12 19:08:02 | [diff] [blame] | 219 | context->set_ftp_transaction_factory( |
| 220 | globals->system_ftp_transaction_factory.get()); |
[email protected] | 273e37d | 2011-08-11 01:49:12 | [diff] [blame] | 221 | context->set_cookie_store(globals->system_cookie_store.get()); |
[email protected] | 9c4eff2 | 2012-03-20 22:42:29 | [diff] [blame] | 222 | context->set_server_bound_cert_service( |
| 223 | globals->system_server_bound_cert_service.get()); |
[email protected] | a73a280 | 2012-05-02 19:20:15 | [diff] [blame] | 224 | context->set_throttler_manager(globals->throttler_manager.get()); |
[email protected] | 815c69cf | 2012-06-30 00:52:08 | [diff] [blame] | 225 | context->set_network_delegate(globals->system_network_delegate.get()); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 226 | return context; |
| 227 | } |
| 228 | |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 229 | } // namespace |
| 230 | |
[email protected] | e0845d5f | 2012-05-29 00:11:41 | [diff] [blame] | 231 | class IOThread::LoggingNetworkChangeObserver |
| 232 | : public net::NetworkChangeNotifier::IPAddressObserver { |
| 233 | public: |
| 234 | // |net_log| must remain valid throughout our lifetime. |
| 235 | explicit LoggingNetworkChangeObserver(net::NetLog* net_log) |
| 236 | : net_log_(net_log) { |
| 237 | net::NetworkChangeNotifier::AddIPAddressObserver(this); |
| 238 | } |
| 239 | |
| 240 | ~LoggingNetworkChangeObserver() { |
| 241 | net::NetworkChangeNotifier::RemoveIPAddressObserver(this); |
| 242 | } |
| 243 | |
| 244 | virtual void OnIPAddressChanged() { |
| 245 | VLOG(1) << "Observed a change to the network IP addresses"; |
| 246 | |
[email protected] | 2fa0891 | 2012-06-14 20:56:26 | [diff] [blame] | 247 | net_log_->AddGlobalEntry(net::NetLog::TYPE_NETWORK_IP_ADDRESSES_CHANGED); |
[email protected] | e0845d5f | 2012-05-29 00:11:41 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | private: |
| 251 | net::NetLog* net_log_; |
| 252 | DISALLOW_COPY_AND_ASSIGN(LoggingNetworkChangeObserver); |
| 253 | }; |
| 254 | |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 255 | class SystemURLRequestContextGetter : public net::URLRequestContextGetter { |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 256 | public: |
| 257 | explicit SystemURLRequestContextGetter(IOThread* io_thread); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 258 | |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 259 | // Implementation for net::UrlRequestContextGetter. |
[email protected] | 4969b012 | 2012-06-16 01:58:28 | [diff] [blame] | 260 | virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE; |
| 261 | virtual scoped_refptr<base::SingleThreadTaskRunner> |
| 262 | GetNetworkTaskRunner() const OVERRIDE; |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 263 | |
[email protected] | 13ed17f8 | 2012-04-06 02:27:18 | [diff] [blame] | 264 | protected: |
| 265 | virtual ~SystemURLRequestContextGetter(); |
| 266 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 267 | private: |
| 268 | IOThread* const io_thread_; // Weak pointer, owned by BrowserProcess. |
[email protected] | 4969b012 | 2012-06-16 01:58:28 | [diff] [blame] | 269 | scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 270 | |
| 271 | base::debug::LeakTracker<SystemURLRequestContextGetter> leak_tracker_; |
| 272 | }; |
| 273 | |
| 274 | SystemURLRequestContextGetter::SystemURLRequestContextGetter( |
| 275 | IOThread* io_thread) |
| 276 | : io_thread_(io_thread), |
[email protected] | 4969b012 | 2012-06-16 01:58:28 | [diff] [blame] | 277 | network_task_runner_( |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 278 | BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)) { |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | SystemURLRequestContextGetter::~SystemURLRequestContextGetter() {} |
| 282 | |
| 283 | net::URLRequestContext* SystemURLRequestContextGetter::GetURLRequestContext() { |
| 284 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 285 | DCHECK(io_thread_->globals()->system_request_context.get()); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 286 | |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 287 | return io_thread_->globals()->system_request_context.get(); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 288 | } |
| 289 | |
[email protected] | 4969b012 | 2012-06-16 01:58:28 | [diff] [blame] | 290 | scoped_refptr<base::SingleThreadTaskRunner> |
| 291 | SystemURLRequestContextGetter::GetNetworkTaskRunner() const { |
| 292 | return network_task_runner_; |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 293 | } |
| 294 | |
[email protected] | c93123fa | 2012-04-19 02:49:48 | [diff] [blame] | 295 | IOThread::Globals:: |
| 296 | SystemRequestContextLeakChecker::SystemRequestContextLeakChecker( |
| 297 | Globals* globals) |
| 298 | : globals_(globals) { |
| 299 | DCHECK(globals_); |
[email protected] | 7613faae | 2012-04-18 01:01:19 | [diff] [blame] | 300 | } |
[email protected] | 1889dc1b | 2010-10-14 22:03:13 | [diff] [blame] | 301 | |
[email protected] | c93123fa | 2012-04-19 02:49:48 | [diff] [blame] | 302 | IOThread::Globals:: |
| 303 | SystemRequestContextLeakChecker::~SystemRequestContextLeakChecker() { |
| 304 | if (globals_->system_request_context.get()) |
| 305 | globals_->system_request_context->AssertNoURLRequests(); |
| 306 | } |
| 307 | |
| 308 | IOThread::Globals::Globals() |
| 309 | : ALLOW_THIS_IN_INITIALIZER_LIST( |
| 310 | system_request_context_leak_checker(this)) {} |
| 311 | IOThread::Globals::~Globals() {} |
| 312 | |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 313 | // |local_state| is passed in explicitly in order to (1) reduce implicit |
| 314 | // dependencies and (2) make IOThread more flexible for testing. |
[email protected] | 3ce0241 | 2011-03-01 12:01:15 | [diff] [blame] | 315 | IOThread::IOThread( |
| 316 | PrefService* local_state, |
| 317 | ChromeNetLog* net_log, |
[email protected] | 5a38dfd | 2012-07-23 23:22:10 | [diff] [blame] | 318 | extensions::EventRouterForwarder* extension_event_router_forwarder) |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 319 | : net_log_(net_log), |
[email protected] | 3ce0241 | 2011-03-01 12:01:15 | [diff] [blame] | 320 | extension_event_router_forwarder_(extension_event_router_forwarder), |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 321 | globals_(NULL), |
[email protected] | 4a10949 | 2011-09-24 21:00:12 | [diff] [blame] | 322 | sdch_manager_(NULL), |
[email protected] | 21ee224e | 2011-11-21 02:17:53 | [diff] [blame] | 323 | ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 324 | // We call RegisterPrefs() here (instead of inside browser_prefs.cc) to make |
| 325 | // sure that everything is initialized in the right order. |
| 326 | RegisterPrefs(local_state); |
| 327 | auth_schemes_ = local_state->GetString(prefs::kAuthSchemes); |
| 328 | negotiate_disable_cname_lookup_ = local_state->GetBoolean( |
| 329 | prefs::kDisableAuthNegotiateCnameLookup); |
| 330 | negotiate_enable_port_ = local_state->GetBoolean( |
| 331 | prefs::kEnableAuthNegotiatePort); |
| 332 | auth_server_whitelist_ = local_state->GetString(prefs::kAuthServerWhitelist); |
| 333 | auth_delegate_whitelist_ = local_state->GetString( |
| 334 | prefs::kAuthNegotiateDelegateWhitelist); |
[email protected] | ac7f3fdb | 2010-11-12 12:47:05 | [diff] [blame] | 335 | gssapi_library_name_ = local_state->GetString(prefs::kGSSAPILibraryName); |
[email protected] | 6f96cbcb | 2011-11-04 02:26:07 | [diff] [blame] | 336 | pref_proxy_config_tracker_.reset( |
| 337 | ProxyServiceFactory::CreatePrefProxyConfigTracker(local_state)); |
[email protected] | 0a8db0d | 2011-04-13 15:15:40 | [diff] [blame] | 338 | ChromeNetworkDelegate::InitializeReferrersEnabled(&system_enable_referrers_, |
| 339 | local_state); |
[email protected] | 4d45a6de | 2011-05-13 05:20:18 | [diff] [blame] | 340 | ssl_config_service_manager_.reset( |
| 341 | SSLConfigServiceManager::CreateDefaultManager(local_state)); |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 342 | |
| 343 | BrowserThread::SetDelegate(BrowserThread::IO, this); |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 344 | } |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 345 | |
| 346 | IOThread::~IOThread() { |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 347 | // This isn't needed for production code, but in tests, IOThread may |
| 348 | // be multiply constructed. |
| 349 | BrowserThread::SetDelegate(BrowserThread::IO, NULL); |
| 350 | |
[email protected] | 6f96cbcb | 2011-11-04 02:26:07 | [diff] [blame] | 351 | if (pref_proxy_config_tracker_.get()) |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 352 | pref_proxy_config_tracker_->DetachFromPrefService(); |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 353 | DCHECK(!globals_); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 354 | } |
| 355 | |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 356 | IOThread::Globals* IOThread::globals() { |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 357 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 358 | return globals_; |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 359 | } |
| 360 | |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 361 | ChromeNetLog* IOThread::net_log() { |
| 362 | return net_log_; |
| 363 | } |
| 364 | |
[email protected] | b09f76d6 | 2011-12-07 01:51:06 | [diff] [blame] | 365 | void IOThread::ChangedToOnTheRecord() { |
| 366 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 367 | BrowserThread::PostTask( |
| 368 | BrowserThread::IO, |
| 369 | FROM_HERE, |
| 370 | base::Bind(&IOThread::ChangedToOnTheRecordOnIOThread, |
| 371 | base::Unretained(this))); |
| 372 | } |
| 373 | |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 374 | net::URLRequestContextGetter* IOThread::system_url_request_context_getter() { |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 375 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 376 | if (!system_url_request_context_getter_) { |
[email protected] | addb324 | 2011-06-13 21:39:16 | [diff] [blame] | 377 | InitSystemRequestContext(); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 378 | } |
| 379 | return system_url_request_context_getter_; |
| 380 | } |
| 381 | |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 382 | void IOThread::Init() { |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 383 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 70b9234 | 2010-10-12 05:54:06 | [diff] [blame] | 384 | |
| 385 | #if defined(USE_NSS) |
[email protected] | 8c434cbc | 2012-03-14 14:25:09 | [diff] [blame] | 386 | net::SetMessageLoopForNSSHttpIO(); |
[email protected] | ecd95ae | 2010-10-20 23:58:17 | [diff] [blame] | 387 | #endif // defined(USE_NSS) |
[email protected] | 70b9234 | 2010-10-12 05:54:06 | [diff] [blame] | 388 | |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 389 | DCHECK(!globals_); |
| 390 | globals_ = new Globals; |
| 391 | |
[email protected] | 58bc704 | 2010-07-07 18:04:14 | [diff] [blame] | 392 | // Add an observer that will emit network change events to the ChromeNetLog. |
| 393 | // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be |
| 394 | // logging the network change before other IO thread consumers respond to it. |
| 395 | network_change_observer_.reset( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 396 | new LoggingNetworkChangeObserver(net_log_)); |
[email protected] | 58bc704 | 2010-07-07 18:04:14 | [diff] [blame] | 397 | |
[email protected] | cde8b3c | 2012-08-13 19:20:52 | [diff] [blame] | 398 | // Setup the HistogramWatcher to run on the IO thread. |
| 399 | net::NetworkChangeNotifier::InitHistogramWatcher(); |
| 400 | |
[email protected] | 3ce0241 | 2011-03-01 12:01:15 | [diff] [blame] | 401 | globals_->extension_event_router_forwarder = |
| 402 | extension_event_router_forwarder_; |
[email protected] | a1d4ab07 | 2012-06-07 13:21:15 | [diff] [blame] | 403 | ChromeNetworkDelegate* network_delegate = new ChromeNetworkDelegate( |
[email protected] | 0a8db0d | 2011-04-13 15:15:40 | [diff] [blame] | 404 | extension_event_router_forwarder_, |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 405 | NULL, |
[email protected] | 67351452 | 2011-07-13 18:17:18 | [diff] [blame] | 406 | NULL, |
[email protected] | 6a5f77c3 | 2011-09-04 19:19:59 | [diff] [blame] | 407 | NULL, |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 408 | NULL, |
[email protected] | e9c41d2 | 2012-08-17 00:08:15 | [diff] [blame] | 409 | NULL, |
[email protected] | 5a07c19 | 2012-07-30 20:18:22 | [diff] [blame] | 410 | &system_enable_referrers_, |
| 411 | NULL); |
[email protected] | a1d4ab07 | 2012-06-07 13:21:15 | [diff] [blame] | 412 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 413 | switches::kDisableExtensionsHttpThrottling)) { |
| 414 | network_delegate->NeverThrottleRequests(); |
| 415 | } |
| 416 | globals_->system_network_delegate.reset(network_delegate); |
[email protected] | 73c4532 | 2010-10-01 23:57:54 | [diff] [blame] | 417 | globals_->host_resolver.reset( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 418 | CreateGlobalHostResolver(net_log_)); |
[email protected] | 9f59fac | 2012-03-21 23:18:11 | [diff] [blame] | 419 | globals_->cert_verifier.reset(net::CertVerifier::CreateDefault()); |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 420 | globals_->transport_security_state.reset(new net::TransportSecurityState()); |
[email protected] | 4d45a6de | 2011-05-13 05:20:18 | [diff] [blame] | 421 | globals_->ssl_config_service = GetSSLConfigService(); |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 422 | globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory( |
[email protected] | 73c4532 | 2010-10-01 23:57:54 | [diff] [blame] | 423 | globals_->host_resolver.get())); |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 424 | globals_->http_server_properties.reset(new net::HttpServerPropertiesImpl); |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 425 | // For the ProxyScriptFetcher, we use a direct ProxyService. |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 426 | globals_->proxy_script_fetcher_proxy_service.reset( |
| 427 | net::ProxyService::CreateDirectWithNetLog(net_log_)); |
[email protected] | 273e37d | 2011-08-11 01:49:12 | [diff] [blame] | 428 | // In-memory cookie store. |
| 429 | globals_->system_cookie_store = new net::CookieMonster(NULL, NULL); |
[email protected] | 9c4eff2 | 2012-03-20 22:42:29 | [diff] [blame] | 430 | // In-memory server bound cert store. |
| 431 | globals_->system_server_bound_cert_service.reset( |
| 432 | new net::ServerBoundCertService( |
[email protected] | 5bab49ec | 2012-05-04 21:13:19 | [diff] [blame] | 433 | new net::DefaultServerBoundCertStore(NULL), |
| 434 | base::WorkerPool::GetTaskRunner(true))); |
[email protected] | a9e0d141 | 2012-08-20 22:13:01 | [diff] [blame^] | 435 | globals_->load_time_stats.reset(new chrome_browser_net::LoadTimeStats()); |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 436 | net::HttpNetworkSession::Params session_params; |
| 437 | session_params.host_resolver = globals_->host_resolver.get(); |
| 438 | session_params.cert_verifier = globals_->cert_verifier.get(); |
[email protected] | 9c4eff2 | 2012-03-20 22:42:29 | [diff] [blame] | 439 | session_params.server_bound_cert_service = |
| 440 | globals_->system_server_bound_cert_service.get(); |
[email protected] | a2a4197 | 2011-12-07 17:47:27 | [diff] [blame] | 441 | session_params.transport_security_state = |
| 442 | globals_->transport_security_state.get(); |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 443 | session_params.proxy_service = |
| 444 | globals_->proxy_script_fetcher_proxy_service.get(); |
| 445 | session_params.http_auth_handler_factory = |
| 446 | globals_->http_auth_handler_factory.get(); |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 447 | session_params.network_delegate = globals_->system_network_delegate.get(); |
[email protected] | db96a88 | 2011-10-09 02:01:54 | [diff] [blame] | 448 | // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the |
| 449 | // system URLRequestContext too. There's no reason this should be tied to a |
| 450 | // profile. |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 451 | session_params.http_server_properties = |
| 452 | globals_->http_server_properties.get(); |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 453 | session_params.net_log = net_log_; |
| 454 | session_params.ssl_config_service = globals_->ssl_config_service; |
[email protected] | 57cb0f7 | 2011-01-28 06:33:58 | [diff] [blame] | 455 | scoped_refptr<net::HttpNetworkSession> network_session( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 456 | new net::HttpNetworkSession(session_params)); |
[email protected] | 57cb0f7 | 2011-01-28 06:33:58 | [diff] [blame] | 457 | globals_->proxy_script_fetcher_http_transaction_factory.reset( |
| 458 | new net::HttpNetworkLayer(network_session)); |
[email protected] | 933bc5c6 | 2011-04-12 19:08:02 | [diff] [blame] | 459 | globals_->proxy_script_fetcher_ftp_transaction_factory.reset( |
| 460 | new net::FtpNetworkLayer(globals_->host_resolver.get())); |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 461 | |
[email protected] | a73a280 | 2012-05-02 19:20:15 | [diff] [blame] | 462 | globals_->throttler_manager.reset(new net::URLRequestThrottlerManager()); |
[email protected] | a1d4ab07 | 2012-06-07 13:21:15 | [diff] [blame] | 463 | globals_->throttler_manager->set_net_log(net_log_); |
[email protected] | a73a280 | 2012-05-02 19:20:15 | [diff] [blame] | 464 | // Always done in production, disabled only for unit tests. |
| 465 | globals_->throttler_manager->set_enable_thread_checks(true); |
[email protected] | a73a280 | 2012-05-02 19:20:15 | [diff] [blame] | 466 | |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 467 | globals_->proxy_script_fetcher_context.reset( |
| 468 | ConstructProxyScriptFetcherContext(globals_, net_log_)); |
[email protected] | 4a10949 | 2011-09-24 21:00:12 | [diff] [blame] | 469 | |
| 470 | sdch_manager_ = new net::SdchManager(); |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 471 | |
| 472 | // InitSystemRequestContext turns right around and posts a task back |
| 473 | // to the IO thread, so we can't let it run until we know the IO |
| 474 | // thread has started. |
| 475 | // |
| 476 | // Note that since we are at BrowserThread::Init time, the UI thread |
| 477 | // is blocked waiting for the thread to start. Therefore, posting |
| 478 | // this task to the main thread's message loop here is guaranteed to |
| 479 | // get it onto the message loop while the IOThread object still |
| 480 | // exists. However, the message might not be processed on the UI |
| 481 | // thread until after IOThread is gone, so use a weak pointer. |
| 482 | BrowserThread::PostTask(BrowserThread::UI, |
| 483 | FROM_HERE, |
| 484 | base::Bind(&IOThread::InitSystemRequestContext, |
| 485 | weak_factory_.GetWeakPtr())); |
| 486 | |
| 487 | // We constructed the weak pointer on the IO thread but it will be |
| 488 | // used on the UI thread. Call this to avoid a thread checker |
| 489 | // error. |
| 490 | weak_factory_.DetachFromThread(); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 491 | } |
| 492 | |
[email protected] | 2a92cd9 | 2010-04-27 00:01:41 | [diff] [blame] | 493 | void IOThread::CleanUp() { |
[email protected] | 075c032 | 2012-02-14 00:56:44 | [diff] [blame] | 494 | base::debug::LeakTracker<SafeBrowsingURLRequestContext>::CheckForLeaks(); |
| 495 | |
[email protected] | 4a10949 | 2011-09-24 21:00:12 | [diff] [blame] | 496 | delete sdch_manager_; |
| 497 | sdch_manager_ = NULL; |
| 498 | |
[email protected] | 59a3b36 | 2010-10-21 21:52:41 | [diff] [blame] | 499 | #if defined(USE_NSS) |
[email protected] | 8c434cbc | 2012-03-14 14:25:09 | [diff] [blame] | 500 | net::ShutdownNSSHttpIO(); |
[email protected] | 59a3b36 | 2010-10-21 21:52:41 | [diff] [blame] | 501 | #endif // defined(USE_NSS) |
| 502 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 503 | system_url_request_context_getter_ = NULL; |
| 504 | |
[email protected] | af66993 | 2012-01-17 19:26:58 | [diff] [blame] | 505 | // Release objects that the net::URLRequestContext could have been pointing |
| 506 | // to. |
[email protected] | 0ee7a3b | 2010-11-09 06:13:40 | [diff] [blame] | 507 | |
| 508 | // This must be reset before the ChromeNetLog is destroyed. |
| 509 | network_change_observer_.reset(); |
| 510 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 511 | system_proxy_config_service_.reset(); |
| 512 | |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 513 | delete globals_; |
| 514 | globals_ = NULL; |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 515 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 516 | base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks(); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 517 | } |
| 518 | |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 519 | // static |
| 520 | void IOThread::RegisterPrefs(PrefService* local_state) { |
| 521 | local_state->RegisterStringPref(prefs::kAuthSchemes, |
| 522 | "basic,digest,ntlm,negotiate"); |
| 523 | local_state->RegisterBooleanPref(prefs::kDisableAuthNegotiateCnameLookup, |
| 524 | false); |
| 525 | local_state->RegisterBooleanPref(prefs::kEnableAuthNegotiatePort, false); |
| 526 | local_state->RegisterStringPref(prefs::kAuthServerWhitelist, ""); |
| 527 | local_state->RegisterStringPref(prefs::kAuthNegotiateDelegateWhitelist, ""); |
[email protected] | ac7f3fdb | 2010-11-12 12:47:05 | [diff] [blame] | 528 | local_state->RegisterStringPref(prefs::kGSSAPILibraryName, ""); |
[email protected] | 0a8db0d | 2011-04-13 15:15:40 | [diff] [blame] | 529 | local_state->RegisterBooleanPref(prefs::kEnableReferrers, true); |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 530 | } |
| 531 | |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 532 | net::HttpAuthHandlerFactory* IOThread::CreateDefaultAuthHandlerFactory( |
| 533 | net::HostResolver* resolver) { |
[email protected] | 9030a63 | 2010-11-19 20:12:09 | [diff] [blame] | 534 | net::HttpAuthFilterWhitelist* auth_filter_default_credentials = NULL; |
| 535 | if (!auth_server_whitelist_.empty()) { |
| 536 | auth_filter_default_credentials = |
| 537 | new net::HttpAuthFilterWhitelist(auth_server_whitelist_); |
| 538 | } |
| 539 | net::HttpAuthFilterWhitelist* auth_filter_delegate = NULL; |
| 540 | if (!auth_delegate_whitelist_.empty()) { |
| 541 | auth_filter_delegate = |
| 542 | new net::HttpAuthFilterWhitelist(auth_delegate_whitelist_); |
| 543 | } |
[email protected] | b4955e7d | 2010-04-16 20:22:30 | [diff] [blame] | 544 | globals_->url_security_manager.reset( |
[email protected] | d201b200e | 2010-08-27 17:35:02 | [diff] [blame] | 545 | net::URLSecurityManager::Create(auth_filter_default_credentials, |
| 546 | auth_filter_delegate)); |
[email protected] | b730416 | 2010-08-23 17:42:29 | [diff] [blame] | 547 | std::vector<std::string> supported_schemes; |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 548 | base::SplitString(auth_schemes_, ',', &supported_schemes); |
[email protected] | b730416 | 2010-08-23 17:42:29 | [diff] [blame] | 549 | |
| 550 | return net::HttpAuthHandlerRegistryFactory::Create( |
| 551 | supported_schemes, |
| 552 | globals_->url_security_manager.get(), |
| 553 | resolver, |
[email protected] | ac7f3fdb | 2010-11-12 12:47:05 | [diff] [blame] | 554 | gssapi_library_name_, |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 555 | negotiate_disable_cname_lookup_, |
| 556 | negotiate_enable_port_); |
[email protected] | eb3cac7 | 2010-02-26 21:07:45 | [diff] [blame] | 557 | } |
| 558 | |
[email protected] | d6f37fc | 2011-02-13 23:58:41 | [diff] [blame] | 559 | void IOThread::ClearHostCache() { |
| 560 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 561 | |
[email protected] | 489d1a8 | 2011-10-12 03:09:11 | [diff] [blame] | 562 | net::HostCache* host_cache = globals_->host_resolver->GetHostCache(); |
| 563 | if (host_cache) |
| 564 | host_cache->clear(); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 565 | } |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 566 | |
[email protected] | 4d45a6de | 2011-05-13 05:20:18 | [diff] [blame] | 567 | net::SSLConfigService* IOThread::GetSSLConfigService() { |
| 568 | return ssl_config_service_manager_->Get(); |
| 569 | } |
| 570 | |
[email protected] | b09f76d6 | 2011-12-07 01:51:06 | [diff] [blame] | 571 | void IOThread::ChangedToOnTheRecordOnIOThread() { |
| 572 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 573 | |
| 574 | // Clear the host cache to avoid showing entries from the OTR session |
| 575 | // in about:net-internals. |
| 576 | ClearHostCache(); |
[email protected] | b09f76d6 | 2011-12-07 01:51:06 | [diff] [blame] | 577 | } |
| 578 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 579 | void IOThread::InitSystemRequestContext() { |
[email protected] | addb324 | 2011-06-13 21:39:16 | [diff] [blame] | 580 | if (system_url_request_context_getter_) |
| 581 | return; |
[email protected] | 63e2682 | 2011-07-16 19:07:35 | [diff] [blame] | 582 | // If we're in unit_tests, IOThread may not be run. |
[email protected] | dd48370 | 2011-12-02 14:47:42 | [diff] [blame] | 583 | if (!BrowserThread::IsMessageLoopValid(BrowserThread::IO)) |
[email protected] | 63e2682 | 2011-07-16 19:07:35 | [diff] [blame] | 584 | return; |
[email protected] | 71fdf77 | 2011-12-18 16:28:38 | [diff] [blame] | 585 | bool wait_for_first_update = (pref_proxy_config_tracker_.get() != NULL); |
[email protected] | 6f96cbcb | 2011-11-04 02:26:07 | [diff] [blame] | 586 | ChromeProxyConfigService* proxy_config_service = |
[email protected] | 71fdf77 | 2011-12-18 16:28:38 | [diff] [blame] | 587 | ProxyServiceFactory::CreateProxyConfigService(wait_for_first_update); |
[email protected] | 6f96cbcb | 2011-11-04 02:26:07 | [diff] [blame] | 588 | system_proxy_config_service_.reset(proxy_config_service); |
| 589 | if (pref_proxy_config_tracker_.get()) { |
| 590 | pref_proxy_config_tracker_->SetChromeProxyConfigService( |
| 591 | proxy_config_service); |
| 592 | } |
[email protected] | addb324 | 2011-06-13 21:39:16 | [diff] [blame] | 593 | system_url_request_context_getter_ = |
| 594 | new SystemURLRequestContextGetter(this); |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 595 | // Safe to post an unretained this pointer, since IOThread is |
| 596 | // guaranteed to outlive the IO BrowserThread. |
[email protected] | dd48370 | 2011-12-02 14:47:42 | [diff] [blame] | 597 | BrowserThread::PostTask( |
| 598 | BrowserThread::IO, |
| 599 | FROM_HERE, |
| 600 | base::Bind(&IOThread::InitSystemRequestContextOnIOThread, |
| 601 | base::Unretained(this))); |
[email protected] | addb324 | 2011-06-13 21:39:16 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | void IOThread::InitSystemRequestContextOnIOThread() { |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 605 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 606 | DCHECK(!globals_->system_proxy_service.get()); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 607 | DCHECK(system_proxy_config_service_.get()); |
| 608 | |
| 609 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 610 | globals_->system_proxy_service.reset( |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 611 | ProxyServiceFactory::CreateProxyService( |
| 612 | net_log_, |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 613 | globals_->proxy_script_fetcher_context.get(), |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 614 | system_proxy_config_service_.release(), |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 615 | command_line)); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 616 | net::HttpNetworkSession::Params system_params; |
| 617 | system_params.host_resolver = globals_->host_resolver.get(); |
| 618 | system_params.cert_verifier = globals_->cert_verifier.get(); |
[email protected] | 9c4eff2 | 2012-03-20 22:42:29 | [diff] [blame] | 619 | system_params.server_bound_cert_service = |
| 620 | globals_->system_server_bound_cert_service.get(); |
[email protected] | a2a4197 | 2011-12-07 17:47:27 | [diff] [blame] | 621 | system_params.transport_security_state = |
| 622 | globals_->transport_security_state.get(); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 623 | system_params.proxy_service = globals_->system_proxy_service.get(); |
| 624 | system_params.ssl_config_service = globals_->ssl_config_service.get(); |
| 625 | system_params.http_auth_handler_factory = |
| 626 | globals_->http_auth_handler_factory.get(); |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 627 | system_params.http_server_properties = globals_->http_server_properties.get(); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 628 | system_params.network_delegate = globals_->system_network_delegate.get(); |
| 629 | system_params.net_log = net_log_; |
| 630 | globals_->system_http_transaction_factory.reset( |
| 631 | new net::HttpNetworkLayer( |
| 632 | new net::HttpNetworkSession(system_params))); |
[email protected] | 933bc5c6 | 2011-04-12 19:08:02 | [diff] [blame] | 633 | globals_->system_ftp_transaction_factory.reset( |
| 634 | new net::FtpNetworkLayer(globals_->host_resolver.get())); |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 635 | globals_->system_request_context.reset( |
| 636 | ConstructSystemRequestContext(globals_, net_log_)); |
[email protected] | d24fc3a0 | 2012-02-11 02:08:34 | [diff] [blame] | 637 | |
| 638 | sdch_manager_->set_sdch_fetcher( |
| 639 | new SdchDictionaryFetcher(system_url_request_context_getter_.get())); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 640 | } |