Skip to content

Commit

Permalink
Revert of Remove support for Alt-Svc/Alternate Protocol Probability (…
Browse files Browse the repository at this point in the history
…patchset chromium#8 id:140001 of https://codereview.chromium.org/1699653002/ )

Reason for revert:
https://bugs.chromium.org/p/chromium/issues/detail?id=594921

Basically parts of http_stream_factory_impl_unittest.cc are only compiled if ENABLE_BIDIRECTIONAL_STREAM is a build flag and you haven't updated these parts of the file.

Original issue's description:
> Remove support forAlt-Svc/Alternate Protocol Probability
>
> Committed: https://crrev.com/dced4c771d25317d26a0f6e258c7b7f64d4e8eea
> Cr-Commit-Position: refs/heads/master@{#379652}
>
> Committed: https://crrev.com/740688bec5c66af00debe117b6d375ecd212e570
> Cr-Commit-Position: refs/heads/master@{#381134}

TBR=bnc@chromium.org,eroman@chromium.org,mef@chromium.org,rch@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true

Review URL: https://codereview.chromium.org/1802893002

Cr-Commit-Position: refs/heads/master@{#381197}
  • Loading branch information
peconn authored and Commit bot committed Mar 15, 2016
1 parent 99cbc47 commit e9c288b
Show file tree
Hide file tree
Showing 30 changed files with 651 additions and 121 deletions.
43 changes: 43 additions & 0 deletions chrome/browser/io_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,8 @@ void IOThread::InitializeNetworkSessionParamsFromGlobals(
&params->parse_alternative_services);
globals.enable_alternative_service_with_different_host.CopyToIfSet(
&params->enable_alternative_service_with_different_host);
globals.alternative_service_probability_threshold.CopyToIfSet(
&params->alternative_service_probability_threshold);

globals.enable_npn.CopyToIfSet(&params->enable_npn);

Expand Down Expand Up @@ -1323,6 +1325,14 @@ void IOThread::ConfigureQuicGlobals(
globals->quic_supported_versions.set(supported_versions);
}

double threshold = GetAlternativeProtocolProbabilityThreshold(
command_line, quic_trial_params);
if (threshold >=0 && threshold <= 1) {
globals->alternative_service_probability_threshold.set(threshold);
globals->http_server_properties->SetAlternativeServiceProbabilityThreshold(
threshold);
}

if (command_line.HasSwitch(switches::kOriginToForceQuicOn)) {
net::HostPortPair quic_origin =
net::HostPortPair::FromString(
Expand Down Expand Up @@ -1400,6 +1410,39 @@ net::QuicTagVector IOThread::GetQuicConnectionOptions(
return net::QuicUtils::ParseQuicConnectionOptions(it->second);
}

double IOThread::GetAlternativeProtocolProbabilityThreshold(
const base::CommandLine& command_line,
const VariationParameters& quic_trial_params) {
double value;
if (command_line.HasSwitch(
switches::kAlternativeServiceProbabilityThreshold)) {
if (base::StringToDouble(
command_line.GetSwitchValueASCII(
switches::kAlternativeServiceProbabilityThreshold),
&value)) {
return value;
}
}
if (command_line.HasSwitch(switches::kEnableQuic)) {
return 0;
}
// TODO(bnc): Remove when new parameter name rolls out and server
// configuration is changed.
if (base::StringToDouble(
GetVariationParam(quic_trial_params,
"alternate_protocol_probability_threshold"),
&value)) {
return value;
}
if (base::StringToDouble(
GetVariationParam(quic_trial_params,
"alternative_service_probability_threshold"),
&value)) {
return value;
}
return -1;
}

bool IOThread::ShouldQuicAlwaysRequireHandshakeConfirmation(
const VariationParameters& quic_trial_params) {
return base::LowerCaseEqualsASCII(
Expand Down
42 changes: 42 additions & 0 deletions chrome/browser/io_thread_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ TEST_F(IOThreadTest, EnableQuicFromFieldTrialGroup) {
EXPECT_FALSE(params.disable_quic_on_timeout_with_open_streams);
EXPECT_TRUE(params.enable_quic_for_proxies);
EXPECT_EQ(1350u, params.quic_max_packet_length);
EXPECT_EQ(1.0, params.alternative_service_probability_threshold);
EXPECT_EQ(default_params.quic_supported_versions,
params.quic_supported_versions);
EXPECT_EQ(net::QuicTagVector(), params.quic_connection_options);
Expand Down Expand Up @@ -603,6 +604,47 @@ TEST_F(IOThreadTest, QuicDelayTcpConnection) {
EXPECT_TRUE(params.quic_delay_tcp_race);
}

TEST_F(IOThreadTest, AlternativeServiceProbabilityThresholdFromFlag) {
command_line_.AppendSwitchASCII("alternative-service-probability-threshold",
"0.5");

ConfigureQuicGlobals();
net::HttpNetworkSession::Params params;
InitializeNetworkSessionParams(&params);
EXPECT_EQ(.5, params.alternative_service_probability_threshold);
}

TEST_F(IOThreadTest, AlternativeServiceProbabilityThresholdFromEnableQuicFlag) {
command_line_.AppendSwitch("enable-quic");

ConfigureQuicGlobals();
net::HttpNetworkSession::Params params;
InitializeNetworkSessionParams(&params);
EXPECT_EQ(0, params.alternative_service_probability_threshold);
}

// TODO(bnc): Remove when new parameter name rolls out and server configuration
// is changed.
TEST_F(IOThreadTest, AlternativeServiceProbabilityThresholdFromOldParams) {
field_trial_group_ = "Enabled";
field_trial_params_["alternate_protocol_probability_threshold"] = ".5";

ConfigureQuicGlobals();
net::HttpNetworkSession::Params params;
InitializeNetworkSessionParams(&params);
EXPECT_EQ(.5, params.alternative_service_probability_threshold);
}

TEST_F(IOThreadTest, AlternativeServiceProbabilityThresholdFromParams) {
field_trial_group_ = "Enabled";
field_trial_params_["alternative_service_probability_threshold"] = ".5";

ConfigureQuicGlobals();
net::HttpNetworkSession::Params params;
InitializeNetworkSessionParams(&params);
EXPECT_EQ(.5, params.alternative_service_probability_threshold);
}

TEST_F(IOThreadTest, QuicWhitelistFromCommandLinet) {
command_line_.AppendSwitch("enable-quic");
command_line_.AppendSwitchASCII("quic-host-whitelist",
Expand Down
6 changes: 6 additions & 0 deletions chrome/browser/resources/net_internals/quic_view.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<div id=quic-view-tab-content class=content-box>
<ul style='margin-top:0'>
<li>QUIC Enabled: <span jscontent="!!quic_enabled"></span></li>
<!-- "alternative_service_probability_threshold" is used since release 44,
see https://crrev.com/1091283007.
"alternate_protocol_probability_threshold" is here to support importing
netlog json files from earlier browsers.
TODO(bnc): Deprecate around 2016 January. --!>
<li>Alternative Service Probability Threshold: <span jscontent="$this.alternative_service_probability_threshold || $this.alternate_protocol_probability_threshold"></span></li>
<li>Origin To Force QUIC On: <span jscontent="origin_to_force_quic_on"></span></li>
<li>Connection options: <span jscontent="connection_options"></span></li>
<li>Consistent Port Selection Enabled: <span jscontent="!!enable_quic_port_selection"></span></li>
Expand Down
6 changes: 6 additions & 0 deletions chrome/common/chrome_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ const char kAllowOutdatedPlugins[] = "allow-outdated-plugins";
// URLs. This provides an override to get the old insecure behavior.
const char kAllowRunningInsecureContent[] = "allow-running-insecure-content";

// Specifies the probability threshold for alternative services: an advertised
// alternative service will only be honored if the advertised probability is
// greater than or equal to this threshold.
const char kAlternativeServiceProbabilityThreshold[] =
"alternative-service-probability-threshold";

// Prevents Chrome from requiring authorization to run certain widely installed
// but less commonly used plugins.
const char kAlwaysAuthorizePlugins[] = "always-authorize-plugins";
Expand Down
1 change: 1 addition & 0 deletions chrome/common/chrome_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extern const char kAllowHttpScreenCapture[];
extern const char kAllowInsecureLocalhost[];
extern const char kAllowOutdatedPlugins[];
extern const char kAllowRunningInsecureContent[];
extern const char kAlternativeServiceProbabilityThreshold[];
extern const char kAlwaysAuthorizePlugins[];
extern const char kAppId[];
extern const char kApp[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,10 @@ void CronetURLRequestContextAdapter::InitializeOnNetworkThread(
}
}

// Currently (circa M39) enabling QUIC requires setting probability threshold.
if (config->enable_quic) {
context_->http_server_properties()
->SetAlternativeServiceProbabilityThreshold(0.0f);
for (auto hint = config->quic_hints.begin();
hint != config->quic_hints.end(); ++hint) {
const URLRequestContextConfig::QuicHint& quic_hint = **hint;
Expand Down Expand Up @@ -521,7 +524,8 @@ void CronetURLRequestContextAdapter::InitializeOnNetworkThread(
net::AlternateProtocol::QUIC, "",
static_cast<uint16_t>(quic_hint.alternate_port));
context_->http_server_properties()->SetAlternativeService(
quic_hint_host_port_pair, alternative_service, base::Time::Max());
quic_hint_host_port_pair, alternative_service, 1.0f,
base::Time::Max());
}
}

Expand Down
6 changes: 5 additions & 1 deletion components/cronet/android/url_request_context_adapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ void URLRequestContextAdapter::InitRequestContextOnNetworkThread() {
new net::SdchOwner(context_->sdch_manager(), context_.get()));
}

// Currently (circa M39) enabling QUIC requires setting probability threshold.
if (config_->enable_quic) {
context_->http_server_properties()
->SetAlternativeServiceProbabilityThreshold(0.0f);
for (size_t hint = 0; hint < config_->quic_hints.size(); ++hint) {
const URLRequestContextConfig::QuicHint& quic_hint =
*config_->quic_hints[hint];
Expand Down Expand Up @@ -201,7 +204,8 @@ void URLRequestContextAdapter::InitRequestContextOnNetworkThread() {
net::AlternateProtocol::QUIC, "",
static_cast<uint16_t>(quic_hint.alternate_port));
context_->http_server_properties()->SetAlternativeService(
quic_hint_host_port_pair, alternative_service, base::Time::Max());
quic_hint_host_port_pair, alternative_service, 1.0f,
base::Time::Max());
}
}
load_disable_cache_ = config_->load_disable_cache;
Expand Down
6 changes: 6 additions & 0 deletions ios/chrome/browser/ios_chrome_io_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class IOSChromeIOThread : public web::WebThreadDelegate {
Optional<bool> enable_http2;
Optional<bool> parse_alternative_services;
Optional<bool> enable_alternative_service_with_different_host;
Optional<double> alternative_service_probability_threshold;

Optional<bool> enable_npn;

Expand Down Expand Up @@ -349,6 +350,11 @@ class IOSChromeIOThread : public web::WebThreadDelegate {
static net::QuicTagVector GetQuicConnectionOptions(
const VariationParameters& quic_trial_params);

// Returns the alternative service probability threshold specified by
// any flags in |quic_trial_params|.
static double GetAlternativeProtocolProbabilityThreshold(
const VariationParameters& quic_trial_params);

static net::URLRequestContext* ConstructSystemRequestContext(
Globals* globals,
net::NetLog* net_log);
Expand Down
30 changes: 30 additions & 0 deletions ios/chrome/browser/ios_chrome_io_thread.mm
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,8 @@ void OnNetworkChanged(
&params->parse_alternative_services);
globals.enable_alternative_service_with_different_host.CopyToIfSet(
&params->enable_alternative_service_with_different_host);
globals.alternative_service_probability_threshold.CopyToIfSet(
&params->alternative_service_probability_threshold);

globals.enable_npn.CopyToIfSet(&params->enable_npn);

Expand Down Expand Up @@ -804,6 +806,14 @@ void OnNetworkChanged(
supported_versions.push_back(version);
globals->quic_supported_versions.set(supported_versions);
}

double threshold =
GetAlternativeProtocolProbabilityThreshold(quic_trial_params);
if (threshold >= 0 && threshold <= 1) {
globals->alternative_service_probability_threshold.set(threshold);
globals->http_server_properties->SetAlternativeServiceProbabilityThreshold(
threshold);
}
}

bool IOSChromeIOThread::ShouldEnableQuic(base::StringPiece quic_trial_group) {
Expand Down Expand Up @@ -832,6 +842,26 @@ void OnNetworkChanged(
return net::QuicUtils::ParseQuicConnectionOptions(it->second);
}

double IOSChromeIOThread::GetAlternativeProtocolProbabilityThreshold(
const VariationParameters& quic_trial_params) {
double value;
// TODO(bnc): Remove when new parameter name rolls out and server
// configuration is changed.
if (base::StringToDouble(
GetVariationParam(quic_trial_params,
"alternate_protocol_probability_threshold"),
&value)) {
return value;
}
if (base::StringToDouble(
GetVariationParam(quic_trial_params,
"alternative_service_probability_threshold"),
&value)) {
return value;
}
return -1;
}

bool IOSChromeIOThread::ShouldQuicAlwaysRequireHandshakeConfirmation(
const VariationParameters& quic_trial_params) {
return base::LowerCaseEqualsASCII(
Expand Down
23 changes: 23 additions & 0 deletions ios/crnet/CrNet.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,29 @@ typedef void(^ClearCacheCallback)(int errorCode);
+ (void)setSDCHEnabled:(BOOL)sdchEnabled
withPrefStore:(NSString*)filename;

// Set the alternate protocol threshold. Servers announce alternate protocols
// with a probability value; any alternate protocol whose probability value is
// greater than this value will be used, so |alternateProtocolThreshold| == 0
// implies any announced alternate protocol will be used, and
// |alternateProtocolThreshold| == 1 implies no alternate protocol will ever be
// used. Note that individual alternate protocols must also be individually
// enabled to be considered; currently the only alternate protocol is QUIC (SPDY
// is not controlled by this mechanism).
//
// For example, imagine your service has two frontends a.service.com and
// b.service.com, and you would like to divide your users into three classes:
// Users who use QUIC for both a and b
// Users who use QUIC for a but not b
// Users who use QUIC for neither a nor b
// You can achieve that effect with:
// a.service.com advertises QUIC with p=0.67
// b.service.com advertises QUIC with p=0.33
// alternateProtocolThreshold set to a uniform random number in [0,1]
// Now equal proportions of users will fall into the three experimental groups.
//
// The default for this value is 1.0, i.e. all alternate protocols disabled.
+ (void)setAlternateProtocolThreshold:(double)alternateProtocolThreshold;

// |userAgent| is expected to be of the form Product/Version.
// Example: Foo/3.0.0.0
//
Expand Down
7 changes: 7 additions & 0 deletions ios/crnet/CrNet.mm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
static BOOL g_sdch_enabled = NO;
static NSString* g_user_agent = nil;
static NSString* g_sdch_pref_store_filename = nil;
static double g_alternate_protocol_threshold = 1.0;
static RequestFilterBlock g_request_filter_block = nil;

@implementation CrNet
Expand All @@ -38,6 +39,10 @@ + (void)setPartialUserAgent:(NSString *)userAgent {
g_user_agent = userAgent;
}

+ (void)setAlternateProtocolThreshold:(double)alternateProtocolThreshold {
g_alternate_protocol_threshold = alternateProtocolThreshold;
}

+ (void)installInternal {
CrNetEnvironment::Initialize();
std::string partial_user_agent = base::SysNSStringToUTF8(g_user_agent);
Expand All @@ -50,6 +55,8 @@ + (void)installInternal {
std::string filename = base::SysNSStringToUTF8(g_sdch_pref_store_filename);
g_chrome_net->set_sdch_pref_store_filename(filename);
}
g_chrome_net->set_alternate_protocol_threshold(
g_alternate_protocol_threshold);

g_chrome_net->Install();
g_chrome_net->SetHTTPProtocolHandlerRegistered(true);
Expand Down
2 changes: 2 additions & 0 deletions ios/crnet/crnet_consumer/crnet_consumer_app_delegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ - (BOOL)application:(UIApplication*)application
didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
[CrNet setPartialUserAgent:@"Dummy/1.0"];
[CrNet setQuicEnabled:YES];
// Always use QUIC if able.
[CrNet setAlternateProtocolThreshold:0.0];
[CrNet setSDCHEnabled:YES withPrefStore:[self SDCHPrefStoreFileName]];
[CrNet install];
[CrNet startNetLogToFile:[self currentNetLogFileName] logBytes:NO];
Expand Down
7 changes: 7 additions & 0 deletions ios/crnet/crnet_environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,16 @@ class CrNetEnvironment {
void set_sdch_pref_store_filename(const std::string& pref_store) {
sdch_pref_store_filename_ = pref_store;
}
void set_alternate_protocol_threshold(double threshold) {
alternate_protocol_threshold_ = threshold;
}

bool spdy_enabled() const { return spdy_enabled_; }
bool quic_enabled() const { return quic_enabled_; }
bool sdch_enabled() const { return sdch_enabled_; }
double alternate_protocol_threshold() const {
return alternate_protocol_threshold_;
}

// Clears the network stack's disk cache.
void ClearCache(ClearCacheCallback callback);
Expand Down Expand Up @@ -136,6 +142,7 @@ class CrNetEnvironment {
bool quic_enabled_;
bool sdch_enabled_;
std::string sdch_pref_store_filename_;
double alternate_protocol_threshold_;

static CrNetEnvironment* chrome_net_;
scoped_ptr<base::Thread> network_io_thread_;
Expand Down
2 changes: 2 additions & 0 deletions ios/crnet/crnet_environment.mm
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,8 @@ bool IsRequestSupported(NSURLRequest* request) override {
params.enable_http2 = spdy_enabled();
params.parse_alternative_services = false;
params.enable_quic = quic_enabled();
params.alternative_service_probability_threshold =
alternate_protocol_threshold_;

if (!params.channel_id_service) {
// The main context may not have a ChannelIDService, since it is lazily
Expand Down
5 changes: 5 additions & 0 deletions net/http/http_network_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ HttpNetworkSession::Params::Params()
time_func(&base::TimeTicks::Now),
parse_alternative_services(false),
enable_alternative_service_with_different_host(false),
alternative_service_probability_threshold(1),
enable_npn(true),
enable_brotli(false),
enable_quic(false),
Expand Down Expand Up @@ -243,6 +244,8 @@ HttpNetworkSession::HttpNetworkSession(const Params& params)

next_protos_.push_back(kProtoHTTP11);

http_server_properties_->SetAlternativeServiceProbabilityThreshold(
params.alternative_service_probability_threshold);
http_server_properties_->SetMaxServerConfigsStoredInProperties(
params.quic_max_server_configs_stored_in_properties);
}
Expand Down Expand Up @@ -318,6 +321,8 @@ scoped_ptr<base::Value> HttpNetworkSession::QuicInfoToValue() const {
dict->Set("connection_options", std::move(connection_options));
dict->SetString("origin_to_force_quic_on",
params_.origin_to_force_quic_on.ToString());
dict->SetDouble("alternative_service_probability_threshold",
params_.alternative_service_probability_threshold);
dict->SetDouble("load_server_info_timeout_srtt_multiplier",
params_.quic_load_server_info_timeout_srtt_multiplier);
dict->SetBoolean("enable_connection_racing",
Expand Down
Loading

0 comments on commit e9c288b

Please sign in to comment.