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

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

Issue 8473009: base::Bind() conversion for IOThread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
« no previous file with comments | « chrome/browser/io_thread.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/bind.h"
11 #include "base/bind_helpers.h"
10 #include "base/debug/leak_tracker.h" 12 #include "base/debug/leak_tracker.h"
11 #include "base/logging.h" 13 #include "base/logging.h"
12 #include "base/metrics/field_trial.h" 14 #include "base/metrics/field_trial.h"
13 #include "base/stl_util.h" 15 #include "base/stl_util.h"
14 #include "base/string_number_conversions.h" 16 #include "base/string_number_conversions.h"
15 #include "base/string_split.h" 17 #include "base/string_split.h"
16 #include "base/string_util.h" 18 #include "base/string_util.h"
17 #include "base/threading/thread_restrictions.h" 19 #include "base/threading/thread_restrictions.h"
18 #include "build/build_config.h" 20 #include "build/build_config.h"
19 #include "chrome/browser/browser_process.h" 21 #include "chrome/browser/browser_process.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 #if defined(USE_NSS) 63 #if defined(USE_NSS)
62 #include "net/ocsp/nss_ocsp.h" 64 #include "net/ocsp/nss_ocsp.h"
63 #endif // defined(USE_NSS) 65 #endif // defined(USE_NSS)
64 66
65 #if defined(OS_CHROMEOS) 67 #if defined(OS_CHROMEOS)
66 #include "chrome/browser/chromeos/proxy_config_service_impl.h" 68 #include "chrome/browser/chromeos/proxy_config_service_impl.h"
67 #endif // defined(OS_CHROMEOS) 69 #endif // defined(OS_CHROMEOS)
68 70
69 using content::BrowserThread; 71 using content::BrowserThread;
70 72
73 // The IOThread object must outlive any tasks posted to the IO thread before the
74 // Quit task, so base::Bind() calls are not refcounted.
75
71 namespace { 76 namespace {
72 77
73 // Custom URLRequestContext used by requests which aren't associated with a 78 // Custom URLRequestContext used by requests which aren't associated with a
74 // particular profile. We need to use a subclass of URLRequestContext in order 79 // particular profile. We need to use a subclass of URLRequestContext in order
75 // to provide the correct User-Agent. 80 // to provide the correct User-Agent.
76 class URLRequestContextWithUserAgent : public net::URLRequestContext { 81 class URLRequestContextWithUserAgent : public net::URLRequestContext {
77 public: 82 public:
78 virtual const std::string& GetUserAgent( 83 virtual const std::string& GetUserAgent(
79 const GURL& url) const OVERRIDE { 84 const GURL& url) const OVERRIDE {
80 return content::GetUserAgent(url); 85 return content::GetUserAgent(url);
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 DCHECK(io_thread_->globals()->system_request_context); 326 DCHECK(io_thread_->globals()->system_request_context);
322 327
323 return io_thread_->globals()->system_request_context; 328 return io_thread_->globals()->system_request_context;
324 } 329 }
325 330
326 scoped_refptr<base::MessageLoopProxy> 331 scoped_refptr<base::MessageLoopProxy>
327 SystemURLRequestContextGetter::GetIOMessageLoopProxy() const { 332 SystemURLRequestContextGetter::GetIOMessageLoopProxy() const {
328 return io_message_loop_proxy_; 333 return io_message_loop_proxy_;
329 } 334 }
330 335
331 // The IOThread object must outlive any tasks posted to the IO thread before the
332 // Quit task.
333 DISABLE_RUNNABLE_METHOD_REFCOUNT(IOThread);
334
335 IOThread::Globals::Globals() {} 336 IOThread::Globals::Globals() {}
336 337
337 IOThread::Globals::~Globals() {} 338 IOThread::Globals::~Globals() {}
338 339
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 : content::BrowserProcessSubThread(BrowserThread::IO),
350 net_log_(net_log), 351 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(weak_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);
361 negotiate_enable_port_ = local_state->GetBoolean( 362 negotiate_enable_port_ = local_state->GetBoolean(
362 prefs::kEnableAuthNegotiatePort); 363 prefs::kEnableAuthNegotiatePort);
363 auth_server_whitelist_ = local_state->GetString(prefs::kAuthServerWhitelist); 364 auth_server_whitelist_ = local_state->GetString(prefs::kAuthServerWhitelist);
364 auth_delegate_whitelist_ = local_state->GetString( 365 auth_delegate_whitelist_ = local_state->GetString(
365 prefs::kAuthNegotiateDelegateWhitelist); 366 prefs::kAuthNegotiateDelegateWhitelist);
366 gssapi_library_name_ = local_state->GetString(prefs::kGSSAPILibraryName); 367 gssapi_library_name_ = local_state->GetString(prefs::kGSSAPILibraryName);
367 pref_proxy_config_tracker_.reset( 368 pref_proxy_config_tracker_.reset(
368 ProxyServiceFactory::CreatePrefProxyConfigTracker(local_state)); 369 ProxyServiceFactory::CreatePrefProxyConfigTracker(local_state));
369 ChromeNetworkDelegate::InitializeReferrersEnabled(&system_enable_referrers_, 370 ChromeNetworkDelegate::InitializeReferrersEnabled(&system_enable_referrers_,
370 local_state); 371 local_state);
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,
James Hawkins 2011/11/20 20:23:55 You could save a line by shifting this: PostTask(
dcheng 2011/11/20 23:09:24 Done.
374 method_factory_.NewRunnableMethod( 375 base::Bind(
375 &IOThread::InitSystemRequestContext)); 376 &IOThread::InitSystemRequestContext,
377 weak_factory_.GetWeakPtr()));
376 } 378 }
377 379
378 IOThread::~IOThread() { 380 IOThread::~IOThread() {
379 if (pref_proxy_config_tracker_.get()) 381 if (pref_proxy_config_tracker_.get())
380 pref_proxy_config_tracker_->DetachFromPrefService(); 382 pref_proxy_config_tracker_->DetachFromPrefService();
381 // We cannot rely on our base class to stop the thread since we want our 383 // We cannot rely on our base class to stop the thread since we want our
382 // CleanUp function to run. 384 // CleanUp function to run.
383 Stop(); 385 Stop();
384 DCHECK(!globals_); 386 DCHECK(!globals_);
385 } 387 }
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 ProxyServiceFactory::CreateProxyConfigService(); 589 ProxyServiceFactory::CreateProxyConfigService();
588 system_proxy_config_service_.reset(proxy_config_service); 590 system_proxy_config_service_.reset(proxy_config_service);
589 if (pref_proxy_config_tracker_.get()) { 591 if (pref_proxy_config_tracker_.get()) {
590 pref_proxy_config_tracker_->SetChromeProxyConfigService( 592 pref_proxy_config_tracker_->SetChromeProxyConfigService(
591 proxy_config_service); 593 proxy_config_service);
592 } 594 }
593 system_url_request_context_getter_ = 595 system_url_request_context_getter_ =
594 new SystemURLRequestContextGetter(this); 596 new SystemURLRequestContextGetter(this);
595 message_loop()->PostTask( 597 message_loop()->PostTask(
596 FROM_HERE, 598 FROM_HERE,
597 NewRunnableMethod( 599 base::Bind(
598 this, 600 &IOThread::InitSystemRequestContextOnIOThread,
James Hawkins 2011/11/20 20:23:55 Can this not fit on the line above?
dcheng 2011/11/20 23:09:24 Done. Not quite, but I rearranged it a bit to fit
599 &IOThread::InitSystemRequestContextOnIOThread)); 601 base::Unretained(this)));
600 } 602 }
601 603
602 void IOThread::InitSystemRequestContextOnIOThread() { 604 void IOThread::InitSystemRequestContextOnIOThread() {
603 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 605 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
604 DCHECK(!globals_->system_proxy_service.get()); 606 DCHECK(!globals_->system_proxy_service.get());
605 DCHECK(system_proxy_config_service_.get()); 607 DCHECK(system_proxy_config_service_.get());
606 608
607 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 609 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
608 globals_->system_proxy_service.reset( 610 globals_->system_proxy_service.reset(
609 ProxyServiceFactory::CreateProxyService( 611 ProxyServiceFactory::CreateProxyService(
(...skipping 17 matching lines...) Expand all
627 system_params.network_delegate = globals_->system_network_delegate.get(); 629 system_params.network_delegate = globals_->system_network_delegate.get();
628 system_params.net_log = net_log_; 630 system_params.net_log = net_log_;
629 globals_->system_http_transaction_factory.reset( 631 globals_->system_http_transaction_factory.reset(
630 new net::HttpNetworkLayer( 632 new net::HttpNetworkLayer(
631 new net::HttpNetworkSession(system_params))); 633 new net::HttpNetworkSession(system_params)));
632 globals_->system_ftp_transaction_factory.reset( 634 globals_->system_ftp_transaction_factory.reset(
633 new net::FtpNetworkLayer(globals_->host_resolver.get())); 635 new net::FtpNetworkLayer(globals_->host_resolver.get()));
634 globals_->system_request_context = 636 globals_->system_request_context =
635 ConstructSystemRequestContext(globals_, net_log_); 637 ConstructSystemRequestContext(globals_, net_log_);
636 } 638 }
OLDNEW
« no previous file with comments | « chrome/browser/io_thread.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698