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

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

Powered by Google App Engine
This is Rietveld 408576698