blob: f20c8a6c507cdd963d63b2ce82cab7e2bbf9280d [file] [log] [blame]
[email protected]0ac83682010-01-22 17:46:271// Copyright (c) 2010 The Chromium Authors. All rights reserved.
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]e83326f2010-07-31 17:29:256
[email protected]bcefe0f2010-11-10 16:19:107#include <vector>
8
[email protected]0ac83682010-01-22 17:46:279#include "base/command_line.h"
[email protected]58580352010-10-26 04:07:5010#include "base/debug/leak_tracker.h"
[email protected]0ac83682010-01-22 17:46:2711#include "base/logging.h"
[email protected]ecd95ae2010-10-20 23:58:1712#include "base/metrics/field_trial.h"
[email protected]86933612010-10-16 23:10:3313#include "base/stl_util-inl.h"
[email protected]e83326f2010-07-31 17:29:2514#include "base/string_number_conversions.h"
[email protected]4e5ae20f2010-09-24 04:52:1115#include "base/string_split.h"
[email protected]f1d81922010-07-31 17:47:0916#include "base/string_util.h"
[email protected]ba74b0d22010-10-23 05:19:2017#include "base/thread_restrictions.h"
[email protected]e36717272010-10-12 12:07:1318#include "chrome/browser/browser_thread.h"
[email protected]1082b1d2010-03-30 00:31:2219#include "chrome/browser/gpu_process_host.h"
[email protected]9e743cd2010-03-16 07:03:5320#include "chrome/browser/net/chrome_net_log.h"
[email protected]0ee7a3b2010-11-09 06:13:4021#include "chrome/browser/net/chrome_url_request_context.h"
[email protected]1889dc1b2010-10-14 22:03:1322#include "chrome/browser/net/connect_interceptor.h"
[email protected]9e743cd2010-03-16 07:03:5323#include "chrome/browser/net/passive_log_collector.h"
[email protected]86933612010-10-16 23:10:3324#include "chrome/browser/net/predictor_api.h"
[email protected]bcefe0f2010-11-10 16:19:1025#include "chrome/browser/prefs/pref_service.h"
[email protected]d077249e2010-12-09 02:44:5826#include "chrome/browser/prerender/prerender_interceptor.h"
[email protected]0ac83682010-01-22 17:46:2727#include "chrome/common/chrome_switches.h"
[email protected]2258c1c92010-10-28 17:51:1928#include "chrome/common/net/raw_host_resolver_proc.h"
[email protected]68d2a05f2010-05-07 21:39:5529#include "chrome/common/net/url_fetcher.h"
[email protected]bcefe0f2010-11-10 16:19:1030#include "chrome/common/pref_names.h"
[email protected]822581d2010-12-16 17:27:1531#include "net/base/cert_verifier.h"
[email protected]2db580532010-10-08 14:32:3732#include "net/base/dnsrr_resolver.h"
[email protected]0ac83682010-01-22 17:46:2733#include "net/base/host_cache.h"
34#include "net/base/host_resolver.h"
[email protected]f2d8c4212010-02-02 00:56:3535#include "net/base/host_resolver_impl.h"
[email protected]86933612010-10-16 23:10:3336#include "net/base/mapped_host_resolver.h"
[email protected]32eaa332010-02-08 22:15:5437#include "net/base/net_util.h"
[email protected]eb3cac72010-02-26 21:07:4538#include "net/http/http_auth_filter.h"
[email protected]fa55e192010-02-15 14:25:5039#include "net/http/http_auth_handler_factory.h"
[email protected]2fb629202010-12-23 23:52:5740#include "net/http/http_network_layer.h"
[email protected]70b92342010-10-12 05:54:0641#if defined(USE_NSS)
42#include "net/ocsp/nss_ocsp.h"
43#endif // defined(USE_NSS)
[email protected]86933612010-10-16 23:10:3344#include "net/proxy/proxy_script_fetcher_impl.h"
[email protected]2fb629202010-12-23 23:52:5745#include "net/socket/client_socket_factory.h"
46#include "net/spdy/spdy_session_pool.h"
[email protected]0ac83682010-01-22 17:46:2747
48namespace {
49
[email protected]ee094b82010-08-24 15:55:5150net::HostResolver* CreateGlobalHostResolver(net::NetLog* net_log) {
[email protected]0ac83682010-01-22 17:46:2751 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]962b98212010-07-17 03:37:5152
53 size_t parallelism = net::HostResolver::kDefaultParallelism;
54
55 // Use the concurrency override from the command-line, if any.
56 if (command_line.HasSwitch(switches::kHostResolverParallelism)) {
57 std::string s =
58 command_line.GetSwitchValueASCII(switches::kHostResolverParallelism);
59
60 // Parse the switch (it should be a positive integer formatted as decimal).
61 int n;
[email protected]e83326f2010-07-31 17:29:2562 if (base::StringToInt(s, &n) && n > 0) {
[email protected]962b98212010-07-17 03:37:5163 parallelism = static_cast<size_t>(n);
64 } else {
65 LOG(ERROR) << "Invalid switch for host resolver parallelism: " << s;
66 }
[email protected]ecd95ae2010-10-20 23:58:1767 } else {
68 // Set up a field trial to see what impact the total number of concurrent
69 // resolutions have on DNS resolutions.
70 base::FieldTrial::Probability kDivisor = 1000;
71 // For each option (i.e., non-default), we have a fixed probability.
72 base::FieldTrial::Probability kProbabilityPerGroup = 100; // 10%.
73
[email protected]ad8e04a2010-11-01 04:16:2774 scoped_refptr<base::FieldTrial> trial(
75 new base::FieldTrial("DnsParallelism", kDivisor));
[email protected]ecd95ae2010-10-20 23:58:1776
77 // List options with different counts.
78 // Firefox limits total to 8 in parallel, and default is currently 50.
79 int parallel_6 = trial->AppendGroup("parallel_6", kProbabilityPerGroup);
[email protected]755a93352010-10-29 06:33:5980 int parallel_7 = trial->AppendGroup("parallel_7", kProbabilityPerGroup);
[email protected]ecd95ae2010-10-20 23:58:1781 int parallel_8 = trial->AppendGroup("parallel_8", kProbabilityPerGroup);
[email protected]755a93352010-10-29 06:33:5982 int parallel_9 = trial->AppendGroup("parallel_9", kProbabilityPerGroup);
[email protected]ecd95ae2010-10-20 23:58:1783 int parallel_10 = trial->AppendGroup("parallel_10", kProbabilityPerGroup);
84 int parallel_14 = trial->AppendGroup("parallel_14", kProbabilityPerGroup);
85 int parallel_20 = trial->AppendGroup("parallel_20", kProbabilityPerGroup);
86
87 trial->AppendGroup("parallel_default",
88 base::FieldTrial::kAllRemainingProbability);
89
90 if (trial->group() == parallel_6)
91 parallelism = 6;
[email protected]755a93352010-10-29 06:33:5992 else if (trial->group() == parallel_7)
93 parallelism = 7;
[email protected]ecd95ae2010-10-20 23:58:1794 else if (trial->group() == parallel_8)
95 parallelism = 8;
[email protected]755a93352010-10-29 06:33:5996 else if (trial->group() == parallel_9)
97 parallelism = 9;
[email protected]ecd95ae2010-10-20 23:58:1798 else if (trial->group() == parallel_10)
99 parallelism = 10;
100 else if (trial->group() == parallel_14)
101 parallelism = 14;
102 else if (trial->group() == parallel_20)
103 parallelism = 20;
[email protected]962b98212010-07-17 03:37:51104 }
105
[email protected]2258c1c92010-10-28 17:51:19106 // Use the specified DNS server for doing raw resolutions if requested
107 // from the command-line.
108 scoped_refptr<net::HostResolverProc> resolver_proc;
109 if (command_line.HasSwitch(switches::kDnsServer)) {
110 std::string dns_ip_string =
111 command_line.GetSwitchValueASCII(switches::kDnsServer);
112 net::IPAddressNumber dns_ip_number;
113 if (net::ParseIPLiteralToNumber(dns_ip_string, &dns_ip_number)) {
114 resolver_proc =
115 new chrome_common_net::RawHostResolverProc(dns_ip_number, NULL);
116 } else {
117 LOG(ERROR) << "Invalid IP address specified for --dns-server: "
118 << dns_ip_string;
119 }
120 }
121
[email protected]962b98212010-07-17 03:37:51122 net::HostResolver* global_host_resolver =
[email protected]2258c1c92010-10-28 17:51:19123 net::CreateSystemHostResolver(parallelism, resolver_proc.get(), net_log);
[email protected]9087aa32010-02-18 08:03:38124
[email protected]0f8f1b432010-03-16 19:06:03125 // Determine if we should disable IPv6 support.
[email protected]9087aa32010-02-18 08:03:38126 if (!command_line.HasSwitch(switches::kEnableIPv6)) {
[email protected]0f8f1b432010-03-16 19:06:03127 if (command_line.HasSwitch(switches::kDisableIPv6)) {
[email protected]46f6e202010-02-26 06:07:25128 global_host_resolver->SetDefaultAddressFamily(net::ADDRESS_FAMILY_IPV4);
[email protected]0f8f1b432010-03-16 19:06:03129 } else {
130 net::HostResolverImpl* host_resolver_impl =
131 global_host_resolver->GetAsHostResolverImpl();
132 if (host_resolver_impl != NULL) {
[email protected]780f8492010-09-16 04:12:15133 // Use probe to decide if support is warranted.
134 host_resolver_impl->ProbeIPv6Support();
[email protected]0f8f1b432010-03-16 19:06:03135 }
136 }
[email protected]9087aa32010-02-18 08:03:38137 }
138
[email protected]9087aa32010-02-18 08:03:38139 // If hostname remappings were specified on the command-line, layer these
140 // rules on top of the real host resolver. This allows forwarding all requests
141 // through a designated test server.
[email protected]0f8f1b432010-03-16 19:06:03142 if (!command_line.HasSwitch(switches::kHostResolverRules))
143 return global_host_resolver;
[email protected]0ac83682010-01-22 17:46:27144
[email protected]0f8f1b432010-03-16 19:06:03145 net::MappedHostResolver* remapped_resolver =
146 new net::MappedHostResolver(global_host_resolver);
147 remapped_resolver->SetRulesFromString(
148 command_line.GetSwitchValueASCII(switches::kHostResolverRules));
149 return remapped_resolver;
[email protected]0ac83682010-01-22 17:46:27150}
151
[email protected]58bc7042010-07-07 18:04:14152class LoggingNetworkChangeObserver
153 : public net::NetworkChangeNotifier::Observer {
154 public:
155 // |net_log| must remain valid throughout our lifetime.
156 explicit LoggingNetworkChangeObserver(net::NetLog* net_log)
157 : net_log_(net_log) {
158 net::NetworkChangeNotifier::AddObserver(this);
159 }
160
161 ~LoggingNetworkChangeObserver() {
162 net::NetworkChangeNotifier::RemoveObserver(this);
163 }
164
165 virtual void OnIPAddressChanged() {
[email protected]8e96e502010-10-21 20:57:12166 VLOG(1) << "Observed a change to the network IP addresses";
[email protected]58bc7042010-07-07 18:04:14167
[email protected]d3aaf3f2010-09-02 20:45:55168 net_log_->AddEntry(net::NetLog::TYPE_NETWORK_IP_ADDRESSES_CHANGED,
[email protected]58bc7042010-07-07 18:04:14169 base::TimeTicks::Now(),
[email protected]d2cbfbe2010-08-12 17:38:16170 net::NetLog::Source(),
[email protected]58bc7042010-07-07 18:04:14171 net::NetLog::PHASE_NONE,
172 NULL);
173 }
174
175 private:
176 net::NetLog* net_log_;
177 DISALLOW_COPY_AND_ASSIGN(LoggingNetworkChangeObserver);
178};
179
[email protected]2fb629202010-12-23 23:52:57180scoped_refptr<URLRequestContext>
181ConstructProxyScriptFetcherContext(IOThread::Globals* globals,
182 net::NetLog* net_log) {
183 scoped_refptr<URLRequestContext> context(new URLRequestContext);
184 context->set_net_log(net_log);
185 context->set_host_resolver(globals->host_resolver.get());
186 context->set_cert_verifier(globals->cert_verifier.get());
187 context->set_dnsrr_resolver(globals->dnsrr_resolver.get());
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]52617df2010-12-24 07:30:01192 globals->proxy_script_fetcher_http_transaction_factory.get());
[email protected]2fb629202010-12-23 23:52:57193 // In-memory cookie store.
194 context->set_cookie_store(new net::CookieMonster(NULL, NULL));
195 return context;
196}
197
[email protected]0ac83682010-01-22 17:46:27198} // namespace
199
200// The IOThread object must outlive any tasks posted to the IO thread before the
201// Quit task.
[email protected]c56428f22010-06-16 02:17:23202DISABLE_RUNNABLE_METHOD_REFCOUNT(IOThread);
[email protected]0ac83682010-01-22 17:46:27203
[email protected]1889dc1b2010-10-14 22:03:13204IOThread::Globals::Globals() {}
205
206IOThread::Globals::~Globals() {}
207
[email protected]bcefe0f2010-11-10 16:19:10208// |local_state| is passed in explicitly in order to (1) reduce implicit
209// dependencies and (2) make IOThread more flexible for testing.
[email protected]b2fcd0e2010-12-01 15:19:40210IOThread::IOThread(PrefService* local_state, ChromeNetLog* net_log)
[email protected]f8b3ef82010-10-11 02:45:52211 : BrowserProcessSubThread(BrowserThread::IO),
[email protected]b2fcd0e2010-12-01 15:19:40212 net_log_(net_log),
[email protected]d13c3272010-02-04 00:24:51213 globals_(NULL),
[email protected]c5629c32010-06-23 01:22:43214 speculative_interceptor_(NULL),
[email protected]bcefe0f2010-11-10 16:19:10215 predictor_(NULL) {
216 // We call RegisterPrefs() here (instead of inside browser_prefs.cc) to make
217 // sure that everything is initialized in the right order.
218 RegisterPrefs(local_state);
219 auth_schemes_ = local_state->GetString(prefs::kAuthSchemes);
220 negotiate_disable_cname_lookup_ = local_state->GetBoolean(
221 prefs::kDisableAuthNegotiateCnameLookup);
222 negotiate_enable_port_ = local_state->GetBoolean(
223 prefs::kEnableAuthNegotiatePort);
224 auth_server_whitelist_ = local_state->GetString(prefs::kAuthServerWhitelist);
225 auth_delegate_whitelist_ = local_state->GetString(
226 prefs::kAuthNegotiateDelegateWhitelist);
[email protected]ac7f3fdb2010-11-12 12:47:05227 gssapi_library_name_ = local_state->GetString(prefs::kGSSAPILibraryName);
[email protected]bcefe0f2010-11-10 16:19:10228}
[email protected]0ac83682010-01-22 17:46:27229
230IOThread::~IOThread() {
231 // We cannot rely on our base class to stop the thread since we want our
232 // CleanUp function to run.
233 Stop();
[email protected]d13c3272010-02-04 00:24:51234 DCHECK(!globals_);
[email protected]0ac83682010-01-22 17:46:27235}
236
[email protected]d13c3272010-02-04 00:24:51237IOThread::Globals* IOThread::globals() {
[email protected]f8b3ef82010-10-11 02:45:52238 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]d13c3272010-02-04 00:24:51239 return globals_;
[email protected]0ac83682010-01-22 17:46:27240}
241
[email protected]b2fcd0e2010-12-01 15:19:40242ChromeNetLog* IOThread::net_log() {
243 return net_log_;
244}
245
[email protected]74be069e82010-06-25 00:12:49246void IOThread::InitNetworkPredictor(
[email protected]0ac83682010-01-22 17:46:27247 bool prefetching_enabled,
[email protected]74be069e82010-06-25 00:12:49248 base::TimeDelta max_dns_queue_delay,
[email protected]755a93352010-10-29 06:33:59249 size_t max_speculative_parallel_resolves,
[email protected]c5629c32010-06-23 01:22:43250 const chrome_common_net::UrlList& startup_urls,
[email protected]760d970a2010-05-18 00:39:18251 ListValue* referral_list,
252 bool preconnect_enabled) {
[email protected]f8b3ef82010-10-11 02:45:52253 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]0ac83682010-01-22 17:46:27254 message_loop()->PostTask(
255 FROM_HERE,
256 NewRunnableMethod(
257 this,
[email protected]74be069e82010-06-25 00:12:49258 &IOThread::InitNetworkPredictorOnIOThread,
[email protected]755a93352010-10-29 06:33:59259 prefetching_enabled, max_dns_queue_delay,
260 max_speculative_parallel_resolves,
[email protected]c5629c32010-06-23 01:22:43261 startup_urls, referral_list, preconnect_enabled));
[email protected]0ac83682010-01-22 17:46:27262}
263
[email protected]0ee7a3b2010-11-09 06:13:40264void IOThread::RegisterURLRequestContextGetter(
265 ChromeURLRequestContextGetter* url_request_context_getter) {
266 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
267 std::list<ChromeURLRequestContextGetter*>::const_iterator it =
268 std::find(url_request_context_getters_.begin(),
269 url_request_context_getters_.end(),
270 url_request_context_getter);
271 DCHECK(it == url_request_context_getters_.end());
272 url_request_context_getters_.push_back(url_request_context_getter);
273}
274
275void IOThread::UnregisterURLRequestContextGetter(
276 ChromeURLRequestContextGetter* url_request_context_getter) {
277 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
278 std::list<ChromeURLRequestContextGetter*>::iterator it =
279 std::find(url_request_context_getters_.begin(),
280 url_request_context_getters_.end(),
281 url_request_context_getter);
282 DCHECK(it != url_request_context_getters_.end());
283 // This does not scale, but we shouldn't have many URLRequestContextGetters in
284 // the first place, so this should be fine.
285 url_request_context_getters_.erase(it);
286}
287
[email protected]0ac83682010-01-22 17:46:27288void IOThread::ChangedToOnTheRecord() {
[email protected]f8b3ef82010-10-11 02:45:52289 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]0ac83682010-01-22 17:46:27290 message_loop()->PostTask(
291 FROM_HERE,
292 NewRunnableMethod(
293 this,
294 &IOThread::ChangedToOnTheRecordOnIOThread));
295}
296
297void IOThread::Init() {
[email protected]45446a52010-11-04 17:41:00298#if !defined(OS_CHROMEOS)
[email protected]ba74b0d22010-10-23 05:19:20299 // TODO(evan): test and enable this on all platforms.
300 // Though this thread is called the "IO" thread, it actually just routes
301 // messages around; it shouldn't be allowed to perform any blocking disk I/O.
302 base::ThreadRestrictions::SetIOAllowed(false);
303#endif
304
[email protected]0ac83682010-01-22 17:46:27305 BrowserProcessSubThread::Init();
306
[email protected]70b92342010-10-12 05:54:06307 DCHECK_EQ(MessageLoop::TYPE_IO, message_loop()->type());
308
309#if defined(USE_NSS)
310 net::SetMessageLoopForOCSP();
[email protected]ecd95ae2010-10-20 23:58:17311#endif // defined(USE_NSS)
[email protected]70b92342010-10-12 05:54:06312
[email protected]d13c3272010-02-04 00:24:51313 DCHECK(!globals_);
314 globals_ = new Globals;
315
[email protected]58bc7042010-07-07 18:04:14316 // Add an observer that will emit network change events to the ChromeNetLog.
317 // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be
318 // logging the network change before other IO thread consumers respond to it.
319 network_change_observer_.reset(
[email protected]b2fcd0e2010-12-01 15:19:40320 new LoggingNetworkChangeObserver(net_log_));
[email protected]58bc7042010-07-07 18:04:14321
[email protected]2fb629202010-12-23 23:52:57322 globals_->client_socket_factory =
323 net::ClientSocketFactory::GetDefaultFactory();
[email protected]73c45322010-10-01 23:57:54324 globals_->host_resolver.reset(
[email protected]b2fcd0e2010-12-01 15:19:40325 CreateGlobalHostResolver(net_log_));
[email protected]822581d2010-12-16 17:27:15326 globals_->cert_verifier.reset(new net::CertVerifier);
[email protected]2db580532010-10-08 14:32:37327 globals_->dnsrr_resolver.reset(new net::DnsRRResolver);
[email protected]2fb629202010-12-23 23:52:57328 // TODO(willchan): Use the real SSLConfigService.
329 globals_->ssl_config_service =
330 net::SSLConfigService::CreateSystemSSLConfigService();
[email protected]65d34382010-07-01 18:12:26331 globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory(
[email protected]73c45322010-10-01 23:57:54332 globals_->host_resolver.get()));
[email protected]2fb629202010-12-23 23:52:57333 // For the ProxyScriptFetcher, we use a direct ProxyService.
334 globals_->proxy_script_fetcher_proxy_service =
335 net::ProxyService::CreateDirectWithNetLog(net_log_);
[email protected]52617df2010-12-24 07:30:01336 globals_->proxy_script_fetcher_http_transaction_factory.reset(
337 new net::HttpNetworkLayer(
338 globals_->client_socket_factory,
339 globals_->host_resolver.get(),
340 globals_->cert_verifier.get(),
341 globals_->dnsrr_resolver.get(),
342 NULL /* dns_cert_checker */,
343 NULL /* ssl_host_info_factory */,
344 globals_->proxy_script_fetcher_proxy_service.get(),
345 globals_->ssl_config_service.get(),
346 new net::SpdySessionPool(globals_->ssl_config_service.get()),
347 globals_->http_auth_handler_factory.get(),
348 &globals_->network_delegate,
349 net_log_));
[email protected]2fb629202010-12-23 23:52:57350
351 scoped_refptr<URLRequestContext> proxy_script_fetcher_context =
352 ConstructProxyScriptFetcherContext(globals_, net_log_);
353 globals_->proxy_script_fetcher_context = proxy_script_fetcher_context;
[email protected]1d14ba552010-11-19 19:07:40354
355 if (CommandLine::ForCurrentProcess()->HasSwitch(
356 switches::kEnablePagePrerender)) {
[email protected]d077249e2010-12-09 02:44:58357 prerender_interceptor_.reset(new PrerenderInterceptor());
[email protected]1d14ba552010-11-19 19:07:40358 }
[email protected]0ac83682010-01-22 17:46:27359}
360
[email protected]2a92cd92010-04-27 00:01:41361void IOThread::CleanUp() {
[email protected]0ee7a3b2010-11-09 06:13:40362 // Step 1: Kill all things that might be holding onto
[email protected]6981d9632010-11-30 21:34:02363 // net::URLRequest/URLRequestContexts.
[email protected]0ee7a3b2010-11-09 06:13:40364
[email protected]59a3b362010-10-21 21:52:41365#if defined(USE_NSS)
366 net::ShutdownOCSP();
367#endif // defined(USE_NSS)
368
[email protected]0b1ad312010-10-22 01:01:38369 // Destroy all URLRequests started by URLFetchers.
370 URLFetcher::CancelAll();
371
[email protected]325a71f2010-05-21 23:05:27372 // If any child processes are still running, terminate them and
[email protected]d27893f62010-07-03 05:47:42373 // and delete the BrowserChildProcessHost instances to release whatever
[email protected]325a71f2010-05-21 23:05:27374 // IO thread only resources they are referencing.
[email protected]d27893f62010-07-03 05:47:42375 BrowserChildProcessHost::TerminateAll();
[email protected]325a71f2010-05-21 23:05:27376
[email protected]0ee7a3b2010-11-09 06:13:40377 std::list<ChromeURLRequestContextGetter*> url_request_context_getters;
378 url_request_context_getters.swap(url_request_context_getters_);
379 for (std::list<ChromeURLRequestContextGetter*>::iterator it =
380 url_request_context_getters.begin();
381 it != url_request_context_getters.end(); ++it) {
382 ChromeURLRequestContextGetter* getter = *it;
[email protected]361fe8a2010-11-24 17:20:49383 // Stop all pending certificate provenance check uploads
384 net::DnsCertProvenanceChecker* checker =
385 getter->GetURLRequestContext()->dns_cert_checker();
386 if (checker)
387 checker->Shutdown();
[email protected]0ee7a3b2010-11-09 06:13:40388 getter->ReleaseURLRequestContext();
389 }
390
391 // Step 2: Release objects that the URLRequestContext could have been pointing
392 // to.
393
394 // This must be reset before the ChromeNetLog is destroyed.
395 network_change_observer_.reset();
396
[email protected]0ac83682010-01-22 17:46:27397 // Not initialized in Init(). May not be initialized.
[email protected]74be069e82010-06-25 00:12:49398 if (predictor_) {
399 predictor_->Shutdown();
[email protected]0ac83682010-01-22 17:46:27400
[email protected]74be069e82010-06-25 00:12:49401 // TODO(willchan): Stop reference counting Predictor. It's owned by
[email protected]0ac83682010-01-22 17:46:27402 // IOThread now.
[email protected]74be069e82010-06-25 00:12:49403 predictor_->Release();
404 predictor_ = NULL;
405 chrome_browser_net::FreePredictorResources();
[email protected]0ac83682010-01-22 17:46:27406 }
407
[email protected]c5629c32010-06-23 01:22:43408 // Deletion will unregister this interceptor.
409 delete speculative_interceptor_;
410 speculative_interceptor_ = NULL;
411
[email protected]1d14ba552010-11-19 19:07:40412 prerender_interceptor_.reset();
413
[email protected]e4d2dd822010-02-05 20:57:33414 // TODO(eroman): hack for http://crbug.com/15513
[email protected]970210c2010-02-19 20:27:02415 if (globals_->host_resolver->GetAsHostResolverImpl()) {
416 globals_->host_resolver.get()->GetAsHostResolverImpl()->Shutdown();
[email protected]e4d2dd822010-02-05 20:57:33417 }
[email protected]0ac83682010-01-22 17:46:27418
[email protected]d13c3272010-02-04 00:24:51419 delete globals_;
420 globals_ = NULL;
[email protected]0ac83682010-01-22 17:46:27421
[email protected]2a92cd92010-04-27 00:01:41422 BrowserProcessSubThread::CleanUp();
423}
424
425void IOThread::CleanUpAfterMessageLoopDestruction() {
[email protected]0ee7a3b2010-11-09 06:13:40426 // This will delete the |notification_service_|. Make sure it's done after
427 // anything else can reference it.
[email protected]9aa33e82010-04-15 00:15:39428 BrowserProcessSubThread::CleanUpAfterMessageLoopDestruction();
[email protected]4411da942010-10-25 15:06:02429
[email protected]6981d9632010-11-30 21:34:02430 // net::URLRequest instances must NOT outlive the IO thread.
[email protected]4411da942010-10-25 15:06:02431 //
432 // To allow for URLRequests to be deleted from
433 // MessageLoop::DestructionObserver this check has to happen after CleanUp
434 // (which runs before DestructionObservers).
[email protected]6981d9632010-11-30 21:34:02435 base::debug::LeakTracker<net::URLRequest>::CheckForLeaks();
[email protected]0ac83682010-01-22 17:46:27436}
437
[email protected]bcefe0f2010-11-10 16:19:10438// static
439void IOThread::RegisterPrefs(PrefService* local_state) {
440 local_state->RegisterStringPref(prefs::kAuthSchemes,
441 "basic,digest,ntlm,negotiate");
442 local_state->RegisterBooleanPref(prefs::kDisableAuthNegotiateCnameLookup,
443 false);
444 local_state->RegisterBooleanPref(prefs::kEnableAuthNegotiatePort, false);
445 local_state->RegisterStringPref(prefs::kAuthServerWhitelist, "");
446 local_state->RegisterStringPref(prefs::kAuthNegotiateDelegateWhitelist, "");
[email protected]ac7f3fdb2010-11-12 12:47:05447 local_state->RegisterStringPref(prefs::kGSSAPILibraryName, "");
[email protected]bcefe0f2010-11-10 16:19:10448}
449
[email protected]65d34382010-07-01 18:12:26450net::HttpAuthHandlerFactory* IOThread::CreateDefaultAuthHandlerFactory(
451 net::HostResolver* resolver) {
[email protected]9030a632010-11-19 20:12:09452 net::HttpAuthFilterWhitelist* auth_filter_default_credentials = NULL;
453 if (!auth_server_whitelist_.empty()) {
454 auth_filter_default_credentials =
455 new net::HttpAuthFilterWhitelist(auth_server_whitelist_);
456 }
457 net::HttpAuthFilterWhitelist* auth_filter_delegate = NULL;
458 if (!auth_delegate_whitelist_.empty()) {
459 auth_filter_delegate =
460 new net::HttpAuthFilterWhitelist(auth_delegate_whitelist_);
461 }
[email protected]b4955e7d2010-04-16 20:22:30462 globals_->url_security_manager.reset(
[email protected]d201b200e2010-08-27 17:35:02463 net::URLSecurityManager::Create(auth_filter_default_credentials,
464 auth_filter_delegate));
[email protected]b7304162010-08-23 17:42:29465 std::vector<std::string> supported_schemes;
[email protected]bcefe0f2010-11-10 16:19:10466 base::SplitString(auth_schemes_, ',', &supported_schemes);
[email protected]b7304162010-08-23 17:42:29467
468 return net::HttpAuthHandlerRegistryFactory::Create(
469 supported_schemes,
470 globals_->url_security_manager.get(),
471 resolver,
[email protected]ac7f3fdb2010-11-12 12:47:05472 gssapi_library_name_,
[email protected]bcefe0f2010-11-10 16:19:10473 negotiate_disable_cname_lookup_,
474 negotiate_enable_port_);
[email protected]eb3cac72010-02-26 21:07:45475}
476
[email protected]74be069e82010-06-25 00:12:49477void IOThread::InitNetworkPredictorOnIOThread(
[email protected]0ac83682010-01-22 17:46:27478 bool prefetching_enabled,
[email protected]74be069e82010-06-25 00:12:49479 base::TimeDelta max_dns_queue_delay,
[email protected]755a93352010-10-29 06:33:59480 size_t max_speculative_parallel_resolves,
[email protected]c5629c32010-06-23 01:22:43481 const chrome_common_net::UrlList& startup_urls,
[email protected]760d970a2010-05-18 00:39:18482 ListValue* referral_list,
483 bool preconnect_enabled) {
[email protected]f8b3ef82010-10-11 02:45:52484 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]74be069e82010-06-25 00:12:49485 CHECK(!predictor_);
[email protected]0ac83682010-01-22 17:46:27486
[email protected]74be069e82010-06-25 00:12:49487 chrome_browser_net::EnablePredictor(prefetching_enabled);
[email protected]0ac83682010-01-22 17:46:27488
[email protected]74be069e82010-06-25 00:12:49489 predictor_ = new chrome_browser_net::Predictor(
[email protected]73c45322010-10-01 23:57:54490 globals_->host_resolver.get(),
[email protected]74be069e82010-06-25 00:12:49491 max_dns_queue_delay,
[email protected]755a93352010-10-29 06:33:59492 max_speculative_parallel_resolves,
[email protected]760d970a2010-05-18 00:39:18493 preconnect_enabled);
[email protected]74be069e82010-06-25 00:12:49494 predictor_->AddRef();
[email protected]0ac83682010-01-22 17:46:27495
[email protected]f4ef861ba2010-07-28 22:37:23496 // Speculative_interceptor_ is used to predict subresource usage.
497 DCHECK(!speculative_interceptor_);
498 speculative_interceptor_ = new chrome_browser_net::ConnectInterceptor;
499
[email protected]bff1f512010-08-15 15:13:49500 FinalizePredictorInitialization(predictor_, startup_urls, referral_list);
[email protected]0ac83682010-01-22 17:46:27501}
502
503void IOThread::ChangedToOnTheRecordOnIOThread() {
[email protected]f8b3ef82010-10-11 02:45:52504 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]0ac83682010-01-22 17:46:27505
[email protected]74be069e82010-06-25 00:12:49506 if (predictor_) {
[email protected]0ac83682010-01-22 17:46:27507 // Destroy all evidence of our OTR session.
[email protected]74be069e82010-06-25 00:12:49508 predictor_->Predictor::DiscardAllResults();
[email protected]0ac83682010-01-22 17:46:27509 }
510
511 // Clear the host cache to avoid showing entries from the OTR session
512 // in about:net-internals.
[email protected]970210c2010-02-19 20:27:02513 if (globals_->host_resolver->GetAsHostResolverImpl()) {
514 net::HostCache* host_cache =
515 globals_->host_resolver.get()->GetAsHostResolverImpl()->cache();
[email protected]f2d8c4212010-02-02 00:56:35516 if (host_cache)
517 host_cache->clear();
518 }
[email protected]9e743cd2010-03-16 07:03:53519 // Clear all of the passively logged data.
520 // TODO(eroman): this is a bit heavy handed, really all we need to do is
521 // clear the data pertaining to off the record context.
[email protected]b2fcd0e2010-12-01 15:19:40522 net_log_->ClearAllPassivelyCapturedEvents();
[email protected]0ac83682010-01-22 17:46:27523}