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

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

Issue 11415219: Move a number of static variables SPDY to HttpNetworkSession::Params. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix comments Created 8 years 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
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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 params->transport_security_state = globals.transport_security_state.get(); 232 params->transport_security_state = globals.transport_security_state.get();
233 params->ssl_config_service = globals.ssl_config_service.get(); 233 params->ssl_config_service = globals.ssl_config_service.get();
234 params->http_auth_handler_factory = globals.http_auth_handler_factory.get(); 234 params->http_auth_handler_factory = globals.http_auth_handler_factory.get();
235 params->http_server_properties = globals.http_server_properties.get(); 235 params->http_server_properties = globals.http_server_properties.get();
236 params->network_delegate = globals.system_network_delegate.get(); 236 params->network_delegate = globals.system_network_delegate.get();
237 params->host_mapping_rules = globals.host_mapping_rules.get(); 237 params->host_mapping_rules = globals.host_mapping_rules.get();
238 params->ignore_certificate_errors = globals.ignore_certificate_errors; 238 params->ignore_certificate_errors = globals.ignore_certificate_errors;
239 params->http_pipelining_enabled = globals.http_pipelining_enabled; 239 params->http_pipelining_enabled = globals.http_pipelining_enabled;
240 params->testing_fixed_http_port = globals.testing_fixed_http_port; 240 params->testing_fixed_http_port = globals.testing_fixed_http_port;
241 params->testing_fixed_https_port = globals.testing_fixed_https_port; 241 params->testing_fixed_https_port = globals.testing_fixed_https_port;
242 params->max_spdy_sessions_per_domain = globals.max_spdy_sessions_per_domain;
243 params->spdy_initial_max_concurrent_streams =
244 globals.initial_max_spdy_concurrent_streams;
245 params->spdy_max_concurrent_streams_limit =
246 globals.max_spdy_concurrent_streams_limit;
247
248 if (globals.force_spdy_single_domain != IOThread::DEFAULT)
249 params->force_spdy_single_domain = globals.force_spdy_single_domain;
250 if (globals.enable_spdy_ip_pooling != IOThread::DEFAULT)
251 params->enable_spdy_ip_pooling = globals.enable_spdy_ip_pooling;
Nico 2012/12/02 03:54:23 Does this even work? params->enabled_spdy_ip_pooli
Ryan Hamilton 2012/12/03 23:04:12 Ugh. Yes, that was a bug. At one point I had DEF
252 if (globals.enable_spdy_credential_frames != IOThread::DEFAULT) {
253 params->enable_spdy_credential_frames =
254 globals.enable_spdy_credential_frames;
255 }
256 if (globals.enable_spdy_compression != IOThread::DEFAULT)
257 params->enable_spdy_compression = globals.enable_spdy_compression;
258 if (globals.enable_spdy_ping_based_connection_checking != IOThread::DEFAULT) {
259 params->enable_spdy_ping_based_connection_checking =
260 globals.enable_spdy_ping_based_connection_checking;
261 }
262 if (globals.spdy_default_protocol != net::kProtoUnknown)
263 params->spdy_default_protocol = globals.spdy_default_protocol;
264 }
265
266 int GetSwitchValueAsInt(const CommandLine& command_line,
267 const std::string& switch_name) {
268 int value;
269 if (!base::StringToInt(command_line.GetSwitchValueASCII(switch_name),
270 &value)) {
271 return 0;
272 }
273 return value;
242 } 274 }
243 275
244 } // namespace 276 } // namespace
245 277
246 class IOThread::LoggingNetworkChangeObserver 278 class IOThread::LoggingNetworkChangeObserver
247 : public net::NetworkChangeNotifier::IPAddressObserver, 279 : public net::NetworkChangeNotifier::IPAddressObserver,
248 public net::NetworkChangeNotifier::ConnectionTypeObserver { 280 public net::NetworkChangeNotifier::ConnectionTypeObserver {
249 public: 281 public:
250 // |net_log| must remain valid throughout our lifetime. 282 // |net_log| must remain valid throughout our lifetime.
251 explicit LoggingNetworkChangeObserver(net::NetLog* net_log) 283 explicit LoggingNetworkChangeObserver(net::NetLog* net_log)
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 if (globals_->system_request_context.get()) 367 if (globals_->system_request_context.get())
336 globals_->system_request_context->AssertNoURLRequests(); 368 globals_->system_request_context->AssertNoURLRequests();
337 } 369 }
338 370
339 IOThread::Globals::Globals() 371 IOThread::Globals::Globals()
340 : ALLOW_THIS_IN_INITIALIZER_LIST( 372 : ALLOW_THIS_IN_INITIALIZER_LIST(
341 system_request_context_leak_checker(this)), 373 system_request_context_leak_checker(this)),
342 ignore_certificate_errors(false), 374 ignore_certificate_errors(false),
343 http_pipelining_enabled(false), 375 http_pipelining_enabled(false),
344 testing_fixed_http_port(0), 376 testing_fixed_http_port(0),
345 testing_fixed_https_port(0) {} 377 testing_fixed_https_port(0),
378 max_spdy_sessions_per_domain(0),
379 initial_max_spdy_concurrent_streams(0),
380 max_spdy_concurrent_streams_limit(0),
381 enable_spdy_ip_pooling(DEFAULT),
382 enable_spdy_credential_frames(DEFAULT),
383 enable_spdy_compression(DEFAULT),
384 enable_spdy_ping_based_connection_checking(DEFAULT),
385 spdy_default_protocol(net::kProtoUnknown) {}
346 386
347 IOThread::Globals::~Globals() {} 387 IOThread::Globals::~Globals() {}
348 388
349 // |local_state| is passed in explicitly in order to (1) reduce implicit 389 // |local_state| is passed in explicitly in order to (1) reduce implicit
350 // dependencies and (2) make IOThread more flexible for testing. 390 // dependencies and (2) make IOThread more flexible for testing.
351 IOThread::IOThread( 391 IOThread::IOThread(
352 PrefService* local_state, 392 PrefService* local_state,
353 policy::PolicyService* policy_service, 393 policy::PolicyService* policy_service,
354 ChromeNetLog* net_log, 394 ChromeNetLog* net_log,
355 extensions::EventRouterForwarder* extension_event_router_forwarder) 395 extensions::EventRouterForwarder* extension_event_router_forwarder)
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 new BasicHttpUserAgentSettings(EmptyString(), EmptyString())); 531 new BasicHttpUserAgentSettings(EmptyString(), EmptyString()));
492 if (command_line.HasSwitch(switches::kHostRules)) { 532 if (command_line.HasSwitch(switches::kHostRules)) {
493 globals_->host_mapping_rules->SetRulesFromString( 533 globals_->host_mapping_rules->SetRulesFromString(
494 command_line.GetSwitchValueASCII(switches::kHostRules)); 534 command_line.GetSwitchValueASCII(switches::kHostRules));
495 } 535 }
496 if (command_line.HasSwitch(switches::kIgnoreCertificateErrors)) 536 if (command_line.HasSwitch(switches::kIgnoreCertificateErrors))
497 globals_->ignore_certificate_errors = true; 537 globals_->ignore_certificate_errors = true;
498 if (command_line.HasSwitch(switches::kEnableHttpPipelining)) 538 if (command_line.HasSwitch(switches::kEnableHttpPipelining))
499 globals_->http_pipelining_enabled = true; 539 globals_->http_pipelining_enabled = true;
500 if (command_line.HasSwitch(switches::kTestingFixedHttpPort)) { 540 if (command_line.HasSwitch(switches::kTestingFixedHttpPort)) {
501 int value; 541 globals_->testing_fixed_http_port =
502 base::StringToInt( 542 GetSwitchValueAsInt(command_line, switches::kTestingFixedHttpPort);
503 command_line.GetSwitchValueASCII(
504 switches::kTestingFixedHttpPort),
505 &value);
506 globals_->testing_fixed_http_port = value;
507 } 543 }
508 if (command_line.HasSwitch(switches::kTestingFixedHttpsPort)) { 544 if (command_line.HasSwitch(switches::kTestingFixedHttpsPort)) {
509 int value; 545 globals_->testing_fixed_https_port =
510 base::StringToInt( 546 GetSwitchValueAsInt(command_line, switches::kTestingFixedHttpsPort);
511 command_line.GetSwitchValueASCII(
512 switches::kTestingFixedHttpsPort),
513 &value);
514 globals_->testing_fixed_https_port = value;
515 } 547 }
516 548
517 net::HttpNetworkSession::Params session_params; 549 net::HttpNetworkSession::Params session_params;
518 InitializeNetworkSessionParams(*globals_, &session_params); 550 InitializeNetworkSessionParams(*globals_, &session_params);
519 session_params.net_log = net_log_; 551 session_params.net_log = net_log_;
520 session_params.proxy_service = 552 session_params.proxy_service =
521 globals_->proxy_script_fetcher_proxy_service.get(); 553 globals_->proxy_script_fetcher_proxy_service.get();
522 554
523 InitializeNetworkOptions(command_line); 555 InitializeNetworkOptions(command_line);
524 556
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 network_change_observer_.reset(); 619 network_change_observer_.reset();
588 620
589 system_proxy_config_service_.reset(); 621 system_proxy_config_service_.reset();
590 622
591 delete globals_; 623 delete globals_;
592 globals_ = NULL; 624 globals_ = NULL;
593 625
594 base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks(); 626 base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks();
595 } 627 }
596 628
597 void IOThread::InitializeNetworkOptions( 629 void IOThread::InitializeNetworkOptions(const CommandLine& command_line) {
598 const CommandLine& parsed_command_line) { 630 if (command_line.HasSwitch(switches::kEnableFileCookies)) {
599 if (parsed_command_line.HasSwitch(switches::kEnableFileCookies)) {
600 // Enable cookie storage for file:// URLs. Must do this before the first 631 // Enable cookie storage for file:// URLs. Must do this before the first
601 // Profile (and therefore the first CookieMonster) is created. 632 // Profile (and therefore the first CookieMonster) is created.
602 net::CookieMonster::EnableFileScheme(); 633 net::CookieMonster::EnableFileScheme();
603 } 634 }
604 635
605 // If "spdy.disabled" preference is controlled via policy, then skip use-spdy 636 // If "spdy.disabled" preference is controlled via policy, then skip use-spdy
606 // command line flags. 637 // command line flags.
607 if (is_spdy_disabled_by_policy_) 638 if (is_spdy_disabled_by_policy_)
608 return; 639 return;
609 640
610 if (parsed_command_line.HasSwitch(switches::kEnableIPPooling)) 641 if (command_line.HasSwitch(switches::kMaxSpdySessionsPerDomain)) {
611 net::SpdySessionPool::enable_ip_pooling(true); 642 globals_->max_spdy_sessions_per_domain =
612 643 GetSwitchValueAsInt(command_line, switches::kMaxSpdySessionsPerDomain);
613 if (parsed_command_line.HasSwitch(switches::kDisableIPPooling))
614 net::SpdySessionPool::enable_ip_pooling(false);
615
616 if (parsed_command_line.HasSwitch(switches::kEnableSpdyCredentialFrames))
617 net::SpdySession::set_enable_credential_frames(true);
618 if (parsed_command_line.HasSwitch(switches::kMaxSpdySessionsPerDomain)) {
619 int value;
620 base::StringToInt(
621 parsed_command_line.GetSwitchValueASCII(
622 switches::kMaxSpdySessionsPerDomain),
623 &value);
624 net::SpdySessionPool::set_max_sessions_per_domain(value);
625 } 644 }
626 645
627 if (parsed_command_line.HasSwitch(switches::kEnableWebSocketOverSpdy)) { 646 if (command_line.HasSwitch(switches::kEnableIPPooling))
647 globals_->enable_spdy_ip_pooling = TRUE;
648
649 if (command_line.HasSwitch(switches::kDisableIPPooling))
650 globals_->enable_spdy_ip_pooling = FALSE;
651
652 if (command_line.HasSwitch(switches::kEnableSpdyCredentialFrames))
653 globals_->enable_spdy_credential_frames = TRUE;
654
655 if (command_line.HasSwitch(switches::kEnableWebSocketOverSpdy)) {
628 // Enable WebSocket over SPDY. 656 // Enable WebSocket over SPDY.
629 net::WebSocketJob::set_websocket_over_spdy_enabled(true); 657 net::WebSocketJob::set_websocket_over_spdy_enabled(true);
630 } 658 }
631 659
632 bool used_spdy_switch = false; 660 bool used_spdy_switch = false;
633 if (parsed_command_line.HasSwitch(switches::kUseSpdy)) { 661 if (command_line.HasSwitch(switches::kUseSpdy)) {
634 std::string spdy_mode = 662 std::string spdy_mode =
635 parsed_command_line.GetSwitchValueASCII(switches::kUseSpdy); 663 command_line.GetSwitchValueASCII(switches::kUseSpdy);
636 EnableSpdy(spdy_mode); 664 EnableSpdy(spdy_mode);
637 used_spdy_switch = true; 665 used_spdy_switch = true;
638 } 666 }
639 if (parsed_command_line.HasSwitch(switches::kEnableSpdy3)) { 667 if (command_line.HasSwitch(switches::kEnableSpdy3)) {
640 net::HttpStreamFactory::EnableNpnSpdy3(); 668 net::HttpStreamFactory::EnableNpnSpdy3();
641 used_spdy_switch = true; 669 used_spdy_switch = true;
642 } else if (parsed_command_line.HasSwitch(switches::kEnableNpn)) { 670 } else if (command_line.HasSwitch(switches::kEnableNpn)) {
643 net::HttpStreamFactory::EnableNpnSpdy(); 671 net::HttpStreamFactory::EnableNpnSpdy();
644 used_spdy_switch = true; 672 used_spdy_switch = true;
645 } else if (parsed_command_line.HasSwitch(switches::kEnableNpnHttpOnly)) { 673 } else if (command_line.HasSwitch(switches::kEnableNpnHttpOnly)) {
646 net::HttpStreamFactory::EnableNpnHttpOnly(); 674 net::HttpStreamFactory::EnableNpnHttpOnly();
647 used_spdy_switch = true; 675 used_spdy_switch = true;
648 } 676 }
649 if (!used_spdy_switch) { 677 if (!used_spdy_switch) {
650 net::HttpStreamFactory::EnableNpnSpdy3(); 678 net::HttpStreamFactory::EnableNpnSpdy3();
651 } 679 }
680 if (command_line.HasSwitch(switches::kMaxSpdyConcurrentStreams)) {
681 globals_->max_spdy_concurrent_streams_limit =
682 GetSwitchValueAsInt(command_line, switches::kMaxSpdyConcurrentStreams);
683 }
652 } 684 }
653 685
654 void IOThread::EnableSpdy(const std::string& mode) { 686 void IOThread::EnableSpdy(const std::string& mode) {
655 static const char kOff[] = "off"; 687 static const char kOff[] = "off";
656 static const char kSSL[] = "ssl"; 688 static const char kSSL[] = "ssl";
657 static const char kDisableSSL[] = "no-ssl"; 689 static const char kDisableSSL[] = "no-ssl";
658 static const char kDisablePing[] = "no-ping"; 690 static const char kDisablePing[] = "no-ping";
659 static const char kExclude[] = "exclude"; // Hosts to exclude 691 static const char kExclude[] = "exclude"; // Hosts to exclude
660 static const char kDisableCompression[] = "no-compress"; 692 static const char kDisableCompression[] = "no-compress";
661 static const char kDisableAltProtocols[] = "no-alt-protocols"; 693 static const char kDisableAltProtocols[] = "no-alt-protocols";
662 static const char kForceAltProtocols[] = "force-alt-protocols"; 694 static const char kForceAltProtocols[] = "force-alt-protocols";
663 static const char kSingleDomain[] = "single-domain"; 695 static const char kSingleDomain[] = "single-domain";
664 696
665 static const char kInitialMaxConcurrentStreams[] = "init-max-streams"; 697 static const char kInitialMaxConcurrentStreams[] = "init-max-streams";
666 698
667 std::vector<std::string> spdy_options; 699 std::vector<std::string> spdy_options;
668 base::SplitString(mode, ',', &spdy_options); 700 base::SplitString(mode, ',', &spdy_options);
669 701
670 for (std::vector<std::string>::iterator it = spdy_options.begin(); 702 for (std::vector<std::string>::iterator it = spdy_options.begin();
671 it != spdy_options.end(); ++it) { 703 it != spdy_options.end(); ++it) {
672 const std::string& element = *it; 704 const std::string& element = *it;
673 std::vector<std::string> name_value; 705 std::vector<std::string> name_value;
674 base::SplitString(element, '=', &name_value); 706 base::SplitString(element, '=', &name_value);
675 const std::string& option = name_value.size() > 0 ? name_value[0] : ""; 707 const std::string& option = name_value.size() > 0 ? name_value[0] : "";
676 const std::string value = name_value.size() > 1 ? name_value[1] : ""; 708 const std::string value = name_value.size() > 1 ? name_value[1] : "";
677 709
678 if (option == kOff) { 710 if (option == kOff) {
679 net::HttpStreamFactory::set_spdy_enabled(false); 711 net::HttpStreamFactory::set_spdy_enabled(false);
680 } else if (option == kDisableSSL) { 712 } else if (option == kDisableSSL) {
681 net::SpdySession::set_default_protocol(net::kProtoSPDY2); 713 globals_->spdy_default_protocol = net::kProtoSPDY2;
682 net::HttpStreamFactory::set_force_spdy_over_ssl(false); 714 net::HttpStreamFactory::set_force_spdy_over_ssl(false);
683 net::HttpStreamFactory::set_force_spdy_always(true); 715 net::HttpStreamFactory::set_force_spdy_always(true);
684 } else if (option == kSSL) { 716 } else if (option == kSSL) {
685 net::SpdySession::set_default_protocol(net::kProtoSPDY2); 717 globals_->spdy_default_protocol = net::kProtoSPDY2;
686 net::HttpStreamFactory::set_force_spdy_over_ssl(true); 718 net::HttpStreamFactory::set_force_spdy_over_ssl(true);
687 net::HttpStreamFactory::set_force_spdy_always(true); 719 net::HttpStreamFactory::set_force_spdy_always(true);
688 } else if (option == kDisablePing) { 720 } else if (option == kDisablePing) {
689 net::SpdySession::set_enable_ping_based_connection_checking(false); 721 globals_->enable_spdy_ping_based_connection_checking = FALSE;
690 } else if (option == kExclude) { 722 } else if (option == kExclude) {
691 net::HttpStreamFactory::add_forced_spdy_exclusion(value); 723 net::HttpStreamFactory::add_forced_spdy_exclusion(value);
692 } else if (option == kDisableCompression) { 724 } else if (option == kDisableCompression) {
693 net::BufferedSpdyFramer::set_enable_compression_default(false); 725 globals_->enable_spdy_compression = FALSE;
694 } else if (option == kDisableAltProtocols) { 726 } else if (option == kDisableAltProtocols) {
695 net::HttpStreamFactory::set_use_alternate_protocols(false); 727 net::HttpStreamFactory::set_use_alternate_protocols(false);
696 } else if (option == kForceAltProtocols) { 728 } else if (option == kForceAltProtocols) {
697 net::PortAlternateProtocolPair pair; 729 net::PortAlternateProtocolPair pair;
698 pair.port = 443; 730 pair.port = 443;
699 pair.protocol = net::NPN_SPDY_2; 731 pair.protocol = net::NPN_SPDY_2;
700 net::HttpServerPropertiesImpl::ForceAlternateProtocol(pair); 732 net::HttpServerPropertiesImpl::ForceAlternateProtocol(pair);
701 } else if (option == kSingleDomain) { 733 } else if (option == kSingleDomain) {
702 DLOG(INFO) << "FORCING SINGLE DOMAIN"; 734 DLOG(INFO) << "FORCING SINGLE DOMAIN";
703 net::SpdySessionPool::ForceSingleDomain(); 735 globals_->force_spdy_single_domain = TRUE;
704 } else if (option == kInitialMaxConcurrentStreams) { 736 } else if (option == kInitialMaxConcurrentStreams) {
705 int streams; 737 int streams;
706 if (base::StringToInt(value, &streams) && streams > 0) 738 if (base::StringToInt(value, &streams))
707 net::SpdySession::set_init_max_concurrent_streams(streams); 739 globals_->initial_max_spdy_concurrent_streams = streams;
708 } else if (option.empty() && it == spdy_options.begin()) { 740 } else if (option.empty() && it == spdy_options.begin()) {
709 continue; 741 continue;
710 } else { 742 } else {
711 LOG(DFATAL) << "Unrecognized spdy option: " << option; 743 LOG(DFATAL) << "Unrecognized spdy option: " << option;
712 } 744 }
713 } 745 }
714 } 746 }
715 747
716 // static 748 // static
717 void IOThread::RegisterPrefs(PrefService* local_state) { 749 void IOThread::RegisterPrefs(PrefService* local_state) {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 globals_->system_request_context.reset( 876 globals_->system_request_context.reset(
845 ConstructSystemRequestContext(globals_, net_log_)); 877 ConstructSystemRequestContext(globals_, net_log_));
846 878
847 sdch_manager_->set_sdch_fetcher( 879 sdch_manager_->set_sdch_fetcher(
848 new SdchDictionaryFetcher(system_url_request_context_getter_.get())); 880 new SdchDictionaryFetcher(system_url_request_context_getter_.get()));
849 } 881 }
850 882
851 void IOThread::UpdateDnsClientEnabled() { 883 void IOThread::UpdateDnsClientEnabled() {
852 globals()->host_resolver->SetDnsClientEnabled(*dns_client_enabled_); 884 globals()->host_resolver->SetDnsClientEnabled(*dns_client_enabled_);
853 } 885 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698