Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/io_thread.h" | 5 #include "chrome/browser/io_thread.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/debug/leak_tracker.h" | 8 #include "base/debug/leak_tracker.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 199 }; | 199 }; |
| 200 | 200 |
| 201 // The IOThread object must outlive any tasks posted to the IO thread before the | 201 // The IOThread object must outlive any tasks posted to the IO thread before the |
| 202 // Quit task. | 202 // Quit task. |
| 203 DISABLE_RUNNABLE_METHOD_REFCOUNT(IOThread); | 203 DISABLE_RUNNABLE_METHOD_REFCOUNT(IOThread); |
| 204 | 204 |
| 205 IOThread::Globals::Globals() {} | 205 IOThread::Globals::Globals() {} |
| 206 | 206 |
| 207 IOThread::Globals::~Globals() {} | 207 IOThread::Globals::~Globals() {} |
| 208 | 208 |
| 209 IOThread::IOThread() | 209 IOThread::IOThread(ChromeNetLog* net_log) |
| 210 : BrowserProcessSubThread(BrowserThread::IO), | 210 : net_log_(net_log), |
|
eroman
2010/11/17 05:59:02
I am not sure what the style guide says, but I thi
mmenke
2010/11/17 21:42:14
Done.
| |
| 211 BrowserProcessSubThread(BrowserThread::IO), | |
| 211 globals_(NULL), | 212 globals_(NULL), |
| 212 speculative_interceptor_(NULL), | 213 speculative_interceptor_(NULL), |
| 213 predictor_(NULL) {} | 214 predictor_(NULL) {} |
| 214 | 215 |
| 215 IOThread::~IOThread() { | 216 IOThread::~IOThread() { |
| 216 // We cannot rely on our base class to stop the thread since we want our | 217 // We cannot rely on our base class to stop the thread since we want our |
| 217 // CleanUp function to run. | 218 // CleanUp function to run. |
| 218 Stop(); | 219 Stop(); |
| 219 DCHECK(!globals_); | 220 DCHECK(!globals_); |
| 220 } | 221 } |
| 221 | 222 |
| 222 IOThread::Globals* IOThread::globals() { | 223 IOThread::Globals* IOThread::globals() { |
| 223 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 224 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 224 return globals_; | 225 return globals_; |
| 225 } | 226 } |
| 226 | 227 |
| 228 ChromeNetLog* IOThread::net_log() { | |
| 229 return net_log_; | |
| 230 } | |
| 231 | |
| 227 void IOThread::InitNetworkPredictor( | 232 void IOThread::InitNetworkPredictor( |
| 228 bool prefetching_enabled, | 233 bool prefetching_enabled, |
| 229 base::TimeDelta max_dns_queue_delay, | 234 base::TimeDelta max_dns_queue_delay, |
| 230 size_t max_speculative_parallel_resolves, | 235 size_t max_speculative_parallel_resolves, |
| 231 const chrome_common_net::UrlList& startup_urls, | 236 const chrome_common_net::UrlList& startup_urls, |
| 232 ListValue* referral_list, | 237 ListValue* referral_list, |
| 233 bool preconnect_enabled) { | 238 bool preconnect_enabled) { |
| 234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 239 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 235 message_loop()->PostTask( | 240 message_loop()->PostTask( |
| 236 FROM_HERE, | 241 FROM_HERE, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 268 | 273 |
| 269 DCHECK_EQ(MessageLoop::TYPE_IO, message_loop()->type()); | 274 DCHECK_EQ(MessageLoop::TYPE_IO, message_loop()->type()); |
| 270 | 275 |
| 271 #if defined(USE_NSS) | 276 #if defined(USE_NSS) |
| 272 net::SetMessageLoopForOCSP(); | 277 net::SetMessageLoopForOCSP(); |
| 273 #endif // defined(USE_NSS) | 278 #endif // defined(USE_NSS) |
| 274 | 279 |
| 275 DCHECK(!globals_); | 280 DCHECK(!globals_); |
| 276 globals_ = new Globals; | 281 globals_ = new Globals; |
| 277 | 282 |
| 278 globals_->net_log.reset(new ChromeNetLog()); | |
| 279 | |
| 280 // Add an observer that will emit network change events to the ChromeNetLog. | 283 // Add an observer that will emit network change events to the ChromeNetLog. |
| 281 // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be | 284 // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be |
| 282 // logging the network change before other IO thread consumers respond to it. | 285 // logging the network change before other IO thread consumers respond to it. |
| 283 network_change_observer_.reset( | 286 network_change_observer_.reset( |
| 284 new LoggingNetworkChangeObserver(globals_->net_log.get())); | 287 new LoggingNetworkChangeObserver(net_log_)); |
| 285 | 288 |
| 286 globals_->host_resolver.reset( | 289 globals_->host_resolver.reset( |
| 287 CreateGlobalHostResolver(globals_->net_log.get())); | 290 CreateGlobalHostResolver(net_log_)); |
| 288 globals_->dnsrr_resolver.reset(new net::DnsRRResolver); | 291 globals_->dnsrr_resolver.reset(new net::DnsRRResolver); |
| 289 globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory( | 292 globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory( |
| 290 globals_->host_resolver.get())); | 293 globals_->host_resolver.get())); |
| 291 } | 294 } |
| 292 | 295 |
| 293 void IOThread::CleanUp() { | 296 void IOThread::CleanUp() { |
| 294 #if defined(USE_NSS) | 297 #if defined(USE_NSS) |
| 295 net::ShutdownOCSP(); | 298 net::ShutdownOCSP(); |
| 296 #endif // defined(USE_NSS) | 299 #endif // defined(USE_NSS) |
| 297 | 300 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 325 if (globals_->host_resolver->GetAsHostResolverImpl()) { | 328 if (globals_->host_resolver->GetAsHostResolverImpl()) { |
| 326 globals_->host_resolver.get()->GetAsHostResolverImpl()->Shutdown(); | 329 globals_->host_resolver.get()->GetAsHostResolverImpl()->Shutdown(); |
| 327 } | 330 } |
| 328 | 331 |
| 329 // Break any cycles between the ProxyScriptFetcher and URLRequestContext. | 332 // Break any cycles between the ProxyScriptFetcher and URLRequestContext. |
| 330 for (ProxyScriptFetchers::const_iterator it = fetchers_.begin(); | 333 for (ProxyScriptFetchers::const_iterator it = fetchers_.begin(); |
| 331 it != fetchers_.end(); ++it) { | 334 it != fetchers_.end(); ++it) { |
| 332 (*it)->Cancel(); | 335 (*it)->Cancel(); |
| 333 } | 336 } |
| 334 | 337 |
| 335 // We will delete the NetLog as part of CleanUpAfterMessageLoopDestruction() | |
| 336 // in case any of the message loop destruction observers try to access it. | |
| 337 deferred_net_log_to_delete_.reset(globals_->net_log.release()); | |
| 338 | |
| 339 delete globals_; | 338 delete globals_; |
| 340 globals_ = NULL; | 339 globals_ = NULL; |
| 341 | 340 |
| 342 BrowserProcessSubThread::CleanUp(); | 341 BrowserProcessSubThread::CleanUp(); |
| 343 } | 342 } |
| 344 | 343 |
| 345 void IOThread::CleanUpAfterMessageLoopDestruction() { | 344 void IOThread::CleanUpAfterMessageLoopDestruction() { |
| 346 // TODO(eroman): get rid of this special case for 39723. If we could instead | |
| 347 // have a method that runs after the message loop destruction obsevers have | |
| 348 // run, but before the message loop itself is destroyed, we could safely | |
| 349 // combine the two cleanups. | |
| 350 deferred_net_log_to_delete_.reset(); | |
| 351 BrowserProcessSubThread::CleanUpAfterMessageLoopDestruction(); | 345 BrowserProcessSubThread::CleanUpAfterMessageLoopDestruction(); |
| 352 | 346 |
| 353 // URLRequest instances must NOT outlive the IO thread. | 347 // URLRequest instances must NOT outlive the IO thread. |
| 354 // | 348 // |
| 355 // To allow for URLRequests to be deleted from | 349 // To allow for URLRequests to be deleted from |
| 356 // MessageLoop::DestructionObserver this check has to happen after CleanUp | 350 // MessageLoop::DestructionObserver this check has to happen after CleanUp |
| 357 // (which runs before DestructionObservers). | 351 // (which runs before DestructionObservers). |
| 358 base::debug::LeakTracker<URLRequest>::CheckForLeaks(); | 352 base::debug::LeakTracker<URLRequest>::CheckForLeaks(); |
| 359 } | 353 } |
| 360 | 354 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 433 // in about:net-internals. | 427 // in about:net-internals. |
| 434 if (globals_->host_resolver->GetAsHostResolverImpl()) { | 428 if (globals_->host_resolver->GetAsHostResolverImpl()) { |
| 435 net::HostCache* host_cache = | 429 net::HostCache* host_cache = |
| 436 globals_->host_resolver.get()->GetAsHostResolverImpl()->cache(); | 430 globals_->host_resolver.get()->GetAsHostResolverImpl()->cache(); |
| 437 if (host_cache) | 431 if (host_cache) |
| 438 host_cache->clear(); | 432 host_cache->clear(); |
| 439 } | 433 } |
| 440 // Clear all of the passively logged data. | 434 // Clear all of the passively logged data. |
| 441 // TODO(eroman): this is a bit heavy handed, really all we need to do is | 435 // TODO(eroman): this is a bit heavy handed, really all we need to do is |
| 442 // clear the data pertaining to off the record context. | 436 // clear the data pertaining to off the record context. |
| 443 globals_->net_log->passive_collector()->Clear(); | 437 net_log_->passive_collector()->Clear(); |
| 444 } | 438 } |
| OLD | NEW |