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

Side by Side Diff: chrome/browser/io_thread.cc

Issue 18405007: Move IOThread initialization to happen asynchronously. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/io_thread.h" 5 #include "chrome/browser/io_thread.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 } 456 }
457 457
458 net::URLRequestContextGetter* IOThread::system_url_request_context_getter() { 458 net::URLRequestContextGetter* IOThread::system_url_request_context_getter() {
459 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 459 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
460 if (!system_url_request_context_getter_.get()) { 460 if (!system_url_request_context_getter_.get()) {
461 InitSystemRequestContext(); 461 InitSystemRequestContext();
462 } 462 }
463 return system_url_request_context_getter_.get(); 463 return system_url_request_context_getter_.get();
464 } 464 }
465 465
466 void IOThread::Init() { 466 void IOThread::DoInitTasks() {
467 TRACE_EVENT0("startup", "IOThread::Init");
468 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
469
470 #if defined(USE_NSS) || defined(OS_IOS) 467 #if defined(USE_NSS) || defined(OS_IOS)
471 net::SetMessageLoopForNSSHttpIO(); 468 net::SetMessageLoopForNSSHttpIO();
472 #endif 469 #endif
473 470
474 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
475
476 DCHECK(!globals_); 471 DCHECK(!globals_);
477 globals_ = new Globals; 472 globals_ = new Globals;
478 473
474 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
475
479 // Add an observer that will emit network change events to the ChromeNetLog. 476 // Add an observer that will emit network change events to the ChromeNetLog.
480 // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be 477 // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be
481 // logging the network change before other IO thread consumers respond to it. 478 // logging the network change before other IO thread consumers respond to it.
482 network_change_observer_.reset( 479 network_change_observer_.reset(new LoggingNetworkChangeObserver(net_log_));
483 new LoggingNetworkChangeObserver(net_log_));
484 480
485 // Setup the HistogramWatcher to run on the IO thread. 481 // Setup the HistogramWatcher to run on the IO thread.
486 net::NetworkChangeNotifier::InitHistogramWatcher(); 482 net::NetworkChangeNotifier::InitHistogramWatcher();
487 483
488 globals_->extension_event_router_forwarder = 484 globals_->extension_event_router_forwarder =
489 extension_event_router_forwarder_; 485 extension_event_router_forwarder_;
490 ChromeNetworkDelegate* network_delegate = 486 ChromeNetworkDelegate* network_delegate = new ChromeNetworkDelegate(
491 new ChromeNetworkDelegate(extension_event_router_forwarder_, 487 extension_event_router_forwarder_, &system_enable_referrers_);
492 &system_enable_referrers_);
493 if (command_line.HasSwitch(switches::kDisableExtensionsHttpThrottling)) 488 if (command_line.HasSwitch(switches::kDisableExtensionsHttpThrottling))
494 network_delegate->NeverThrottleRequests(); 489 network_delegate->NeverThrottleRequests();
495 globals_->system_network_delegate.reset(network_delegate); 490 globals_->system_network_delegate.reset(network_delegate);
496 globals_->host_resolver = CreateGlobalHostResolver(net_log_); 491 globals_->host_resolver = CreateGlobalHostResolver(net_log_);
497 UpdateDnsClientEnabled(); 492 UpdateDnsClientEnabled();
498 globals_->cert_verifier.reset(net::CertVerifier::CreateDefault()); 493 globals_->cert_verifier.reset(net::CertVerifier::CreateDefault());
499 globals_->transport_security_state.reset(new net::TransportSecurityState()); 494 globals_->transport_security_state.reset(new net::TransportSecurityState());
500 globals_->ssl_config_service = GetSSLConfigService(); 495 globals_->ssl_config_service = GetSSLConfigService();
501 if (command_line.HasSwitch(switches::kSpdyProxyAuthOrigin)) { 496 if (command_line.HasSwitch(switches::kSpdyProxyAuthOrigin)) {
502 spdyproxy_auth_origin_ = 497 spdyproxy_auth_origin_ =
503 command_line.GetSwitchValueASCII(switches::kSpdyProxyAuthOrigin); 498 command_line.GetSwitchValueASCII(switches::kSpdyProxyAuthOrigin);
504 } else { 499 } else {
505 #if defined(SPDY_PROXY_AUTH_ORIGIN) 500 #if defined(SPDY_PROXY_AUTH_ORIGIN)
506 spdyproxy_auth_origin_ = SPDY_PROXY_AUTH_ORIGIN; 501 spdyproxy_auth_origin_ = SPDY_PROXY_AUTH_ORIGIN;
507 #endif 502 #endif
508 } 503 }
509 globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory( 504 globals_->http_auth_handler_factory
510 globals_->host_resolver.get())); 505 .reset(CreateDefaultAuthHandlerFactory(globals_->host_resolver.get()));
mmenke 2013/07/10 18:48:24 nit: For all of these, it's much more common acro
mmenke 2013/07/10 18:51:04 "On the same line as the object name", rather.
511 globals_->http_server_properties.reset(new net::HttpServerPropertiesImpl); 506 globals_->http_server_properties.reset(new net::HttpServerPropertiesImpl);
512 // For the ProxyScriptFetcher, we use a direct ProxyService. 507 // For the ProxyScriptFetcher, we use a direct ProxyService.
513 globals_->proxy_script_fetcher_proxy_service.reset( 508 globals_->proxy_script_fetcher_proxy_service
514 net::ProxyService::CreateDirectWithNetLog(net_log_)); 509 .reset(net::ProxyService::CreateDirectWithNetLog(net_log_));
515 // In-memory cookie store. 510 // In-memory cookie store.
516 globals_->system_cookie_store = new net::CookieMonster(NULL, NULL); 511 globals_->system_cookie_store = new net::CookieMonster(NULL, NULL);
517 // In-memory server bound cert store. 512 // In-memory server bound cert store.
518 globals_->system_server_bound_cert_service.reset( 513 globals_->system_server_bound_cert_service
519 new net::ServerBoundCertService( 514 .reset(new net::ServerBoundCertService(
520 new net::DefaultServerBoundCertStore(NULL), 515 new net::DefaultServerBoundCertStore(NULL),
521 base::WorkerPool::GetTaskRunner(true))); 516 base::WorkerPool::GetTaskRunner(true)));
522 globals_->dns_probe_service.reset(new chrome_browser_net::DnsProbeService()); 517 globals_->dns_probe_service.reset(new chrome_browser_net::DnsProbeService());
523 globals_->load_time_stats.reset(new chrome_browser_net::LoadTimeStats()); 518 globals_->load_time_stats.reset(new chrome_browser_net::LoadTimeStats());
524 globals_->host_mapping_rules.reset(new net::HostMappingRules()); 519 globals_->host_mapping_rules.reset(new net::HostMappingRules());
525 globals_->http_user_agent_settings.reset( 520 globals_->http_user_agent_settings
526 new BasicHttpUserAgentSettings(std::string())); 521 .reset(new BasicHttpUserAgentSettings(std::string()));
527 if (command_line.HasSwitch(switches::kHostRules)) { 522 if (command_line.HasSwitch(switches::kHostRules)) {
528 TRACE_EVENT_BEGIN0("startup", "IOThread::Init:SetRulesFromString"); 523 TRACE_EVENT_BEGIN0("startup", "IOThread::Init:SetRulesFromString");
529 globals_->host_mapping_rules->SetRulesFromString( 524 globals_->host_mapping_rules->SetRulesFromString(
530 command_line.GetSwitchValueASCII(switches::kHostRules)); 525 command_line.GetSwitchValueASCII(switches::kHostRules));
531 TRACE_EVENT_END0("startup", "IOThread::Init:SetRulesFromString"); 526 TRACE_EVENT_END0("startup", "IOThread::Init:SetRulesFromString");
532 } 527 }
533 if (command_line.HasSwitch(switches::kIgnoreCertificateErrors)) 528 if (command_line.HasSwitch(switches::kIgnoreCertificateErrors))
534 globals_->ignore_certificate_errors = true; 529 globals_->ignore_certificate_errors = true;
535 if (command_line.HasSwitch(switches::kTestingFixedHttpPort)) { 530 if (command_line.HasSwitch(switches::kTestingFixedHttpPort)) {
536 globals_->testing_fixed_http_port = 531 globals_->testing_fixed_http_port =
537 GetSwitchValueAsInt(command_line, switches::kTestingFixedHttpPort); 532 GetSwitchValueAsInt(command_line, switches::kTestingFixedHttpPort);
538 } 533 }
539 if (command_line.HasSwitch(switches::kTestingFixedHttpsPort)) { 534 if (command_line.HasSwitch(switches::kTestingFixedHttpsPort)) {
540 globals_->testing_fixed_https_port = 535 globals_->testing_fixed_https_port =
541 GetSwitchValueAsInt(command_line, switches::kTestingFixedHttpsPort); 536 GetSwitchValueAsInt(command_line, switches::kTestingFixedHttpsPort);
542 } 537 }
543 globals_->enable_quic.set(ShouldEnableQuic(command_line)); 538 globals_->enable_quic.set(ShouldEnableQuic(command_line));
544 if (command_line.HasSwitch(switches::kOriginToForceQuicOn)) { 539 if (command_line.HasSwitch(switches::kOriginToForceQuicOn)) {
545 net::HostPortPair quic_origin = 540 net::HostPortPair quic_origin = net::HostPortPair::FromString(
546 net::HostPortPair::FromString( 541 command_line.GetSwitchValueASCII(switches::kOriginToForceQuicOn));
547 command_line.GetSwitchValueASCII(switches::kOriginToForceQuicOn));
548 if (!quic_origin.IsEmpty()) { 542 if (!quic_origin.IsEmpty()) {
549 globals_->origin_to_force_quic_on.set(quic_origin); 543 globals_->origin_to_force_quic_on.set(quic_origin);
550 } 544 }
551 } 545 }
552 if (command_line.HasSwitch( 546 if (command_line.HasSwitch(switches::kEnableUserAlternateProtocolPorts)) {
553 switches::kEnableUserAlternateProtocolPorts)) {
554 globals_->enable_user_alternate_protocol_ports = true; 547 globals_->enable_user_alternate_protocol_ports = true;
555 } 548 }
556 InitializeNetworkOptions(command_line); 549 InitializeNetworkOptions(command_line);
557 550
558 net::HttpNetworkSession::Params session_params; 551 net::HttpNetworkSession::Params session_params;
559 InitializeNetworkSessionParams(&session_params); 552 InitializeNetworkSessionParams(&session_params);
560 session_params.net_log = net_log_; 553 session_params.net_log = net_log_;
561 session_params.proxy_service = 554 session_params.proxy_service =
562 globals_->proxy_script_fetcher_proxy_service.get(); 555 globals_->proxy_script_fetcher_proxy_service.get();
563 556
564 TRACE_EVENT_BEGIN0("startup", "IOThread::Init:HttpNetworkSession"); 557 TRACE_EVENT_BEGIN0("startup", "IOThread::Init:HttpNetworkSession");
565 scoped_refptr<net::HttpNetworkSession> network_session( 558 scoped_refptr<net::HttpNetworkSession> network_session(
566 new net::HttpNetworkSession(session_params)); 559 new net::HttpNetworkSession(session_params));
567 globals_->proxy_script_fetcher_http_transaction_factory 560 globals_->proxy_script_fetcher_http_transaction_factory
568 .reset(new net::HttpNetworkLayer(network_session.get())); 561 .reset(new net::HttpNetworkLayer(network_session.get()));
569 TRACE_EVENT_END0("startup", "IOThread::Init:HttpNetworkSession"); 562 TRACE_EVENT_END0("startup", "IOThread::Init:HttpNetworkSession");
570 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( 563 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory(
571 new net::URLRequestJobFactoryImpl()); 564 new net::URLRequestJobFactoryImpl());
572 job_factory->SetProtocolHandler(chrome::kDataScheme, 565 job_factory->SetProtocolHandler(chrome::kDataScheme,
573 new net::DataProtocolHandler()); 566 new net::DataProtocolHandler());
574 job_factory->SetProtocolHandler(chrome::kFileScheme, 567 job_factory->SetProtocolHandler(chrome::kFileScheme,
575 new net::FileProtocolHandler()); 568 new net::FileProtocolHandler());
576 #if !defined(DISABLE_FTP_SUPPORT) 569 #if !defined(DISABLE_FTP_SUPPORT)
577 globals_->proxy_script_fetcher_ftp_transaction_factory.reset( 570 globals_->proxy_script_fetcher_ftp_transaction_factory
578 new net::FtpNetworkLayer(globals_->host_resolver.get())); 571 .reset(new net::FtpNetworkLayer(globals_->host_resolver.get()));
579 job_factory->SetProtocolHandler( 572 job_factory->SetProtocolHandler(
580 chrome::kFtpScheme, 573 chrome::kFtpScheme,
581 new net::FtpProtocolHandler( 574 new net::FtpProtocolHandler(
582 globals_->proxy_script_fetcher_ftp_transaction_factory.get())); 575 globals_->proxy_script_fetcher_ftp_transaction_factory.get()));
583 #endif 576 #endif
584 globals_->proxy_script_fetcher_url_request_job_factory = 577 globals_->proxy_script_fetcher_url_request_job_factory =
585 job_factory.PassAs<net::URLRequestJobFactory>(); 578 job_factory.PassAs<net::URLRequestJobFactory>();
586 579
587 globals_->throttler_manager.reset(new net::URLRequestThrottlerManager()); 580 globals_->throttler_manager.reset(new net::URLRequestThrottlerManager());
588 globals_->throttler_manager->set_net_log(net_log_); 581 globals_->throttler_manager->set_net_log(net_log_);
589 // Always done in production, disabled only for unit tests. 582 // Always done in production, disabled only for unit tests.
590 globals_->throttler_manager->set_enable_thread_checks(true); 583 globals_->throttler_manager->set_enable_thread_checks(true);
591 584
592 globals_->proxy_script_fetcher_context.reset( 585 globals_->proxy_script_fetcher_context
593 ConstructProxyScriptFetcherContext(globals_, net_log_)); 586 .reset(ConstructProxyScriptFetcherContext(globals_, net_log_));
594 587
595 globals_->network_time_notifier.reset( 588 globals_->network_time_notifier.reset(new net::NetworkTimeNotifier(
596 new net::NetworkTimeNotifier( 589 scoped_ptr<base::TickClock>(new base::DefaultTickClock())));
597 scoped_ptr<base::TickClock>(new base::DefaultTickClock())));
598 590
599 sdch_manager_ = new net::SdchManager(); 591 sdch_manager_ = new net::SdchManager();
600 592
601 #if defined(OS_MACOSX) && !defined(OS_IOS) 593 #if defined(OS_MACOSX) && !defined(OS_IOS)
602 // Start observing Keychain events. This needs to be done on the UI thread, 594 // Start observing Keychain events. This needs to be done on the UI thread,
603 // as Keychain services requires a CFRunLoop. 595 // as Keychain services requires a CFRunLoop.
604 BrowserThread::PostTask(BrowserThread::UI, 596 BrowserThread::PostTask(
605 FROM_HERE, 597 BrowserThread::UI, FROM_HERE, base::Bind(&ObserveKeychainEvents));
606 base::Bind(&ObserveKeychainEvents));
607 #endif 598 #endif
608 599
609 // InitSystemRequestContext turns right around and posts a task back 600 // InitSystemRequestContext turns right around and posts a task back
610 // to the IO thread, so we can't let it run until we know the IO 601 // to the IO thread, so we can't let it run until we know the IO
611 // thread has started. 602 // thread has started.
612 // 603 //
613 // Note that since we are at BrowserThread::Init time, the UI thread 604 // Note that since we are at BrowserThread::Init time, the UI thread
614 // is blocked waiting for the thread to start. Therefore, posting 605 // is blocked waiting for the thread to start. Therefore, posting
615 // this task to the main thread's message loop here is guaranteed to 606 // this task to the main thread's message loop here is guaranteed to
616 // get it onto the message loop while the IOThread object still 607 // get it onto the message loop while the IOThread object still
617 // exists. However, the message might not be processed on the UI 608 // exists. However, the message might not be processed on the UI
618 // thread until after IOThread is gone, so use a weak pointer. 609 // thread until after IOThread is gone, so use a weak pointer.
619 BrowserThread::PostTask(BrowserThread::UI, 610 BrowserThread::PostTask(BrowserThread::UI,
620 FROM_HERE, 611 FROM_HERE,
621 base::Bind(&IOThread::InitSystemRequestContext, 612 base::Bind(&IOThread::InitSystemRequestContext,
622 weak_factory_.GetWeakPtr())); 613 weak_factory_.GetWeakPtr()));
623 } 614 }
624 615
616 void IOThread::Init() {
617 TRACE_EVENT0("startup", "IOThread::Init");
618 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
awong 2013/07/10 18:45:47 This confuses me... My understanding of the origi
619
620 BrowserThread::PostTask(
621 BrowserThread::IO,
622 FROM_HERE,
623 base::Bind(&IOThread::DoInitTasks, base::Unretained(this)));
624 }
625
625 void IOThread::CleanUp() { 626 void IOThread::CleanUp() {
626 base::debug::LeakTracker<SafeBrowsingURLRequestContext>::CheckForLeaks(); 627 base::debug::LeakTracker<SafeBrowsingURLRequestContext>::CheckForLeaks();
627 628
628 delete sdch_manager_; 629 delete sdch_manager_;
629 sdch_manager_ = NULL; 630 sdch_manager_ = NULL;
630 631
631 #if defined(USE_NSS) || defined(OS_IOS) 632 #if defined(USE_NSS) || defined(OS_IOS)
632 net::ShutdownNSSHttpIO(); 633 net::ShutdownNSSHttpIO();
633 #endif 634 #endif
634 635
635 system_url_request_context_getter_ = NULL; 636 system_url_request_context_getter_ = NULL;
636 637
637 // Release objects that the net::URLRequestContext could have been pointing 638 // Release objects that the net::URLRequestContext could have been pointing
638 // to. 639 // to.
639 640
640 // This must be reset before the ChromeNetLog is destroyed. 641 // This must be reset before the ChromeNetLog is destroyed.
641 network_change_observer_.reset(); 642 network_change_observer_.reset();
642 643
643 system_proxy_config_service_.reset(); 644 system_proxy_config_service_.reset();
644 645
645 delete globals_; 646 delete globals_;
646 globals_ = NULL; 647 globals_ = NULL;
647 648
648 base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks(); 649 base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks();
649 } 650 }
650 651
651 void IOThread::InitializeNetworkOptions(const CommandLine& command_line) { 652 void IOThread::InitializeNetworkOptions(const CommandLine& command_line) {
652 if (command_line.HasSwitch(switches::kEnableFileCookies)) { 653 if (command_line.HasSwitch(switches::kEnableFileCookies)) {
653 // Enable cookie storage for file:// URLs. Must do this before the first 654 // Enable cookie storage for file:// URLs. Must do this before the first
654 // Profile (and therefore the first CookieMonster) is created. 655 // Profile (and therefore the first CookieMonster) is created.
mmenke 2013/07/10 18:48:24 After this CL, this can actually be done after the
655 net::CookieMonster::EnableFileScheme(); 656 net::CookieMonster::EnableFileScheme();
656 } 657 }
657 658
658 // If "spdy.disabled" preference is controlled via policy, then skip use-spdy 659 // If "spdy.disabled" preference is controlled via policy, then skip use-spdy
659 // command line flags. 660 // command line flags.
660 if (is_spdy_disabled_by_policy_) 661 if (is_spdy_disabled_by_policy_)
661 return; 662 return;
662 663
663 if (command_line.HasSwitch(switches::kEnableIPPooling)) 664 if (command_line.HasSwitch(switches::kEnableIPPooling))
664 globals_->enable_spdy_ip_pooling.set(true); 665 globals_->enable_spdy_ip_pooling.set(true);
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 base::FieldTrialList::FindFullName(kQuicFieldTrialName); 961 base::FieldTrialList::FindFullName(kQuicFieldTrialName);
961 962
962 if (command_line.HasSwitch(switches::kDisableQuic)) 963 if (command_line.HasSwitch(switches::kDisableQuic))
963 return false; 964 return false;
964 965
965 if (command_line.HasSwitch(switches::kEnableQuic)) 966 if (command_line.HasSwitch(switches::kEnableQuic))
966 return true; 967 return true;
967 968
968 return quic_trial_group == kQuicFieldTrialEnabledGroupName; 969 return quic_trial_group == kQuicFieldTrialEnabledGroupName;
969 } 970 }
OLDNEW
« no previous file with comments | « chrome/browser/io_thread.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698