Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 // * A "holdback" group with SPDY disabled, and corresponding control | 129 // * A "holdback" group with SPDY disabled, and corresponding control |
| 130 // (SPDY/3.1). The primary purpose of the holdback group is to encourage site | 130 // (SPDY/3.1). The primary purpose of the holdback group is to encourage site |
| 131 // operators to do feature detection rather than UA-sniffing. As such, this | 131 // operators to do feature detection rather than UA-sniffing. As such, this |
| 132 // trial runs continuously. | 132 // trial runs continuously. |
| 133 // * A SPDY/4 experiment, for SPDY/4 (aka HTTP/2) vs SPDY/3.1 comparisons and | 133 // * A SPDY/4 experiment, for SPDY/4 (aka HTTP/2) vs SPDY/3.1 comparisons and |
| 134 // eventual SPDY/4 deployment. | 134 // eventual SPDY/4 deployment. |
| 135 const char kSpdyFieldTrialName[] = "SPDY"; | 135 const char kSpdyFieldTrialName[] = "SPDY"; |
| 136 const char kSpdyFieldTrialHoldbackGroupNamePrefix[] = "SpdyDisabled"; | 136 const char kSpdyFieldTrialHoldbackGroupNamePrefix[] = "SpdyDisabled"; |
| 137 const char kSpdyFieldTrialSpdy31GroupNamePrefix[] = "Spdy31Enabled"; | 137 const char kSpdyFieldTrialSpdy31GroupNamePrefix[] = "Spdy31Enabled"; |
| 138 const char kSpdyFieldTrialSpdy4GroupNamePrefix[] = "Spdy4Enabled"; | 138 const char kSpdyFieldTrialSpdy4GroupNamePrefix[] = "Spdy4Enabled"; |
| 139 const char kSpdyFieldTrialParametrizedPrefix[] = "Parametrized"; | |
| 139 | 140 |
| 140 // Field trial for Cache-Control: stale-while-revalidate directive. | 141 // Field trial for Cache-Control: stale-while-revalidate directive. |
| 141 const char kStaleWhileRevalidateFieldTrialName[] = "StaleWhileRevalidate"; | 142 const char kStaleWhileRevalidateFieldTrialName[] = "StaleWhileRevalidate"; |
| 142 | 143 |
| 143 #if defined(OS_MACOSX) && !defined(OS_IOS) | 144 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 144 void ObserveKeychainEvents() { | 145 void ObserveKeychainEvents() { |
| 145 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 146 net::CertDatabase::GetInstance()->SetMessageLoopForKeychainEvents(); | 147 net::CertDatabase::GetInstance()->SetMessageLoopForKeychainEvents(); |
| 147 } | 148 } |
| 148 #endif | 149 #endif |
| (...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 858 } | 859 } |
| 859 | 860 |
| 860 void IOThread::InitializeNetworkOptions(const base::CommandLine& command_line) { | 861 void IOThread::InitializeNetworkOptions(const base::CommandLine& command_line) { |
| 861 // Only handle use-spdy command line flags if "spdy.disabled" preference is | 862 // Only handle use-spdy command line flags if "spdy.disabled" preference is |
| 862 // not disabled via policy. | 863 // not disabled via policy. |
| 863 if (is_spdy_disabled_by_policy_) { | 864 if (is_spdy_disabled_by_policy_) { |
| 864 base::FieldTrial* trial = base::FieldTrialList::Find(kSpdyFieldTrialName); | 865 base::FieldTrial* trial = base::FieldTrialList::Find(kSpdyFieldTrialName); |
| 865 if (trial) | 866 if (trial) |
| 866 trial->Disable(); | 867 trial->Disable(); |
| 867 } else { | 868 } else { |
| 868 if (command_line.HasSwitch(switches::kTrustedSpdyProxy)) { | 869 std::string group = base::FieldTrialList::FindFullName(kSpdyFieldTrialName); |
| 869 globals_->trusted_spdy_proxy.set( | 870 VariationParameters params; |
| 870 command_line.GetSwitchValueASCII(switches::kTrustedSpdyProxy)); | 871 if (!variations::GetVariationParams(kSpdyFieldTrialName, ¶ms)) { |
| 872 params.clear(); | |
| 871 } | 873 } |
| 872 if (command_line.HasSwitch(switches::kIgnoreUrlFetcherCertRequests)) | 874 ConfigureSpdyGlobals(command_line, group, params, globals_); |
| 873 net::URLFetcher::SetIgnoreCertificateRequests(true); | |
| 874 | |
| 875 if (command_line.HasSwitch(switches::kUseSpdy)) { | |
| 876 std::string spdy_mode = | |
| 877 command_line.GetSwitchValueASCII(switches::kUseSpdy); | |
| 878 EnableSpdy(spdy_mode); | |
| 879 } else if (command_line.HasSwitch(switches::kEnableSpdy4)) { | |
| 880 globals_->next_protos = net::NextProtosSpdy4Http2(); | |
| 881 globals_->use_alternate_protocols.set(true); | |
| 882 } else if (command_line.HasSwitch(switches::kEnableNpnHttpOnly)) { | |
| 883 globals_->next_protos = net::NextProtosHttpOnly(); | |
| 884 globals_->use_alternate_protocols.set(false); | |
| 885 } else { | |
| 886 // No SPDY command-line flags have been specified. Examine trial groups. | |
| 887 ConfigureSpdyFromTrial( | |
| 888 base::FieldTrialList::FindFullName(kSpdyFieldTrialName), globals_); | |
| 889 } | |
| 890 } | 875 } |
| 891 | 876 |
| 892 ConfigureTCPFastOpen(command_line); | 877 ConfigureTCPFastOpen(command_line); |
| 893 ConfigureSdch(); | 878 ConfigureSdch(); |
| 894 | 879 |
| 895 // TODO(rch): Make the client socket factory a per-network session | 880 // TODO(rch): Make the client socket factory a per-network session |
| 896 // instance, constructed from a NetworkSession::Params, to allow us | 881 // instance, constructed from a NetworkSession::Params, to allow us |
| 897 // to move this option to IOThread::Globals & | 882 // to move this option to IOThread::Globals & |
| 898 // HttpNetworkSession::Params. | 883 // HttpNetworkSession::Params. |
| 899 } | 884 } |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 923 base::FieldTrialList::FindFullName(kSdchFieldTrialName); | 908 base::FieldTrialList::FindFullName(kSdchFieldTrialName); |
| 924 base::StringPiece sdch_trial_group(sdch_trial_group_string); | 909 base::StringPiece sdch_trial_group(sdch_trial_group_string); |
| 925 if (sdch_trial_group.starts_with(kEnabledHttpOnlyGroupName)) { | 910 if (sdch_trial_group.starts_with(kEnabledHttpOnlyGroupName)) { |
| 926 net::SdchManager::EnableSdchSupport(true); | 911 net::SdchManager::EnableSdchSupport(true); |
| 927 net::SdchManager::EnableSecureSchemeSupport(false); | 912 net::SdchManager::EnableSecureSchemeSupport(false); |
| 928 } else if (sdch_trial_group.starts_with(kDisabledAllGroupName)) { | 913 } else if (sdch_trial_group.starts_with(kDisabledAllGroupName)) { |
| 929 net::SdchManager::EnableSdchSupport(false); | 914 net::SdchManager::EnableSdchSupport(false); |
| 930 } | 915 } |
| 931 } | 916 } |
| 932 | 917 |
| 933 void IOThread::ConfigureSpdyFromTrial(base::StringPiece spdy_trial_group, | 918 // static |
| 934 Globals* globals) { | 919 void IOThread::ConfigureSpdyGlobals( |
| 935 if (spdy_trial_group.starts_with(kSpdyFieldTrialHoldbackGroupNamePrefix)) { | 920 const base::CommandLine& command_line, |
| 936 // TODO(jgraettinger): Use net::NextProtosHttpOnly() instead? | 921 base::StringPiece spdy_trial_group, |
| 937 net::HttpStreamFactory::set_spdy_enabled(false); | 922 const VariationParameters& spdy_trial_params, |
| 938 } else if (spdy_trial_group.starts_with( | 923 IOThread::Globals* globals) { |
| 939 kSpdyFieldTrialSpdy31GroupNamePrefix)) { | 924 if (command_line.HasSwitch(switches::kTrustedSpdyProxy)) { |
| 940 globals->next_protos = net::NextProtosSpdy31(); | 925 globals->trusted_spdy_proxy.set( |
| 926 command_line.GetSwitchValueASCII(switches::kTrustedSpdyProxy)); | |
| 927 } | |
| 928 if (command_line.HasSwitch(switches::kIgnoreUrlFetcherCertRequests)) | |
| 929 net::URLFetcher::SetIgnoreCertificateRequests(true); | |
| 930 | |
| 931 if (command_line.HasSwitch(switches::kUseSpdy)) { | |
|
Ryan Hamilton
2015/03/20 23:38:07
Let's use early-return to clean up this mess :>
i
Bence
2015/03/23 14:19:13
Done.
| |
| 932 std::string spdy_mode = | |
| 933 command_line.GetSwitchValueASCII(switches::kUseSpdy); | |
| 934 EnableSpdy(spdy_mode, globals); | |
|
Ryan Hamilton
2015/03/20 23:38:07
Ah, so here's the one place this method is called.
Bence
2015/03/23 14:19:13
Great idea. Done.
| |
| 935 } else if (command_line.HasSwitch(switches::kEnableSpdy4)) { | |
| 936 globals->next_protos = net::NextProtos(true, true, true, true); | |
| 941 globals->use_alternate_protocols.set(true); | 937 globals->use_alternate_protocols.set(true); |
| 942 } else if (spdy_trial_group.starts_with( | 938 } else if (command_line.HasSwitch(switches::kEnableNpnHttpOnly)) { |
| 943 kSpdyFieldTrialSpdy4GroupNamePrefix)) { | 939 globals->next_protos = net::NextProtos(false, false, false, false); |
| 944 globals->next_protos = net::NextProtosSpdy4Http2(); | 940 globals->use_alternate_protocols.set(false); |
| 945 globals->use_alternate_protocols.set(true); | |
| 946 } else { | 941 } else { |
| 947 // By default, enable HTTP/2. | 942 // No SPDY command-line flags have been specified. Examine trial groups. |
| 948 globals->next_protos = net::NextProtosSpdy4Http2(); | 943 if (spdy_trial_group.starts_with(kSpdyFieldTrialHoldbackGroupNamePrefix)) { |
| 949 globals->use_alternate_protocols.set(true); | 944 // TODO(jgraettinger): Use net::NextProtosHttpOnly() instead? |
| 945 net::HttpStreamFactory::set_spdy_enabled(false); | |
| 946 } else if (spdy_trial_group.starts_with( | |
| 947 kSpdyFieldTrialSpdy31GroupNamePrefix)) { | |
| 948 globals->next_protos = net::NextProtosSpdy31(); | |
| 949 globals->use_alternate_protocols.set(true); | |
| 950 } else if (spdy_trial_group.starts_with( | |
| 951 kSpdyFieldTrialSpdy4GroupNamePrefix)) { | |
| 952 globals->next_protos = net::NextProtos(true, true, true, true); | |
| 953 globals->use_alternate_protocols.set(true); | |
| 954 } else if (spdy_trial_group.starts_with( | |
| 955 kSpdyFieldTrialParametrizedPrefix)) { | |
| 956 bool quic_enabled = LowerCaseEqualsASCII( | |
| 957 GetVariationParam(spdy_trial_params, "quic_enabled"), "true"); | |
|
Ryan Hamilton
2015/03/20 23:38:07
I think this is going to fight with the QUIC field
Bence
2015/03/23 14:19:13
Good point. I have the impression that this is pr
| |
| 958 bool spdy31_enabled = LowerCaseEqualsASCII( | |
| 959 GetVariationParam(spdy_trial_params, "spdy31_enabled"), "true"); | |
| 960 bool h2_14_enabled = LowerCaseEqualsASCII( | |
| 961 GetVariationParam(spdy_trial_params, "h2_14_enabled"), "true"); | |
| 962 bool h2_enabled = LowerCaseEqualsASCII( | |
| 963 GetVariationParam(spdy_trial_params, "h2_enabled"), "true"); | |
| 964 globals->next_protos = net::NextProtos(quic_enabled, spdy31_enabled, | |
| 965 h2_14_enabled, h2_enabled); | |
| 966 globals->use_alternate_protocols.set(true); | |
| 967 } else { | |
| 968 // By default, enable HTTP/2. | |
| 969 globals->next_protos = net::NextProtos(true, true, true, true); | |
| 970 globals->use_alternate_protocols.set(true); | |
| 971 } | |
| 950 } | 972 } |
| 951 } | 973 } |
| 952 | 974 |
| 953 void IOThread::EnableSpdy(const std::string& mode) { | 975 // static |
| 976 void IOThread::EnableSpdy(const std::string& mode, IOThread::Globals* globals) { | |
| 954 static const char kOff[] = "off"; | 977 static const char kOff[] = "off"; |
| 955 static const char kSSL[] = "ssl"; | 978 static const char kSSL[] = "ssl"; |
| 956 static const char kDisableSSL[] = "no-ssl"; | 979 static const char kDisableSSL[] = "no-ssl"; |
| 957 static const char kDisablePing[] = "no-ping"; | 980 static const char kDisablePing[] = "no-ping"; |
| 958 static const char kExclude[] = "exclude"; // Hosts to exclude | 981 static const char kExclude[] = "exclude"; // Hosts to exclude |
| 959 static const char kDisableCompression[] = "no-compress"; | 982 static const char kDisableCompression[] = "no-compress"; |
| 960 static const char kDisableAltProtocols[] = "no-alt-protocols"; | 983 static const char kDisableAltProtocols[] = "no-alt-protocols"; |
| 961 static const char kForceAltProtocols[] = "force-alt-protocols"; | 984 static const char kForceAltProtocols[] = "force-alt-protocols"; |
| 962 static const char kSingleDomain[] = "single-domain"; | 985 static const char kSingleDomain[] = "single-domain"; |
| 963 | 986 |
| 964 static const char kInitialMaxConcurrentStreams[] = "init-max-streams"; | 987 static const char kInitialMaxConcurrentStreams[] = "init-max-streams"; |
| 965 | 988 |
| 966 std::vector<std::string> spdy_options; | 989 std::vector<std::string> spdy_options; |
| 967 base::SplitString(mode, ',', &spdy_options); | 990 base::SplitString(mode, ',', &spdy_options); |
| 968 | 991 |
| 969 for (std::vector<std::string>::iterator it = spdy_options.begin(); | 992 for (std::vector<std::string>::iterator it = spdy_options.begin(); |
| 970 it != spdy_options.end(); ++it) { | 993 it != spdy_options.end(); ++it) { |
| 971 const std::string& element = *it; | 994 const std::string& element = *it; |
| 972 std::vector<std::string> name_value; | 995 std::vector<std::string> name_value; |
| 973 base::SplitString(element, '=', &name_value); | 996 base::SplitString(element, '=', &name_value); |
| 974 const std::string& option = | 997 const std::string& option = |
| 975 name_value.size() > 0 ? name_value[0] : std::string(); | 998 name_value.size() > 0 ? name_value[0] : std::string(); |
| 976 const std::string value = | 999 const std::string value = |
| 977 name_value.size() > 1 ? name_value[1] : std::string(); | 1000 name_value.size() > 1 ? name_value[1] : std::string(); |
| 978 | 1001 |
| 979 if (option == kOff) { | 1002 if (option == kOff) { |
| 980 net::HttpStreamFactory::set_spdy_enabled(false); | 1003 net::HttpStreamFactory::set_spdy_enabled(false); |
| 981 } else if (option == kDisableSSL) { | 1004 } else if (option == kDisableSSL) { |
| 982 globals_->spdy_default_protocol.set(net::kProtoSPDY31); | 1005 globals->spdy_default_protocol.set(net::kProtoSPDY31); |
| 983 globals_->force_spdy_over_ssl.set(false); | 1006 globals->force_spdy_over_ssl.set(false); |
| 984 globals_->force_spdy_always.set(true); | 1007 globals->force_spdy_always.set(true); |
| 985 } else if (option == kSSL) { | 1008 } else if (option == kSSL) { |
| 986 globals_->spdy_default_protocol.set(net::kProtoSPDY31); | 1009 globals->spdy_default_protocol.set(net::kProtoSPDY31); |
| 987 globals_->force_spdy_over_ssl.set(true); | 1010 globals->force_spdy_over_ssl.set(true); |
| 988 globals_->force_spdy_always.set(true); | 1011 globals->force_spdy_always.set(true); |
| 989 } else if (option == kDisablePing) { | 1012 } else if (option == kDisablePing) { |
| 990 globals_->enable_spdy_ping_based_connection_checking.set(false); | 1013 globals->enable_spdy_ping_based_connection_checking.set(false); |
| 991 } else if (option == kExclude) { | 1014 } else if (option == kExclude) { |
| 992 globals_->forced_spdy_exclusions.insert( | 1015 globals->forced_spdy_exclusions.insert( |
| 993 net::HostPortPair::FromURL(GURL(value))); | 1016 net::HostPortPair::FromURL(GURL(value))); |
| 994 } else if (option == kDisableCompression) { | 1017 } else if (option == kDisableCompression) { |
| 995 globals_->enable_spdy_compression.set(false); | 1018 globals->enable_spdy_compression.set(false); |
| 996 } else if (option == kDisableAltProtocols) { | 1019 } else if (option == kDisableAltProtocols) { |
| 997 globals_->use_alternate_protocols.set(false); | 1020 globals->use_alternate_protocols.set(false); |
| 998 } else if (option == kForceAltProtocols) { | 1021 } else if (option == kForceAltProtocols) { |
| 999 net::AlternateProtocolInfo pair(443, net::NPN_SPDY_3, 1); | 1022 net::AlternateProtocolInfo pair(443, net::NPN_SPDY_3, 1); |
| 1000 net::HttpServerPropertiesImpl::ForceAlternateProtocol(pair); | 1023 net::HttpServerPropertiesImpl::ForceAlternateProtocol(pair); |
| 1001 } else if (option == kSingleDomain) { | 1024 } else if (option == kSingleDomain) { |
| 1002 DVLOG(1) << "FORCING SINGLE DOMAIN"; | 1025 DVLOG(1) << "FORCING SINGLE DOMAIN"; |
| 1003 globals_->force_spdy_single_domain.set(true); | 1026 globals->force_spdy_single_domain.set(true); |
| 1004 } else if (option == kInitialMaxConcurrentStreams) { | 1027 } else if (option == kInitialMaxConcurrentStreams) { |
| 1005 int streams; | 1028 int streams; |
| 1006 if (base::StringToInt(value, &streams)) | 1029 if (base::StringToInt(value, &streams)) |
| 1007 globals_->initial_max_spdy_concurrent_streams.set(streams); | 1030 globals->initial_max_spdy_concurrent_streams.set(streams); |
| 1008 } else if (option.empty() && it == spdy_options.begin()) { | 1031 } else if (option.empty() && it == spdy_options.begin()) { |
| 1009 continue; | 1032 continue; |
| 1010 } else { | 1033 } else { |
| 1011 LOG(DFATAL) << "Unrecognized spdy option: " << option; | 1034 LOG(DFATAL) << "Unrecognized spdy option: " << option; |
| 1012 } | 1035 } |
| 1013 } | 1036 } |
| 1014 } | 1037 } |
| 1015 | 1038 |
| 1016 // static | 1039 // static |
| 1017 void IOThread::RegisterPrefs(PrefRegistrySimple* registry) { | 1040 void IOThread::RegisterPrefs(PrefRegistrySimple* registry) { |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1514 net::QuicVersionVector supported_versions = net::QuicSupportedVersions(); | 1537 net::QuicVersionVector supported_versions = net::QuicSupportedVersions(); |
| 1515 for (size_t i = 0; i < supported_versions.size(); ++i) { | 1538 for (size_t i = 0; i < supported_versions.size(); ++i) { |
| 1516 net::QuicVersion version = supported_versions[i]; | 1539 net::QuicVersion version = supported_versions[i]; |
| 1517 if (net::QuicVersionToString(version) == quic_version) { | 1540 if (net::QuicVersionToString(version) == quic_version) { |
| 1518 return version; | 1541 return version; |
| 1519 } | 1542 } |
| 1520 } | 1543 } |
| 1521 | 1544 |
| 1522 return net::QUIC_VERSION_UNSUPPORTED; | 1545 return net::QUIC_VERSION_UNSUPPORTED; |
| 1523 } | 1546 } |
| OLD | NEW |