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

Side by Side Diff: ios/components/io_thread/io_thread.mm

Issue 2908613002: Move common functionality of IOSChromeIOThread to ios/components. (Closed)
Patch Set: Remove bug todo. 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 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/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 IOThread 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
89 namespace { 82 namespace {
90 83
91 const char kSupportedAuthSchemes[] = "basic,digest,ntlm"; 84 const char kSupportedAuthSchemes[] = "basic,digest,ntlm";
92 85
93 // Field trial for network quality estimator. Seeds RTT and downstream 86 // Field trial for network quality estimator. Seeds RTT and downstream
94 // throughput observations with values that correspond to the connection type 87 // throughput observations with values that correspond to the connection type
95 // determined by the operating system. 88 // determined by the operating system.
96 const char kNetworkQualityEstimatorFieldTrialName[] = "NetworkQualityEstimator"; 89 const char kNetworkQualityEstimatorFieldTrialName[] = "NetworkQualityEstimator";
97 90
91 } // namespace
92
93 namespace io_thread {
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", "IOThread::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 IOThread::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(IOThread* 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 IOThread* 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 IOThread* 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 IOThread::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 IOThread::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 IOThread::Globals::Globals() : system_request_context_leak_checker(this) {}
268 : system_request_context_leak_checker(this) {}
269 237
270 IOSChromeIOThread::Globals::~Globals() {} 238 IOThread::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 IOThread more flexible for testing.
274 IOSChromeIOThread::IOSChromeIOThread(PrefService* local_state, 242 IOThread::IOThread(PrefService* local_state, net_log::ChromeNetLog* net_log)
275 net_log::ChromeNetLog* net_log)
276 : net_log_(net_log), 243 : net_log_(net_log),
277 globals_(nullptr), 244 globals_(nullptr),
278 creation_time_(base::TimeTicks::Now()), 245 creation_time_(base::TimeTicks::Now()),
279 weak_factory_(this) { 246 weak_factory_(this) {
280 pref_proxy_config_tracker_ = 247 pref_proxy_config_tracker_ =
281 ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState( 248 ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState(
282 local_state); 249 local_state);
283 IOSChromeNetworkDelegate::InitializePrefsOnUIThread(nullptr, local_state);
284 ssl_config_service_manager_.reset( 250 ssl_config_service_manager_.reset(
285 ssl_config::SSLConfigServiceManager::CreateDefaultManager( 251 ssl_config::SSLConfigServiceManager::CreateDefaultManager(
286 local_state, 252 local_state,
287 web::WebThread::GetTaskRunnerForThread(web::WebThread::IO))); 253 web::WebThread::GetTaskRunnerForThread(web::WebThread::IO)));
288 254
289 web::WebThread::SetDelegate(web::WebThread::IO, this); 255 web::WebThread::SetDelegate(web::WebThread::IO, this);
290 } 256 }
291 257
292 IOSChromeIOThread::~IOSChromeIOThread() { 258 IOThread::~IOThread() {
293 // This isn't needed for production code, but in tests, IOSChromeIOThread may 259 // This isn't needed for production code, but in tests, IOThread may
294 // be multiply constructed. 260 // be multiply constructed.
295 web::WebThread::SetDelegate(web::WebThread::IO, nullptr); 261 web::WebThread::SetDelegate(web::WebThread::IO, nullptr);
296 262
297 pref_proxy_config_tracker_->DetachFromPrefService(); 263 pref_proxy_config_tracker_->DetachFromPrefService();
298 DCHECK(!globals_); 264 DCHECK(!globals_);
299 } 265 }
300 266
301 IOSChromeIOThread::Globals* IOSChromeIOThread::globals() { 267 IOThread::Globals* IOThread::globals() {
302 DCHECK_CURRENTLY_ON(web::WebThread::IO); 268 DCHECK_CURRENTLY_ON(web::WebThread::IO);
303 return globals_; 269 return globals_;
304 } 270 }
305 271
306 void IOSChromeIOThread::SetGlobalsForTesting(Globals* globals) { 272 void IOThread::SetGlobalsForTesting(Globals* globals) {
307 DCHECK_CURRENTLY_ON(web::WebThread::IO); 273 DCHECK_CURRENTLY_ON(web::WebThread::IO);
308 DCHECK(!globals || !globals_); 274 DCHECK(!globals || !globals_);
309 globals_ = globals; 275 globals_ = globals;
310 } 276 }
311 277
312 net_log::ChromeNetLog* IOSChromeIOThread::net_log() { 278 net_log::ChromeNetLog* IOThread::net_log() {
313 return net_log_; 279 return net_log_;
314 } 280 }
315 281
316 void IOSChromeIOThread::ChangedToOnTheRecord() { 282 void IOThread::ChangedToOnTheRecord() {
317 DCHECK_CURRENTLY_ON(web::WebThread::UI); 283 DCHECK_CURRENTLY_ON(web::WebThread::UI);
318 web::WebThread::PostTask( 284 web::WebThread::PostTask(web::WebThread::IO, FROM_HERE,
319 web::WebThread::IO, FROM_HERE, 285 base::Bind(&IOThread::ChangedToOnTheRecordOnIOThread,
320 base::Bind(&IOSChromeIOThread::ChangedToOnTheRecordOnIOThread, 286 base::Unretained(this)));
321 base::Unretained(this)));
322 } 287 }
323 288
324 net::URLRequestContextGetter* 289 net::URLRequestContextGetter* IOThread::system_url_request_context_getter() {
325 IOSChromeIOThread::system_url_request_context_getter() {
326 DCHECK_CURRENTLY_ON(web::WebThread::UI); 290 DCHECK_CURRENTLY_ON(web::WebThread::UI);
327 if (!system_url_request_context_getter_.get()) { 291 if (!system_url_request_context_getter_.get()) {
328 InitSystemRequestContext(); 292 InitSystemRequestContext();
329 } 293 }
330 return system_url_request_context_getter_.get(); 294 return system_url_request_context_getter_.get();
331 } 295 }
332 296
333 void IOSChromeIOThread::Init() { 297 void IOThread::Init() {
334 TRACE_EVENT0("startup", "IOSChromeIOThread::Init"); 298 TRACE_EVENT0("startup", "IOThread::Init");
335 DCHECK_CURRENTLY_ON(web::WebThread::IO); 299 DCHECK_CURRENTLY_ON(web::WebThread::IO);
336 300
337 const base::CommandLine& command_line =
338 *base::CommandLine::ForCurrentProcess();
339
340 DCHECK(!globals_); 301 DCHECK(!globals_);
341 globals_ = new Globals; 302 globals_ = new Globals;
342 303
343 // Add an observer that will emit network change events to the ChromeNetLog. 304 // Add an observer that will emit network change events to the ChromeNetLog.
344 // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be 305 // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be
345 // logging the network change before other IO thread consumers respond to it. 306 // logging the network change before other IO thread consumers respond to it.
346 network_change_observer_.reset(new LoggingNetworkChangeObserver(net_log_)); 307 network_change_observer_.reset(new LoggingNetworkChangeObserver(net_log_));
347 308
348 // Setup the HistogramWatcher to run on the IO thread. 309 // Setup the HistogramWatcher to run on the IO thread.
349 net::NetworkChangeNotifier::InitHistogramWatcher(); 310 net::NetworkChangeNotifier::InitHistogramWatcher();
350 311
351 std::unique_ptr<IOSChromeNetworkDelegate> chrome_network_delegate( 312 globals_->system_network_delegate = GetSystemNetworkDelegate();
352 new IOSChromeNetworkDelegate());
353
354 globals_->system_network_delegate = std::move(chrome_network_delegate);
355 globals_->host_resolver = CreateGlobalHostResolver(net_log_); 313 globals_->host_resolver = CreateGlobalHostResolver(net_log_);
356 314
357 std::map<std::string, std::string> network_quality_estimator_params; 315 std::map<std::string, std::string> network_quality_estimator_params;
358 variations::GetVariationParams(kNetworkQualityEstimatorFieldTrialName, 316 variations::GetVariationParams(kNetworkQualityEstimatorFieldTrialName,
359 &network_quality_estimator_params); 317 &network_quality_estimator_params);
360 318
361 std::unique_ptr<net::ExternalEstimateProvider> external_estimate_provider; 319 std::unique_ptr<net::ExternalEstimateProvider> external_estimate_provider;
362 // Pass ownership. 320 // Pass ownership.
363 globals_->network_quality_estimator.reset(new net::NetworkQualityEstimator( 321 globals_->network_quality_estimator.reset(new net::NetworkQualityEstimator(
364 std::move(external_estimate_provider), network_quality_estimator_params, 322 std::move(external_estimate_provider), network_quality_estimator_params,
(...skipping 20 matching lines...) Expand all
385 // In-memory cookie store. 343 // In-memory cookie store.
386 globals_->system_cookie_store.reset(new net::CookieMonster(nullptr, nullptr)); 344 globals_->system_cookie_store.reset(new net::CookieMonster(nullptr, nullptr));
387 // In-memory channel ID store. 345 // In-memory channel ID store.
388 globals_->system_channel_id_service.reset( 346 globals_->system_channel_id_service.reset(
389 new net::ChannelIDService(new net::DefaultChannelIDStore(nullptr))); 347 new net::ChannelIDService(new net::DefaultChannelIDStore(nullptr)));
390 globals_->system_cookie_store->SetChannelIDServiceID( 348 globals_->system_cookie_store->SetChannelIDServiceID(
391 globals_->system_channel_id_service->GetUniqueID()); 349 globals_->system_channel_id_service->GetUniqueID());
392 globals_->http_user_agent_settings.reset(new net::StaticHttpUserAgentSettings( 350 globals_->http_user_agent_settings.reset(new net::StaticHttpUserAgentSettings(
393 std::string(), 351 std::string(),
394 web::GetWebClient()->GetUserAgent(web::UserAgentType::MOBILE))); 352 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 353
404 params_.ignore_certificate_errors = false; 354 params_.ignore_certificate_errors = false;
405 params_.enable_user_alternate_protocol_ports = false; 355 params_.enable_user_alternate_protocol_ports = false;
406 356
407 std::string quic_user_agent_id = ::GetChannelString(); 357 std::string quic_user_agent_id = GetChannelString();
408 if (!quic_user_agent_id.empty()) 358 if (!quic_user_agent_id.empty())
409 quic_user_agent_id.push_back(' '); 359 quic_user_agent_id.push_back(' ');
410 quic_user_agent_id.append( 360 quic_user_agent_id.append(
411 version_info::GetProductNameAndVersionForUserAgent()); 361 version_info::GetProductNameAndVersionForUserAgent());
412 quic_user_agent_id.push_back(' '); 362 quic_user_agent_id.push_back(' ');
413 quic_user_agent_id.append(web::BuildOSCpuInfo()); 363 quic_user_agent_id.append(web::BuildOSCpuInfo());
414 364
415 network_session_configurator::ParseFieldTrials( 365 network_session_configurator::ParseFieldTrials(
416 /*is_quic_force_disabled=*/false, 366 /*is_quic_force_disabled=*/false,
417 /*is_quic_force_enabled=*/false, quic_user_agent_id, &params_); 367 /*is_quic_force_enabled=*/false, quic_user_agent_id, &params_);
418 368
419 // InitSystemRequestContext turns right around and posts a task back 369 // 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 370 // to the IO thread, so we can't let it run until we know the IO
421 // thread has started. 371 // thread has started.
422 // 372 //
423 // Note that since we are at WebThread::Init time, the UI thread 373 // Note that since we are at WebThread::Init time, the UI thread
424 // is blocked waiting for the thread to start. Therefore, posting 374 // is blocked waiting for the thread to start. Therefore, posting
425 // this task to the main thread's message loop here is guaranteed to 375 // 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 376 // get it onto the message loop while the IOThread object still
427 // exists. However, the message might not be processed on the UI 377 // exists. However, the message might not be processed on the UI
428 // thread until after IOSChromeIOThread is gone, so use a weak pointer. 378 // thread until after IOThread is gone, so use a weak pointer.
429 web::WebThread::PostTask( 379 web::WebThread::PostTask(web::WebThread::UI, FROM_HERE,
430 web::WebThread::UI, FROM_HERE, 380 base::Bind(&IOThread::InitSystemRequestContext,
431 base::Bind(&IOSChromeIOThread::InitSystemRequestContext, 381 weak_factory_.GetWeakPtr()));
432 weak_factory_.GetWeakPtr()));
433 } 382 }
434 383
435 void IOSChromeIOThread::CleanUp() { 384 void IOThread::CleanUp() {
436 system_url_request_context_getter_->Shutdown(); 385 system_url_request_context_getter_->Shutdown();
437 system_url_request_context_getter_ = nullptr; 386 system_url_request_context_getter_ = nullptr;
438 387
439 // Release objects that the net::URLRequestContext could have been pointing 388 // Release objects that the net::URLRequestContext could have been pointing
440 // to. 389 // to.
441 390
442 // Shutdown the HistogramWatcher on the IO thread. 391 // Shutdown the HistogramWatcher on the IO thread.
443 net::NetworkChangeNotifier::ShutdownHistogramWatcher(); 392 net::NetworkChangeNotifier::ShutdownHistogramWatcher();
444 393
445 // This must be reset before the ChromeNetLog is destroyed. 394 // This must be reset before the ChromeNetLog is destroyed.
446 network_change_observer_.reset(); 395 network_change_observer_.reset();
447 396
448 system_proxy_config_service_.reset(); 397 system_proxy_config_service_.reset();
449 398
450 delete globals_; 399 delete globals_;
451 globals_ = nullptr; 400 globals_ = nullptr;
452 401
453 base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks(); 402 base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks();
454 } 403 }
455 404
456 void IOSChromeIOThread::CreateDefaultAuthHandlerFactory() { 405 void IOThread::CreateDefaultAuthHandlerFactory() {
457 std::vector<std::string> supported_schemes = 406 std::vector<std::string> supported_schemes =
458 base::SplitString(kSupportedAuthSchemes, ",", base::TRIM_WHITESPACE, 407 base::SplitString(kSupportedAuthSchemes, ",", base::TRIM_WHITESPACE,
459 base::SPLIT_WANT_NONEMPTY); 408 base::SPLIT_WANT_NONEMPTY);
460 globals_->http_auth_preferences.reset( 409 globals_->http_auth_preferences.reset(
461 new net::HttpAuthPreferences(supported_schemes, std::string())); 410 new net::HttpAuthPreferences(supported_schemes, std::string()));
462 globals_->http_auth_handler_factory = 411 globals_->http_auth_handler_factory =
463 net::HttpAuthHandlerRegistryFactory::Create( 412 net::HttpAuthHandlerRegistryFactory::Create(
464 globals_->http_auth_preferences.get(), globals_->host_resolver.get()); 413 globals_->http_auth_preferences.get(), globals_->host_resolver.get());
465 } 414 }
466 415
467 void IOSChromeIOThread::ClearHostCache() { 416 void IOThread::ClearHostCache() {
468 DCHECK_CURRENTLY_ON(web::WebThread::IO); 417 DCHECK_CURRENTLY_ON(web::WebThread::IO);
469 418
470 net::HostCache* host_cache = globals_->host_resolver->GetHostCache(); 419 net::HostCache* host_cache = globals_->host_resolver->GetHostCache();
471 if (host_cache) 420 if (host_cache)
472 host_cache->clear(); 421 host_cache->clear();
473 } 422 }
474 423
475 const net::HttpNetworkSession::Params& IOSChromeIOThread::NetworkSessionParams() 424 const net::HttpNetworkSession::Params& IOThread::NetworkSessionParams() const {
476 const {
477 return params_; 425 return params_;
478 } 426 }
479 427
480 base::TimeTicks IOSChromeIOThread::creation_time() const { 428 base::TimeTicks IOThread::creation_time() const {
481 return creation_time_; 429 return creation_time_;
482 } 430 }
483 431
484 net::SSLConfigService* IOSChromeIOThread::GetSSLConfigService() { 432 std::string IOThread::GetChannelString() {
433 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.
434 }
435
436 net::SSLConfigService* IOThread::GetSSLConfigService() {
485 return ssl_config_service_manager_->Get(); 437 return ssl_config_service_manager_->Get();
486 } 438 }
487 439
488 void IOSChromeIOThread::ChangedToOnTheRecordOnIOThread() { 440 void IOThread::ChangedToOnTheRecordOnIOThread() {
489 DCHECK_CURRENTLY_ON(web::WebThread::IO); 441 DCHECK_CURRENTLY_ON(web::WebThread::IO);
490 442
491 // Clear the host cache to avoid showing entries from the OTR session 443 // Clear the host cache to avoid showing entries from the OTR session
492 // in about:net-internals. 444 // in about:net-internals.
493 ClearHostCache(); 445 ClearHostCache();
494 } 446 }
495 447
496 void IOSChromeIOThread::InitSystemRequestContext() { 448 void IOThread::InitSystemRequestContext() {
497 if (system_url_request_context_getter_.get()) 449 if (system_url_request_context_getter_.get())
498 return; 450 return;
499 // If we're in unit_tests, IOSChromeIOThread may not be run. 451 // If we're in unit_tests, IOThread may not be run.
500 if (!web::WebThread::IsMessageLoopValid(web::WebThread::IO)) 452 if (!web::WebThread::IsMessageLoopValid(web::WebThread::IO))
501 return; 453 return;
502 system_proxy_config_service_ = ProxyServiceFactory::CreateProxyConfigService( 454 system_proxy_config_service_ = ProxyServiceFactory::CreateProxyConfigService(
503 pref_proxy_config_tracker_.get()); 455 pref_proxy_config_tracker_.get());
504 456
505 system_url_request_context_getter_ = new SystemURLRequestContextGetter(this); 457 system_url_request_context_getter_ = new SystemURLRequestContextGetter(this);
506 // Safe to post an unretained this pointer, since IOSChromeIOThread is 458 // Safe to post an unretained this pointer, since IOThread is
507 // guaranteed to outlive the IO WebThread. 459 // guaranteed to outlive the IO WebThread.
508 web::WebThread::PostTask( 460 web::WebThread::PostTask(
509 web::WebThread::IO, FROM_HERE, 461 web::WebThread::IO, FROM_HERE,
510 base::Bind(&IOSChromeIOThread::InitSystemRequestContextOnIOThread, 462 base::Bind(&IOThread::InitSystemRequestContextOnIOThread,
511 base::Unretained(this))); 463 base::Unretained(this)));
512 } 464 }
513 465
514 void IOSChromeIOThread::InitSystemRequestContextOnIOThread() { 466 void IOThread::InitSystemRequestContextOnIOThread() {
515 DCHECK_CURRENTLY_ON(web::WebThread::IO); 467 DCHECK_CURRENTLY_ON(web::WebThread::IO);
516 DCHECK(!globals_->system_proxy_service.get()); 468 DCHECK(!globals_->system_proxy_service.get());
517 DCHECK(system_proxy_config_service_.get()); 469 DCHECK(system_proxy_config_service_.get());
518 470
519 globals_->system_proxy_service = ProxyServiceFactory::CreateProxyService( 471 globals_->system_proxy_service = ProxyServiceFactory::CreateProxyService(
520 net_log_, nullptr, globals_->system_network_delegate.get(), 472 net_log_, nullptr, globals_->system_network_delegate.get(),
521 std::move(system_proxy_config_service_), true /* quick_check_enabled */); 473 std::move(system_proxy_config_service_), true /* quick_check_enabled */);
522 474
523 globals_->system_request_context.reset( 475 globals_->system_request_context.reset(
524 ConstructSystemRequestContext(globals_, params_, net_log_)); 476 ConstructSystemRequestContext(globals_, params_, net_log_));
525 } 477 }
526 478
527 net::URLRequestContext* IOSChromeIOThread::ConstructSystemRequestContext( 479 net::URLRequestContext* IOThread::ConstructSystemRequestContext(
528 IOSChromeIOThread::Globals* globals, 480 IOThread::Globals* globals,
529 const net::HttpNetworkSession::Params& params, 481 const net::HttpNetworkSession::Params& params,
530 net::NetLog* net_log) { 482 net::NetLog* net_log) {
531 net::URLRequestContext* context = new SystemURLRequestContext; 483 net::URLRequestContext* context = new SystemURLRequestContext;
532 context->set_net_log(net_log); 484 context->set_net_log(net_log);
533 context->set_host_resolver(globals->host_resolver.get()); 485 context->set_host_resolver(globals->host_resolver.get());
534 context->set_cert_verifier(globals->cert_verifier.get()); 486 context->set_cert_verifier(globals->cert_verifier.get());
535 context->set_transport_security_state( 487 context->set_transport_security_state(
536 globals->transport_security_state.get()); 488 globals->transport_security_state.get());
537 context->set_cert_transparency_verifier( 489 context->set_cert_transparency_verifier(
538 globals->cert_transparency_verifier.get()); 490 globals->cert_transparency_verifier.get());
(...skipping 29 matching lines...) Expand all
568 520
569 globals->system_http_network_session.reset( 521 globals->system_http_network_session.reset(
570 new net::HttpNetworkSession(system_params)); 522 new net::HttpNetworkSession(system_params));
571 globals->system_http_transaction_factory.reset( 523 globals->system_http_transaction_factory.reset(
572 new net::HttpNetworkLayer(globals->system_http_network_session.get())); 524 new net::HttpNetworkLayer(globals->system_http_network_session.get()));
573 context->set_http_transaction_factory( 525 context->set_http_transaction_factory(
574 globals->system_http_transaction_factory.get()); 526 globals->system_http_transaction_factory.get());
575 527
576 return context; 528 return context;
577 } 529 }
530
531 } // namespace io_thread
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698