Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
[Cronet] Add QUIC experimental params
Browse files Browse the repository at this point in the history
This CL plumbs four QUIC experimental params (
quic_store_server_configs_in_properties,
quic_delay_tcp_race,
quic_max_number_of_lossy_connections,
quic_packet_loss_threshold) from Cronet's
setExperimentalOptions API to net::HttpNetworkSession.

This CL also adds a unittests target to run the unittests.
A followup CL will enable the unittests on the cronet bots.

BUG=545118
NOTRY=true
NOPRESUBMIT=true

Committed: https://crrev.com/fde0b72c603cd111c36ca4cc416d82a7395bcf6c
Cr-Commit-Position: refs/heads/master@{#360454}

Committed: https://crrev.com/8ece3aa6845350c1971a3e824bf148f3e8de3253
Cr-Commit-Position: refs/heads/master@{#360875}

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

Cr-Commit-Position: refs/heads/master@{#361138}
(cherry picked from commit f24ee5f)

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

Cr-Commit-Position: refs/branch-heads/2564@{#161}
Cr-Branched-From: 1283eca-refs/heads/master@{#359700}
  • Loading branch information
xunjieli authored and Commit bot committed Nov 30, 2015
1 parent 0499800 commit 21daec0
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 10 deletions.
5 changes: 0 additions & 5 deletions components/components_tests.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,6 @@
'copresence/rpc/rpc_handler_unittest.cc',
'copresence/timed_map_unittest.cc',
],
'cronet_unittest_sources': [
'cronet/histogram_manager_unittest.cc',
],
'data_use_measurement_unittest_sources': [
'data_use_measurement/content/data_use_measurement_unittest.cc',
],
Expand Down Expand Up @@ -1286,7 +1283,6 @@
}],
['OS == "android"', {
'sources': [
'<@(cronet_unittest_sources)',
'data_reduction_proxy/content/browser/data_reduction_proxy_debug_blocking_page_unittest.cc',
'data_reduction_proxy/content/browser/data_reduction_proxy_debug_resource_throttle_unittest.cc',
'data_reduction_proxy/content/browser/data_reduction_proxy_debug_ui_manager_unittest.cc',
Expand All @@ -1309,7 +1305,6 @@
'web_modal/web_contents_modal_dialog_manager_unittest.cc',
],
'dependencies': [
'components.gyp:cronet_static',
'components.gyp:data_reduction_proxy_content',
'components.gyp:data_usage_android',
'components.gyp:safe_json_java',
Expand Down
34 changes: 32 additions & 2 deletions components/cronet.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
],
'dependencies': [
'../net/net.gyp:net_small',
'../url/url.gyp:url_lib_use_icu_alternatives_on_android',
],
'conditions': [
['enable_data_reduction_proxy_support==1',
Expand All @@ -183,6 +184,7 @@
'dependencies': [
'../base/base.gyp:base_i18n',
'../net/net.gyp:net',
'../url/url.gyp:url_lib',
],
'conditions': [
['enable_data_reduction_proxy_support==1',
Expand All @@ -205,7 +207,6 @@
'cronet_static_small',
'../base/base.gyp:base',
'../net/net.gyp:net_small',
'../url/url.gyp:url_lib_use_icu_alternatives_on_android',
],
},
{ # cronet_api.jar defines Cronet API and provides implementation of
Expand Down Expand Up @@ -363,7 +364,6 @@
'../net/net.gyp:net_quic_proto',
'../net/net.gyp:net_test_support',
'../net/net.gyp:simple_quic_tools',
'../url/url.gyp:url_lib',
'../base/base.gyp:base_i18n',
'../third_party/icu/icu.gyp:icui18n',
'../third_party/icu/icu.gyp:icuuc',
Expand Down Expand Up @@ -445,6 +445,36 @@
},
'includes': [ '../build/java_apk.gypi' ],
},
{
'target_name': 'cronet_unittests',
'type': '<(gtest_target_type)',
'dependencies': [
'cronet_static',
'metrics',
'../base/base.gyp:base',
'../base/base.gyp:test_support_base',
'../testing/gtest.gyp:gtest',
'../testing/android/native_test.gyp:native_test_native_code',
],
'sources': [
'cronet/run_all_unittests.cc',
'cronet/url_request_context_config_unittest.cc',
'cronet/histogram_manager_unittest.cc',
],
},
{
'target_name': 'cronet_unittests_apk',
'type': 'none',
'dependencies': [
'cronet_unittests',
],
'variables': {
'test_suite_name': 'cronet_unittests',
},
'includes': [
'../build/apk_test.gypi',
],
},
{
'target_name': 'cronet_package',
'type': 'none',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ protected void setUp() throws Exception {
builder.addQuicHint(QuicTestServer.getServerHost(), QuicTestServer.getServerPort(),
QuicTestServer.getServerPort());

JSONObject quicParams =
new JSONObject().put("connection_options", "PACE,IW10,FOO,DEADBEEF");
JSONObject quicParams = new JSONObject()
.put("connection_options", "PACE,IW10,FOO,DEADBEEF")
.put("store_server_configs_in_properties", true)
.put("delay_tcp_race", true)
.put("max_number_of_lossy_connections", 10)
.put("packet_loss_threshold", 0.5);
JSONObject experimentalOptions = new JSONObject().put("QUIC", quicParams);
builder.setExperimentalOptions(experimentalOptions.toString());

Expand Down
14 changes: 14 additions & 0 deletions components/cronet/run_all_unittests.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/bind.h"
#include "base/test/launcher/unit_test_launcher.h"
#include "base/test/test_suite.h"

int main(int argc, char** argv) {
base::TestSuite test_suite(argc, argv);
return base::LaunchUnitTests(
argc, argv,
base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite)));
}
33 changes: 33 additions & 0 deletions components/cronet/url_request_context_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ namespace {
// TODO(xunjieli): Refactor constants in io_thread.cc.
const char kQuicFieldTrialName[] = "QUIC";
const char kQuicConnectionOptions[] = "connection_options";
const char kQuicStoreServerConfigsInProperties[] =
"store_server_configs_in_properties";
const char kQuicDelayTcpRace[] = "delay_tcp_race";
const char kQuicMaxNumberOfLossyConnections[] =
"max_number_of_lossy_connections";
const char kQuicPacketLossThreshold[] = "packet_loss_threshold";

// Using a reference to scoped_ptr is unavoidable because of the semantics of
// RegisterCustomField.
Expand All @@ -41,6 +47,7 @@ void ParseAndSetExperimentalOptions(
if (experimental_options.empty())
return;

DVLOG(1) << "Experimental Options:" << experimental_options;
scoped_ptr<base::Value> options =
base::JSONReader::Read(experimental_options);

Expand All @@ -67,6 +74,32 @@ void ParseAndSetExperimentalOptions(
context_builder->set_quic_connection_options(
net::QuicUtils::ParseQuicConnectionOptions(quic_connection_options));
}

bool quic_store_server_configs_in_properties = false;
if (quic_args->GetBoolean(kQuicStoreServerConfigsInProperties,
&quic_store_server_configs_in_properties)) {
context_builder->set_quic_store_server_configs_in_properties(
quic_store_server_configs_in_properties);
}

bool quic_delay_tcp_race = false;
if (quic_args->GetBoolean(kQuicDelayTcpRace, &quic_delay_tcp_race)) {
context_builder->set_quic_delay_tcp_race(quic_delay_tcp_race);
}

int quic_max_number_of_lossy_connections = 0;
if (quic_args->GetInteger(kQuicMaxNumberOfLossyConnections,
&quic_max_number_of_lossy_connections)) {
context_builder->set_quic_max_number_of_lossy_connections(
quic_max_number_of_lossy_connections);
}

double quic_packet_loss_threshold = 0.0;
if (quic_args->GetDouble(kQuicPacketLossThreshold,
&quic_packet_loss_threshold)) {
context_builder->set_quic_packet_loss_threshold(
quic_packet_loss_threshold);
}
}
}

Expand Down
62 changes: 62 additions & 0 deletions components/cronet/url_request_context_config_unittest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/cronet/url_request_context_config.h"

#include "net/http/http_network_session.h"
#include "net/proxy/proxy_config.h"
#include "net/proxy/proxy_config_service_fixed.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_builder.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace cronet {

TEST(URLRequestContextConfigTest, SetQuicExperimentalOptions) {
URLRequestContextConfig config;

std::string args =
"{\"QUIC_HINTS\":[{\"QUIC_HINT_ALT_PORT\":6121,\"QUIC_HINT_PORT\":6121,"
"\"QUIC_HINT_HOST\":\"test.example.com\"}],"
"\"HTTP_CACHE\":\"HTTP_CACHE_DISK\",\"ENABLE_SDCH\":false,"
"\"ENABLE_LEGACY_MODE\":false,\"HTTP_CACHE_MAX_SIZE\":1024000,"
"\"NATIVE_LIBRARY_NAME\":\"cronet_tests\",\"USER_AGENT\":\"fake agent\","
"\"STORAGE_PATH\":"
"\"\\/data\\/data\\/org.chromium.net\\/app_cronet_test\\/test_storage\","
"\"ENABLE_SPDY\":true,"
"\"ENABLE_QUIC\":true,\"LOAD_DISABLE_CACHE\":true,"
"\"EXPERIMENTAL_OPTIONS\":"
"\"{\\\"QUIC\\\":{\\\"store_server_configs_in_properties\\\":true,"
"\\\"delay_tcp_race\\\":true,"
"\\\"max_number_of_lossy_connections\\\":10,"
"\\\"packet_loss_threshold\\\":0.5,"
"\\\"connection_options\\\":\\\"TIME,TBBR,REJ\\\"}}\"}";
config.LoadFromJSON(args);
net::URLRequestContextBuilder builder;
config.ConfigureURLRequestContextBuilder(&builder);
// Set a ProxyConfigService to avoid DCHECK failure when building.
builder.set_proxy_config_service(make_scoped_ptr(
new net::ProxyConfigServiceFixed(net::ProxyConfig::CreateDirect())));
scoped_ptr<net::URLRequestContext> context(builder.Build());
const net::HttpNetworkSession::Params* params =
context->GetNetworkSessionParams();
// Check Quic Connection options.
net::QuicTagVector quic_connection_options;
quic_connection_options.push_back(net::kTIME);
quic_connection_options.push_back(net::kTBBR);
quic_connection_options.push_back(net::kREJ);
EXPECT_EQ(quic_connection_options, params->quic_connection_options);

// Check store_server_configs_in_properties.
EXPECT_TRUE(params->quic_store_server_configs_in_properties);

// Check delay_tcp_race.
EXPECT_TRUE(params->quic_delay_tcp_race);

// Check max_number_of_lossy_connections and packet_loss_threshold.
EXPECT_EQ(10, params->quic_max_number_of_lossy_connections);
EXPECT_FLOAT_EQ(0.5f, params->quic_packet_loss_threshold);
}

} // namespace cronet
14 changes: 13 additions & 1 deletion net/url_request/url_request_context_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,11 @@ URLRequestContextBuilder::HttpNetworkSessionParams::HttpNetworkSessionParams()
testing_fixed_https_port(0),
next_protos(NextProtosDefaults()),
use_alternative_services(true),
enable_quic(false) {}
enable_quic(false),
quic_store_server_configs_in_properties(false),
quic_delay_tcp_race(false),
quic_max_number_of_lossy_connections(0),
quic_packet_loss_threshold(1.0f) {}

URLRequestContextBuilder::HttpNetworkSessionParams::~HttpNetworkSessionParams()
{}
Expand Down Expand Up @@ -389,6 +393,14 @@ scoped_ptr<URLRequestContext> URLRequestContextBuilder::Build() {
http_network_session_params_.trusted_spdy_proxy;
network_session_params.next_protos = http_network_session_params_.next_protos;
network_session_params.enable_quic = http_network_session_params_.enable_quic;
network_session_params.quic_store_server_configs_in_properties =
http_network_session_params_.quic_store_server_configs_in_properties;
network_session_params.quic_delay_tcp_race =
http_network_session_params_.quic_delay_tcp_race;
network_session_params.quic_max_number_of_lossy_connections =
http_network_session_params_.quic_max_number_of_lossy_connections;
network_session_params.quic_packet_loss_threshold =
http_network_session_params_.quic_packet_loss_threshold;
network_session_params.quic_connection_options =
http_network_session_params_.quic_connection_options;
network_session_params.ssl_session_cache_shard =
Expand Down
25 changes: 25 additions & 0 deletions net/url_request/url_request_context_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ class NET_EXPORT URLRequestContextBuilder {
std::string trusted_spdy_proxy;
bool use_alternative_services;
bool enable_quic;
bool quic_store_server_configs_in_properties;
bool quic_delay_tcp_race;
int quic_max_number_of_lossy_connections;
float quic_packet_loss_threshold;
QuicTagVector quic_connection_options;
std::string ssl_session_cache_shard;
};
Expand Down Expand Up @@ -194,6 +198,27 @@ class NET_EXPORT URLRequestContextBuilder {
ssl_session_cache_shard;
}

void set_quic_store_server_configs_in_properties(
bool quic_store_server_configs_in_properties) {
http_network_session_params_.quic_store_server_configs_in_properties =
quic_store_server_configs_in_properties;
}

void set_quic_delay_tcp_race(bool quic_delay_tcp_race) {
http_network_session_params_.quic_delay_tcp_race = quic_delay_tcp_race;
}

void set_quic_max_number_of_lossy_connections(
int quic_max_number_of_lossy_connections) {
http_network_session_params_.quic_max_number_of_lossy_connections =
quic_max_number_of_lossy_connections;
}

void set_quic_packet_loss_threshold(float quic_packet_loss_threshold) {
http_network_session_params_.quic_packet_loss_threshold =
quic_packet_loss_threshold;
}

void set_throttling_enabled(bool throttling_enabled) {
throttling_enabled_ = throttling_enabled;
}
Expand Down

0 comments on commit 21daec0

Please sign in to comment.