blob: 8772ffd6c9550177b429b4e637c0168c6b456439 [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]0ac83682010-01-22 17:46:277#include "base/command_line.h"
8#include "base/leak_tracker.h"
9#include "base/logging.h"
[email protected]ecd95ae2010-10-20 23:58:1710#include "base/metrics/field_trial.h"
[email protected]86933612010-10-16 23:10:3311#include "base/stl_util-inl.h"
[email protected]e83326f2010-07-31 17:29:2512#include "base/string_number_conversions.h"
[email protected]4e5ae20f2010-09-24 04:52:1113#include "base/string_split.h"
[email protected]f1d81922010-07-31 17:47:0914#include "base/string_util.h"
[email protected]ba74b0d22010-10-23 05:19:2015#include "base/thread_restrictions.h"
[email protected]0ac83682010-01-22 17:46:2716#include "chrome/browser/browser_process.h"
[email protected]e36717272010-10-12 12:07:1317#include "chrome/browser/browser_thread.h"
[email protected]1082b1d2010-03-30 00:31:2218#include "chrome/browser/gpu_process_host.h"
[email protected]9e743cd2010-03-16 07:03:5319#include "chrome/browser/net/chrome_net_log.h"
[email protected]562d71e2010-10-22 22:24:4620#include "chrome/browser/net/chrome_url_request_context.h"
[email protected]1889dc1b2010-10-14 22:03:1321#include "chrome/browser/net/connect_interceptor.h"
[email protected]9e743cd2010-03-16 07:03:5322#include "chrome/browser/net/passive_log_collector.h"
[email protected]86933612010-10-16 23:10:3323#include "chrome/browser/net/predictor_api.h"
[email protected]0ac83682010-01-22 17:46:2724#include "chrome/common/chrome_switches.h"
[email protected]68d2a05f2010-05-07 21:39:5525#include "chrome/common/net/url_fetcher.h"
[email protected]2db580532010-10-08 14:32:3726#include "net/base/dnsrr_resolver.h"
[email protected]0ac83682010-01-22 17:46:2727#include "net/base/host_cache.h"
28#include "net/base/host_resolver.h"
[email protected]f2d8c4212010-02-02 00:56:3529#include "net/base/host_resolver_impl.h"
[email protected]86933612010-10-16 23:10:3330#include "net/base/mapped_host_resolver.h"
[email protected]32eaa332010-02-08 22:15:5431#include "net/base/net_util.h"
[email protected]eb3cac72010-02-26 21:07:4532#include "net/http/http_auth_filter.h"
[email protected]fa55e192010-02-15 14:25:5033#include "net/http/http_auth_handler_factory.h"
[email protected]70b92342010-10-12 05:54:0634#if defined(USE_NSS)
35#include "net/ocsp/nss_ocsp.h"
36#endif // defined(USE_NSS)
[email protected]86933612010-10-16 23:10:3337#include "net/proxy/proxy_script_fetcher_impl.h"
[email protected]0ac83682010-01-22 17:46:2738
39namespace {
40
[email protected]ee094b82010-08-24 15:55:5141net::HostResolver* CreateGlobalHostResolver(net::NetLog* net_log) {
[email protected]0ac83682010-01-22 17:46:2742 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]962b98212010-07-17 03:37:5143
44 size_t parallelism = net::HostResolver::kDefaultParallelism;
45
46 // Use the concurrency override from the command-line, if any.
47 if (command_line.HasSwitch(switches::kHostResolverParallelism)) {
48 std::string s =
49 command_line.GetSwitchValueASCII(switches::kHostResolverParallelism);
50
51 // Parse the switch (it should be a positive integer formatted as decimal).
52 int n;
[email protected]e83326f2010-07-31 17:29:2553 if (base::StringToInt(s, &n) && n > 0) {
[email protected]962b98212010-07-17 03:37:5154 parallelism = static_cast<size_t>(n);
55 } else {
56 LOG(ERROR) << "Invalid switch for host resolver parallelism: " << s;
57 }
[email protected]ecd95ae2010-10-20 23:58:1758 } else {
59 // Set up a field trial to see what impact the total number of concurrent
60 // resolutions have on DNS resolutions.
61 base::FieldTrial::Probability kDivisor = 1000;
62 // For each option (i.e., non-default), we have a fixed probability.
63 base::FieldTrial::Probability kProbabilityPerGroup = 100; // 10%.
64
65 scoped_refptr<base::FieldTrial> trial =
66 new base::FieldTrial("DnsParallelism", kDivisor);
67
68 // List options with different counts.
69 // Firefox limits total to 8 in parallel, and default is currently 50.
70 int parallel_6 = trial->AppendGroup("parallel_6", kProbabilityPerGroup);
71 int parallel_8 = trial->AppendGroup("parallel_8", kProbabilityPerGroup);
72 int parallel_10 = trial->AppendGroup("parallel_10", kProbabilityPerGroup);
73 int parallel_14 = trial->AppendGroup("parallel_14", kProbabilityPerGroup);
74 int parallel_20 = trial->AppendGroup("parallel_20", kProbabilityPerGroup);
75
76 trial->AppendGroup("parallel_default",
77 base::FieldTrial::kAllRemainingProbability);
78
79 if (trial->group() == parallel_6)
80 parallelism = 6;
81 else if (trial->group() == parallel_8)
82 parallelism = 8;
83 else if (trial->group() == parallel_10)
84 parallelism = 10;
85 else if (trial->group() == parallel_14)
86 parallelism = 14;
87 else if (trial->group() == parallel_20)
88 parallelism = 20;
[email protected]962b98212010-07-17 03:37:5189 }
90
91 net::HostResolver* global_host_resolver =
[email protected]ee094b82010-08-24 15:55:5192 net::CreateSystemHostResolver(parallelism, net_log);
[email protected]9087aa32010-02-18 08:03:3893
[email protected]0f8f1b432010-03-16 19:06:0394 // Determine if we should disable IPv6 support.
[email protected]9087aa32010-02-18 08:03:3895 if (!command_line.HasSwitch(switches::kEnableIPv6)) {
[email protected]0f8f1b432010-03-16 19:06:0396 if (command_line.HasSwitch(switches::kDisableIPv6)) {
[email protected]46f6e202010-02-26 06:07:2597 global_host_resolver->SetDefaultAddressFamily(net::ADDRESS_FAMILY_IPV4);
[email protected]0f8f1b432010-03-16 19:06:0398 } else {
99 net::HostResolverImpl* host_resolver_impl =
100 global_host_resolver->GetAsHostResolverImpl();
101 if (host_resolver_impl != NULL) {
[email protected]780f8492010-09-16 04:12:15102 // Use probe to decide if support is warranted.
103 host_resolver_impl->ProbeIPv6Support();
[email protected]0f8f1b432010-03-16 19:06:03104 }
105 }
[email protected]9087aa32010-02-18 08:03:38106 }
107
[email protected]9087aa32010-02-18 08:03:38108 // If hostname remappings were specified on the command-line, layer these
109 // rules on top of the real host resolver. This allows forwarding all requests
110 // through a designated test server.
[email protected]0f8f1b432010-03-16 19:06:03111 if (!command_line.HasSwitch(switches::kHostResolverRules))
112 return global_host_resolver;
[email protected]0ac83682010-01-22 17:46:27113
[email protected]0f8f1b432010-03-16 19:06:03114 net::MappedHostResolver* remapped_resolver =
115 new net::MappedHostResolver(global_host_resolver);
116 remapped_resolver->SetRulesFromString(
117 command_line.GetSwitchValueASCII(switches::kHostResolverRules));
118 return remapped_resolver;
[email protected]0ac83682010-01-22 17:46:27119}
120
[email protected]58bc7042010-07-07 18:04:14121class LoggingNetworkChangeObserver
122 : public net::NetworkChangeNotifier::Observer {
123 public:
124 // |net_log| must remain valid throughout our lifetime.
125 explicit LoggingNetworkChangeObserver(net::NetLog* net_log)
126 : net_log_(net_log) {
127 net::NetworkChangeNotifier::AddObserver(this);
128 }
129
130 ~LoggingNetworkChangeObserver() {
131 net::NetworkChangeNotifier::RemoveObserver(this);
132 }
133
134 virtual void OnIPAddressChanged() {
[email protected]8e96e502010-10-21 20:57:12135 VLOG(1) << "Observed a change to the network IP addresses";
[email protected]58bc7042010-07-07 18:04:14136
[email protected]d3aaf3f2010-09-02 20:45:55137 net_log_->AddEntry(net::NetLog::TYPE_NETWORK_IP_ADDRESSES_CHANGED,
[email protected]58bc7042010-07-07 18:04:14138 base::TimeTicks::Now(),
[email protected]d2cbfbe2010-08-12 17:38:16139 net::NetLog::Source(),
[email protected]58bc7042010-07-07 18:04:14140 net::NetLog::PHASE_NONE,
141 NULL);
142 }
143
144 private:
145 net::NetLog* net_log_;
146 DISALLOW_COPY_AND_ASSIGN(LoggingNetworkChangeObserver);
147};
148
[email protected]0ac83682010-01-22 17:46:27149} // namespace
150
[email protected]86933612010-10-16 23:10:33151// This is a wrapper class around ProxyScriptFetcherImpl that will
152// keep track of live instances.
153class IOThread::ManagedProxyScriptFetcher
154 : public net::ProxyScriptFetcherImpl {
155 public:
156 ManagedProxyScriptFetcher(URLRequestContext* context,
157 IOThread* io_thread)
158 : net::ProxyScriptFetcherImpl(context),
159 io_thread_(io_thread) {
160 DCHECK(!ContainsKey(*fetchers(), this));
161 fetchers()->insert(this);
162 }
163
164 virtual ~ManagedProxyScriptFetcher() {
165 DCHECK(ContainsKey(*fetchers(), this));
166 fetchers()->erase(this);
167 }
168
169 private:
170 ProxyScriptFetchers* fetchers() {
171 return &io_thread_->fetchers_;
172 }
173
174 IOThread* io_thread_;
175
176 DISALLOW_COPY_AND_ASSIGN(ManagedProxyScriptFetcher);
177};
178
[email protected]0ac83682010-01-22 17:46:27179// The IOThread object must outlive any tasks posted to the IO thread before the
180// Quit task.
[email protected]c56428f22010-06-16 02:17:23181DISABLE_RUNNABLE_METHOD_REFCOUNT(IOThread);
[email protected]0ac83682010-01-22 17:46:27182
[email protected]1889dc1b2010-10-14 22:03:13183IOThread::Globals::Globals() {}
184
185IOThread::Globals::~Globals() {}
186
[email protected]0ac83682010-01-22 17:46:27187IOThread::IOThread()
[email protected]f8b3ef82010-10-11 02:45:52188 : BrowserProcessSubThread(BrowserThread::IO),
[email protected]d13c3272010-02-04 00:24:51189 globals_(NULL),
[email protected]c5629c32010-06-23 01:22:43190 speculative_interceptor_(NULL),
[email protected]74be069e82010-06-25 00:12:49191 predictor_(NULL) {}
[email protected]0ac83682010-01-22 17:46:27192
193IOThread::~IOThread() {
194 // We cannot rely on our base class to stop the thread since we want our
195 // CleanUp function to run.
196 Stop();
[email protected]d13c3272010-02-04 00:24:51197 DCHECK(!globals_);
[email protected]0ac83682010-01-22 17:46:27198}
199
[email protected]d13c3272010-02-04 00:24:51200IOThread::Globals* IOThread::globals() {
[email protected]f8b3ef82010-10-11 02:45:52201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]d13c3272010-02-04 00:24:51202 return globals_;
[email protected]0ac83682010-01-22 17:46:27203}
204
[email protected]74be069e82010-06-25 00:12:49205void IOThread::InitNetworkPredictor(
[email protected]0ac83682010-01-22 17:46:27206 bool prefetching_enabled,
[email protected]74be069e82010-06-25 00:12:49207 base::TimeDelta max_dns_queue_delay,
[email protected]0ac83682010-01-22 17:46:27208 size_t max_concurrent,
[email protected]c5629c32010-06-23 01:22:43209 const chrome_common_net::UrlList& startup_urls,
[email protected]760d970a2010-05-18 00:39:18210 ListValue* referral_list,
211 bool preconnect_enabled) {
[email protected]f8b3ef82010-10-11 02:45:52212 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]0ac83682010-01-22 17:46:27213 message_loop()->PostTask(
214 FROM_HERE,
215 NewRunnableMethod(
216 this,
[email protected]74be069e82010-06-25 00:12:49217 &IOThread::InitNetworkPredictorOnIOThread,
218 prefetching_enabled, max_dns_queue_delay, max_concurrent,
[email protected]c5629c32010-06-23 01:22:43219 startup_urls, referral_list, preconnect_enabled));
[email protected]0ac83682010-01-22 17:46:27220}
221
[email protected]562d71e2010-10-22 22:24:46222void IOThread::RegisterURLRequestContextGetter(
223 ChromeURLRequestContextGetter* url_request_context_getter) {
224 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
225 std::list<ChromeURLRequestContextGetter*>::const_iterator it =
226 std::find(url_request_context_getters_.begin(),
227 url_request_context_getters_.end(),
228 url_request_context_getter);
229 DCHECK(it == url_request_context_getters_.end());
230 url_request_context_getters_.push_back(url_request_context_getter);
231}
232
233void IOThread::UnregisterURLRequestContextGetter(
234 ChromeURLRequestContextGetter* url_request_context_getter) {
235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
236 std::list<ChromeURLRequestContextGetter*>::iterator it =
237 std::find(url_request_context_getters_.begin(),
238 url_request_context_getters_.end(),
239 url_request_context_getter);
240 DCHECK(it != url_request_context_getters_.end());
241 // This does not scale, but we shouldn't have many URLRequestContextGetters in
242 // the first place, so this should be fine.
243 url_request_context_getters_.erase(it);
244}
245
[email protected]0ac83682010-01-22 17:46:27246void IOThread::ChangedToOnTheRecord() {
[email protected]f8b3ef82010-10-11 02:45:52247 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]0ac83682010-01-22 17:46:27248 message_loop()->PostTask(
249 FROM_HERE,
250 NewRunnableMethod(
251 this,
252 &IOThread::ChangedToOnTheRecordOnIOThread));
253}
254
[email protected]86933612010-10-16 23:10:33255net::ProxyScriptFetcher* IOThread::CreateAndRegisterProxyScriptFetcher(
256 URLRequestContext* url_request_context) {
257 return new ManagedProxyScriptFetcher(url_request_context, this);
258}
259
[email protected]0ac83682010-01-22 17:46:27260void IOThread::Init() {
[email protected]ba74b0d22010-10-23 05:19:20261#if defined(OS_LINUX)
262 // TODO(evan): test and enable this on all platforms.
263 // Though this thread is called the "IO" thread, it actually just routes
264 // messages around; it shouldn't be allowed to perform any blocking disk I/O.
265 base::ThreadRestrictions::SetIOAllowed(false);
266#endif
267
[email protected]0ac83682010-01-22 17:46:27268 BrowserProcessSubThread::Init();
269
[email protected]70b92342010-10-12 05:54:06270 DCHECK_EQ(MessageLoop::TYPE_IO, message_loop()->type());
271
272#if defined(USE_NSS)
273 net::SetMessageLoopForOCSP();
[email protected]ecd95ae2010-10-20 23:58:17274#endif // defined(USE_NSS)
[email protected]70b92342010-10-12 05:54:06275
[email protected]d13c3272010-02-04 00:24:51276 DCHECK(!globals_);
277 globals_ = new Globals;
278
[email protected]aa92ba22010-06-21 23:17:24279 globals_->net_log.reset(new ChromeNetLog());
[email protected]58bc7042010-07-07 18:04:14280
281 // Add an observer that will emit network change events to the ChromeNetLog.
282 // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be
283 // logging the network change before other IO thread consumers respond to it.
284 network_change_observer_.reset(
285 new LoggingNetworkChangeObserver(globals_->net_log.get()));
286
[email protected]73c45322010-10-01 23:57:54287 globals_->host_resolver.reset(
288 CreateGlobalHostResolver(globals_->net_log.get()));
[email protected]2db580532010-10-08 14:32:37289 globals_->dnsrr_resolver.reset(new net::DnsRRResolver);
[email protected]65d34382010-07-01 18:12:26290 globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory(
[email protected]73c45322010-10-01 23:57:54291 globals_->host_resolver.get()));
[email protected]0ac83682010-01-22 17:46:27292}
293
[email protected]2a92cd92010-04-27 00:01:41294void IOThread::CleanUp() {
[email protected]562d71e2010-10-22 22:24:46295 // Step 1: Kill all things that might be holding onto
296 // URLRequest/URLRequestContexts.
297
[email protected]59a3b362010-10-21 21:52:41298#if defined(USE_NSS)
299 net::ShutdownOCSP();
300#endif // defined(USE_NSS)
301
[email protected]0b1ad312010-10-22 01:01:38302 // Destroy all URLRequests started by URLFetchers.
303 URLFetcher::CancelAll();
304
[email protected]562d71e2010-10-22 22:24:46305 // Break any cycles between the ProxyScriptFetcher and URLRequestContext.
306 for (ProxyScriptFetchers::const_iterator it = fetchers_.begin();
307 it != fetchers_.end(); ++it) {
308 (*it)->Cancel();
309 }
[email protected]58bc7042010-07-07 18:04:14310
[email protected]325a71f2010-05-21 23:05:27311 // If any child processes are still running, terminate them and
[email protected]d27893f62010-07-03 05:47:42312 // and delete the BrowserChildProcessHost instances to release whatever
[email protected]325a71f2010-05-21 23:05:27313 // IO thread only resources they are referencing.
[email protected]d27893f62010-07-03 05:47:42314 BrowserChildProcessHost::TerminateAll();
[email protected]325a71f2010-05-21 23:05:27315
[email protected]562d71e2010-10-22 22:24:46316 std::list<ChromeURLRequestContextGetter*> url_request_context_getters;
317 url_request_context_getters.swap(url_request_context_getters_);
318 for (std::list<ChromeURLRequestContextGetter*>::iterator it =
319 url_request_context_getters.begin();
320 it != url_request_context_getters.end(); ++it) {
321 ChromeURLRequestContextGetter* getter = *it;
322 getter->ReleaseURLRequestContext();
323 }
324
325 // Step 2: Release objects that the URLRequestContext could have been pointing
326 // to.
327
328 // This must be reset before the ChromeNetLog is destroyed.
329 network_change_observer_.reset();
330
[email protected]0ac83682010-01-22 17:46:27331 // Not initialized in Init(). May not be initialized.
[email protected]74be069e82010-06-25 00:12:49332 if (predictor_) {
333 predictor_->Shutdown();
[email protected]0ac83682010-01-22 17:46:27334
[email protected]74be069e82010-06-25 00:12:49335 // TODO(willchan): Stop reference counting Predictor. It's owned by
[email protected]0ac83682010-01-22 17:46:27336 // IOThread now.
[email protected]74be069e82010-06-25 00:12:49337 predictor_->Release();
338 predictor_ = NULL;
339 chrome_browser_net::FreePredictorResources();
[email protected]0ac83682010-01-22 17:46:27340 }
341
[email protected]c5629c32010-06-23 01:22:43342 // Deletion will unregister this interceptor.
343 delete speculative_interceptor_;
344 speculative_interceptor_ = NULL;
345
[email protected]e4d2dd822010-02-05 20:57:33346 // TODO(eroman): hack for http://crbug.com/15513
[email protected]970210c2010-02-19 20:27:02347 if (globals_->host_resolver->GetAsHostResolverImpl()) {
348 globals_->host_resolver.get()->GetAsHostResolverImpl()->Shutdown();
[email protected]e4d2dd822010-02-05 20:57:33349 }
[email protected]0ac83682010-01-22 17:46:27350
[email protected]2a92cd92010-04-27 00:01:41351 // We will delete the NetLog as part of CleanUpAfterMessageLoopDestruction()
352 // in case any of the message loop destruction observers try to access it.
353 deferred_net_log_to_delete_.reset(globals_->net_log.release());
354
[email protected]d13c3272010-02-04 00:24:51355 delete globals_;
356 globals_ = NULL;
[email protected]0ac83682010-01-22 17:46:27357
[email protected]2a92cd92010-04-27 00:01:41358 BrowserProcessSubThread::CleanUp();
359}
360
361void IOThread::CleanUpAfterMessageLoopDestruction() {
362 // TODO(eroman): get rid of this special case for 39723. If we could instead
[email protected]562d71e2010-10-22 22:24:46363 // have a method that runs after the message loop destruction observers have
[email protected]2a92cd92010-04-27 00:01:41364 // run, but before the message loop itself is destroyed, we could safely
365 // combine the two cleanups.
366 deferred_net_log_to_delete_.reset();
[email protected]562d71e2010-10-22 22:24:46367
368 // This will delete the |notification_service_|. Make sure it's done after
369 // anything else can reference it.
[email protected]9aa33e82010-04-15 00:15:39370 BrowserProcessSubThread::CleanUpAfterMessageLoopDestruction();
[email protected]23c386b2010-09-15 22:14:36371
372 // URLRequest instances must NOT outlive the IO thread.
373 //
374 // To allow for URLRequests to be deleted from
375 // MessageLoop::DestructionObserver this check has to happen after CleanUp
376 // (which runs before DestructionObservers).
377 base::LeakTracker<URLRequest>::CheckForLeaks();
[email protected]0ac83682010-01-22 17:46:27378}
379
[email protected]65d34382010-07-01 18:12:26380net::HttpAuthHandlerFactory* IOThread::CreateDefaultAuthHandlerFactory(
381 net::HostResolver* resolver) {
[email protected]b7304162010-08-23 17:42:29382 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]eb3cac72010-02-26 21:07:45383
384 // Get the whitelist information from the command line, create an
385 // HttpAuthFilterWhitelist, and attach it to the HttpAuthHandlerFactory.
[email protected]d201b200e2010-08-27 17:35:02386 net::HttpAuthFilterWhitelist* auth_filter_default_credentials = NULL;
[email protected]eb3cac72010-02-26 21:07:45387 if (command_line.HasSwitch(switches::kAuthServerWhitelist)) {
[email protected]d201b200e2010-08-27 17:35:02388 auth_filter_default_credentials = new net::HttpAuthFilterWhitelist(
389 command_line.GetSwitchValueASCII(switches::kAuthServerWhitelist));
390 }
391 net::HttpAuthFilterWhitelist* auth_filter_delegate = NULL;
392 if (command_line.HasSwitch(switches::kAuthNegotiateDelegateWhitelist)) {
393 auth_filter_delegate = new net::HttpAuthFilterWhitelist(
394 command_line.GetSwitchValueASCII(
395 switches::kAuthNegotiateDelegateWhitelist));
[email protected]eb3cac72010-02-26 21:07:45396 }
[email protected]b4955e7d2010-04-16 20:22:30397 globals_->url_security_manager.reset(
[email protected]d201b200e2010-08-27 17:35:02398 net::URLSecurityManager::Create(auth_filter_default_credentials,
399 auth_filter_delegate));
[email protected]b4955e7d2010-04-16 20:22:30400
[email protected]b7304162010-08-23 17:42:29401 // Determine which schemes are supported.
402 std::string csv_auth_schemes = "basic,digest,ntlm,negotiate";
403 if (command_line.HasSwitch(switches::kAuthSchemes))
404 csv_auth_schemes = StringToLowerASCII(
405 command_line.GetSwitchValueASCII(switches::kAuthSchemes));
406 std::vector<std::string> supported_schemes;
[email protected]76eb0242010-10-14 00:35:36407 base::SplitString(csv_auth_schemes, ',', &supported_schemes);
[email protected]b7304162010-08-23 17:42:29408
409 return net::HttpAuthHandlerRegistryFactory::Create(
410 supported_schemes,
411 globals_->url_security_manager.get(),
412 resolver,
413 command_line.HasSwitch(switches::kDisableAuthNegotiateCnameLookup),
414 command_line.HasSwitch(switches::kEnableAuthNegotiatePort));
[email protected]eb3cac72010-02-26 21:07:45415}
416
[email protected]74be069e82010-06-25 00:12:49417void IOThread::InitNetworkPredictorOnIOThread(
[email protected]0ac83682010-01-22 17:46:27418 bool prefetching_enabled,
[email protected]74be069e82010-06-25 00:12:49419 base::TimeDelta max_dns_queue_delay,
[email protected]0ac83682010-01-22 17:46:27420 size_t max_concurrent,
[email protected]c5629c32010-06-23 01:22:43421 const chrome_common_net::UrlList& startup_urls,
[email protected]760d970a2010-05-18 00:39:18422 ListValue* referral_list,
423 bool preconnect_enabled) {
[email protected]f8b3ef82010-10-11 02:45:52424 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]74be069e82010-06-25 00:12:49425 CHECK(!predictor_);
[email protected]0ac83682010-01-22 17:46:27426
[email protected]74be069e82010-06-25 00:12:49427 chrome_browser_net::EnablePredictor(prefetching_enabled);
[email protected]0ac83682010-01-22 17:46:27428
[email protected]74be069e82010-06-25 00:12:49429 predictor_ = new chrome_browser_net::Predictor(
[email protected]73c45322010-10-01 23:57:54430 globals_->host_resolver.get(),
[email protected]74be069e82010-06-25 00:12:49431 max_dns_queue_delay,
[email protected]760d970a2010-05-18 00:39:18432 max_concurrent,
433 preconnect_enabled);
[email protected]74be069e82010-06-25 00:12:49434 predictor_->AddRef();
[email protected]0ac83682010-01-22 17:46:27435
[email protected]f4ef861ba2010-07-28 22:37:23436 // Speculative_interceptor_ is used to predict subresource usage.
437 DCHECK(!speculative_interceptor_);
438 speculative_interceptor_ = new chrome_browser_net::ConnectInterceptor;
439
[email protected]bff1f512010-08-15 15:13:49440 FinalizePredictorInitialization(predictor_, startup_urls, referral_list);
[email protected]0ac83682010-01-22 17:46:27441}
442
443void IOThread::ChangedToOnTheRecordOnIOThread() {
[email protected]f8b3ef82010-10-11 02:45:52444 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]0ac83682010-01-22 17:46:27445
[email protected]74be069e82010-06-25 00:12:49446 if (predictor_) {
[email protected]0ac83682010-01-22 17:46:27447 // Destroy all evidence of our OTR session.
[email protected]74be069e82010-06-25 00:12:49448 predictor_->Predictor::DiscardAllResults();
[email protected]0ac83682010-01-22 17:46:27449 }
450
451 // Clear the host cache to avoid showing entries from the OTR session
452 // in about:net-internals.
[email protected]970210c2010-02-19 20:27:02453 if (globals_->host_resolver->GetAsHostResolverImpl()) {
454 net::HostCache* host_cache =
455 globals_->host_resolver.get()->GetAsHostResolverImpl()->cache();
[email protected]f2d8c4212010-02-02 00:56:35456 if (host_cache)
457 host_cache->clear();
458 }
[email protected]9e743cd2010-03-16 07:03:53459 // Clear all of the passively logged data.
460 // TODO(eroman): this is a bit heavy handed, really all we need to do is
461 // clear the data pertaining to off the record context.
462 globals_->net_log->passive_collector()->Clear();
[email protected]0ac83682010-01-22 17:46:27463}