Chromium Code Reviews| Index: ios/components/io_thread/io_thread.mm |
| diff --git a/ios/chrome/browser/ios_chrome_io_thread.mm b/ios/components/io_thread/io_thread.mm |
| similarity index 76% |
| copy from ios/chrome/browser/ios_chrome_io_thread.mm |
| copy to ios/components/io_thread/io_thread.mm |
| index 9508c6766973e378ad7091c575461713a3224c2b..b40c685a8a56eac8db5ffe0045dac5f8b80fa9d4 100644 |
| --- a/ios/chrome/browser/ios_chrome_io_thread.mm |
| +++ b/ios/components/io_thread/io_thread.mm |
| @@ -1,8 +1,8 @@ |
| -// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "ios/chrome/browser/ios_chrome_io_thread.h" |
| +#include "ios/components/io_thread/io_thread.h" |
| #include <stddef.h> |
| @@ -11,7 +11,6 @@ |
| #include "base/bind.h" |
| #include "base/bind_helpers.h" |
| -#include "base/command_line.h" |
| #include "base/compiler_specific.h" |
| #include "base/debug/leak_tracker.h" |
| #include "base/environment.h" |
| @@ -19,7 +18,6 @@ |
| #include "base/macros.h" |
| #include "base/memory/ptr_util.h" |
| #include "base/metrics/field_trial.h" |
| -#include "base/single_thread_task_runner.h" |
| #include "base/stl_util.h" |
| #include "base/strings/string_number_conversions.h" |
| #include "base/strings/string_split.h" |
| @@ -35,10 +33,6 @@ |
| #include "components/proxy_config/pref_proxy_config_tracker.h" |
| #include "components/variations/variations_associated_data.h" |
| #include "components/version_info/version_info.h" |
| -#include "ios/chrome/browser/chrome_switches.h" |
| -#include "ios/chrome/browser/net/cookie_util.h" |
| -#include "ios/chrome/browser/net/ios_chrome_network_delegate.h" |
| -#include "ios/chrome/common/channel_info.h" |
| #include "ios/web/public/user_agent.h" |
| #include "ios/web/public/web_client.h" |
| #include "ios/web/public/web_thread.h" |
| @@ -54,7 +48,6 @@ |
| #include "net/cookies/cookie_store.h" |
| #include "net/dns/host_cache.h" |
| #include "net/dns/host_resolver.h" |
| -#include "net/dns/mapped_host_resolver.h" |
| #include "net/http/http_auth_filter.h" |
| #include "net/http/http_auth_handler_factory.h" |
| #include "net/http/http_auth_preferences.h" |
| @@ -83,7 +76,7 @@ |
| #error "This file requires ARC support." |
| #endif |
| -// The IOSChromeIOThread object must outlive any tasks posted to the IO thread |
| +// The IOThread object must outlive any tasks posted to the IO thread |
| // before the Quit task, so base::Bind() calls are not refcounted. |
| namespace { |
| @@ -95,55 +88,31 @@ const char kSupportedAuthSchemes[] = "basic,digest,ntlm"; |
| // determined by the operating system. |
| const char kNetworkQualityEstimatorFieldTrialName[] = "NetworkQualityEstimator"; |
| +} // namespace |
| + |
| +namespace io_thread { |
| + |
| // Used for the "system" URLRequestContext. |
| class SystemURLRequestContext : public net::URLRequestContext { |
| public: |
| - SystemURLRequestContext() { |
| - } |
| + SystemURLRequestContext() = default; |
| private: |
| - ~SystemURLRequestContext() override { |
| - AssertNoURLRequests(); |
| - } |
| + ~SystemURLRequestContext() override { AssertNoURLRequests(); } |
| }; |
| std::unique_ptr<net::HostResolver> CreateGlobalHostResolver( |
| net::NetLog* net_log) { |
| - TRACE_EVENT0("startup", "IOSChromeIOThread::CreateGlobalHostResolver"); |
| - const base::CommandLine& command_line = |
| - *base::CommandLine::ForCurrentProcess(); |
| + TRACE_EVENT0("startup", "IOThread::CreateGlobalHostResolver"); |
| std::unique_ptr<net::HostResolver> global_host_resolver = |
| net::HostResolver::CreateSystemResolver(net::HostResolver::Options(), |
| net_log); |
| - // If hostname remappings were specified on the command-line, layer these |
| - // rules on top of the real host resolver. This allows forwarding all requests |
| - // through a designated test server. |
| - if (!command_line.HasSwitch(switches::kIOSHostResolverRules)) |
| - return global_host_resolver; |
| - |
| - std::unique_ptr<net::MappedHostResolver> remapped_resolver( |
| - new net::MappedHostResolver(std::move(global_host_resolver))); |
| - remapped_resolver->SetRulesFromString( |
| - command_line.GetSwitchValueASCII(switches::kIOSHostResolverRules)); |
| - // TODO(crbug.com/703565): remove std::move() once Xcode 9.0+ is required. |
| - return std::move(remapped_resolver); |
| + return global_host_resolver; |
| } |
| -int GetSwitchValueAsInt(const base::CommandLine& command_line, |
| - const std::string& switch_name) { |
| - int value; |
| - if (!base::StringToInt(command_line.GetSwitchValueASCII(switch_name), |
| - &value)) { |
| - return 0; |
| - } |
| - return value; |
| -} |
| - |
| -} // namespace |
| - |
| -class IOSChromeIOThread::LoggingNetworkChangeObserver |
| +class IOThread::LoggingNetworkChangeObserver |
| : public net::NetworkChangeNotifier::IPAddressObserver, |
| public net::NetworkChangeNotifier::ConnectionTypeObserver, |
| public net::NetworkChangeNotifier::NetworkChangeObserver { |
| @@ -204,7 +173,7 @@ class IOSChromeIOThread::LoggingNetworkChangeObserver |
| class SystemURLRequestContextGetter : public net::URLRequestContextGetter { |
| public: |
| - explicit SystemURLRequestContextGetter(IOSChromeIOThread* io_thread); |
| + explicit SystemURLRequestContextGetter(IOThread* io_thread); |
| // Implementation for net::UrlRequestContextGetter. |
| net::URLRequestContext* GetURLRequestContext() override; |
| @@ -218,14 +187,14 @@ class SystemURLRequestContextGetter : public net::URLRequestContextGetter { |
| ~SystemURLRequestContextGetter() override; |
| private: |
| - IOSChromeIOThread* io_thread_; // Weak pointer, owned by ApplicationContext. |
| + IOThread* io_thread_; // Weak pointer, owned by ApplicationContext. |
| scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
| base::debug::LeakTracker<SystemURLRequestContextGetter> leak_tracker_; |
| }; |
| SystemURLRequestContextGetter::SystemURLRequestContextGetter( |
| - IOSChromeIOThread* io_thread) |
| + IOThread* io_thread) |
| : io_thread_(io_thread), |
| network_task_runner_( |
| web::WebThread::GetTaskRunnerForThread(web::WebThread::IO)) {} |
| @@ -252,27 +221,25 @@ void SystemURLRequestContextGetter::Shutdown() { |
| NotifyContextShuttingDown(); |
| } |
| -IOSChromeIOThread::Globals::SystemRequestContextLeakChecker:: |
| +IOThread::Globals::SystemRequestContextLeakChecker:: |
| SystemRequestContextLeakChecker(Globals* globals) |
| : globals_(globals) { |
| DCHECK(globals_); |
| } |
| -IOSChromeIOThread::Globals::SystemRequestContextLeakChecker:: |
| +IOThread::Globals::SystemRequestContextLeakChecker:: |
| ~SystemRequestContextLeakChecker() { |
| if (globals_->system_request_context.get()) |
| globals_->system_request_context->AssertNoURLRequests(); |
| } |
| -IOSChromeIOThread::Globals::Globals() |
| - : system_request_context_leak_checker(this) {} |
| +IOThread::Globals::Globals() : system_request_context_leak_checker(this) {} |
| -IOSChromeIOThread::Globals::~Globals() {} |
| +IOThread::Globals::~Globals() {} |
| // |local_state| is passed in explicitly in order to (1) reduce implicit |
| -// dependencies and (2) make IOSChromeIOThread more flexible for testing. |
| -IOSChromeIOThread::IOSChromeIOThread(PrefService* local_state, |
| - net_log::ChromeNetLog* net_log) |
| +// dependencies and (2) make IOThread more flexible for testing. |
| +IOThread::IOThread(PrefService* local_state, net_log::ChromeNetLog* net_log) |
| : net_log_(net_log), |
| globals_(nullptr), |
| creation_time_(base::TimeTicks::Now()), |
| @@ -280,7 +247,6 @@ IOSChromeIOThread::IOSChromeIOThread(PrefService* local_state, |
| pref_proxy_config_tracker_ = |
| ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState( |
| local_state); |
| - IOSChromeNetworkDelegate::InitializePrefsOnUIThread(nullptr, local_state); |
| ssl_config_service_manager_.reset( |
| ssl_config::SSLConfigServiceManager::CreateDefaultManager( |
| local_state, |
| @@ -289,8 +255,8 @@ IOSChromeIOThread::IOSChromeIOThread(PrefService* local_state, |
| web::WebThread::SetDelegate(web::WebThread::IO, this); |
| } |
| -IOSChromeIOThread::~IOSChromeIOThread() { |
| - // This isn't needed for production code, but in tests, IOSChromeIOThread may |
| +IOThread::~IOThread() { |
| + // This isn't needed for production code, but in tests, IOThread may |
| // be multiply constructed. |
| web::WebThread::SetDelegate(web::WebThread::IO, nullptr); |
| @@ -298,31 +264,29 @@ IOSChromeIOThread::~IOSChromeIOThread() { |
| DCHECK(!globals_); |
| } |
| -IOSChromeIOThread::Globals* IOSChromeIOThread::globals() { |
| +IOThread::Globals* IOThread::globals() { |
| DCHECK_CURRENTLY_ON(web::WebThread::IO); |
| return globals_; |
| } |
| -void IOSChromeIOThread::SetGlobalsForTesting(Globals* globals) { |
| +void IOThread::SetGlobalsForTesting(Globals* globals) { |
| DCHECK_CURRENTLY_ON(web::WebThread::IO); |
| DCHECK(!globals || !globals_); |
| globals_ = globals; |
| } |
| -net_log::ChromeNetLog* IOSChromeIOThread::net_log() { |
| +net_log::ChromeNetLog* IOThread::net_log() { |
| return net_log_; |
| } |
| -void IOSChromeIOThread::ChangedToOnTheRecord() { |
| +void IOThread::ChangedToOnTheRecord() { |
| DCHECK_CURRENTLY_ON(web::WebThread::UI); |
| - web::WebThread::PostTask( |
| - web::WebThread::IO, FROM_HERE, |
| - base::Bind(&IOSChromeIOThread::ChangedToOnTheRecordOnIOThread, |
| - base::Unretained(this))); |
| + web::WebThread::PostTask(web::WebThread::IO, FROM_HERE, |
| + base::Bind(&IOThread::ChangedToOnTheRecordOnIOThread, |
| + base::Unretained(this))); |
| } |
| -net::URLRequestContextGetter* |
| -IOSChromeIOThread::system_url_request_context_getter() { |
| +net::URLRequestContextGetter* IOThread::system_url_request_context_getter() { |
| DCHECK_CURRENTLY_ON(web::WebThread::UI); |
| if (!system_url_request_context_getter_.get()) { |
| InitSystemRequestContext(); |
| @@ -330,13 +294,10 @@ IOSChromeIOThread::system_url_request_context_getter() { |
| return system_url_request_context_getter_.get(); |
| } |
| -void IOSChromeIOThread::Init() { |
| - TRACE_EVENT0("startup", "IOSChromeIOThread::Init"); |
| +void IOThread::Init() { |
| + TRACE_EVENT0("startup", "IOThread::Init"); |
| DCHECK_CURRENTLY_ON(web::WebThread::IO); |
| - const base::CommandLine& command_line = |
| - *base::CommandLine::ForCurrentProcess(); |
| - |
| DCHECK(!globals_); |
| globals_ = new Globals; |
| @@ -348,10 +309,7 @@ void IOSChromeIOThread::Init() { |
| // Setup the HistogramWatcher to run on the IO thread. |
| net::NetworkChangeNotifier::InitHistogramWatcher(); |
| - std::unique_ptr<IOSChromeNetworkDelegate> chrome_network_delegate( |
| - new IOSChromeNetworkDelegate()); |
| - |
| - globals_->system_network_delegate = std::move(chrome_network_delegate); |
| + globals_->system_network_delegate = GetSystemNetworkDelegate(); |
| globals_->host_resolver = CreateGlobalHostResolver(net_log_); |
| std::map<std::string, std::string> network_quality_estimator_params; |
| @@ -392,19 +350,11 @@ void IOSChromeIOThread::Init() { |
| globals_->http_user_agent_settings.reset(new net::StaticHttpUserAgentSettings( |
| std::string(), |
| web::GetWebClient()->GetUserAgent(web::UserAgentType::MOBILE))); |
| - if (command_line.HasSwitch(switches::kIOSTestingFixedHttpPort)) { |
| - params_.testing_fixed_http_port = |
| - GetSwitchValueAsInt(command_line, switches::kIOSTestingFixedHttpPort); |
| - } |
| - if (command_line.HasSwitch(switches::kIOSTestingFixedHttpsPort)) { |
| - params_.testing_fixed_https_port = |
| - GetSwitchValueAsInt(command_line, switches::kIOSTestingFixedHttpsPort); |
| - } |
| params_.ignore_certificate_errors = false; |
| params_.enable_user_alternate_protocol_ports = false; |
| - std::string quic_user_agent_id = ::GetChannelString(); |
| + std::string quic_user_agent_id = GetChannelString(); |
| if (!quic_user_agent_id.empty()) |
| quic_user_agent_id.push_back(' '); |
| quic_user_agent_id.append( |
| @@ -423,16 +373,15 @@ void IOSChromeIOThread::Init() { |
| // Note that since we are at WebThread::Init time, the UI thread |
| // is blocked waiting for the thread to start. Therefore, posting |
| // this task to the main thread's message loop here is guaranteed to |
| - // get it onto the message loop while the IOSChromeIOThread object still |
| + // get it onto the message loop while the IOThread object still |
| // exists. However, the message might not be processed on the UI |
| - // thread until after IOSChromeIOThread is gone, so use a weak pointer. |
| - web::WebThread::PostTask( |
| - web::WebThread::UI, FROM_HERE, |
| - base::Bind(&IOSChromeIOThread::InitSystemRequestContext, |
| - weak_factory_.GetWeakPtr())); |
| + // thread until after IOThread is gone, so use a weak pointer. |
| + web::WebThread::PostTask(web::WebThread::UI, FROM_HERE, |
| + base::Bind(&IOThread::InitSystemRequestContext, |
| + weak_factory_.GetWeakPtr())); |
| } |
| -void IOSChromeIOThread::CleanUp() { |
| +void IOThread::CleanUp() { |
| system_url_request_context_getter_->Shutdown(); |
| system_url_request_context_getter_ = nullptr; |
| @@ -453,7 +402,7 @@ void IOSChromeIOThread::CleanUp() { |
| base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks(); |
| } |
| -void IOSChromeIOThread::CreateDefaultAuthHandlerFactory() { |
| +void IOThread::CreateDefaultAuthHandlerFactory() { |
| std::vector<std::string> supported_schemes = |
| base::SplitString(kSupportedAuthSchemes, ",", base::TRIM_WHITESPACE, |
| base::SPLIT_WANT_NONEMPTY); |
| @@ -464,7 +413,7 @@ void IOSChromeIOThread::CreateDefaultAuthHandlerFactory() { |
| globals_->http_auth_preferences.get(), globals_->host_resolver.get()); |
| } |
| -void IOSChromeIOThread::ClearHostCache() { |
| +void IOThread::ClearHostCache() { |
| DCHECK_CURRENTLY_ON(web::WebThread::IO); |
| net::HostCache* host_cache = globals_->host_resolver->GetHostCache(); |
| @@ -472,20 +421,23 @@ void IOSChromeIOThread::ClearHostCache() { |
| host_cache->clear(); |
| } |
| -const net::HttpNetworkSession::Params& IOSChromeIOThread::NetworkSessionParams() |
| - const { |
| +const net::HttpNetworkSession::Params& IOThread::NetworkSessionParams() const { |
| return params_; |
| } |
| -base::TimeTicks IOSChromeIOThread::creation_time() const { |
| +base::TimeTicks IOThread::creation_time() const { |
| return creation_time_; |
| } |
| -net::SSLConfigService* IOSChromeIOThread::GetSSLConfigService() { |
| +std::string IOThread::GetChannelString() { |
| + return std::string(); |
|
Eugene But (OOO till 7-30)
2017/05/25 22:05:22
Should we even have default implementation?
michaeldo
2017/05/26 07:24:43
Removed and made this method virtual.
|
| +} |
| + |
| +net::SSLConfigService* IOThread::GetSSLConfigService() { |
| return ssl_config_service_manager_->Get(); |
| } |
| -void IOSChromeIOThread::ChangedToOnTheRecordOnIOThread() { |
| +void IOThread::ChangedToOnTheRecordOnIOThread() { |
| DCHECK_CURRENTLY_ON(web::WebThread::IO); |
| // Clear the host cache to avoid showing entries from the OTR session |
| @@ -493,25 +445,25 @@ void IOSChromeIOThread::ChangedToOnTheRecordOnIOThread() { |
| ClearHostCache(); |
| } |
| -void IOSChromeIOThread::InitSystemRequestContext() { |
| +void IOThread::InitSystemRequestContext() { |
| if (system_url_request_context_getter_.get()) |
| return; |
| - // If we're in unit_tests, IOSChromeIOThread may not be run. |
| + // If we're in unit_tests, IOThread may not be run. |
| if (!web::WebThread::IsMessageLoopValid(web::WebThread::IO)) |
| return; |
| system_proxy_config_service_ = ProxyServiceFactory::CreateProxyConfigService( |
| pref_proxy_config_tracker_.get()); |
| system_url_request_context_getter_ = new SystemURLRequestContextGetter(this); |
| - // Safe to post an unretained this pointer, since IOSChromeIOThread is |
| + // Safe to post an unretained this pointer, since IOThread is |
| // guaranteed to outlive the IO WebThread. |
| web::WebThread::PostTask( |
| web::WebThread::IO, FROM_HERE, |
| - base::Bind(&IOSChromeIOThread::InitSystemRequestContextOnIOThread, |
| + base::Bind(&IOThread::InitSystemRequestContextOnIOThread, |
| base::Unretained(this))); |
| } |
| -void IOSChromeIOThread::InitSystemRequestContextOnIOThread() { |
| +void IOThread::InitSystemRequestContextOnIOThread() { |
| DCHECK_CURRENTLY_ON(web::WebThread::IO); |
| DCHECK(!globals_->system_proxy_service.get()); |
| DCHECK(system_proxy_config_service_.get()); |
| @@ -524,8 +476,8 @@ void IOSChromeIOThread::InitSystemRequestContextOnIOThread() { |
| ConstructSystemRequestContext(globals_, params_, net_log_)); |
| } |
| -net::URLRequestContext* IOSChromeIOThread::ConstructSystemRequestContext( |
| - IOSChromeIOThread::Globals* globals, |
| +net::URLRequestContext* IOThread::ConstructSystemRequestContext( |
| + IOThread::Globals* globals, |
| const net::HttpNetworkSession::Params& params, |
| net::NetLog* net_log) { |
| net::URLRequestContext* context = new SystemURLRequestContext; |
| @@ -575,3 +527,5 @@ net::URLRequestContext* IOSChromeIOThread::ConstructSystemRequestContext( |
| return context; |
| } |
| + |
| +} // namespace io_thread |