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/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 Loading... |
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 Loading... |
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( |
374 method_factory_.NewRunnableMethod( | 375 FROM_HERE, base::Bind(&IOThread::InitSystemRequestContext, |
375 &IOThread::InitSystemRequestContext)); | 376 weak_factory_.GetWeakPtr())); |
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 // We cannot rely on our base class to stop the thread since we want our |
382 // CleanUp function to run. | 383 // CleanUp function to run. |
383 Stop(); | 384 Stop(); |
384 DCHECK(!globals_); | 385 DCHECK(!globals_); |
385 } | 386 } |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 ChromeProxyConfigService* proxy_config_service = | 587 ChromeProxyConfigService* proxy_config_service = |
587 ProxyServiceFactory::CreateProxyConfigService(); | 588 ProxyServiceFactory::CreateProxyConfigService(); |
588 system_proxy_config_service_.reset(proxy_config_service); | 589 system_proxy_config_service_.reset(proxy_config_service); |
589 if (pref_proxy_config_tracker_.get()) { | 590 if (pref_proxy_config_tracker_.get()) { |
590 pref_proxy_config_tracker_->SetChromeProxyConfigService( | 591 pref_proxy_config_tracker_->SetChromeProxyConfigService( |
591 proxy_config_service); | 592 proxy_config_service); |
592 } | 593 } |
593 system_url_request_context_getter_ = | 594 system_url_request_context_getter_ = |
594 new SystemURLRequestContextGetter(this); | 595 new SystemURLRequestContextGetter(this); |
595 message_loop()->PostTask( | 596 message_loop()->PostTask( |
596 FROM_HERE, | 597 FROM_HERE, base::Bind(&IOThread::InitSystemRequestContextOnIOThread, |
597 NewRunnableMethod( | 598 base::Unretained(this))); |
598 this, | |
599 &IOThread::InitSystemRequestContextOnIOThread)); | |
600 } | 599 } |
601 | 600 |
602 void IOThread::InitSystemRequestContextOnIOThread() { | 601 void IOThread::InitSystemRequestContextOnIOThread() { |
603 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 602 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
604 DCHECK(!globals_->system_proxy_service.get()); | 603 DCHECK(!globals_->system_proxy_service.get()); |
605 DCHECK(system_proxy_config_service_.get()); | 604 DCHECK(system_proxy_config_service_.get()); |
606 | 605 |
607 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 606 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
608 globals_->system_proxy_service.reset( | 607 globals_->system_proxy_service.reset( |
609 ProxyServiceFactory::CreateProxyService( | 608 ProxyServiceFactory::CreateProxyService( |
(...skipping 17 matching lines...) Expand all Loading... |
627 system_params.network_delegate = globals_->system_network_delegate.get(); | 626 system_params.network_delegate = globals_->system_network_delegate.get(); |
628 system_params.net_log = net_log_; | 627 system_params.net_log = net_log_; |
629 globals_->system_http_transaction_factory.reset( | 628 globals_->system_http_transaction_factory.reset( |
630 new net::HttpNetworkLayer( | 629 new net::HttpNetworkLayer( |
631 new net::HttpNetworkSession(system_params))); | 630 new net::HttpNetworkSession(system_params))); |
632 globals_->system_ftp_transaction_factory.reset( | 631 globals_->system_ftp_transaction_factory.reset( |
633 new net::FtpNetworkLayer(globals_->host_resolver.get())); | 632 new net::FtpNetworkLayer(globals_->host_resolver.get())); |
634 globals_->system_request_context = | 633 globals_->system_request_context = |
635 ConstructSystemRequestContext(globals_, net_log_); | 634 ConstructSystemRequestContext(globals_, net_log_); |
636 } | 635 } |
OLD | NEW |