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

Unified Diff: ios/components/io_thread/ios_io_thread.mm

Issue 2908613002: Move common functionality of IOSChromeIOThread to ios/components. (Closed)
Patch Set: Respond to comments. Created 3 years, 7 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/components/io_thread/ios_io_thread.h ('k') | ios/components/io_thread/ios_io_thread_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/components/io_thread/ios_io_thread.mm
diff --git a/ios/chrome/browser/ios_chrome_io_thread.mm b/ios/components/io_thread/ios_io_thread.mm
similarity index 77%
copy from ios/chrome/browser/ios_chrome_io_thread.mm
copy to ios/components/io_thread/ios_io_thread.mm
index 9508c6766973e378ad7091c575461713a3224c2b..59b6047cc148b9ea9c8f2ca84ee08832d9d30370 100644
--- a/ios/chrome/browser/ios_chrome_io_thread.mm
+++ b/ios/components/io_thread/ios_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/ios_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,9 +76,11 @@
#error "This file requires ARC support."
#endif
-// The IOSChromeIOThread object must outlive any tasks posted to the IO thread
+// The IOSIOThread object must outlive any tasks posted to the IO thread
// before the Quit task, so base::Bind() calls are not refcounted.
+namespace io_thread {
+
namespace {
const char kSupportedAuthSchemes[] = "basic,digest,ntlm";
@@ -95,55 +90,29 @@ const char kSupportedAuthSchemes[] = "basic,digest,ntlm";
// determined by the operating system.
const char kNetworkQualityEstimatorFieldTrialName[] = "NetworkQualityEstimator";
+} // namespace
+
// 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", "IOSIOThread::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);
-}
-
-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;
+ return global_host_resolver;
}
-} // namespace
-
-class IOSChromeIOThread::LoggingNetworkChangeObserver
+class IOSIOThread::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(IOSIOThread* 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.
+ IOSIOThread* 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)
+ IOSIOThread* io_thread)
: io_thread_(io_thread),
network_task_runner_(
web::WebThread::GetTaskRunnerForThread(web::WebThread::IO)) {}
@@ -252,27 +221,26 @@ void SystemURLRequestContextGetter::Shutdown() {
NotifyContextShuttingDown();
}
-IOSChromeIOThread::Globals::SystemRequestContextLeakChecker::
+IOSIOThread::Globals::SystemRequestContextLeakChecker::
SystemRequestContextLeakChecker(Globals* globals)
: globals_(globals) {
DCHECK(globals_);
}
-IOSChromeIOThread::Globals::SystemRequestContextLeakChecker::
+IOSIOThread::Globals::SystemRequestContextLeakChecker::
~SystemRequestContextLeakChecker() {
if (globals_->system_request_context.get())
globals_->system_request_context->AssertNoURLRequests();
}
-IOSChromeIOThread::Globals::Globals()
- : system_request_context_leak_checker(this) {}
+IOSIOThread::Globals::Globals() : system_request_context_leak_checker(this) {}
-IOSChromeIOThread::Globals::~Globals() {}
+IOSIOThread::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 IOSIOThread more flexible for testing.
+IOSIOThread::IOSIOThread(PrefService* local_state,
+ net_log::ChromeNetLog* net_log)
: net_log_(net_log),
globals_(nullptr),
creation_time_(base::TimeTicks::Now()),
@@ -280,7 +248,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 +256,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
+IOSIOThread::~IOSIOThread() {
+ // This isn't needed for production code, but in tests, IOSIOThread may
// be multiply constructed.
web::WebThread::SetDelegate(web::WebThread::IO, nullptr);
@@ -298,31 +265,30 @@ IOSChromeIOThread::~IOSChromeIOThread() {
DCHECK(!globals_);
}
-IOSChromeIOThread::Globals* IOSChromeIOThread::globals() {
+IOSIOThread::Globals* IOSIOThread::globals() {
DCHECK_CURRENTLY_ON(web::WebThread::IO);
return globals_;
}
-void IOSChromeIOThread::SetGlobalsForTesting(Globals* globals) {
+void IOSIOThread::SetGlobalsForTesting(Globals* globals) {
DCHECK_CURRENTLY_ON(web::WebThread::IO);
DCHECK(!globals || !globals_);
globals_ = globals;
}
-net_log::ChromeNetLog* IOSChromeIOThread::net_log() {
+net_log::ChromeNetLog* IOSIOThread::net_log() {
return net_log_;
}
-void IOSChromeIOThread::ChangedToOnTheRecord() {
+void IOSIOThread::ChangedToOnTheRecord() {
DCHECK_CURRENTLY_ON(web::WebThread::UI);
web::WebThread::PostTask(
web::WebThread::IO, FROM_HERE,
- base::Bind(&IOSChromeIOThread::ChangedToOnTheRecordOnIOThread,
+ base::Bind(&IOSIOThread::ChangedToOnTheRecordOnIOThread,
base::Unretained(this)));
}
-net::URLRequestContextGetter*
-IOSChromeIOThread::system_url_request_context_getter() {
+net::URLRequestContextGetter* IOSIOThread::system_url_request_context_getter() {
DCHECK_CURRENTLY_ON(web::WebThread::UI);
if (!system_url_request_context_getter_.get()) {
InitSystemRequestContext();
@@ -330,13 +296,10 @@ IOSChromeIOThread::system_url_request_context_getter() {
return system_url_request_context_getter_.get();
}
-void IOSChromeIOThread::Init() {
- TRACE_EVENT0("startup", "IOSChromeIOThread::Init");
+void IOSIOThread::Init() {
+ TRACE_EVENT0("startup", "IOSIOThread::Init");
DCHECK_CURRENTLY_ON(web::WebThread::IO);
- const base::CommandLine& command_line =
- *base::CommandLine::ForCurrentProcess();
-
DCHECK(!globals_);
globals_ = new Globals;
@@ -348,10 +311,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 = CreateSystemNetworkDelegate();
globals_->host_resolver = CreateGlobalHostResolver(net_log_);
std::map<std::string, std::string> network_quality_estimator_params;
@@ -392,19 +352,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 +375,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 IOSIOThread 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 IOSIOThread is gone, so use a weak pointer.
+ web::WebThread::PostTask(web::WebThread::UI, FROM_HERE,
+ base::Bind(&IOSIOThread::InitSystemRequestContext,
+ weak_factory_.GetWeakPtr()));
}
-void IOSChromeIOThread::CleanUp() {
+void IOSIOThread::CleanUp() {
system_url_request_context_getter_->Shutdown();
system_url_request_context_getter_ = nullptr;
@@ -453,7 +404,7 @@ void IOSChromeIOThread::CleanUp() {
base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks();
}
-void IOSChromeIOThread::CreateDefaultAuthHandlerFactory() {
+void IOSIOThread::CreateDefaultAuthHandlerFactory() {
std::vector<std::string> supported_schemes =
base::SplitString(kSupportedAuthSchemes, ",", base::TRIM_WHITESPACE,
base::SPLIT_WANT_NONEMPTY);
@@ -464,7 +415,7 @@ void IOSChromeIOThread::CreateDefaultAuthHandlerFactory() {
globals_->http_auth_preferences.get(), globals_->host_resolver.get());
}
-void IOSChromeIOThread::ClearHostCache() {
+void IOSIOThread::ClearHostCache() {
DCHECK_CURRENTLY_ON(web::WebThread::IO);
net::HostCache* host_cache = globals_->host_resolver->GetHostCache();
@@ -472,20 +423,20 @@ void IOSChromeIOThread::ClearHostCache() {
host_cache->clear();
}
-const net::HttpNetworkSession::Params& IOSChromeIOThread::NetworkSessionParams()
+const net::HttpNetworkSession::Params& IOSIOThread::NetworkSessionParams()
const {
return params_;
}
-base::TimeTicks IOSChromeIOThread::creation_time() const {
+base::TimeTicks IOSIOThread::creation_time() const {
return creation_time_;
}
-net::SSLConfigService* IOSChromeIOThread::GetSSLConfigService() {
+net::SSLConfigService* IOSIOThread::GetSSLConfigService() {
return ssl_config_service_manager_->Get();
}
-void IOSChromeIOThread::ChangedToOnTheRecordOnIOThread() {
+void IOSIOThread::ChangedToOnTheRecordOnIOThread() {
DCHECK_CURRENTLY_ON(web::WebThread::IO);
// Clear the host cache to avoid showing entries from the OTR session
@@ -493,25 +444,25 @@ void IOSChromeIOThread::ChangedToOnTheRecordOnIOThread() {
ClearHostCache();
}
-void IOSChromeIOThread::InitSystemRequestContext() {
+void IOSIOThread::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, IOSIOThread 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 IOSIOThread is
// guaranteed to outlive the IO WebThread.
web::WebThread::PostTask(
web::WebThread::IO, FROM_HERE,
- base::Bind(&IOSChromeIOThread::InitSystemRequestContextOnIOThread,
+ base::Bind(&IOSIOThread::InitSystemRequestContextOnIOThread,
base::Unretained(this)));
}
-void IOSChromeIOThread::InitSystemRequestContextOnIOThread() {
+void IOSIOThread::InitSystemRequestContextOnIOThread() {
DCHECK_CURRENTLY_ON(web::WebThread::IO);
DCHECK(!globals_->system_proxy_service.get());
DCHECK(system_proxy_config_service_.get());
@@ -524,8 +475,8 @@ void IOSChromeIOThread::InitSystemRequestContextOnIOThread() {
ConstructSystemRequestContext(globals_, params_, net_log_));
}
-net::URLRequestContext* IOSChromeIOThread::ConstructSystemRequestContext(
- IOSChromeIOThread::Globals* globals,
+net::URLRequestContext* IOSIOThread::ConstructSystemRequestContext(
+ IOSIOThread::Globals* globals,
const net::HttpNetworkSession::Params& params,
net::NetLog* net_log) {
net::URLRequestContext* context = new SystemURLRequestContext;
@@ -575,3 +526,5 @@ net::URLRequestContext* IOSChromeIOThread::ConstructSystemRequestContext(
return context;
}
+
+} // namespace io_thread
« no previous file with comments | « ios/components/io_thread/ios_io_thread.h ('k') | ios/components/io_thread/ios_io_thread_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698