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

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

Issue 2943783002: Make iOS's IOThread set up the SystemURLRequestContext all at once. (Closed)
Patch Set: Oops 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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 // dependencies and (2) make IOSIOThread more flexible for testing. 235 // dependencies and (2) make IOSIOThread more flexible for testing.
236 IOSIOThread::IOSIOThread(PrefService* local_state, 236 IOSIOThread::IOSIOThread(PrefService* local_state,
237 net_log::ChromeNetLog* net_log) 237 net_log::ChromeNetLog* net_log)
238 : net_log_(net_log), 238 : net_log_(net_log),
239 globals_(nullptr), 239 globals_(nullptr),
240 creation_time_(base::TimeTicks::Now()), 240 creation_time_(base::TimeTicks::Now()),
241 weak_factory_(this) { 241 weak_factory_(this) {
242 pref_proxy_config_tracker_ = 242 pref_proxy_config_tracker_ =
243 ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState( 243 ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState(
244 local_state); 244 local_state);
245 system_proxy_config_service_ = ProxyServiceFactory::CreateProxyConfigService(
246 pref_proxy_config_tracker_.get());
247
245 ssl_config_service_manager_.reset( 248 ssl_config_service_manager_.reset(
246 ssl_config::SSLConfigServiceManager::CreateDefaultManager( 249 ssl_config::SSLConfigServiceManager::CreateDefaultManager(
247 local_state, 250 local_state,
248 web::WebThread::GetTaskRunnerForThread(web::WebThread::IO))); 251 web::WebThread::GetTaskRunnerForThread(web::WebThread::IO)));
249 252
250 web::WebThread::SetDelegate(web::WebThread::IO, this); 253 web::WebThread::SetDelegate(web::WebThread::IO, this);
251 } 254 }
252 255
253 IOSIOThread::~IOSIOThread() { 256 IOSIOThread::~IOSIOThread() {
254 // This isn't needed for production code, but in tests, IOSIOThread may 257 // This isn't needed for production code, but in tests, IOSIOThread may
(...skipping 23 matching lines...) Expand all
278 DCHECK_CURRENTLY_ON(web::WebThread::UI); 281 DCHECK_CURRENTLY_ON(web::WebThread::UI);
279 web::WebThread::PostTask( 282 web::WebThread::PostTask(
280 web::WebThread::IO, FROM_HERE, 283 web::WebThread::IO, FROM_HERE,
281 base::Bind(&IOSIOThread::ChangedToOnTheRecordOnIOThread, 284 base::Bind(&IOSIOThread::ChangedToOnTheRecordOnIOThread,
282 base::Unretained(this))); 285 base::Unretained(this)));
283 } 286 }
284 287
285 net::URLRequestContextGetter* IOSIOThread::system_url_request_context_getter() { 288 net::URLRequestContextGetter* IOSIOThread::system_url_request_context_getter() {
286 DCHECK_CURRENTLY_ON(web::WebThread::UI); 289 DCHECK_CURRENTLY_ON(web::WebThread::UI);
287 if (!system_url_request_context_getter_.get()) { 290 if (!system_url_request_context_getter_.get()) {
288 InitSystemRequestContext(); 291 // If we're in unit_tests, IOSIOThread may not be run.
292 if (!web::WebThread::IsMessageLoopValid(web::WebThread::IO))
293 return nullptr;
294 system_url_request_context_getter_ =
295 new SystemURLRequestContextGetter(this);
289 } 296 }
290 return system_url_request_context_getter_.get(); 297 return system_url_request_context_getter_.get();
291 } 298 }
292 299
293 void IOSIOThread::Init() { 300 void IOSIOThread::Init() {
294 TRACE_EVENT0("startup", "IOSIOThread::Init"); 301 TRACE_EVENT0("startup", "IOSIOThread::Init");
295 DCHECK_CURRENTLY_ON(web::WebThread::IO); 302 DCHECK_CURRENTLY_ON(web::WebThread::IO);
296 303
297 DCHECK(!globals_); 304 DCHECK(!globals_);
298 globals_ = new Globals; 305 globals_ = new Globals;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 quic_user_agent_id.append( 353 quic_user_agent_id.append(
347 version_info::GetProductNameAndVersionForUserAgent()); 354 version_info::GetProductNameAndVersionForUserAgent());
348 quic_user_agent_id.push_back(' '); 355 quic_user_agent_id.push_back(' ');
349 quic_user_agent_id.append(web::BuildOSCpuInfo()); 356 quic_user_agent_id.append(web::BuildOSCpuInfo());
350 357
351 // Set up field trials, ignoring debug command line options. 358 // Set up field trials, ignoring debug command line options.
352 network_session_configurator::ParseCommandLineAndFieldTrials( 359 network_session_configurator::ParseCommandLineAndFieldTrials(
353 base::CommandLine(base::CommandLine::NO_PROGRAM), 360 base::CommandLine(base::CommandLine::NO_PROGRAM),
354 /*is_quic_force_disabled=*/false, quic_user_agent_id, &params_); 361 /*is_quic_force_disabled=*/false, quic_user_agent_id, &params_);
355 362
356 // InitSystemRequestContext turns right around and posts a task back 363 globals_->system_proxy_service = ProxyServiceFactory::CreateProxyService(
357 // to the IO thread, so we can't let it run until we know the IO 364 net_log_, nullptr, globals_->system_network_delegate.get(),
358 // thread has started. 365 std::move(system_proxy_config_service_), true /* quick_check_enabled */);
359 // 366
360 // Note that since we are at WebThread::Init time, the UI thread 367 globals_->system_request_context.reset(
361 // is blocked waiting for the thread to start. Therefore, posting 368 ConstructSystemRequestContext(globals_, params_, net_log_));
362 // this task to the main thread's message loop here is guaranteed to
363 // get it onto the message loop while the IOSIOThread object still
364 // exists. However, the message might not be processed on the UI
365 // thread until after IOSIOThread is gone, so use a weak pointer.
366 web::WebThread::PostTask(web::WebThread::UI, FROM_HERE,
367 base::Bind(&IOSIOThread::InitSystemRequestContext,
368 weak_factory_.GetWeakPtr()));
369 } 369 }
370 370
371 void IOSIOThread::CleanUp() { 371 void IOSIOThread::CleanUp() {
372 system_url_request_context_getter_->Shutdown(); 372 system_url_request_context_getter_->Shutdown();
373 system_url_request_context_getter_ = nullptr; 373 system_url_request_context_getter_ = nullptr;
374 374
375 // Release objects that the net::URLRequestContext could have been pointing 375 // Release objects that the net::URLRequestContext could have been pointing
376 // to. 376 // to.
377 377
378 // Shutdown the HistogramWatcher on the IO thread. 378 // Shutdown the HistogramWatcher on the IO thread.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 } 422 }
423 423
424 void IOSIOThread::ChangedToOnTheRecordOnIOThread() { 424 void IOSIOThread::ChangedToOnTheRecordOnIOThread() {
425 DCHECK_CURRENTLY_ON(web::WebThread::IO); 425 DCHECK_CURRENTLY_ON(web::WebThread::IO);
426 426
427 // Clear the host cache to avoid showing entries from the OTR session 427 // Clear the host cache to avoid showing entries from the OTR session
428 // in about:net-internals. 428 // in about:net-internals.
429 ClearHostCache(); 429 ClearHostCache();
430 } 430 }
431 431
432 void IOSIOThread::InitSystemRequestContext() {
433 if (system_url_request_context_getter_.get())
434 return;
435 // If we're in unit_tests, IOSIOThread may not be run.
436 if (!web::WebThread::IsMessageLoopValid(web::WebThread::IO))
437 return;
438 system_proxy_config_service_ = ProxyServiceFactory::CreateProxyConfigService(
439 pref_proxy_config_tracker_.get());
440
441 system_url_request_context_getter_ = new SystemURLRequestContextGetter(this);
442 // Safe to post an unretained this pointer, since IOSIOThread is
443 // guaranteed to outlive the IO WebThread.
444 web::WebThread::PostTask(
445 web::WebThread::IO, FROM_HERE,
446 base::Bind(&IOSIOThread::InitSystemRequestContextOnIOThread,
447 base::Unretained(this)));
448 }
449
450 void IOSIOThread::InitSystemRequestContextOnIOThread() {
451 DCHECK_CURRENTLY_ON(web::WebThread::IO);
452 DCHECK(!globals_->system_proxy_service.get());
453 DCHECK(system_proxy_config_service_.get());
454
455 globals_->system_proxy_service = ProxyServiceFactory::CreateProxyService(
456 net_log_, nullptr, globals_->system_network_delegate.get(),
457 std::move(system_proxy_config_service_), true /* quick_check_enabled */);
458
459 globals_->system_request_context.reset(
460 ConstructSystemRequestContext(globals_, params_, net_log_));
461 }
462
463 net::URLRequestContext* IOSIOThread::ConstructSystemRequestContext( 432 net::URLRequestContext* IOSIOThread::ConstructSystemRequestContext(
464 IOSIOThread::Globals* globals, 433 IOSIOThread::Globals* globals,
465 const net::HttpNetworkSession::Params& params, 434 const net::HttpNetworkSession::Params& params,
466 net::NetLog* net_log) { 435 net::NetLog* net_log) {
467 net::URLRequestContext* context = new SystemURLRequestContext; 436 net::URLRequestContext* context = new SystemURLRequestContext;
468 context->set_net_log(net_log); 437 context->set_net_log(net_log);
469 context->set_host_resolver(globals->host_resolver.get()); 438 context->set_host_resolver(globals->host_resolver.get());
470 context->set_cert_verifier(globals->cert_verifier.get()); 439 context->set_cert_verifier(globals->cert_verifier.get());
471 context->set_transport_security_state( 440 context->set_transport_security_state(
472 globals->transport_security_state.get()); 441 globals->transport_security_state.get());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 new net::HttpNetworkSession(params, system_context)); 473 new net::HttpNetworkSession(params, system_context));
505 globals->system_http_transaction_factory.reset( 474 globals->system_http_transaction_factory.reset(
506 new net::HttpNetworkLayer(globals->system_http_network_session.get())); 475 new net::HttpNetworkLayer(globals->system_http_network_session.get()));
507 context->set_http_transaction_factory( 476 context->set_http_transaction_factory(
508 globals->system_http_transaction_factory.get()); 477 globals->system_http_transaction_factory.get());
509 478
510 return context; 479 return context;
511 } 480 }
512 481
513 } // namespace io_thread 482 } // 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