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

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

Issue 2946533002: Make iOS's IOThread class use URLRequestContextBuilder.
Patch Set: Minor fix, more needed 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
« no previous file with comments | « ios/components/io_thread/ios_io_thread.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 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/components/io_thread/ios_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>
(...skipping 19 matching lines...) Expand all
30 #include "components/net_log/chrome_net_log.h" 30 #include "components/net_log/chrome_net_log.h"
31 #include "components/network_session_configurator/browser/network_session_config urator.h" 31 #include "components/network_session_configurator/browser/network_session_config urator.h"
32 #include "components/prefs/pref_service.h" 32 #include "components/prefs/pref_service.h"
33 #include "components/proxy_config/ios/proxy_service_factory.h" 33 #include "components/proxy_config/ios/proxy_service_factory.h"
34 #include "components/proxy_config/pref_proxy_config_tracker.h" 34 #include "components/proxy_config/pref_proxy_config_tracker.h"
35 #include "components/variations/variations_associated_data.h" 35 #include "components/variations/variations_associated_data.h"
36 #include "components/version_info/version_info.h" 36 #include "components/version_info/version_info.h"
37 #include "ios/web/public/user_agent.h" 37 #include "ios/web/public/user_agent.h"
38 #include "ios/web/public/web_client.h" 38 #include "ios/web/public/web_client.h"
39 #include "ios/web/public/web_thread.h" 39 #include "ios/web/public/web_thread.h"
40 #include "net/base/sdch_manager.h"
41 #include "net/cert/cert_verifier.h"
42 #include "net/cert/ct_known_logs.h" 40 #include "net/cert/ct_known_logs.h"
43 #include "net/cert/ct_log_verifier.h" 41 #include "net/cert/ct_log_verifier.h"
44 #include "net/cert/ct_policy_enforcer.h"
45 #include "net/cert/ct_verifier.h" 42 #include "net/cert/ct_verifier.h"
46 #include "net/cert/multi_log_ct_verifier.h" 43 #include "net/cert/multi_log_ct_verifier.h"
47 #include "net/cert/multi_threaded_cert_verifier.h" 44 #include "net/cert/multi_threaded_cert_verifier.h"
48 #include "net/cookies/cookie_monster.h"
49 #include "net/cookies/cookie_store.h"
50 #include "net/dns/host_cache.h"
51 #include "net/dns/host_resolver.h"
52 #include "net/http/http_auth_filter.h"
53 #include "net/http/http_auth_handler_factory.h"
54 #include "net/http/http_auth_preferences.h"
55 #include "net/http/http_network_layer.h"
56 #include "net/http/http_server_properties_impl.h"
57 #include "net/log/net_log_event_type.h" 45 #include "net/log/net_log_event_type.h"
58 #include "net/proxy/proxy_config_service.h" 46 #include "net/proxy/proxy_config_service.h"
59 #include "net/proxy/proxy_script_fetcher_impl.h"
60 #include "net/proxy/proxy_service.h"
61 #include "net/socket/tcp_client_socket.h" 47 #include "net/socket/tcp_client_socket.h"
62 #include "net/spdy/chromium/spdy_session.h"
63 #include "net/ssl/channel_id_service.h"
64 #include "net/ssl/default_channel_id_store.h" 48 #include "net/ssl/default_channel_id_store.h"
65 #include "net/url_request/data_protocol_handler.h"
66 #include "net/url_request/file_protocol_handler.h"
67 #include "net/url_request/static_http_user_agent_settings.h"
68 #include "net/url_request/url_request_context.h" 49 #include "net/url_request/url_request_context.h"
69 #include "net/url_request/url_request_context_builder.h" 50 #include "net/url_request/url_request_context_builder.h"
70 #include "net/url_request/url_request_context_getter.h" 51 #include "net/url_request/url_request_context_getter.h"
71 #include "net/url_request/url_request_job_factory_impl.h"
72 #include "url/url_constants.h"
73 52
74 #if !defined(__has_feature) || !__has_feature(objc_arc) 53 #if !defined(__has_feature) || !__has_feature(objc_arc)
75 #error "This file requires ARC support." 54 #error "This file requires ARC support."
76 #endif 55 #endif
77 56
78 // The IOSIOThread object must outlive any tasks posted to the IO thread 57 // The IOSIOThread object must outlive any tasks posted to the IO thread
79 // before the Quit task, so base::Bind() calls are not refcounted. 58 // before the Quit task, so base::Bind() calls are not refcounted.
80 59
81 namespace io_thread { 60 namespace io_thread {
82 61
83 namespace {
84
85 const char kSupportedAuthSchemes[] = "basic,digest,ntlm";
86
87 } // namespace
88
89 // Used for the "system" URLRequestContext. 62 // Used for the "system" URLRequestContext.
90 class SystemURLRequestContext : public net::URLRequestContext { 63 class SystemURLRequestContext : public net::URLRequestContext {
91 public: 64 public:
92 SystemURLRequestContext() = default; 65 SystemURLRequestContext() = default;
93 66
94 private: 67 private:
95 ~SystemURLRequestContext() override { AssertNoURLRequests(); } 68 ~SystemURLRequestContext() override { AssertNoURLRequests(); }
96 }; 69 };
97 70
98 std::unique_ptr<net::HostResolver> CreateGlobalHostResolver( 71 std::unique_ptr<net::HostResolver> CreateGlobalHostResolver(
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 globals_ = new Globals; 278 globals_ = new Globals;
306 279
307 // Add an observer that will emit network change events to the ChromeNetLog. 280 // Add an observer that will emit network change events to the ChromeNetLog.
308 // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be 281 // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be
309 // logging the network change before other IO thread consumers respond to it. 282 // logging the network change before other IO thread consumers respond to it.
310 network_change_observer_.reset(new LoggingNetworkChangeObserver(net_log_)); 283 network_change_observer_.reset(new LoggingNetworkChangeObserver(net_log_));
311 284
312 // Setup the HistogramWatcher to run on the IO thread. 285 // Setup the HistogramWatcher to run on the IO thread.
313 net::NetworkChangeNotifier::InitHistogramWatcher(); 286 net::NetworkChangeNotifier::InitHistogramWatcher();
314 287
315 globals_->system_network_delegate = CreateSystemNetworkDelegate(); 288 net::URLrequestContextBuilder builder;
316 globals_->host_resolver = CreateGlobalHostResolver(net_log_); 289 builder.set_net_log(net_log_);
317 290 builder.set_network_delegate(CreateSystemNetworkDelegate());
318 globals_->cert_verifier = net::CertVerifier::CreateDefault();
319
320 globals_->transport_security_state.reset(new net::TransportSecurityState());
321 291
322 std::vector<scoped_refptr<const net::CTLogVerifier>> ct_logs( 292 std::vector<scoped_refptr<const net::CTLogVerifier>> ct_logs(
323 net::ct::CreateLogVerifiersForKnownLogs()); 293 net::ct::CreateLogVerifiersForKnownLogs());
324 294
325 net::MultiLogCTVerifier* ct_verifier = new net::MultiLogCTVerifier(); 295 std::unique_ptr<net::MultiLogCTVerifier> ct_verifier(
326 globals_->cert_transparency_verifier.reset(ct_verifier); 296 base::MakeUnique<net::MultiLogCTVerifier>());
327 // Add built-in logs 297 // Add built-in logs
328 ct_verifier->AddLogs(ct_logs); 298 ct_verifier->AddLogs(ct_logs);
299 builder.set_ct_verifier(std::move(ct_verfier));
329 300
330 globals_->ct_policy_enforcer.reset(new net::CTPolicyEnforcer()); 301 builder.set_ssl_config_service(
302 base::scoped_refptr<net::SSLConfigService>(GetSSLConfigService()));
331 303
332 globals_->ssl_config_service = GetSSLConfigService(); 304 builder.set_user_agent(
333 305 web::GetWebClient()->GetUserAgent(web::UserAgentType::MOBILE));
334 CreateDefaultAuthHandlerFactory();
335 globals_->http_server_properties.reset(new net::HttpServerPropertiesImpl());
336 // In-memory cookie store.
337 globals_->system_cookie_store.reset(new net::CookieMonster(nullptr, nullptr));
338 // In-memory channel ID store.
339 globals_->system_channel_id_service.reset(
340 new net::ChannelIDService(new net::DefaultChannelIDStore(nullptr)));
341 globals_->system_cookie_store->SetChannelIDServiceID(
342 globals_->system_channel_id_service->GetUniqueID());
343 globals_->http_user_agent_settings.reset(new net::StaticHttpUserAgentSettings(
344 std::string(),
345 web::GetWebClient()->GetUserAgent(web::UserAgentType::MOBILE)));
346 306
347 params_.ignore_certificate_errors = false; 307 params_.ignore_certificate_errors = false;
348 params_.enable_user_alternate_protocol_ports = false; 308 params_.enable_user_alternate_protocol_ports = false;
349 309
350 std::string quic_user_agent_id = GetChannelString(); 310 std::string quic_user_agent_id = GetChannelString();
351 if (!quic_user_agent_id.empty()) 311 if (!quic_user_agent_id.empty())
352 quic_user_agent_id.push_back(' '); 312 quic_user_agent_id.push_back(' ');
353 quic_user_agent_id.append( 313 quic_user_agent_id.append(
354 version_info::GetProductNameAndVersionForUserAgent()); 314 version_info::GetProductNameAndVersionForUserAgent());
355 quic_user_agent_id.push_back(' '); 315 quic_user_agent_id.push_back(' ');
356 quic_user_agent_id.append(web::BuildOSCpuInfo()); 316 quic_user_agent_id.append(web::BuildOSCpuInfo());
357 317
358 // Set up field trials, ignoring debug command line options. 318 // Set up field trials, ignoring debug command line options.
359 network_session_configurator::ParseCommandLineAndFieldTrials( 319 network_session_configurator::ParseCommandLineAndFieldTrials(
360 base::CommandLine(base::CommandLine::NO_PROGRAM), 320 base::CommandLine(base::CommandLine::NO_PROGRAM),
361 /*is_quic_force_disabled=*/false, quic_user_agent_id, &params_); 321 /*is_quic_force_disabled=*/false, quic_user_agent_id, &params_);
322 builder.set_http_network_session_params(params_);
362 323
363 globals_->system_proxy_service = ProxyServiceFactory::CreateProxyService( 324 builder.set_data_enabled(true);
364 net_log_, nullptr, globals_->system_network_delegate.get(),
365 std::move(system_proxy_config_service_), true /* quick_check_enabled */);
366 325
367 globals_->system_request_context.reset( 326 globals_->system_request_context = builder.build();
368 ConstructSystemRequestContext(globals_, params_, net_log_));
369 } 327 }
370 328
371 void IOSIOThread::CleanUp() { 329 void IOSIOThread::CleanUp() {
372 system_url_request_context_getter_->Shutdown(); 330 system_url_request_context_getter_->Shutdown();
373 system_url_request_context_getter_ = nullptr; 331 system_url_request_context_getter_ = nullptr;
374 332
375 // Release objects that the net::URLRequestContext could have been pointing 333 // Release objects that the net::URLRequestContext could have been pointing
376 // to. 334 // to.
377 335
378 // Shutdown the HistogramWatcher on the IO thread. 336 // Shutdown the HistogramWatcher on the IO thread.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 } 380 }
423 381
424 void IOSIOThread::ChangedToOnTheRecordOnIOThread() { 382 void IOSIOThread::ChangedToOnTheRecordOnIOThread() {
425 DCHECK_CURRENTLY_ON(web::WebThread::IO); 383 DCHECK_CURRENTLY_ON(web::WebThread::IO);
426 384
427 // Clear the host cache to avoid showing entries from the OTR session 385 // Clear the host cache to avoid showing entries from the OTR session
428 // in about:net-internals. 386 // in about:net-internals.
429 ClearHostCache(); 387 ClearHostCache();
430 } 388 }
431 389
432 net::URLRequestContext* IOSIOThread::ConstructSystemRequestContext(
433 IOSIOThread::Globals* globals,
434 const net::HttpNetworkSession::Params& params,
435 net::NetLog* net_log) {
436 net::URLRequestContext* context = new SystemURLRequestContext;
437 context->set_net_log(net_log);
438 context->set_host_resolver(globals->host_resolver.get());
439 context->set_cert_verifier(globals->cert_verifier.get());
440 context->set_transport_security_state(
441 globals->transport_security_state.get());
442 context->set_cert_transparency_verifier(
443 globals->cert_transparency_verifier.get());
444 context->set_ssl_config_service(globals->ssl_config_service.get());
445 context->set_http_auth_handler_factory(
446 globals->http_auth_handler_factory.get());
447 context->set_proxy_service(globals->system_proxy_service.get());
448 context->set_ct_policy_enforcer(globals->ct_policy_enforcer.get());
449
450 net::URLRequestJobFactoryImpl* system_job_factory =
451 new net::URLRequestJobFactoryImpl();
452 // Data URLs are always loaded through the system request context on iOS
453 // (due to UIWebView limitations).
454 bool set_protocol = system_job_factory->SetProtocolHandler(
455 url::kDataScheme, base::MakeUnique<net::DataProtocolHandler>());
456 DCHECK(set_protocol);
457 globals->system_url_request_job_factory.reset(system_job_factory);
458 context->set_job_factory(globals->system_url_request_job_factory.get());
459
460 context->set_cookie_store(globals->system_cookie_store.get());
461 context->set_channel_id_service(globals->system_channel_id_service.get());
462 context->set_network_delegate(globals->system_network_delegate.get());
463 context->set_http_user_agent_settings(
464 globals->http_user_agent_settings.get());
465
466 context->set_http_server_properties(globals->http_server_properties.get());
467
468 net::HttpNetworkSession::Context system_context;
469 net::URLRequestContextBuilder::SetHttpNetworkSessionComponents(
470 context, &system_context);
471
472 globals->system_http_network_session.reset(
473 new net::HttpNetworkSession(params, system_context));
474 globals->system_http_transaction_factory.reset(
475 new net::HttpNetworkLayer(globals->system_http_network_session.get()));
476 context->set_http_transaction_factory(
477 globals->system_http_transaction_factory.get());
478
479 return context;
480 }
481
482 } // namespace io_thread 390 } // namespace io_thread
OLDNEW
« no previous file with comments | « ios/components/io_thread/ios_io_thread.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698