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

Side by Side 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, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "ios/chrome/browser/ios_chrome_io_thread.h" 5 #include "ios/components/io_thread/ios_io_thread.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/command_line.h"
15 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
16 #include "base/debug/leak_tracker.h" 15 #include "base/debug/leak_tracker.h"
17 #include "base/environment.h" 16 #include "base/environment.h"
18 #include "base/logging.h" 17 #include "base/logging.h"
19 #include "base/macros.h" 18 #include "base/macros.h"
20 #include "base/memory/ptr_util.h" 19 #include "base/memory/ptr_util.h"
21 #include "base/metrics/field_trial.h" 20 #include "base/metrics/field_trial.h"
22 #include "base/single_thread_task_runner.h"
23 #include "base/stl_util.h" 21 #include "base/stl_util.h"
24 #include "base/strings/string_number_conversions.h" 22 #include "base/strings/string_number_conversions.h"
25 #include "base/strings/string_split.h" 23 #include "base/strings/string_split.h"
26 #include "base/strings/string_util.h" 24 #include "base/strings/string_util.h"
27 #include "base/threading/sequenced_worker_pool.h" 25 #include "base/threading/sequenced_worker_pool.h"
28 #include "base/threading/thread.h" 26 #include "base/threading/thread.h"
29 #include "base/time/time.h" 27 #include "base/time/time.h"
30 #include "base/trace_event/trace_event.h" 28 #include "base/trace_event/trace_event.h"
31 #include "components/net_log/chrome_net_log.h" 29 #include "components/net_log/chrome_net_log.h"
32 #include "components/network_session_configurator/network_session_configurator.h " 30 #include "components/network_session_configurator/network_session_configurator.h "
33 #include "components/prefs/pref_service.h" 31 #include "components/prefs/pref_service.h"
34 #include "components/proxy_config/ios/proxy_service_factory.h" 32 #include "components/proxy_config/ios/proxy_service_factory.h"
35 #include "components/proxy_config/pref_proxy_config_tracker.h" 33 #include "components/proxy_config/pref_proxy_config_tracker.h"
36 #include "components/variations/variations_associated_data.h" 34 #include "components/variations/variations_associated_data.h"
37 #include "components/version_info/version_info.h" 35 #include "components/version_info/version_info.h"
38 #include "ios/chrome/browser/chrome_switches.h"
39 #include "ios/chrome/browser/net/cookie_util.h"
40 #include "ios/chrome/browser/net/ios_chrome_network_delegate.h"
41 #include "ios/chrome/common/channel_info.h"
42 #include "ios/web/public/user_agent.h" 36 #include "ios/web/public/user_agent.h"
43 #include "ios/web/public/web_client.h" 37 #include "ios/web/public/web_client.h"
44 #include "ios/web/public/web_thread.h" 38 #include "ios/web/public/web_thread.h"
45 #include "net/base/sdch_manager.h" 39 #include "net/base/sdch_manager.h"
46 #include "net/cert/cert_verifier.h" 40 #include "net/cert/cert_verifier.h"
47 #include "net/cert/ct_known_logs.h" 41 #include "net/cert/ct_known_logs.h"
48 #include "net/cert/ct_log_verifier.h" 42 #include "net/cert/ct_log_verifier.h"
49 #include "net/cert/ct_policy_enforcer.h" 43 #include "net/cert/ct_policy_enforcer.h"
50 #include "net/cert/ct_verifier.h" 44 #include "net/cert/ct_verifier.h"
51 #include "net/cert/multi_log_ct_verifier.h" 45 #include "net/cert/multi_log_ct_verifier.h"
52 #include "net/cert/multi_threaded_cert_verifier.h" 46 #include "net/cert/multi_threaded_cert_verifier.h"
53 #include "net/cookies/cookie_monster.h" 47 #include "net/cookies/cookie_monster.h"
54 #include "net/cookies/cookie_store.h" 48 #include "net/cookies/cookie_store.h"
55 #include "net/dns/host_cache.h" 49 #include "net/dns/host_cache.h"
56 #include "net/dns/host_resolver.h" 50 #include "net/dns/host_resolver.h"
57 #include "net/dns/mapped_host_resolver.h"
58 #include "net/http/http_auth_filter.h" 51 #include "net/http/http_auth_filter.h"
59 #include "net/http/http_auth_handler_factory.h" 52 #include "net/http/http_auth_handler_factory.h"
60 #include "net/http/http_auth_preferences.h" 53 #include "net/http/http_auth_preferences.h"
61 #include "net/http/http_network_layer.h" 54 #include "net/http/http_network_layer.h"
62 #include "net/http/http_server_properties_impl.h" 55 #include "net/http/http_server_properties_impl.h"
63 #include "net/log/net_log_event_type.h" 56 #include "net/log/net_log_event_type.h"
64 #include "net/nqe/external_estimate_provider.h" 57 #include "net/nqe/external_estimate_provider.h"
65 #include "net/nqe/network_quality_estimator.h" 58 #include "net/nqe/network_quality_estimator.h"
66 #include "net/proxy/proxy_config_service.h" 59 #include "net/proxy/proxy_config_service.h"
67 #include "net/proxy/proxy_script_fetcher_impl.h" 60 #include "net/proxy/proxy_script_fetcher_impl.h"
68 #include "net/proxy/proxy_service.h" 61 #include "net/proxy/proxy_service.h"
69 #include "net/socket/tcp_client_socket.h" 62 #include "net/socket/tcp_client_socket.h"
70 #include "net/spdy/chromium/spdy_session.h" 63 #include "net/spdy/chromium/spdy_session.h"
71 #include "net/ssl/channel_id_service.h" 64 #include "net/ssl/channel_id_service.h"
72 #include "net/ssl/default_channel_id_store.h" 65 #include "net/ssl/default_channel_id_store.h"
73 #include "net/url_request/data_protocol_handler.h" 66 #include "net/url_request/data_protocol_handler.h"
74 #include "net/url_request/file_protocol_handler.h" 67 #include "net/url_request/file_protocol_handler.h"
75 #include "net/url_request/static_http_user_agent_settings.h" 68 #include "net/url_request/static_http_user_agent_settings.h"
76 #include "net/url_request/url_request_context.h" 69 #include "net/url_request/url_request_context.h"
77 #include "net/url_request/url_request_context_builder.h" 70 #include "net/url_request/url_request_context_builder.h"
78 #include "net/url_request/url_request_context_getter.h" 71 #include "net/url_request/url_request_context_getter.h"
79 #include "net/url_request/url_request_job_factory_impl.h" 72 #include "net/url_request/url_request_job_factory_impl.h"
80 #include "url/url_constants.h" 73 #include "url/url_constants.h"
81 74
82 #if !defined(__has_feature) || !__has_feature(objc_arc) 75 #if !defined(__has_feature) || !__has_feature(objc_arc)
83 #error "This file requires ARC support." 76 #error "This file requires ARC support."
84 #endif 77 #endif
85 78
86 // The IOSChromeIOThread object must outlive any tasks posted to the IO thread 79 // The IOSIOThread object must outlive any tasks posted to the IO thread
87 // before the Quit task, so base::Bind() calls are not refcounted. 80 // before the Quit task, so base::Bind() calls are not refcounted.
88 81
82 namespace io_thread {
83
89 namespace { 84 namespace {
90 85
91 const char kSupportedAuthSchemes[] = "basic,digest,ntlm"; 86 const char kSupportedAuthSchemes[] = "basic,digest,ntlm";
92 87
93 // Field trial for network quality estimator. Seeds RTT and downstream 88 // Field trial for network quality estimator. Seeds RTT and downstream
94 // throughput observations with values that correspond to the connection type 89 // throughput observations with values that correspond to the connection type
95 // determined by the operating system. 90 // determined by the operating system.
96 const char kNetworkQualityEstimatorFieldTrialName[] = "NetworkQualityEstimator"; 91 const char kNetworkQualityEstimatorFieldTrialName[] = "NetworkQualityEstimator";
97 92
93 } // namespace
94
98 // Used for the "system" URLRequestContext. 95 // Used for the "system" URLRequestContext.
99 class SystemURLRequestContext : public net::URLRequestContext { 96 class SystemURLRequestContext : public net::URLRequestContext {
100 public: 97 public:
101 SystemURLRequestContext() { 98 SystemURLRequestContext() = default;
102 }
103 99
104 private: 100 private:
105 ~SystemURLRequestContext() override { 101 ~SystemURLRequestContext() override { AssertNoURLRequests(); }
106 AssertNoURLRequests();
107 }
108 }; 102 };
109 103
110 std::unique_ptr<net::HostResolver> CreateGlobalHostResolver( 104 std::unique_ptr<net::HostResolver> CreateGlobalHostResolver(
111 net::NetLog* net_log) { 105 net::NetLog* net_log) {
112 TRACE_EVENT0("startup", "IOSChromeIOThread::CreateGlobalHostResolver"); 106 TRACE_EVENT0("startup", "IOSIOThread::CreateGlobalHostResolver");
113 const base::CommandLine& command_line =
114 *base::CommandLine::ForCurrentProcess();
115 107
116 std::unique_ptr<net::HostResolver> global_host_resolver = 108 std::unique_ptr<net::HostResolver> global_host_resolver =
117 net::HostResolver::CreateSystemResolver(net::HostResolver::Options(), 109 net::HostResolver::CreateSystemResolver(net::HostResolver::Options(),
118 net_log); 110 net_log);
119 111
120 // If hostname remappings were specified on the command-line, layer these 112 return global_host_resolver;
121 // rules on top of the real host resolver. This allows forwarding all requests
122 // through a designated test server.
123 if (!command_line.HasSwitch(switches::kIOSHostResolverRules))
124 return global_host_resolver;
125
126 std::unique_ptr<net::MappedHostResolver> remapped_resolver(
127 new net::MappedHostResolver(std::move(global_host_resolver)));
128 remapped_resolver->SetRulesFromString(
129 command_line.GetSwitchValueASCII(switches::kIOSHostResolverRules));
130 // TODO(crbug.com/703565): remove std::move() once Xcode 9.0+ is required.
131 return std::move(remapped_resolver);
132 } 113 }
133 114
134 int GetSwitchValueAsInt(const base::CommandLine& command_line, 115 class IOSIOThread::LoggingNetworkChangeObserver
135 const std::string& switch_name) {
136 int value;
137 if (!base::StringToInt(command_line.GetSwitchValueASCII(switch_name),
138 &value)) {
139 return 0;
140 }
141 return value;
142 }
143
144 } // namespace
145
146 class IOSChromeIOThread::LoggingNetworkChangeObserver
147 : public net::NetworkChangeNotifier::IPAddressObserver, 116 : public net::NetworkChangeNotifier::IPAddressObserver,
148 public net::NetworkChangeNotifier::ConnectionTypeObserver, 117 public net::NetworkChangeNotifier::ConnectionTypeObserver,
149 public net::NetworkChangeNotifier::NetworkChangeObserver { 118 public net::NetworkChangeNotifier::NetworkChangeObserver {
150 public: 119 public:
151 // |net_log| must remain valid throughout our lifetime. 120 // |net_log| must remain valid throughout our lifetime.
152 explicit LoggingNetworkChangeObserver(net::NetLog* net_log) 121 explicit LoggingNetworkChangeObserver(net::NetLog* net_log)
153 : net_log_(net_log) { 122 : net_log_(net_log) {
154 net::NetworkChangeNotifier::AddIPAddressObserver(this); 123 net::NetworkChangeNotifier::AddIPAddressObserver(this);
155 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); 124 net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
156 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); 125 net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 net::NetLog::StringCallback("new_connection_type", &type_as_string)); 166 net::NetLog::StringCallback("new_connection_type", &type_as_string));
198 } 167 }
199 168
200 private: 169 private:
201 net::NetLog* net_log_; 170 net::NetLog* net_log_;
202 DISALLOW_COPY_AND_ASSIGN(LoggingNetworkChangeObserver); 171 DISALLOW_COPY_AND_ASSIGN(LoggingNetworkChangeObserver);
203 }; 172 };
204 173
205 class SystemURLRequestContextGetter : public net::URLRequestContextGetter { 174 class SystemURLRequestContextGetter : public net::URLRequestContextGetter {
206 public: 175 public:
207 explicit SystemURLRequestContextGetter(IOSChromeIOThread* io_thread); 176 explicit SystemURLRequestContextGetter(IOSIOThread* io_thread);
208 177
209 // Implementation for net::UrlRequestContextGetter. 178 // Implementation for net::UrlRequestContextGetter.
210 net::URLRequestContext* GetURLRequestContext() override; 179 net::URLRequestContext* GetURLRequestContext() override;
211 scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() 180 scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner()
212 const override; 181 const override;
213 182
214 // Tells the getter that the URLRequestContext is about to be shut down. 183 // Tells the getter that the URLRequestContext is about to be shut down.
215 void Shutdown(); 184 void Shutdown();
216 185
217 protected: 186 protected:
218 ~SystemURLRequestContextGetter() override; 187 ~SystemURLRequestContextGetter() override;
219 188
220 private: 189 private:
221 IOSChromeIOThread* io_thread_; // Weak pointer, owned by ApplicationContext. 190 IOSIOThread* io_thread_; // Weak pointer, owned by ApplicationContext.
222 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; 191 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
223 192
224 base::debug::LeakTracker<SystemURLRequestContextGetter> leak_tracker_; 193 base::debug::LeakTracker<SystemURLRequestContextGetter> leak_tracker_;
225 }; 194 };
226 195
227 SystemURLRequestContextGetter::SystemURLRequestContextGetter( 196 SystemURLRequestContextGetter::SystemURLRequestContextGetter(
228 IOSChromeIOThread* io_thread) 197 IOSIOThread* io_thread)
229 : io_thread_(io_thread), 198 : io_thread_(io_thread),
230 network_task_runner_( 199 network_task_runner_(
231 web::WebThread::GetTaskRunnerForThread(web::WebThread::IO)) {} 200 web::WebThread::GetTaskRunnerForThread(web::WebThread::IO)) {}
232 201
233 SystemURLRequestContextGetter::~SystemURLRequestContextGetter() {} 202 SystemURLRequestContextGetter::~SystemURLRequestContextGetter() {}
234 203
235 net::URLRequestContext* SystemURLRequestContextGetter::GetURLRequestContext() { 204 net::URLRequestContext* SystemURLRequestContextGetter::GetURLRequestContext() {
236 DCHECK_CURRENTLY_ON(web::WebThread::IO); 205 DCHECK_CURRENTLY_ON(web::WebThread::IO);
237 if (!io_thread_) 206 if (!io_thread_)
238 return nullptr; 207 return nullptr;
239 DCHECK(io_thread_->globals()->system_request_context.get()); 208 DCHECK(io_thread_->globals()->system_request_context.get());
240 209
241 return io_thread_->globals()->system_request_context.get(); 210 return io_thread_->globals()->system_request_context.get();
242 } 211 }
243 212
244 scoped_refptr<base::SingleThreadTaskRunner> 213 scoped_refptr<base::SingleThreadTaskRunner>
245 SystemURLRequestContextGetter::GetNetworkTaskRunner() const { 214 SystemURLRequestContextGetter::GetNetworkTaskRunner() const {
246 return network_task_runner_; 215 return network_task_runner_;
247 } 216 }
248 217
249 void SystemURLRequestContextGetter::Shutdown() { 218 void SystemURLRequestContextGetter::Shutdown() {
250 DCHECK_CURRENTLY_ON(web::WebThread::IO); 219 DCHECK_CURRENTLY_ON(web::WebThread::IO);
251 io_thread_ = nullptr; 220 io_thread_ = nullptr;
252 NotifyContextShuttingDown(); 221 NotifyContextShuttingDown();
253 } 222 }
254 223
255 IOSChromeIOThread::Globals::SystemRequestContextLeakChecker:: 224 IOSIOThread::Globals::SystemRequestContextLeakChecker::
256 SystemRequestContextLeakChecker(Globals* globals) 225 SystemRequestContextLeakChecker(Globals* globals)
257 : globals_(globals) { 226 : globals_(globals) {
258 DCHECK(globals_); 227 DCHECK(globals_);
259 } 228 }
260 229
261 IOSChromeIOThread::Globals::SystemRequestContextLeakChecker:: 230 IOSIOThread::Globals::SystemRequestContextLeakChecker::
262 ~SystemRequestContextLeakChecker() { 231 ~SystemRequestContextLeakChecker() {
263 if (globals_->system_request_context.get()) 232 if (globals_->system_request_context.get())
264 globals_->system_request_context->AssertNoURLRequests(); 233 globals_->system_request_context->AssertNoURLRequests();
265 } 234 }
266 235
267 IOSChromeIOThread::Globals::Globals() 236 IOSIOThread::Globals::Globals() : system_request_context_leak_checker(this) {}
268 : system_request_context_leak_checker(this) {}
269 237
270 IOSChromeIOThread::Globals::~Globals() {} 238 IOSIOThread::Globals::~Globals() {}
271 239
272 // |local_state| is passed in explicitly in order to (1) reduce implicit 240 // |local_state| is passed in explicitly in order to (1) reduce implicit
273 // dependencies and (2) make IOSChromeIOThread more flexible for testing. 241 // dependencies and (2) make IOSIOThread more flexible for testing.
274 IOSChromeIOThread::IOSChromeIOThread(PrefService* local_state, 242 IOSIOThread::IOSIOThread(PrefService* local_state,
275 net_log::ChromeNetLog* net_log) 243 net_log::ChromeNetLog* net_log)
276 : net_log_(net_log), 244 : net_log_(net_log),
277 globals_(nullptr), 245 globals_(nullptr),
278 creation_time_(base::TimeTicks::Now()), 246 creation_time_(base::TimeTicks::Now()),
279 weak_factory_(this) { 247 weak_factory_(this) {
280 pref_proxy_config_tracker_ = 248 pref_proxy_config_tracker_ =
281 ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState( 249 ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState(
282 local_state); 250 local_state);
283 IOSChromeNetworkDelegate::InitializePrefsOnUIThread(nullptr, local_state);
284 ssl_config_service_manager_.reset( 251 ssl_config_service_manager_.reset(
285 ssl_config::SSLConfigServiceManager::CreateDefaultManager( 252 ssl_config::SSLConfigServiceManager::CreateDefaultManager(
286 local_state, 253 local_state,
287 web::WebThread::GetTaskRunnerForThread(web::WebThread::IO))); 254 web::WebThread::GetTaskRunnerForThread(web::WebThread::IO)));
288 255
289 web::WebThread::SetDelegate(web::WebThread::IO, this); 256 web::WebThread::SetDelegate(web::WebThread::IO, this);
290 } 257 }
291 258
292 IOSChromeIOThread::~IOSChromeIOThread() { 259 IOSIOThread::~IOSIOThread() {
293 // This isn't needed for production code, but in tests, IOSChromeIOThread may 260 // This isn't needed for production code, but in tests, IOSIOThread may
294 // be multiply constructed. 261 // be multiply constructed.
295 web::WebThread::SetDelegate(web::WebThread::IO, nullptr); 262 web::WebThread::SetDelegate(web::WebThread::IO, nullptr);
296 263
297 pref_proxy_config_tracker_->DetachFromPrefService(); 264 pref_proxy_config_tracker_->DetachFromPrefService();
298 DCHECK(!globals_); 265 DCHECK(!globals_);
299 } 266 }
300 267
301 IOSChromeIOThread::Globals* IOSChromeIOThread::globals() { 268 IOSIOThread::Globals* IOSIOThread::globals() {
302 DCHECK_CURRENTLY_ON(web::WebThread::IO); 269 DCHECK_CURRENTLY_ON(web::WebThread::IO);
303 return globals_; 270 return globals_;
304 } 271 }
305 272
306 void IOSChromeIOThread::SetGlobalsForTesting(Globals* globals) { 273 void IOSIOThread::SetGlobalsForTesting(Globals* globals) {
307 DCHECK_CURRENTLY_ON(web::WebThread::IO); 274 DCHECK_CURRENTLY_ON(web::WebThread::IO);
308 DCHECK(!globals || !globals_); 275 DCHECK(!globals || !globals_);
309 globals_ = globals; 276 globals_ = globals;
310 } 277 }
311 278
312 net_log::ChromeNetLog* IOSChromeIOThread::net_log() { 279 net_log::ChromeNetLog* IOSIOThread::net_log() {
313 return net_log_; 280 return net_log_;
314 } 281 }
315 282
316 void IOSChromeIOThread::ChangedToOnTheRecord() { 283 void IOSIOThread::ChangedToOnTheRecord() {
317 DCHECK_CURRENTLY_ON(web::WebThread::UI); 284 DCHECK_CURRENTLY_ON(web::WebThread::UI);
318 web::WebThread::PostTask( 285 web::WebThread::PostTask(
319 web::WebThread::IO, FROM_HERE, 286 web::WebThread::IO, FROM_HERE,
320 base::Bind(&IOSChromeIOThread::ChangedToOnTheRecordOnIOThread, 287 base::Bind(&IOSIOThread::ChangedToOnTheRecordOnIOThread,
321 base::Unretained(this))); 288 base::Unretained(this)));
322 } 289 }
323 290
324 net::URLRequestContextGetter* 291 net::URLRequestContextGetter* IOSIOThread::system_url_request_context_getter() {
325 IOSChromeIOThread::system_url_request_context_getter() {
326 DCHECK_CURRENTLY_ON(web::WebThread::UI); 292 DCHECK_CURRENTLY_ON(web::WebThread::UI);
327 if (!system_url_request_context_getter_.get()) { 293 if (!system_url_request_context_getter_.get()) {
328 InitSystemRequestContext(); 294 InitSystemRequestContext();
329 } 295 }
330 return system_url_request_context_getter_.get(); 296 return system_url_request_context_getter_.get();
331 } 297 }
332 298
333 void IOSChromeIOThread::Init() { 299 void IOSIOThread::Init() {
334 TRACE_EVENT0("startup", "IOSChromeIOThread::Init"); 300 TRACE_EVENT0("startup", "IOSIOThread::Init");
335 DCHECK_CURRENTLY_ON(web::WebThread::IO); 301 DCHECK_CURRENTLY_ON(web::WebThread::IO);
336 302
337 const base::CommandLine& command_line =
338 *base::CommandLine::ForCurrentProcess();
339
340 DCHECK(!globals_); 303 DCHECK(!globals_);
341 globals_ = new Globals; 304 globals_ = new Globals;
342 305
343 // Add an observer that will emit network change events to the ChromeNetLog. 306 // Add an observer that will emit network change events to the ChromeNetLog.
344 // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be 307 // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be
345 // logging the network change before other IO thread consumers respond to it. 308 // logging the network change before other IO thread consumers respond to it.
346 network_change_observer_.reset(new LoggingNetworkChangeObserver(net_log_)); 309 network_change_observer_.reset(new LoggingNetworkChangeObserver(net_log_));
347 310
348 // Setup the HistogramWatcher to run on the IO thread. 311 // Setup the HistogramWatcher to run on the IO thread.
349 net::NetworkChangeNotifier::InitHistogramWatcher(); 312 net::NetworkChangeNotifier::InitHistogramWatcher();
350 313
351 std::unique_ptr<IOSChromeNetworkDelegate> chrome_network_delegate( 314 globals_->system_network_delegate = CreateSystemNetworkDelegate();
352 new IOSChromeNetworkDelegate());
353
354 globals_->system_network_delegate = std::move(chrome_network_delegate);
355 globals_->host_resolver = CreateGlobalHostResolver(net_log_); 315 globals_->host_resolver = CreateGlobalHostResolver(net_log_);
356 316
357 std::map<std::string, std::string> network_quality_estimator_params; 317 std::map<std::string, std::string> network_quality_estimator_params;
358 variations::GetVariationParams(kNetworkQualityEstimatorFieldTrialName, 318 variations::GetVariationParams(kNetworkQualityEstimatorFieldTrialName,
359 &network_quality_estimator_params); 319 &network_quality_estimator_params);
360 320
361 std::unique_ptr<net::ExternalEstimateProvider> external_estimate_provider; 321 std::unique_ptr<net::ExternalEstimateProvider> external_estimate_provider;
362 // Pass ownership. 322 // Pass ownership.
363 globals_->network_quality_estimator.reset(new net::NetworkQualityEstimator( 323 globals_->network_quality_estimator.reset(new net::NetworkQualityEstimator(
364 std::move(external_estimate_provider), network_quality_estimator_params, 324 std::move(external_estimate_provider), network_quality_estimator_params,
(...skipping 20 matching lines...) Expand all
385 // In-memory cookie store. 345 // In-memory cookie store.
386 globals_->system_cookie_store.reset(new net::CookieMonster(nullptr, nullptr)); 346 globals_->system_cookie_store.reset(new net::CookieMonster(nullptr, nullptr));
387 // In-memory channel ID store. 347 // In-memory channel ID store.
388 globals_->system_channel_id_service.reset( 348 globals_->system_channel_id_service.reset(
389 new net::ChannelIDService(new net::DefaultChannelIDStore(nullptr))); 349 new net::ChannelIDService(new net::DefaultChannelIDStore(nullptr)));
390 globals_->system_cookie_store->SetChannelIDServiceID( 350 globals_->system_cookie_store->SetChannelIDServiceID(
391 globals_->system_channel_id_service->GetUniqueID()); 351 globals_->system_channel_id_service->GetUniqueID());
392 globals_->http_user_agent_settings.reset(new net::StaticHttpUserAgentSettings( 352 globals_->http_user_agent_settings.reset(new net::StaticHttpUserAgentSettings(
393 std::string(), 353 std::string(),
394 web::GetWebClient()->GetUserAgent(web::UserAgentType::MOBILE))); 354 web::GetWebClient()->GetUserAgent(web::UserAgentType::MOBILE)));
395 if (command_line.HasSwitch(switches::kIOSTestingFixedHttpPort)) {
396 params_.testing_fixed_http_port =
397 GetSwitchValueAsInt(command_line, switches::kIOSTestingFixedHttpPort);
398 }
399 if (command_line.HasSwitch(switches::kIOSTestingFixedHttpsPort)) {
400 params_.testing_fixed_https_port =
401 GetSwitchValueAsInt(command_line, switches::kIOSTestingFixedHttpsPort);
402 }
403 355
404 params_.ignore_certificate_errors = false; 356 params_.ignore_certificate_errors = false;
405 params_.enable_user_alternate_protocol_ports = false; 357 params_.enable_user_alternate_protocol_ports = false;
406 358
407 std::string quic_user_agent_id = ::GetChannelString(); 359 std::string quic_user_agent_id = GetChannelString();
408 if (!quic_user_agent_id.empty()) 360 if (!quic_user_agent_id.empty())
409 quic_user_agent_id.push_back(' '); 361 quic_user_agent_id.push_back(' ');
410 quic_user_agent_id.append( 362 quic_user_agent_id.append(
411 version_info::GetProductNameAndVersionForUserAgent()); 363 version_info::GetProductNameAndVersionForUserAgent());
412 quic_user_agent_id.push_back(' '); 364 quic_user_agent_id.push_back(' ');
413 quic_user_agent_id.append(web::BuildOSCpuInfo()); 365 quic_user_agent_id.append(web::BuildOSCpuInfo());
414 366
415 network_session_configurator::ParseFieldTrials( 367 network_session_configurator::ParseFieldTrials(
416 /*is_quic_force_disabled=*/false, 368 /*is_quic_force_disabled=*/false,
417 /*is_quic_force_enabled=*/false, quic_user_agent_id, &params_); 369 /*is_quic_force_enabled=*/false, quic_user_agent_id, &params_);
418 370
419 // InitSystemRequestContext turns right around and posts a task back 371 // InitSystemRequestContext turns right around and posts a task back
420 // to the IO thread, so we can't let it run until we know the IO 372 // to the IO thread, so we can't let it run until we know the IO
421 // thread has started. 373 // thread has started.
422 // 374 //
423 // Note that since we are at WebThread::Init time, the UI thread 375 // Note that since we are at WebThread::Init time, the UI thread
424 // is blocked waiting for the thread to start. Therefore, posting 376 // is blocked waiting for the thread to start. Therefore, posting
425 // this task to the main thread's message loop here is guaranteed to 377 // this task to the main thread's message loop here is guaranteed to
426 // get it onto the message loop while the IOSChromeIOThread object still 378 // get it onto the message loop while the IOSIOThread object still
427 // exists. However, the message might not be processed on the UI 379 // exists. However, the message might not be processed on the UI
428 // thread until after IOSChromeIOThread is gone, so use a weak pointer. 380 // thread until after IOSIOThread is gone, so use a weak pointer.
429 web::WebThread::PostTask( 381 web::WebThread::PostTask(web::WebThread::UI, FROM_HERE,
430 web::WebThread::UI, FROM_HERE, 382 base::Bind(&IOSIOThread::InitSystemRequestContext,
431 base::Bind(&IOSChromeIOThread::InitSystemRequestContext, 383 weak_factory_.GetWeakPtr()));
432 weak_factory_.GetWeakPtr()));
433 } 384 }
434 385
435 void IOSChromeIOThread::CleanUp() { 386 void IOSIOThread::CleanUp() {
436 system_url_request_context_getter_->Shutdown(); 387 system_url_request_context_getter_->Shutdown();
437 system_url_request_context_getter_ = nullptr; 388 system_url_request_context_getter_ = nullptr;
438 389
439 // Release objects that the net::URLRequestContext could have been pointing 390 // Release objects that the net::URLRequestContext could have been pointing
440 // to. 391 // to.
441 392
442 // Shutdown the HistogramWatcher on the IO thread. 393 // Shutdown the HistogramWatcher on the IO thread.
443 net::NetworkChangeNotifier::ShutdownHistogramWatcher(); 394 net::NetworkChangeNotifier::ShutdownHistogramWatcher();
444 395
445 // This must be reset before the ChromeNetLog is destroyed. 396 // This must be reset before the ChromeNetLog is destroyed.
446 network_change_observer_.reset(); 397 network_change_observer_.reset();
447 398
448 system_proxy_config_service_.reset(); 399 system_proxy_config_service_.reset();
449 400
450 delete globals_; 401 delete globals_;
451 globals_ = nullptr; 402 globals_ = nullptr;
452 403
453 base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks(); 404 base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks();
454 } 405 }
455 406
456 void IOSChromeIOThread::CreateDefaultAuthHandlerFactory() { 407 void IOSIOThread::CreateDefaultAuthHandlerFactory() {
457 std::vector<std::string> supported_schemes = 408 std::vector<std::string> supported_schemes =
458 base::SplitString(kSupportedAuthSchemes, ",", base::TRIM_WHITESPACE, 409 base::SplitString(kSupportedAuthSchemes, ",", base::TRIM_WHITESPACE,
459 base::SPLIT_WANT_NONEMPTY); 410 base::SPLIT_WANT_NONEMPTY);
460 globals_->http_auth_preferences.reset( 411 globals_->http_auth_preferences.reset(
461 new net::HttpAuthPreferences(supported_schemes, std::string())); 412 new net::HttpAuthPreferences(supported_schemes, std::string()));
462 globals_->http_auth_handler_factory = 413 globals_->http_auth_handler_factory =
463 net::HttpAuthHandlerRegistryFactory::Create( 414 net::HttpAuthHandlerRegistryFactory::Create(
464 globals_->http_auth_preferences.get(), globals_->host_resolver.get()); 415 globals_->http_auth_preferences.get(), globals_->host_resolver.get());
465 } 416 }
466 417
467 void IOSChromeIOThread::ClearHostCache() { 418 void IOSIOThread::ClearHostCache() {
468 DCHECK_CURRENTLY_ON(web::WebThread::IO); 419 DCHECK_CURRENTLY_ON(web::WebThread::IO);
469 420
470 net::HostCache* host_cache = globals_->host_resolver->GetHostCache(); 421 net::HostCache* host_cache = globals_->host_resolver->GetHostCache();
471 if (host_cache) 422 if (host_cache)
472 host_cache->clear(); 423 host_cache->clear();
473 } 424 }
474 425
475 const net::HttpNetworkSession::Params& IOSChromeIOThread::NetworkSessionParams() 426 const net::HttpNetworkSession::Params& IOSIOThread::NetworkSessionParams()
476 const { 427 const {
477 return params_; 428 return params_;
478 } 429 }
479 430
480 base::TimeTicks IOSChromeIOThread::creation_time() const { 431 base::TimeTicks IOSIOThread::creation_time() const {
481 return creation_time_; 432 return creation_time_;
482 } 433 }
483 434
484 net::SSLConfigService* IOSChromeIOThread::GetSSLConfigService() { 435 net::SSLConfigService* IOSIOThread::GetSSLConfigService() {
485 return ssl_config_service_manager_->Get(); 436 return ssl_config_service_manager_->Get();
486 } 437 }
487 438
488 void IOSChromeIOThread::ChangedToOnTheRecordOnIOThread() { 439 void IOSIOThread::ChangedToOnTheRecordOnIOThread() {
489 DCHECK_CURRENTLY_ON(web::WebThread::IO); 440 DCHECK_CURRENTLY_ON(web::WebThread::IO);
490 441
491 // Clear the host cache to avoid showing entries from the OTR session 442 // Clear the host cache to avoid showing entries from the OTR session
492 // in about:net-internals. 443 // in about:net-internals.
493 ClearHostCache(); 444 ClearHostCache();
494 } 445 }
495 446
496 void IOSChromeIOThread::InitSystemRequestContext() { 447 void IOSIOThread::InitSystemRequestContext() {
497 if (system_url_request_context_getter_.get()) 448 if (system_url_request_context_getter_.get())
498 return; 449 return;
499 // If we're in unit_tests, IOSChromeIOThread may not be run. 450 // If we're in unit_tests, IOSIOThread may not be run.
500 if (!web::WebThread::IsMessageLoopValid(web::WebThread::IO)) 451 if (!web::WebThread::IsMessageLoopValid(web::WebThread::IO))
501 return; 452 return;
502 system_proxy_config_service_ = ProxyServiceFactory::CreateProxyConfigService( 453 system_proxy_config_service_ = ProxyServiceFactory::CreateProxyConfigService(
503 pref_proxy_config_tracker_.get()); 454 pref_proxy_config_tracker_.get());
504 455
505 system_url_request_context_getter_ = new SystemURLRequestContextGetter(this); 456 system_url_request_context_getter_ = new SystemURLRequestContextGetter(this);
506 // Safe to post an unretained this pointer, since IOSChromeIOThread is 457 // Safe to post an unretained this pointer, since IOSIOThread is
507 // guaranteed to outlive the IO WebThread. 458 // guaranteed to outlive the IO WebThread.
508 web::WebThread::PostTask( 459 web::WebThread::PostTask(
509 web::WebThread::IO, FROM_HERE, 460 web::WebThread::IO, FROM_HERE,
510 base::Bind(&IOSChromeIOThread::InitSystemRequestContextOnIOThread, 461 base::Bind(&IOSIOThread::InitSystemRequestContextOnIOThread,
511 base::Unretained(this))); 462 base::Unretained(this)));
512 } 463 }
513 464
514 void IOSChromeIOThread::InitSystemRequestContextOnIOThread() { 465 void IOSIOThread::InitSystemRequestContextOnIOThread() {
515 DCHECK_CURRENTLY_ON(web::WebThread::IO); 466 DCHECK_CURRENTLY_ON(web::WebThread::IO);
516 DCHECK(!globals_->system_proxy_service.get()); 467 DCHECK(!globals_->system_proxy_service.get());
517 DCHECK(system_proxy_config_service_.get()); 468 DCHECK(system_proxy_config_service_.get());
518 469
519 globals_->system_proxy_service = ProxyServiceFactory::CreateProxyService( 470 globals_->system_proxy_service = ProxyServiceFactory::CreateProxyService(
520 net_log_, nullptr, globals_->system_network_delegate.get(), 471 net_log_, nullptr, globals_->system_network_delegate.get(),
521 std::move(system_proxy_config_service_), true /* quick_check_enabled */); 472 std::move(system_proxy_config_service_), true /* quick_check_enabled */);
522 473
523 globals_->system_request_context.reset( 474 globals_->system_request_context.reset(
524 ConstructSystemRequestContext(globals_, params_, net_log_)); 475 ConstructSystemRequestContext(globals_, params_, net_log_));
525 } 476 }
526 477
527 net::URLRequestContext* IOSChromeIOThread::ConstructSystemRequestContext( 478 net::URLRequestContext* IOSIOThread::ConstructSystemRequestContext(
528 IOSChromeIOThread::Globals* globals, 479 IOSIOThread::Globals* globals,
529 const net::HttpNetworkSession::Params& params, 480 const net::HttpNetworkSession::Params& params,
530 net::NetLog* net_log) { 481 net::NetLog* net_log) {
531 net::URLRequestContext* context = new SystemURLRequestContext; 482 net::URLRequestContext* context = new SystemURLRequestContext;
532 context->set_net_log(net_log); 483 context->set_net_log(net_log);
533 context->set_host_resolver(globals->host_resolver.get()); 484 context->set_host_resolver(globals->host_resolver.get());
534 context->set_cert_verifier(globals->cert_verifier.get()); 485 context->set_cert_verifier(globals->cert_verifier.get());
535 context->set_transport_security_state( 486 context->set_transport_security_state(
536 globals->transport_security_state.get()); 487 globals->transport_security_state.get());
537 context->set_cert_transparency_verifier( 488 context->set_cert_transparency_verifier(
538 globals->cert_transparency_verifier.get()); 489 globals->cert_transparency_verifier.get());
(...skipping 29 matching lines...) Expand all
568 519
569 globals->system_http_network_session.reset( 520 globals->system_http_network_session.reset(
570 new net::HttpNetworkSession(system_params)); 521 new net::HttpNetworkSession(system_params));
571 globals->system_http_transaction_factory.reset( 522 globals->system_http_transaction_factory.reset(
572 new net::HttpNetworkLayer(globals->system_http_network_session.get())); 523 new net::HttpNetworkLayer(globals->system_http_network_session.get()));
573 context->set_http_transaction_factory( 524 context->set_http_transaction_factory(
574 globals->system_http_transaction_factory.get()); 525 globals->system_http_transaction_factory.get());
575 526
576 return context; 527 return context;
577 } 528 }
529
530 } // namespace io_thread
OLDNEW
« 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