| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/io_thread.h" | 5 #include "chrome/browser/io_thread.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/debug/leak_tracker.h" | 10 #include "base/debug/leak_tracker.h" |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 private: | 304 private: |
| 305 IOThread* const io_thread_; // Weak pointer, owned by BrowserProcess. | 305 IOThread* const io_thread_; // Weak pointer, owned by BrowserProcess. |
| 306 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; | 306 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; |
| 307 | 307 |
| 308 base::debug::LeakTracker<SystemURLRequestContextGetter> leak_tracker_; | 308 base::debug::LeakTracker<SystemURLRequestContextGetter> leak_tracker_; |
| 309 }; | 309 }; |
| 310 | 310 |
| 311 SystemURLRequestContextGetter::SystemURLRequestContextGetter( | 311 SystemURLRequestContextGetter::SystemURLRequestContextGetter( |
| 312 IOThread* io_thread) | 312 IOThread* io_thread) |
| 313 : io_thread_(io_thread), | 313 : io_thread_(io_thread), |
| 314 io_message_loop_proxy_(io_thread->message_loop_proxy()) { | 314 io_message_loop_proxy_( |
| 315 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)) { |
| 315 } | 316 } |
| 316 | 317 |
| 317 SystemURLRequestContextGetter::~SystemURLRequestContextGetter() {} | 318 SystemURLRequestContextGetter::~SystemURLRequestContextGetter() {} |
| 318 | 319 |
| 319 net::URLRequestContext* SystemURLRequestContextGetter::GetURLRequestContext() { | 320 net::URLRequestContext* SystemURLRequestContextGetter::GetURLRequestContext() { |
| 320 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 321 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 321 DCHECK(io_thread_->globals()->system_request_context); | 322 DCHECK(io_thread_->globals()->system_request_context); |
| 322 | 323 |
| 323 return io_thread_->globals()->system_request_context; | 324 return io_thread_->globals()->system_request_context; |
| 324 } | 325 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 339 IOThread::Globals::MediaGlobals::MediaGlobals() {} | 340 IOThread::Globals::MediaGlobals::MediaGlobals() {} |
| 340 | 341 |
| 341 IOThread::Globals::MediaGlobals::~MediaGlobals() {} | 342 IOThread::Globals::MediaGlobals::~MediaGlobals() {} |
| 342 | 343 |
| 343 // |local_state| is passed in explicitly in order to (1) reduce implicit | 344 // |local_state| is passed in explicitly in order to (1) reduce implicit |
| 344 // dependencies and (2) make IOThread more flexible for testing. | 345 // dependencies and (2) make IOThread more flexible for testing. |
| 345 IOThread::IOThread( | 346 IOThread::IOThread( |
| 346 PrefService* local_state, | 347 PrefService* local_state, |
| 347 ChromeNetLog* net_log, | 348 ChromeNetLog* net_log, |
| 348 ExtensionEventRouterForwarder* extension_event_router_forwarder) | 349 ExtensionEventRouterForwarder* extension_event_router_forwarder) |
| 349 : content::BrowserProcessSubThread(BrowserThread::IO), | 350 : net_log_(net_log), |
| 350 net_log_(net_log), | |
| 351 extension_event_router_forwarder_(extension_event_router_forwarder), | 351 extension_event_router_forwarder_(extension_event_router_forwarder), |
| 352 globals_(NULL), | 352 globals_(NULL), |
| 353 sdch_manager_(NULL), | 353 sdch_manager_(NULL), |
| 354 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 354 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
| 355 // We call RegisterPrefs() here (instead of inside browser_prefs.cc) to make | 355 // We call RegisterPrefs() here (instead of inside browser_prefs.cc) to make |
| 356 // sure that everything is initialized in the right order. | 356 // sure that everything is initialized in the right order. |
| 357 RegisterPrefs(local_state); | 357 RegisterPrefs(local_state); |
| 358 auth_schemes_ = local_state->GetString(prefs::kAuthSchemes); | 358 auth_schemes_ = local_state->GetString(prefs::kAuthSchemes); |
| 359 negotiate_disable_cname_lookup_ = local_state->GetBoolean( | 359 negotiate_disable_cname_lookup_ = local_state->GetBoolean( |
| 360 prefs::kDisableAuthNegotiateCnameLookup); | 360 prefs::kDisableAuthNegotiateCnameLookup); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 371 ssl_config_service_manager_.reset( | 371 ssl_config_service_manager_.reset( |
| 372 SSLConfigServiceManager::CreateDefaultManager(local_state)); | 372 SSLConfigServiceManager::CreateDefaultManager(local_state)); |
| 373 MessageLoop::current()->PostTask(FROM_HERE, | 373 MessageLoop::current()->PostTask(FROM_HERE, |
| 374 method_factory_.NewRunnableMethod( | 374 method_factory_.NewRunnableMethod( |
| 375 &IOThread::InitSystemRequestContext)); | 375 &IOThread::InitSystemRequestContext)); |
| 376 } | 376 } |
| 377 | 377 |
| 378 IOThread::~IOThread() { | 378 IOThread::~IOThread() { |
| 379 if (pref_proxy_config_tracker_.get()) | 379 if (pref_proxy_config_tracker_.get()) |
| 380 pref_proxy_config_tracker_->DetachFromPrefService(); | 380 pref_proxy_config_tracker_->DetachFromPrefService(); |
| 381 // We cannot rely on our base class to stop the thread since we want our | |
| 382 // CleanUp function to run. | |
| 383 Stop(); | |
| 384 DCHECK(!globals_); | 381 DCHECK(!globals_); |
| 385 } | 382 } |
| 386 | 383 |
| 387 IOThread::Globals* IOThread::globals() { | 384 IOThread::Globals* IOThread::globals() { |
| 388 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 385 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 389 return globals_; | 386 return globals_; |
| 390 } | 387 } |
| 391 | 388 |
| 392 ChromeNetLog* IOThread::net_log() { | 389 ChromeNetLog* IOThread::net_log() { |
| 393 return net_log_; | 390 return net_log_; |
| 394 } | 391 } |
| 395 | 392 |
| 396 net::URLRequestContextGetter* IOThread::system_url_request_context_getter() { | 393 net::URLRequestContextGetter* IOThread::system_url_request_context_getter() { |
| 397 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 394 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 398 if (!system_url_request_context_getter_) { | 395 if (!system_url_request_context_getter_) { |
| 399 InitSystemRequestContext(); | 396 InitSystemRequestContext(); |
| 400 } | 397 } |
| 401 return system_url_request_context_getter_; | 398 return system_url_request_context_getter_; |
| 402 } | 399 } |
| 403 | 400 |
| 404 void IOThread::Init() { | 401 void IOThread::Init() { |
| 405 // Though this thread is called the "IO" thread, it actually just routes | 402 // Though this thread is called the "IO" thread, it actually just routes |
| 406 // messages around; it shouldn't be allowed to perform any blocking disk I/O. | 403 // messages around; it shouldn't be allowed to perform any blocking disk I/O. |
| 407 base::ThreadRestrictions::SetIOAllowed(false); | 404 base::ThreadRestrictions::SetIOAllowed(false); |
| 408 | 405 |
| 409 content::BrowserProcessSubThread::Init(); | 406 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 410 | |
| 411 DCHECK_EQ(MessageLoop::TYPE_IO, message_loop()->type()); | |
| 412 | 407 |
| 413 #if defined(USE_NSS) | 408 #if defined(USE_NSS) |
| 414 net::SetMessageLoopForOCSP(); | 409 net::SetMessageLoopForOCSP(); |
| 415 #endif // defined(USE_NSS) | 410 #endif // defined(USE_NSS) |
| 416 | 411 |
| 417 DCHECK(!globals_); | 412 DCHECK(!globals_); |
| 418 globals_ = new Globals; | 413 globals_ = new Globals; |
| 419 | 414 |
| 420 globals_->media.media_internals.reset(new MediaInternals()); | 415 globals_->media.media_internals.reset(new MediaInternals()); |
| 421 | 416 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 | 507 |
| 513 system_proxy_config_service_.reset(); | 508 system_proxy_config_service_.reset(); |
| 514 | 509 |
| 515 delete globals_; | 510 delete globals_; |
| 516 globals_ = NULL; | 511 globals_ = NULL; |
| 517 | 512 |
| 518 // net::URLRequest instances must NOT outlive the IO thread. | 513 // net::URLRequest instances must NOT outlive the IO thread. |
| 519 base::debug::LeakTracker<net::URLRequest>::CheckForLeaks(); | 514 base::debug::LeakTracker<net::URLRequest>::CheckForLeaks(); |
| 520 | 515 |
| 521 base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks(); | 516 base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks(); |
| 522 | |
| 523 // This will delete the |notification_service_|. Make sure it's done after | |
| 524 // anything else can reference it. | |
| 525 content::BrowserProcessSubThread::CleanUp(); | |
| 526 } | 517 } |
| 527 | 518 |
| 528 // static | 519 // static |
| 529 void IOThread::RegisterPrefs(PrefService* local_state) { | 520 void IOThread::RegisterPrefs(PrefService* local_state) { |
| 530 local_state->RegisterStringPref(prefs::kAuthSchemes, | 521 local_state->RegisterStringPref(prefs::kAuthSchemes, |
| 531 "basic,digest,ntlm,negotiate"); | 522 "basic,digest,ntlm,negotiate"); |
| 532 local_state->RegisterBooleanPref(prefs::kDisableAuthNegotiateCnameLookup, | 523 local_state->RegisterBooleanPref(prefs::kDisableAuthNegotiateCnameLookup, |
| 533 false); | 524 false); |
| 534 local_state->RegisterBooleanPref(prefs::kEnableAuthNegotiatePort, false); | 525 local_state->RegisterBooleanPref(prefs::kEnableAuthNegotiatePort, false); |
| 535 local_state->RegisterStringPref(prefs::kAuthServerWhitelist, ""); | 526 local_state->RegisterStringPref(prefs::kAuthServerWhitelist, ""); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 } | 558 } |
| 568 | 559 |
| 569 void IOThread::ClearHostCache() { | 560 void IOThread::ClearHostCache() { |
| 570 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 561 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 571 | 562 |
| 572 net::HostCache* host_cache = globals_->host_resolver->GetHostCache(); | 563 net::HostCache* host_cache = globals_->host_resolver->GetHostCache(); |
| 573 if (host_cache) | 564 if (host_cache) |
| 574 host_cache->clear(); | 565 host_cache->clear(); |
| 575 } | 566 } |
| 576 | 567 |
| 568 MessageLoop* IOThread::message_loop() const { |
| 569 return BrowserThread::UnsafeGetBrowserThread( |
| 570 BrowserThread::IO)->message_loop(); |
| 571 } |
| 572 |
| 577 net::SSLConfigService* IOThread::GetSSLConfigService() { | 573 net::SSLConfigService* IOThread::GetSSLConfigService() { |
| 578 return ssl_config_service_manager_->Get(); | 574 return ssl_config_service_manager_->Get(); |
| 579 } | 575 } |
| 580 | 576 |
| 581 void IOThread::InitSystemRequestContext() { | 577 void IOThread::InitSystemRequestContext() { |
| 582 if (system_url_request_context_getter_) | 578 if (system_url_request_context_getter_) |
| 583 return; | 579 return; |
| 584 // If we're in unit_tests, IOThread may not be run. | 580 // If we're in unit_tests, IOThread may not be run. |
| 585 if (!message_loop()) | 581 if (!message_loop()) |
| 586 return; | 582 return; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 system_params.network_delegate = globals_->system_network_delegate.get(); | 624 system_params.network_delegate = globals_->system_network_delegate.get(); |
| 629 system_params.net_log = net_log_; | 625 system_params.net_log = net_log_; |
| 630 globals_->system_http_transaction_factory.reset( | 626 globals_->system_http_transaction_factory.reset( |
| 631 new net::HttpNetworkLayer( | 627 new net::HttpNetworkLayer( |
| 632 new net::HttpNetworkSession(system_params))); | 628 new net::HttpNetworkSession(system_params))); |
| 633 globals_->system_ftp_transaction_factory.reset( | 629 globals_->system_ftp_transaction_factory.reset( |
| 634 new net::FtpNetworkLayer(globals_->host_resolver.get())); | 630 new net::FtpNetworkLayer(globals_->host_resolver.get())); |
| 635 globals_->system_request_context = | 631 globals_->system_request_context = |
| 636 ConstructSystemRequestContext(globals_, net_log_); | 632 ConstructSystemRequestContext(globals_, net_log_); |
| 637 } | 633 } |
| OLD | NEW |