summaryrefslogtreecommitdiffstats
path: root/components/data_reduction_proxy
diff options
context:
space:
mode:
authorjeremyim <jeremyim@chromium.org>2015-02-27 20:47:20 -0800
committerCommit bot <commit-bot@chromium.org>2015-02-28 04:48:25 +0000
commit6ccace4dafa0b74c6933d14caea548a2cbfd3244 (patch)
tree7c3ba1a380fdc29078106f3a14fc8d9c4c83cfde /components/data_reduction_proxy
parent4ed28f898039bbf0784f31774db3a4512d55a7a9 (diff)
downloadchromium_src-6ccace4dafa0b74c6933d14caea548a2cbfd3244.zip
chromium_src-6ccace4dafa0b74c6933d14caea548a2cbfd3244.tar.gz
chromium_src-6ccace4dafa0b74c6933d14caea548a2cbfd3244.tar.bz2
Migrate most DataReductionProxyParams methods to be private.
This further shifts Data Reduction Proxy code from using Params to using Config. BUG=452773 Review URL: https://codereview.chromium.org/958683002 Cr-Commit-Position: refs/heads/master@{#318596}
Diffstat (limited to 'components/data_reduction_proxy')
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc47
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h28
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.cc11
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.h12
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc4
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator_unittest.cc8
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor_unittest.cc22
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc3
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_metrics_unittest.cc6
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.cc5
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.cc8
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_unittest.cc4
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats_unittest.cc55
-rw-r--r--components/data_reduction_proxy/core/common/data_reduction_proxy_params.h44
14 files changed, 146 insertions, 111 deletions
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc
index 05849d3..29458b4 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc
@@ -53,7 +53,8 @@ DataReductionProxyConfig::DataReductionProxyConfig(
net::NetLog* net_log,
scoped_ptr<DataReductionProxyParams> params,
DataReductionProxyConfigurator* configurator,
- DataReductionProxyEventStore* event_store)
+ DataReductionProxyEventStore* event_store,
+ bool enable_quic)
: restricted_by_carrier_(false),
disabled_on_vpn_(false),
unreachable_(false),
@@ -69,6 +70,7 @@ DataReductionProxyConfig::DataReductionProxyConfig(
DCHECK(ui_task_runner);
DCHECK(configurator);
DCHECK(event_store);
+ params_->EnableQuic(enable_quic);
InitOnIOThread();
}
@@ -152,6 +154,33 @@ bool DataReductionProxyConfig::ContainsDataReductionProxy(
return false;
}
+bool DataReductionProxyConfig::UsingHTTPTunnel(
+ const net::HostPortPair& proxy_server) const {
+ return params_->ssl_origin().is_valid() &&
+ params_->ssl_origin().host_port_pair().Equals(proxy_server);
+}
+
+const net::ProxyServer& DataReductionProxyConfig::Origin() {
+ return params_->origin();
+}
+
+// Returns true if the Data Reduction Proxy configuration may be used.
+bool DataReductionProxyConfig::allowed() {
+ return params_->allowed();
+}
+
+// Returns true if the alternative Data Reduction Proxy configuration may be
+// used.
+bool DataReductionProxyConfig::alternative_allowed() {
+ return params_->alternative_allowed();
+}
+
+// Returns true if the Data Reduction Proxy promo may be shown. This is not
+// tied to whether the Data Reduction Proxy is enabled.
+bool DataReductionProxyConfig::promo_allowed() {
+ return params_->promo_allowed();
+}
+
void DataReductionProxyConfig::SetProxyConfigOnIOThread(
bool enabled, bool alternative_enabled, bool at_startup) {
enabled_by_user_ = enabled;
@@ -161,7 +190,7 @@ void DataReductionProxyConfig::SetProxyConfigOnIOThread(
// Check if the proxy has been restricted explicitly by the carrier.
if (enabled &&
- !(alternative_enabled && !params()->alternative_fallback_allowed())) {
+ !(alternative_enabled && !params_->alternative_fallback_allowed())) {
ui_task_runner_->PostTask(
FROM_HERE, base::Bind(&DataReductionProxyConfig::StartSecureProxyCheck,
base::Unretained(this)));
@@ -177,16 +206,16 @@ void DataReductionProxyConfig::UpdateConfigurator(bool enabled,
LogProxyState(enabled, restricted, at_startup);
// The alternative is only configured if the standard configuration is
// is enabled.
- if (enabled & !params()->holdback()) {
+ if (enabled & !params_->holdback()) {
if (alternative_enabled) {
configurator_->Enable(restricted,
- !params()->alternative_fallback_allowed(),
- params()->alt_origin().ToURI(), std::string(),
- params()->ssl_origin().ToURI());
+ !params_->alternative_fallback_allowed(),
+ params_->alt_origin().ToURI(), std::string(),
+ params_->ssl_origin().ToURI());
} else {
- configurator_->Enable(restricted, !params()->fallback_allowed(),
- params()->origin().ToURI(),
- params()->fallback_origin().ToURI(), std::string());
+ configurator_->Enable(restricted, !params_->fallback_allowed(),
+ params_->origin().ToURI(),
+ params_->fallback_origin().ToURI(), std::string());
}
} else {
configurator_->Disable();
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h
index 6b96798..85e8b6e 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h
@@ -5,6 +5,7 @@
#ifndef COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_CONFIG_H_
#define COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_CONFIG_H_
+#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
@@ -77,14 +78,10 @@ class DataReductionProxyConfig
net::NetLog* net_log,
scoped_ptr<DataReductionProxyParams> params,
DataReductionProxyConfigurator* configurator,
- DataReductionProxyEventStore* event_store);
+ DataReductionProxyEventStore* event_store,
+ bool enable_quic);
~DataReductionProxyConfig() override;
- // Returns the underlying |DataReductionProxyParams| instance.
- DataReductionProxyParams* params() const {
- return params_.get();
- }
-
void SetDataReductionProxyService(
base::WeakPtr<DataReductionProxyService> data_reduction_proxy_service);
@@ -148,6 +145,23 @@ class DataReductionProxyConfig
virtual bool ContainsDataReductionProxy(
const net::ProxyConfig::ProxyRules& proxy_rules);
+ // Returns true if the proxy was using the HTTP tunnel for a HTTPS origin.
+ bool UsingHTTPTunnel(const net::HostPortPair& proxy_server) const;
+
+ // Returns the Data Reduction Proxy primary origin.
+ const net::ProxyServer& Origin();
+
+ // Returns true if the Data Reduction Proxy configuration may be used.
+ bool allowed();
+
+ // Returns true if the alternative Data Reduction Proxy configuration may be
+ // used.
+ bool alternative_allowed();
+
+ // Returns true if the Data Reduction Proxy promo may be shown. This is not
+ // tied to whether the Data Reduction Proxy is enabled.
+ bool promo_allowed();
+
protected:
// Sets the proxy configs, enabling or disabling the proxy according to
// the value of |enabled| and |alternative_enabled|. Use the alternative
@@ -177,6 +191,8 @@ class DataReductionProxyConfig
friend class MockDataReductionProxyConfig;
friend class TestDataReductionProxyConfig;
FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigTest,
+ TestGetDataReductionProxies);
+ FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigTest,
TestOnIPAddressChanged);
FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigTest,
TestSetProxyConfigsHoldback);
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.cc
index 416dcb2..2505105 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.cc
@@ -26,7 +26,7 @@ TestDataReductionProxyConfig::TestDataReductionProxyConfig(
make_scoped_ptr(
new TestDataReductionProxyParams(params_flags, params_definitions))
.Pass(),
- configurator, event_store) {
+ configurator, event_store, false /* enable_quic */) {
network_interfaces_.reset(new net::NetworkInterfaceList());
}
@@ -40,6 +40,10 @@ void TestDataReductionProxyConfig::GetNetworkList(
interfaces->push_back(network_interfaces_->at(i));
}
+void TestDataReductionProxyConfig::EnableQuic(bool enable) {
+ params_->EnableQuic(enable);
+}
+
void TestDataReductionProxyConfig::ResetParamFlagsForTest(int flags) {
params_ = make_scoped_ptr(
new TestDataReductionProxyParams(
@@ -50,11 +54,6 @@ void TestDataReductionProxyConfig::ResetParamFlagsForTest(int flags) {
.Pass();
}
-void TestDataReductionProxyConfig::ResetParamsForTest(
- scoped_ptr<TestDataReductionProxyParams> params) {
- params_ = params.Pass();
-}
-
TestDataReductionProxyParams* TestDataReductionProxyConfig::test_params() {
return static_cast<TestDataReductionProxyParams*>(params_.get());
}
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.h
index 9bd8b97..4155880 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.h
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.h
@@ -44,11 +44,11 @@ class TestDataReductionProxyConfig : public DataReductionProxyConfig {
void GetNetworkList(net::NetworkInterfaceList* interfaces,
int policy) override;
- // Allows tests to reset the params being used for configuration.
- void ResetParamFlagsForTest(int flags);
+ // If true, uses QUIC instead of SPDY to connect to proxies that use TLS.
+ void EnableQuic(bool enable);
// Allows tests to reset the params being used for configuration.
- void ResetParamsForTest(scoped_ptr<TestDataReductionProxyParams> params);
+ void ResetParamFlagsForTest(int flags);
// Retrieves the test params being used for the configuration.
TestDataReductionProxyParams* test_params();
@@ -87,6 +87,12 @@ class MockDataReductionProxyConfig : public TestDataReductionProxyConfig {
void(bool enabled, bool restricted, bool at_startup));
MOCK_METHOD3(SetProxyPrefs,
void(bool enabled, bool alternative_enabled, bool at_startup));
+ MOCK_CONST_METHOD2(IsDataReductionProxy,
+ bool(const net::HostPortPair& host_port_pair,
+ DataReductionProxyTypeInfo* proxy_info));
+ MOCK_CONST_METHOD2(WasDataReductionProxyUsed,
+ bool(const net::URLRequest*,
+ DataReductionProxyTypeInfo* proxy_info));
MOCK_METHOD1(ContainsDataReductionProxy,
bool(const net::ProxyConfig::ProxyRules& proxy_rules));
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc
index 35d9baf..bd5a10db 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc
@@ -172,14 +172,14 @@ class DataReductionProxyConfigTest : public testing::Test {
};
TEST_F(DataReductionProxyConfigTest, TestGetDataReductionProxyOrigin) {
- EXPECT_EQ(params()->DefaultOrigin(), config()->params()->origin().ToURI());
+ EXPECT_EQ(params()->DefaultOrigin(), config()->Origin().ToURI());
}
TEST_F(DataReductionProxyConfigTest, TestGetDataReductionProxyDevOrigin) {
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kDataReductionProxyDev, params()->DefaultDevOrigin());
ResetSettings(true, true, false, true, false);
- EXPECT_EQ(params()->DefaultDevOrigin(), config()->params()->origin().ToURI());
+ EXPECT_EQ(params()->DefaultDevOrigin(), config()->Origin().ToURI());
}
TEST_F(DataReductionProxyConfigTest, TestGetDataReductionProxies) {
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator_unittest.cc
index c8869ea..fce83fbe 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator_unittest.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator_unittest.cc
@@ -10,7 +10,6 @@
#include "base/test/test_simple_task_runner.h"
#include "base/values.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.h"
-#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
#include "net/base/capturing_net_log.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -186,13 +185,10 @@ TEST_F(DataReductionProxyConfiguratorTest, TestFallbackRestrictedQuic) {
}
TEST_F(DataReductionProxyConfiguratorTest, TestDisable) {
- data_reduction_proxy::DataReductionProxyParams params(
- data_reduction_proxy::DataReductionProxyParams::
- kAllowAllProxyConfigurations);
config_->Enable(false,
false,
- params.origin().ToURI(),
- params.fallback_origin().ToURI(),
+ "https://www.foo.com:443/",
+ "http://www.bar.com:80/",
"");
config_->Disable();
CheckProxyConfig(net::ProxyConfig::ProxyRules::TYPE_NO_RULES, "", "", "");
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor_unittest.cc
index 1e0c25f..29c4f9e 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor_unittest.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor_unittest.cc
@@ -82,10 +82,10 @@ class CountingURLRequestInterceptor : public net::URLRequestInterceptor {
class TestURLRequestContextWithDataReductionProxy
: public net::TestURLRequestContext {
public:
- TestURLRequestContextWithDataReductionProxy(DataReductionProxyParams* params,
+ TestURLRequestContextWithDataReductionProxy(DataReductionProxyConfig* config,
net::NetworkDelegate* delegate)
: net::TestURLRequestContext(true) {
- std::string proxy = params->origin().ToURI();
+ std::string proxy = config->Origin().ToURI();
context_storage_.set_proxy_service(net::ProxyService::CreateFixed(proxy));
set_network_delegate(delegate);
}
@@ -95,13 +95,17 @@ class TestURLRequestContextWithDataReductionProxy
class DataReductionProxyInterceptorTest : public testing::Test {
public:
- DataReductionProxyInterceptorTest()
- : params_(DataReductionProxyParams::kAllowed) {
+ DataReductionProxyInterceptorTest() {
+ test_context_ =
+ DataReductionProxyTestContext::Builder()
+ .WithParamsFlags(DataReductionProxyParams::kAllowed)
+ .WithParamsDefinitions(TestDataReductionProxyParams::HAS_EVERYTHING)
+ .Build();
default_context_.reset(
new TestURLRequestContextWithDataReductionProxy(
- &params_, &default_network_delegate_));
+ test_context_->config(), &default_network_delegate_));
default_context_->set_network_delegate(&default_network_delegate_);
- default_context_->set_net_log(&net_log_);
+ default_context_->set_net_log(test_context_->net_log());
}
~DataReductionProxyInterceptorTest() override {
@@ -115,12 +119,10 @@ class DataReductionProxyInterceptorTest : public testing::Test {
default_context_->Init();
}
- DataReductionProxyParams params_;
- net::CapturingNetLog net_log_;
+ scoped_ptr<DataReductionProxyTestContext> test_context_;
net::TestNetworkDelegate default_network_delegate_;
scoped_ptr<net::URLRequestJobFactory> job_factory_;
scoped_ptr<net::TestURLRequestContext> default_context_;
- base::MessageLoopForIO loop_;
};
TEST_F(DataReductionProxyInterceptorTest, TestJobFactoryChaining) {
@@ -196,7 +198,7 @@ class DataReductionProxyInterceptorWithServerTest : public testing::Test {
test_context_->config()->test_params()->set_origin(
net::ProxyServer::FromURI(spec, net::ProxyServer::SCHEME_HTTP));
std::string proxy_name =
- test_context_->config()->params()->origin().ToURI();
+ test_context_->config()->Origin().ToURI();
proxy_service_.reset(
net::ProxyService::CreateFixedFromPacResult(
"PROXY " + proxy_name + "; DIRECT"));
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc
index a0f1e7c..0d9c328 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc
@@ -40,13 +40,12 @@ DataReductionProxyIOData::DataReductionProxyIOData(
DCHECK(ui_task_runner_.get());
scoped_ptr<DataReductionProxyParams> params(
new DataReductionProxyParams(param_flags));
- params->EnableQuic(enable_quic);
event_store_.reset(new DataReductionProxyEventStore(ui_task_runner));
configurator_.reset(new DataReductionProxyConfigurator(
io_task_runner, net_log, event_store_.get()));
config_.reset(new DataReductionProxyConfig(
io_task_runner_, ui_task_runner_, net_log, params.Pass(),
- configurator_.get(), event_store_.get()));
+ configurator_.get(), event_store_.get(), enable_quic));
request_options_.reset(new DataReductionProxyRequestOptions(
client_, config_.get(), io_task_runner_));
request_options_->Init();
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_metrics_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_metrics_unittest.cc
index 24140c9..053394b 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_metrics_unittest.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_metrics_unittest.cc
@@ -677,11 +677,11 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest,
.WithParamsFlags(DataReductionProxyParams::kAllowed)
.WithParamsDefinitions(TestDataReductionProxyParams::HAS_ORIGIN)
.Build();
- TestDataReductionProxyParams* params = test_context->config()->test_params();
+ TestDataReductionProxyConfig* config = test_context->config();
net::ProxyConfig data_reduction_proxy_config;
data_reduction_proxy_config.proxy_rules().ParseFromString(
- "http=" + params->origin().host_port_pair().ToString() + ",direct://");
+ "http=" + config->Origin().host_port_pair().ToString() + ",direct://");
data_reduction_proxy_config.proxy_rules().bypass_rules.ParseFromString(
"localbypass.com");
@@ -695,7 +695,7 @@ TEST_F(ChromeNetworkDailyDataSavingMetricsTest,
};
const TestCase test_cases[] = {
{ GURL("http://foo.com"),
- params->origin(),
+ config->Origin(),
base::TimeDelta(),
net::LOAD_NORMAL,
"HTTP/1.1 200 OK\r\nVia: 1.1 Chrome-Compression-Proxy\r\n\r\n",
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.cc
index 200852e..985dfa5 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.cc
@@ -281,9 +281,8 @@ void DataReductionProxyRequestOptions::MaybeAddRequestHeaderImpl(
return;
if (data_reduction_proxy_config_ &&
data_reduction_proxy_config_->IsDataReductionProxy(proxy_server, NULL) &&
- ((data_reduction_proxy_config_->params()->ssl_origin().is_valid() &&
- data_reduction_proxy_config_->params()->ssl_origin().host_port_pair()
- .Equals(proxy_server)) == expect_ssl)) {
+ data_reduction_proxy_config_->UsingHTTPTunnel(proxy_server) ==
+ expect_ssl) {
SetHeader(request_headers);
}
}
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.cc
index 534e60d..1f3c75c 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.cc
@@ -82,10 +82,10 @@ void DataReductionProxySettings::InitPrefMembers() {
void DataReductionProxySettings::UpdateConfigValues() {
DCHECK(config_);
- allowed_ = config_->params()->allowed();
- alternative_allowed_ = config_->params()->alternative_allowed();
- promo_allowed_ = config_->params()->promo_allowed();
- primary_origin_ = config_->params()->origin().ToURI();
+ allowed_ = config_->allowed();
+ alternative_allowed_ = config_->alternative_allowed();
+ promo_allowed_ = config_->promo_allowed();
+ primary_origin_ = config_->Origin().ToURI();
}
void DataReductionProxySettings::InitDataReductionProxySettings(
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_unittest.cc
index c1df94e..c32e38b 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_unittest.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_unittest.cc
@@ -373,7 +373,7 @@ TEST_F(DataReductionProxySettingsTest, CheckQUICFieldTrials) {
DataReductionProxyParams::GetQuicFieldTrialName(),
"Disabled");
}
- test_context_->config()->params()->EnableQuic(enable_quic);
+ test_context_->config()->EnableQuic(enable_quic);
settings_->SetOnDataReductionEnabledCallback(
base::Bind(&DataReductionProxySettingsTestBase::
@@ -381,7 +381,7 @@ TEST_F(DataReductionProxySettingsTest, CheckQUICFieldTrials) {
base::Unretained(this)));
EXPECT_EQ(enable_quic,
- test_context_->config()->params()->origin().is_quic()) << i;
+ test_context_->config()->Origin().is_quic()) << i;
}
}
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats_unittest.cc
index 338bdec..8278b51 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats_unittest.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats_unittest.cc
@@ -50,27 +50,6 @@ namespace data_reduction_proxy {
namespace {
-class DataReductionProxyParamsMock :
- public TestDataReductionProxyParams {
- public:
- DataReductionProxyParamsMock() :
- TestDataReductionProxyParams(
- 0, TestDataReductionProxyParams::HAS_EVERYTHING) {}
- virtual ~DataReductionProxyParamsMock() {}
-
- MOCK_CONST_METHOD2(
- IsDataReductionProxy,
- bool(const net::HostPortPair& host_port_pair,
- DataReductionProxyTypeInfo* proxy_info));
- MOCK_CONST_METHOD2(
- WasDataReductionProxyUsed,
- bool(const net::URLRequest*,
- DataReductionProxyTypeInfo* proxy_info));
-
- private:
- DISALLOW_COPY_AND_ASSIGN(DataReductionProxyParamsMock);
-};
-
const std::string kBody = "hello";
const std::string kNextBody = "hello again";
const std::string kErrorBody = "bad";
@@ -99,13 +78,10 @@ class DataReductionProxyUsageStatsTest : public testing::Test {
TestDataReductionProxyParams::HAS_EVERYTHING &
~TestDataReductionProxyParams::HAS_DEV_ORIGIN &
~TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN)
+ .WithMockConfig()
.Build();
mock_url_request_ = context_.CreateRequest(GURL(), net::IDLE, &delegate_,
NULL);
- scoped_ptr<DataReductionProxyParamsMock> mock_params =
- make_scoped_ptr(new DataReductionProxyParamsMock());
- mock_params_ = mock_params.get();
- test_context_->config()->ResetParamsForTest(mock_params.Pass());
}
scoped_ptr<net::URLRequest> CreateURLRequestWithResponseHeaders(
@@ -147,8 +123,8 @@ class DataReductionProxyUsageStatsTest : public testing::Test {
return mock_url_request_.get();
}
- DataReductionProxyParamsMock* params() const {
- return mock_params_;
+ MockDataReductionProxyConfig* config() const {
+ return test_context_->mock_config();
}
void RunUntilIdle() {
@@ -158,7 +134,6 @@ class DataReductionProxyUsageStatsTest : public testing::Test {
private:
net::TestURLRequestContext context_;
net::TestDelegate delegate_;
- DataReductionProxyParamsMock* mock_params_;
scoped_ptr<net::URLRequest> mock_url_request_;
// |test_job_interceptor_| is owned by |test_job_factory_|.
net::TestJobInterceptor* test_job_interceptor_;
@@ -200,10 +175,10 @@ TEST_F(DataReductionProxyUsageStatsTest, IsDataReductionProxyUnreachable) {
for (size_t i = 0; i < arraysize(test_cases); ++i) {
TestCase test_case = test_cases[i];
- EXPECT_CALL(*params(), IsDataReductionProxy(testing::_, testing::_))
+ EXPECT_CALL(*config(), IsDataReductionProxy(testing::_, testing::_))
.WillRepeatedly(testing::Return(
test_case.fallback_proxy_server_is_data_reduction_proxy));
- EXPECT_CALL(*params(),
+ EXPECT_CALL(*config(),
WasDataReductionProxyUsed(url_request(), testing::_))
.WillRepeatedly(testing::Return(test_case.was_proxy_used));
@@ -222,9 +197,9 @@ TEST_F(DataReductionProxyUsageStatsTest, ProxyUnreachableThenReachable) {
net::ProxyServer fallback_proxy_server =
net::ProxyServer::FromURI("foo.com", net::ProxyServer::SCHEME_HTTP);
scoped_ptr<DataReductionProxyUsageStats> usage_stats = BuildUsageStats();
- EXPECT_CALL(*params(), IsDataReductionProxy(testing::_, testing::_))
+ EXPECT_CALL(*config(), IsDataReductionProxy(testing::_, testing::_))
.WillOnce(testing::Return(true));
- EXPECT_CALL(*params(),
+ EXPECT_CALL(*config(),
WasDataReductionProxyUsed(url_request(), testing::_))
.WillOnce(testing::Return(true));
@@ -244,10 +219,10 @@ TEST_F(DataReductionProxyUsageStatsTest, ProxyReachableThenUnreachable) {
net::ProxyServer fallback_proxy_server =
net::ProxyServer::FromURI("foo.com", net::ProxyServer::SCHEME_HTTP);
scoped_ptr<DataReductionProxyUsageStats> usage_stats = BuildUsageStats();
- EXPECT_CALL(*params(),
+ EXPECT_CALL(*config(),
WasDataReductionProxyUsed(url_request(), testing::_))
.WillOnce(testing::Return(true));
- EXPECT_CALL(*params(), IsDataReductionProxy(testing::_, testing::_))
+ EXPECT_CALL(*config(), IsDataReductionProxy(testing::_, testing::_))
.WillRepeatedly(testing::Return(true));
// Proxy succeeds.
@@ -456,7 +431,7 @@ TEST_F(DataReductionProxyUsageStatsTest, RecordMissingViaHeaderBytes) {
raw_headers));
fake_request->set_received_response_content_length(kResponseContentLength);
- EXPECT_CALL(*params(),
+ EXPECT_CALL(*config(),
WasDataReductionProxyUsed(fake_request.get(), testing::_))
.WillRepeatedly(Return(test_cases[i].was_proxy_used));
@@ -537,7 +512,7 @@ TEST_F(DataReductionProxyUsageStatsTest, RequestCompletionErrorCodes) {
DataReductionProxyTypeInfo proxy_info;
proxy_info.is_fallback = test_cases[i].is_fallback;
- EXPECT_CALL(*params(), WasDataReductionProxyUsed(fake_request.get(),
+ EXPECT_CALL(*config(), WasDataReductionProxyUsed(fake_request.get(),
testing::NotNull()))
.WillRepeatedly(testing::DoAll(testing::SetArgPointee<1>(proxy_info),
Return(test_cases[i].was_proxy_used)));
@@ -615,7 +590,7 @@ class DataReductionProxyUsageStatsEndToEndTest : public testing::Test {
context_.set_job_factory(job_factory_.get());
test_context_->configurator()->Enable(false, true,
- params()->origin().ToURI(),
+ config()->Origin().ToURI(),
std::string(), std::string());
test_context_->RunUntilIdle();
}
@@ -680,8 +655,8 @@ class DataReductionProxyUsageStatsEndToEndTest : public testing::Test {
return test_context_->settings();
}
- const DataReductionProxyParams* params() const {
- return test_context_->config()->test_params();
+ DataReductionProxyConfig* config() const {
+ return test_context_->config();
}
void ClearBadProxies() {
@@ -944,7 +919,7 @@ TEST_F(DataReductionProxyUsageStatsEndToEndTest, BypassedBytesNetErrorOther) {
// Make the data reduction proxy host fail to resolve.
scoped_ptr<net::MockHostResolver> host_resolver(new net::MockHostResolver());
host_resolver->rules()->AddSimulatedFailure(
- params()->origin().host_port_pair().host());
+ config()->Origin().host_port_pair().host());
set_host_resolver(host_resolver.get());
InitializeContext();
diff --git a/components/data_reduction_proxy/core/common/data_reduction_proxy_params.h b/components/data_reduction_proxy/core/common/data_reduction_proxy_params.h
index 16d1b65..b43da33 100644
--- a/components/data_reduction_proxy/core/common/data_reduction_proxy_params.h
+++ b/components/data_reduction_proxy/core/common/data_reduction_proxy_params.h
@@ -9,6 +9,7 @@
#include <utility>
#include <vector>
+#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
#include "net/base/host_port_pair.h"
#include "net/proxy/proxy_config.h"
@@ -118,9 +119,6 @@ class DataReductionProxyParams {
static std::string GetQuicFieldTrialName();
- // If true, uses QUIC instead of SPDY to connect to proxies that use TLS.
- void EnableQuic(bool enable);
-
// Constructs configuration parameters. If |kAllowed|, then the standard
// data reduction proxy configuration is allowed to be used. If
// |kfallbackAllowed| a fallback proxy can be used if the primary proxy is
@@ -137,18 +135,6 @@ class DataReductionProxyParams {
virtual ~DataReductionProxyParams();
- // Returns true if a data reduction proxy was used for the given |request|.
- // If true, |proxy_info.proxy_servers.first| will contain the name of the
- // proxy that was used. |proxy_info.proxy_servers.second| will contain the
- // name of the data reduction proxy server that would be used if
- // |proxy_info.proxy_server.first| is bypassed, if one exists. In addition,
- // |proxy_info| will note if the proxy used was a fallback, an alternative,
- // or a proxy for ssl; these are not mutually exclusive. |proxy_info| can be
- // NULL if the caller isn't interested in its values.
- virtual bool WasDataReductionProxyUsed(
- const net::URLRequest* request,
- DataReductionProxyTypeInfo* proxy_info) const;
-
// Returns true if the specified |host_port_pair| matches a data reduction
// proxy. If true, |proxy_info.proxy_servers.first| will contain the name of
// the proxy that matches. |proxy_info.proxy_servers.second| will contain the
@@ -161,6 +147,7 @@ class DataReductionProxyParams {
const net::HostPortPair& host_port_pair,
DataReductionProxyTypeInfo* proxy_info) const;
+ protected:
// Returns true if this request would be bypassed by the data request proxy
// based on applying the |data_reduction_proxy_config| param rules to the
// request URL. Virutal for testing.
@@ -180,6 +167,33 @@ class DataReductionProxyParams {
const net::ProxyConfig& data_reduction_proxy_config,
base::TimeDelta* min_retry_delay) const;
+ private:
+ // TODO(jeremyim) Remove these temporary friends.
+ friend class DataReductionProxyConfig;
+ friend class DataReductionProxyParamsTest;
+ friend class TestDataReductionProxyConfig;
+ FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigTest,
+ TestGetDataReductionProxies);
+ FRIEND_TEST_ALL_PREFIXES(DataReductionProxyParamsTest,
+ AreProxiesBypassed);
+ FRIEND_TEST_ALL_PREFIXES(DataReductionProxyParamsTest,
+ AreProxiesBypassedRetryDelay);
+
+ // If true, uses QUIC instead of SPDY to connect to proxies that use TLS.
+ void EnableQuic(bool enable);
+
+ // Returns true if a data reduction proxy was used for the given |request|.
+ // If true, |proxy_info.proxy_servers.first| will contain the name of the
+ // proxy that was used. |proxy_info.proxy_servers.second| will contain the
+ // name of the data reduction proxy server that would be used if
+ // |proxy_info.proxy_server.first| is bypassed, if one exists. In addition,
+ // |proxy_info| will note if the proxy used was a fallback, an alternative,
+ // or a proxy for ssl; these are not mutually exclusive. |proxy_info| can be
+ // NULL if the caller isn't interested in its values.
+ virtual bool WasDataReductionProxyUsed(
+ const net::URLRequest* request,
+ DataReductionProxyTypeInfo* proxy_info) const;
+
// Checks if all configured data reduction proxies are in the retry map.
// Returns true if the request is bypassed by all configured data reduction
// proxies that apply to the request scheme. If all possible data reduction