Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(494)

Side by Side Diff: chrome/browser/io_thread.cc

Issue 8477004: Have content/ create and destroy its own threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: With this patchset, Chrome runs and exits normally on Linux. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/metrics/field_trial.h" 12 #include "base/metrics/field_trial.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/string_number_conversions.h" 14 #include "base/string_number_conversions.h"
15 #include "base/string_split.h" 15 #include "base/string_split.h"
16 #include "base/string_util.h" 16 #include "base/string_util.h"
17 #include "base/threading/thread.h"
17 #include "base/threading/thread_restrictions.h" 18 #include "base/threading/thread_restrictions.h"
18 #include "build/build_config.h" 19 #include "build/build_config.h"
19 #include "chrome/browser/browser_process.h" 20 #include "chrome/browser/browser_process.h"
20 #include "chrome/browser/extensions/extension_event_router_forwarder.h" 21 #include "chrome/browser/extensions/extension_event_router_forwarder.h"
21 #include "chrome/browser/media/media_internals.h" 22 #include "chrome/browser/media/media_internals.h"
22 #include "chrome/browser/net/chrome_net_log.h" 23 #include "chrome/browser/net/chrome_net_log.h"
23 #include "chrome/browser/net/chrome_network_delegate.h" 24 #include "chrome/browser/net/chrome_network_delegate.h"
24 #include "chrome/browser/net/chrome_url_request_context.h" 25 #include "chrome/browser/net/chrome_url_request_context.h"
25 #include "chrome/browser/net/connect_interceptor.h" 26 #include "chrome/browser/net/connect_interceptor.h"
26 #include "chrome/browser/net/passive_log_collector.h" 27 #include "chrome/browser/net/passive_log_collector.h"
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 private: 305 private:
305 IOThread* const io_thread_; // Weak pointer, owned by BrowserProcess. 306 IOThread* const io_thread_; // Weak pointer, owned by BrowserProcess.
306 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; 307 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
307 308
308 base::debug::LeakTracker<SystemURLRequestContextGetter> leak_tracker_; 309 base::debug::LeakTracker<SystemURLRequestContextGetter> leak_tracker_;
309 }; 310 };
310 311
311 SystemURLRequestContextGetter::SystemURLRequestContextGetter( 312 SystemURLRequestContextGetter::SystemURLRequestContextGetter(
312 IOThread* io_thread) 313 IOThread* io_thread)
313 : io_thread_(io_thread), 314 : io_thread_(io_thread),
314 io_message_loop_proxy_(io_thread->message_loop_proxy()) { 315 io_message_loop_proxy_(
316 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)) {
315 } 317 }
316 318
317 SystemURLRequestContextGetter::~SystemURLRequestContextGetter() {} 319 SystemURLRequestContextGetter::~SystemURLRequestContextGetter() {}
318 320
319 net::URLRequestContext* SystemURLRequestContextGetter::GetURLRequestContext() { 321 net::URLRequestContext* SystemURLRequestContextGetter::GetURLRequestContext() {
320 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 322 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
321 DCHECK(io_thread_->globals()->system_request_context); 323 DCHECK(io_thread_->globals()->system_request_context);
322 324
323 return io_thread_->globals()->system_request_context; 325 return io_thread_->globals()->system_request_context;
324 } 326 }
(...skipping 14 matching lines...) Expand all
339 IOThread::Globals::MediaGlobals::MediaGlobals() {} 341 IOThread::Globals::MediaGlobals::MediaGlobals() {}
340 342
341 IOThread::Globals::MediaGlobals::~MediaGlobals() {} 343 IOThread::Globals::MediaGlobals::~MediaGlobals() {}
342 344
343 // |local_state| is passed in explicitly in order to (1) reduce implicit 345 // |local_state| is passed in explicitly in order to (1) reduce implicit
344 // dependencies and (2) make IOThread more flexible for testing. 346 // dependencies and (2) make IOThread more flexible for testing.
345 IOThread::IOThread( 347 IOThread::IOThread(
346 PrefService* local_state, 348 PrefService* local_state,
347 ChromeNetLog* net_log, 349 ChromeNetLog* net_log,
348 ExtensionEventRouterForwarder* extension_event_router_forwarder) 350 ExtensionEventRouterForwarder* extension_event_router_forwarder)
349 : content::BrowserProcessSubThread(BrowserThread::IO), 351 : net_log_(net_log),
350 net_log_(net_log),
351 extension_event_router_forwarder_(extension_event_router_forwarder), 352 extension_event_router_forwarder_(extension_event_router_forwarder),
352 globals_(NULL), 353 globals_(NULL),
353 sdch_manager_(NULL), 354 sdch_manager_(NULL),
354 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { 355 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
355 // We call RegisterPrefs() here (instead of inside browser_prefs.cc) to make 356 // We call RegisterPrefs() here (instead of inside browser_prefs.cc) to make
356 // sure that everything is initialized in the right order. 357 // sure that everything is initialized in the right order.
357 RegisterPrefs(local_state); 358 RegisterPrefs(local_state);
358 auth_schemes_ = local_state->GetString(prefs::kAuthSchemes); 359 auth_schemes_ = local_state->GetString(prefs::kAuthSchemes);
359 negotiate_disable_cname_lookup_ = local_state->GetBoolean( 360 negotiate_disable_cname_lookup_ = local_state->GetBoolean(
360 prefs::kDisableAuthNegotiateCnameLookup); 361 prefs::kDisableAuthNegotiateCnameLookup);
(...skipping 10 matching lines...) Expand all
371 ssl_config_service_manager_.reset( 372 ssl_config_service_manager_.reset(
372 SSLConfigServiceManager::CreateDefaultManager(local_state)); 373 SSLConfigServiceManager::CreateDefaultManager(local_state));
373 MessageLoop::current()->PostTask(FROM_HERE, 374 MessageLoop::current()->PostTask(FROM_HERE,
374 method_factory_.NewRunnableMethod( 375 method_factory_.NewRunnableMethod(
375 &IOThread::InitSystemRequestContext)); 376 &IOThread::InitSystemRequestContext));
376 } 377 }
377 378
378 IOThread::~IOThread() { 379 IOThread::~IOThread() {
379 if (pref_proxy_config_tracker_.get()) 380 if (pref_proxy_config_tracker_.get())
380 pref_proxy_config_tracker_->DetachFromPrefService(); 381 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_); 382 DCHECK(!globals_);
385 } 383 }
386 384
387 IOThread::Globals* IOThread::globals() { 385 IOThread::Globals* IOThread::globals() {
388 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 386 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
389 return globals_; 387 return globals_;
390 } 388 }
391 389
392 ChromeNetLog* IOThread::net_log() { 390 ChromeNetLog* IOThread::net_log() {
393 return net_log_; 391 return net_log_;
394 } 392 }
395 393
396 net::URLRequestContextGetter* IOThread::system_url_request_context_getter() { 394 net::URLRequestContextGetter* IOThread::system_url_request_context_getter() {
397 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 395 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
398 if (!system_url_request_context_getter_) { 396 if (!system_url_request_context_getter_) {
399 InitSystemRequestContext(); 397 InitSystemRequestContext();
400 } 398 }
401 return system_url_request_context_getter_; 399 return system_url_request_context_getter_;
402 } 400 }
403 401
404 void IOThread::Init() { 402 void IOThread::Init() {
405 // Though this thread is called the "IO" thread, it actually just routes 403 // 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. 404 // messages around; it shouldn't be allowed to perform any blocking disk I/O.
407 base::ThreadRestrictions::SetIOAllowed(false); 405 base::ThreadRestrictions::SetIOAllowed(false);
408 406
409 content::BrowserProcessSubThread::Init(); 407 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
410
411 DCHECK_EQ(MessageLoop::TYPE_IO, message_loop()->type());
412 408
413 #if defined(USE_NSS) 409 #if defined(USE_NSS)
414 net::SetMessageLoopForOCSP(); 410 net::SetMessageLoopForOCSP();
415 #endif // defined(USE_NSS) 411 #endif // defined(USE_NSS)
416 412
417 DCHECK(!globals_); 413 DCHECK(!globals_);
418 globals_ = new Globals; 414 globals_ = new Globals;
419 415
420 globals_->media.media_internals.reset(new MediaInternals()); 416 globals_->media.media_internals.reset(new MediaInternals());
421 417
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 508
513 system_proxy_config_service_.reset(); 509 system_proxy_config_service_.reset();
514 510
515 delete globals_; 511 delete globals_;
516 globals_ = NULL; 512 globals_ = NULL;
517 513
518 // net::URLRequest instances must NOT outlive the IO thread. 514 // net::URLRequest instances must NOT outlive the IO thread.
519 base::debug::LeakTracker<net::URLRequest>::CheckForLeaks(); 515 base::debug::LeakTracker<net::URLRequest>::CheckForLeaks();
520 516
521 base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks(); 517 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 } 518 }
527 519
528 // static 520 // static
529 void IOThread::RegisterPrefs(PrefService* local_state) { 521 void IOThread::RegisterPrefs(PrefService* local_state) {
530 local_state->RegisterStringPref(prefs::kAuthSchemes, 522 local_state->RegisterStringPref(prefs::kAuthSchemes,
531 "basic,digest,ntlm,negotiate"); 523 "basic,digest,ntlm,negotiate");
532 local_state->RegisterBooleanPref(prefs::kDisableAuthNegotiateCnameLookup, 524 local_state->RegisterBooleanPref(prefs::kDisableAuthNegotiateCnameLookup,
533 false); 525 false);
534 local_state->RegisterBooleanPref(prefs::kEnableAuthNegotiatePort, false); 526 local_state->RegisterBooleanPref(prefs::kEnableAuthNegotiatePort, false);
535 local_state->RegisterStringPref(prefs::kAuthServerWhitelist, ""); 527 local_state->RegisterStringPref(prefs::kAuthServerWhitelist, "");
(...skipping 30 matching lines...) Expand all
566 } 558 }
567 559
568 void IOThread::ClearHostCache() { 560 void IOThread::ClearHostCache() {
569 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 561 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
570 562
571 net::HostCache* host_cache = globals_->host_resolver->GetHostCache(); 563 net::HostCache* host_cache = globals_->host_resolver->GetHostCache();
572 if (host_cache) 564 if (host_cache)
573 host_cache->clear(); 565 host_cache->clear();
574 } 566 }
575 567
568 MessageLoop* IOThread::message_loop() const {
569 return BrowserThread::UnsafeGetBrowserThread(
570 BrowserThread::IO)->message_loop();
571 }
572
576 net::SSLConfigService* IOThread::GetSSLConfigService() { 573 net::SSLConfigService* IOThread::GetSSLConfigService() {
577 return ssl_config_service_manager_->Get(); 574 return ssl_config_service_manager_->Get();
578 } 575 }
579 576
580 void IOThread::InitSystemRequestContext() { 577 void IOThread::InitSystemRequestContext() {
581 if (system_url_request_context_getter_) 578 if (system_url_request_context_getter_)
582 return; 579 return;
583 // If we're in unit_tests, IOThread may not be run. 580 // If we're in unit_tests, IOThread may not be run.
584 if (!message_loop()) 581 if (!message_loop())
585 return; 582 return;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 system_params.network_delegate = globals_->system_network_delegate.get(); 624 system_params.network_delegate = globals_->system_network_delegate.get();
628 system_params.net_log = net_log_; 625 system_params.net_log = net_log_;
629 globals_->system_http_transaction_factory.reset( 626 globals_->system_http_transaction_factory.reset(
630 new net::HttpNetworkLayer( 627 new net::HttpNetworkLayer(
631 new net::HttpNetworkSession(system_params))); 628 new net::HttpNetworkSession(system_params)));
632 globals_->system_ftp_transaction_factory.reset( 629 globals_->system_ftp_transaction_factory.reset(
633 new net::FtpNetworkLayer(globals_->host_resolver.get())); 630 new net::FtpNetworkLayer(globals_->host_resolver.get()));
634 globals_->system_request_context = 631 globals_->system_request_context =
635 ConstructSystemRequestContext(globals_, net_log_); 632 ConstructSystemRequestContext(globals_, net_log_);
636 } 633 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698