diff options
author | jeremyim <jeremyim@chromium.org> | 2015-03-25 12:51:30 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-03-25 19:52:27 +0000 |
commit | c558244dc68392b18424e1300adc2acfe383746a (patch) | |
tree | d58eff25b75cd08df1b81c38f5d12774f883816e /components | |
parent | bc0b05bd43245357433854cba3179f28ad52d5f0 (diff) | |
download | chromium_src-c558244dc68392b18424e1300adc2acfe383746a.zip chromium_src-c558244dc68392b18424e1300adc2acfe383746a.tar.gz chromium_src-c558244dc68392b18424e1300adc2acfe383746a.tar.bz2 |
Add the ability to use DataReductionProxyParams from DataReductionProxyConfigServiceClient.
- Permit DRP RequestOptions to take auth credentials instead of always internally
generating them.
- Permit DRP Config to perform a reload of the configuration
- Create a new DRP MutableConfigValues class which can have its underlying values
updated.
- Add a configuration refresh timer to DRP ConfigServiceClient, along with
backoff logic.
BUG=466753
Review URL: https://codereview.chromium.org/1024553009
Cr-Commit-Position: refs/heads/master@{#322217}
Diffstat (limited to 'components')
22 files changed, 1033 insertions, 78 deletions
diff --git a/components/data_reduction_proxy.gypi b/components/data_reduction_proxy.gypi index 098c8a1..f8b37a5 100644 --- a/components/data_reduction_proxy.gypi +++ b/components/data_reduction_proxy.gypi @@ -108,6 +108,8 @@ 'data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h', 'data_reduction_proxy/core/browser/data_reduction_proxy_metrics.cc', 'data_reduction_proxy/core/browser/data_reduction_proxy_metrics.h', + 'data_reduction_proxy/core/browser/data_reduction_proxy_mutable_config_values.cc', + 'data_reduction_proxy/core/browser/data_reduction_proxy_mutable_config_values.h', 'data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc', 'data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.h', 'data_reduction_proxy/core/browser/data_reduction_proxy_prefs.cc', diff --git a/components/data_reduction_proxy/core/browser/BUILD.gn b/components/data_reduction_proxy/core/browser/BUILD.gn index 5790d4c..3e660fd 100644 --- a/components/data_reduction_proxy/core/browser/BUILD.gn +++ b/components/data_reduction_proxy/core/browser/BUILD.gn @@ -21,6 +21,8 @@ static_library("browser") { "data_reduction_proxy_io_data.h", "data_reduction_proxy_metrics.cc", "data_reduction_proxy_metrics.h", + "data_reduction_proxy_mutable_config_values.cc", + "data_reduction_proxy_mutable_config_values.h", "data_reduction_proxy_network_delegate.cc", "data_reduction_proxy_network_delegate.h", "data_reduction_proxy_prefs.cc", 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 bb7ab76..932af6f 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 @@ -90,6 +90,12 @@ void DataReductionProxyConfig::SetProxyPrefs(bool enabled, alternative_enabled, at_startup)); } +void DataReductionProxyConfig::ReloadConfig() { + DCHECK(io_task_runner_->BelongsToCurrentThread()); + UpdateConfigurator(enabled_by_user_, alternative_enabled_by_user_, + restricted_by_carrier_, false /* at_startup */); +} + bool DataReductionProxyConfig::WasDataReductionProxyUsed( const net::URLRequest* request, DataReductionProxyTypeInfo* proxy_info) const { @@ -276,18 +282,31 @@ void DataReductionProxyConfig::UpdateConfigurator(bool enabled, LogProxyState(enabled, restricted, at_startup); // The alternative is only configured if the standard configuration is // is enabled. - if (enabled & !config_values_->holdback()) { + std::string origin; + std::string fallback_origin; + std::string ssl_origin; + bool fallback_allowed = false; + if (enabled && !disabled_on_vpn_ && !config_values_->holdback()) { if (alternative_enabled) { - configurator_->Enable(restricted, - !config_values_->alternative_fallback_allowed(), - config_values_->alt_origin().ToURI(), std::string(), - config_values_->ssl_origin().ToURI()); + fallback_allowed = config_values_->alternative_fallback_allowed(); + if (config_values_->alt_origin().is_valid()) + origin = config_values_->alt_origin().ToURI(); + if (config_values_->ssl_origin().is_valid()) + ssl_origin = config_values_->ssl_origin().ToURI(); } else { - configurator_->Enable(restricted, !config_values_->fallback_allowed(), - config_values_->origin().ToURI(), - config_values_->fallback_origin().ToURI(), - std::string()); + fallback_allowed = config_values_->fallback_allowed(); + if (config_values_->origin().is_valid()) + origin = config_values_->origin().ToURI(); + if (config_values_->fallback_origin().is_valid()) + fallback_origin = config_values_->fallback_origin().ToURI(); } + } + + // TODO(jeremyim): Enable should take std::vector<net::ProxyServer> as its + // parameters. + if (!origin.empty() || !fallback_origin.empty() || !ssl_origin.empty()) { + configurator_->Enable(restricted, !fallback_allowed, origin, + fallback_origin, ssl_origin); } else { configurator_->Disable(); } @@ -475,17 +494,18 @@ bool DataReductionProxyConfig::DisableIfVPN() { interface_name.begin(), interface_name.begin() + vpn_interface_name_prefix.size(), vpn_interface_name_prefix.c_str())) { - UpdateConfigurator(false, alternative_enabled_by_user_, false, false); disabled_on_vpn_ = true; + UpdateConfigurator(enabled_by_user_, alternative_enabled_by_user_, + restricted_by_carrier_, false); RecordNetworkChangeEvent(DISABLED_ON_VPN); return true; } } if (disabled_on_vpn_) { + disabled_on_vpn_ = false; UpdateConfigurator(enabled_by_user_, alternative_enabled_by_user_, restricted_by_carrier_, false); } - disabled_on_vpn_ = false; return false; } 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 6573338..69098b7 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 @@ -90,6 +90,11 @@ class DataReductionProxyConfig bool alternative_enabled, bool at_startup); + // Provides a mechanism for an external object to force |this| to refresh + // the Data Reduction Proxy configuration from |config_values_| and apply to + // |configurator_|. Used by the Data Reduction Proxy config service client. + void ReloadConfig(); + // 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 diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.cc index 39a9481..59081c3 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.cc +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.cc @@ -4,27 +4,169 @@ #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.h" +#include <string> +#include <vector> + +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/json/json_writer.h" +#include "base/location.h" #include "base/logging.h" +#include "base/single_thread_task_runner.h" +#include "base/time/time.h" #include "base/values.h" +#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h" +#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_mutable_config_values.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.h" +#include "components/data_reduction_proxy/core/common/data_reduction_proxy_client_config_parser.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h" +#include "components/data_reduction_proxy/proto/client_config.pb.h" +#include "net/base/host_port_pair.h" +#include "net/proxy/proxy_server.h" namespace data_reduction_proxy { +namespace { + +// This is the default backoff policy used to communicate with the Data +// Reduction Proxy configuration service. +const net::BackoffEntry::Policy kDefaultBackoffPolicy = { + 0, // num_errors_to_ignore + 1 * 1000, // initial_delay_ms + 4, // multiply_factor + 0.10, // jitter_factor, + 30 * 60 * 1000, // maximum_backoff_ms + -1, // entry_lifetime_ms + true, // always_use_initial_delay +}; + +// Extracts the list of Data Reduction Proxy servers to use for HTTP requests. +std::vector<net::ProxyServer> GetProxiesForHTTP( + const data_reduction_proxy::ProxyConfig& proxy_config) { + std::vector<net::ProxyServer> proxies; + for (const auto& server : proxy_config.http_proxy_servers()) { + if (server.scheme() != ProxyServer_ProxyScheme_UNSPECIFIED) { + proxies.push_back(net::ProxyServer( + config_parser::SchemeFromProxyScheme(server.scheme()), + net::HostPortPair(server.host(), server.port()))); + } + } + + return proxies; +} + +// Calculate the next time at which the Data Reduction Proxy configuration +// should be retrieved, based on response success, configuration expiration, +// and the backoff delay. |backoff_delay| must be non-negative. Note that it is +// possible for |config_expiration| to be prior to |now|, but on a successful +// config refresh, |backoff_delay| will be returned. +base::TimeDelta CalculateNextConfigRefreshTime( + bool fetch_succeeded, + const base::Time& config_expiration, + const base::Time& now, + const base::TimeDelta& backoff_delay) { + DCHECK(backoff_delay >= base::TimeDelta()); + if (fetch_succeeded) { + base::TimeDelta success_delay = config_expiration - now; + if (success_delay > backoff_delay) + return success_delay; + } + + return backoff_delay; +} + +} // namespace + +const net::BackoffEntry::Policy& GetBackoffPolicy() { + return kDefaultBackoffPolicy; +} + DataReductionProxyConfigServiceClient::DataReductionProxyConfigServiceClient( - DataReductionProxyParams* params, - DataReductionProxyRequestOptions* request_options) - : params_(params), - request_options_(request_options) { - DCHECK(params); + scoped_ptr<DataReductionProxyParams> params, + const net::BackoffEntry::Policy& backoff_policy, + DataReductionProxyRequestOptions* request_options, + DataReductionProxyMutableConfigValues* config_values, + DataReductionProxyConfig* config, + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) + : params_(params.Pass()), + request_options_(request_options), + config_values_(config_values), + config_(config), + io_task_runner_(io_task_runner), + backoff_entry_(&backoff_policy) { DCHECK(request_options); + DCHECK(config_values); + DCHECK(config); + DCHECK(io_task_runner.get()); + io_task_runner_->PostTask( + FROM_HERE, + base::Bind(&DataReductionProxyConfigServiceClient::RetrieveConfig, + base::Unretained(this))); } DataReductionProxyConfigServiceClient:: ~DataReductionProxyConfigServiceClient() { } +void DataReductionProxyConfigServiceClient::RetrieveConfig() { + DCHECK(io_task_runner_->BelongsToCurrentThread()); + + std::string static_response = ConstructStaticResponse(); + ClientConfig config; + bool succeeded = false; + if (config_parser::ParseClientConfig(static_response, &config)) { + if (config.has_proxy_config()) { + net::ProxyServer origin; + net::ProxyServer fallback_origin; + std::vector<net::ProxyServer> proxies = + GetProxiesForHTTP(config.proxy_config()); + if (proxies.size() > 0) { + origin = proxies[0]; + if (proxies.size() > 1) + fallback_origin = proxies[1]; + + std::string session; + std::string credentials; + if (DataReductionProxyRequestOptions::ParseLocalSessionKey( + config.session_key(), &session, &credentials)) { + request_options_->SetCredentials(session, credentials); + config_values_->UpdateValues(origin, fallback_origin); + config_->ReloadConfig(); + succeeded = true; + } + } + } + } + + base::Time expiration_time; + if (succeeded) { + expiration_time = config_parser::TimestampToTime(config.expire_time()); + } + + GetBackoffEntry()->InformOfRequest(succeeded); + base::TimeDelta next_config_refresh_time = + CalculateNextConfigRefreshTime(succeeded, expiration_time, Now(), + GetBackoffEntry()->GetTimeUntilRelease()); + SetConfigRefreshTimer(next_config_refresh_time); +} + +net::BackoffEntry* DataReductionProxyConfigServiceClient::GetBackoffEntry() { + return &backoff_entry_; +} + +void DataReductionProxyConfigServiceClient::SetConfigRefreshTimer( + const base::TimeDelta& delay) { + DCHECK(delay >= base::TimeDelta()); + config_refresh_timer_.Stop(); + config_refresh_timer_.Start( + FROM_HERE, delay, this, + &DataReductionProxyConfigServiceClient::RetrieveConfig); +} + +base::Time DataReductionProxyConfigServiceClient::Now() const { + return base::Time::Now(); +} + std::string DataReductionProxyConfigServiceClient::ConstructStaticResponse() const { std::string response; diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.h index 648cee4..3f6ae23 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.h +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.h @@ -9,38 +9,95 @@ #include "base/gtest_prod_util.h" #include "base/macros.h" +#include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" +#include "base/timer/timer.h" +#include "net/base/backoff_entry.h" + +namespace base { +class SingleThreadTaskRunner; +class Time; +class TimeDelta; +} namespace data_reduction_proxy { +class DataReductionProxyConfig; +class DataReductionProxyMutableConfigValues; class DataReductionProxyParams; class DataReductionProxyRequestOptions; +// Retrieves the default net::BackoffEntry::Policy for the Data Reduction Proxy +// configuration service client. +const net::BackoffEntry::Policy& GetBackoffPolicy(); + // Retrieves the Data Reduction Proxy configuration from a remote service. This // object lives on the IO thread. class DataReductionProxyConfigServiceClient { public: // The caller must ensure that all parameters remain alive for the lifetime of - // the |DataReductionProxyConfigClient|. + // the |DataReductionProxyConfigClient|, with the exception of |params| + // which this instance will own. DataReductionProxyConfigServiceClient( - DataReductionProxyParams* params, - DataReductionProxyRequestOptions* request_options); + scoped_ptr<DataReductionProxyParams> params, + const net::BackoffEntry::Policy& backoff_policy, + DataReductionProxyRequestOptions* request_options, + DataReductionProxyMutableConfigValues* config_values, + DataReductionProxyConfig* config, + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner); - ~DataReductionProxyConfigServiceClient(); + virtual ~DataReductionProxyConfigServiceClient(); - private: - FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigClientTest, - TestConstructStaticResponse); + // Request the retrieval of the Data Reduction Proxy configuration. + void RetrieveConfig(); + + protected: + // Retrieves the backoff entry object being used to throttle request failures. + // Virtual for testing. + virtual net::BackoffEntry* GetBackoffEntry(); + + // Sets a timer to determine when to next refresh the Data Reduction Proxy + // configuration. + // Virtual for testing. + virtual void SetConfigRefreshTimer(const base::TimeDelta& delay); + + // Returns the current time. + // Virtual for testing. + virtual base::Time Now() const; // Constructs a synthetic response based on |params_|. - std::string ConstructStaticResponse() const; + // Virtual for testing. + virtual std::string ConstructStaticResponse() const; - // The caller must ensure that the |params_| outlives this instance. - DataReductionProxyParams* params_; + private: + FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigServiceClientTest, + TestConstructStaticResponse); + friend class TestDataReductionProxyConfigServiceClient; + + // Contains the static configuration data to use. + scoped_ptr<DataReductionProxyParams> params_; // The caller must ensure that the |request_options_| outlives this instance. DataReductionProxyRequestOptions* request_options_; + // The caller must ensure that the |config_values_| outlives this instance. + DataReductionProxyMutableConfigValues* config_values_; + + // The caller must ensure that the |config_| outlives this instance. + DataReductionProxyConfig* config_; + + // |io_task_runner_| should be the task runner for running operations on the + // IO thread. + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; + + // Used to calculate the backoff time on request failures. + net::BackoffEntry backoff_entry_; + + // An event that fires when it is time to refresh the Data Reduction Proxy + // configuration. + base::OneShotTimer<DataReductionProxyConfigServiceClient> + config_refresh_timer_; + DISALLOW_COPY_AND_ASSIGN(DataReductionProxyConfigServiceClient); }; diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client_unittest.cc index 6b44ceb..f8e7c0f 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client_unittest.cc +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client_unittest.cc @@ -7,8 +7,10 @@ #include <string> #include "base/memory/scoped_ptr.h" +#include "base/time/tick_clock.h" #include "base/values.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.h" +#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator_test_utils.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_client_config_parser.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h" @@ -19,7 +21,34 @@ namespace data_reduction_proxy { -class DataReductionProxyConfigClientTest : public testing::Test { +namespace { + +class RequestOptionsPopulator { + public: + RequestOptionsPopulator(const base::Time& expiration_time, + const base::TimeDelta& increment) + : expiration_time_(expiration_time), + increment_(increment) { + } + + void PopulateResponse(base::DictionaryValue* response) { + response->SetString("sessionKey", "abcdef|1234-5678-12345678"); + response->SetString("expireTime", + config_parser::TimeToISO8601(expiration_time_)); + expiration_time_ += increment_; + } + + private: + base::Time expiration_time_; + base::TimeDelta increment_; +}; + +void PopulateResponseFailure(base::DictionaryValue* response) { +} + +} // namespace + +class DataReductionProxyConfigServiceClientTest : public testing::Test { protected: void SetUp() override { test_context_ = @@ -28,20 +57,62 @@ class DataReductionProxyConfigClientTest : public testing::Test { DataReductionProxyParams::kFallbackAllowed | DataReductionProxyParams::kPromoAllowed) .WithParamsDefinitions(TestDataReductionProxyParams::HAS_EVERYTHING) + .WithTestConfigurator() + .WithMockRequestOptions() + .WithTestConfigClient() .Build(); + test_context_->test_config_client()->SetCustomReleaseTime( + base::TimeTicks::UnixEpoch()); + test_context_->test_config_client()->SetNow(base::Time::UnixEpoch()); + } + + void SetDataReductionProxyEnabled(bool enabled) { + test_context_->config()->SetStateForTest(enabled, false, false); } scoped_ptr<DataReductionProxyConfigServiceClient> BuildConfigClient() { - return make_scoped_ptr(new DataReductionProxyConfigServiceClient( - test_context_->config()->test_params(), - test_context_->io_data()->request_options())); + scoped_ptr<DataReductionProxyParams> params(new DataReductionProxyParams( + DataReductionProxyParams::kAllowed | + DataReductionProxyParams::kFallbackAllowed | + DataReductionProxyParams::kPromoAllowed)); + request_options_.reset( + new DataReductionProxyRequestOptions(Client::UNKNOWN, + test_context_->io_data()->config(), + test_context_->task_runner())); + return scoped_ptr<DataReductionProxyConfigServiceClient>( + new DataReductionProxyConfigServiceClient( + params.Pass(), GetBackoffPolicy(), + request_options_.get(), + test_context_->mutable_config_values(), + test_context_->io_data()->config(), test_context_->task_runner())); + } + + DataReductionProxyParams* params() { + return test_context_->test_params(); + } + + TestDataReductionProxyConfigServiceClient* config_client() { + return test_context_->test_config_client(); + } + + TestDataReductionProxyConfigurator* configurator() { + return test_context_->test_configurator(); + } + + MockDataReductionProxyRequestOptions* request_options() { + return test_context_->mock_request_options(); + } + + void RunUntilIdle() { + test_context_->RunUntilIdle(); } private: scoped_ptr<DataReductionProxyTestContext> test_context_; + scoped_ptr<DataReductionProxyRequestOptions> request_options_; }; -TEST_F(DataReductionProxyConfigClientTest, TestConstructStaticResponse) { +TEST_F(DataReductionProxyConfigServiceClientTest, TestConstructStaticResponse) { scoped_ptr<DataReductionProxyConfigServiceClient> config_client = BuildConfigClient(); std::string config_data = config_client->ConstructStaticResponse(); @@ -49,4 +120,93 @@ TEST_F(DataReductionProxyConfigClientTest, TestConstructStaticResponse) { EXPECT_TRUE(config_parser::ParseClientConfig(config_data, &config)); } +TEST_F(DataReductionProxyConfigServiceClientTest, SuccessfulLoop) { + RequestOptionsPopulator populator( + base::Time::UnixEpoch() + base::TimeDelta::FromDays(1), + base::TimeDelta::FromDays(1)); + SetDataReductionProxyEnabled(true); + EXPECT_TRUE(configurator()->origin().empty()); + EXPECT_TRUE(configurator()->fallback_origin().empty()); + EXPECT_TRUE(configurator()->ssl_origin().empty()); + EXPECT_CALL(*request_options(), PopulateConfigResponse(testing::_)) + .Times(2) + .WillRepeatedly( + testing::Invoke(&populator, + &RequestOptionsPopulator::PopulateResponse)); + RunUntilIdle(); + EXPECT_EQ(base::TimeDelta::FromDays(1), config_client()->GetDelay()); + EXPECT_EQ(params()->origin().ToURI(), configurator()->origin()); + EXPECT_EQ(params()->fallback_origin().ToURI(), + configurator()->fallback_origin()); + EXPECT_TRUE(configurator()->ssl_origin().empty()); + config_client()->SetNow(base::Time::UnixEpoch() + base::TimeDelta::FromDays(1) + + base::TimeDelta::FromSeconds(5)); + config_client()->RetrieveConfig(); + EXPECT_EQ(base::TimeDelta::FromDays(1) - base::TimeDelta::FromSeconds(5), + config_client()->GetDelay()); + EXPECT_EQ(params()->origin().ToURI(), configurator()->origin()); + EXPECT_EQ(params()->fallback_origin().ToURI(), + configurator()->fallback_origin()); + EXPECT_TRUE(configurator()->ssl_origin().empty()); +} + +TEST_F(DataReductionProxyConfigServiceClientTest, SuccessfulLoopShortDuration) { + RequestOptionsPopulator populator( + base::Time::UnixEpoch() + base::TimeDelta::FromSeconds(1), + base::TimeDelta::FromSeconds(1)); + SetDataReductionProxyEnabled(true); + EXPECT_TRUE(configurator()->origin().empty()); + EXPECT_TRUE(configurator()->fallback_origin().empty()); + EXPECT_TRUE(configurator()->ssl_origin().empty()); + EXPECT_CALL(*request_options(), PopulateConfigResponse(testing::_)) + .Times(1) + .WillOnce(testing::Invoke(&populator, + &RequestOptionsPopulator::PopulateResponse)); + RunUntilIdle(); + EXPECT_EQ(base::TimeDelta::FromSeconds(10), config_client()->GetDelay()); + EXPECT_EQ(params()->origin().ToURI(), configurator()->origin()); + EXPECT_EQ(params()->fallback_origin().ToURI(), + configurator()->fallback_origin()); + EXPECT_TRUE(configurator()->ssl_origin().empty()); +} + +TEST_F(DataReductionProxyConfigServiceClientTest, EnsureBackoff) { + SetDataReductionProxyEnabled(true); + EXPECT_TRUE(configurator()->origin().empty()); + EXPECT_TRUE(configurator()->fallback_origin().empty()); + EXPECT_TRUE(configurator()->ssl_origin().empty()); + EXPECT_CALL(*request_options(), PopulateConfigResponse(testing::_)) + .Times(2) + .WillRepeatedly(testing::Invoke(&PopulateResponseFailure)); + config_client()->RetrieveConfig(); + EXPECT_TRUE(configurator()->origin().empty()); + EXPECT_TRUE(configurator()->fallback_origin().empty()); + EXPECT_TRUE(configurator()->ssl_origin().empty()); + EXPECT_EQ(base::TimeDelta::FromSeconds(20), config_client()->GetDelay()); + config_client()->RetrieveConfig(); + EXPECT_TRUE(configurator()->origin().empty()); + EXPECT_TRUE(configurator()->fallback_origin().empty()); + EXPECT_TRUE(configurator()->ssl_origin().empty()); + EXPECT_EQ(base::TimeDelta::FromSeconds(40), config_client()->GetDelay()); +} + +TEST_F(DataReductionProxyConfigServiceClientTest, ConfigDisabled) { + RequestOptionsPopulator populator( + base::Time::UnixEpoch() + base::TimeDelta::FromDays(1), + base::TimeDelta::FromDays(1)); + SetDataReductionProxyEnabled(false); + EXPECT_TRUE(configurator()->origin().empty()); + EXPECT_TRUE(configurator()->fallback_origin().empty()); + EXPECT_TRUE(configurator()->ssl_origin().empty()); + EXPECT_CALL(*request_options(), PopulateConfigResponse(testing::_)) + .Times(1) + .WillOnce(testing::Invoke(&populator, + &RequestOptionsPopulator::PopulateResponse)); + RunUntilIdle(); + EXPECT_TRUE(configurator()->origin().empty()); + EXPECT_TRUE(configurator()->fallback_origin().empty()); + EXPECT_TRUE(configurator()->ssl_origin().empty()); + EXPECT_EQ(base::TimeDelta::FromDays(1), config_client()->GetDelay()); +} + } // namespace data_reduction_proxy 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 03676c9..f6e836c 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 @@ -4,6 +4,7 @@ #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.h" +#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_mutable_config_values.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.h" #include "net/base/net_util.h" #include "net/url_request/test_url_fetcher_factory.h" @@ -21,12 +22,28 @@ TestDataReductionProxyConfig::TestDataReductionProxyConfig( net::NetLog* net_log, DataReductionProxyConfigurator* configurator, DataReductionProxyEventStore* event_store) - : DataReductionProxyConfig( - task_runner, task_runner, net_log, - make_scoped_ptr( - new TestDataReductionProxyParams(params_flags, params_definitions)) - .Pass(), - configurator, event_store) { + : TestDataReductionProxyConfig( + make_scoped_ptr( + new TestDataReductionProxyParams(params_flags, + params_definitions)).Pass(), + task_runner, + net_log, + configurator, + event_store) { +} + +TestDataReductionProxyConfig::TestDataReductionProxyConfig( + scoped_ptr<DataReductionProxyConfigValues> config_values, + scoped_refptr<base::SingleThreadTaskRunner> task_runner, + net::NetLog* net_log, + DataReductionProxyConfigurator* configurator, + DataReductionProxyEventStore* event_store) + : DataReductionProxyConfig(task_runner, + task_runner, + net_log, + config_values.Pass(), + configurator, + event_store) { network_interfaces_.reset(new net::NetworkInterfaceList()); } @@ -58,28 +75,30 @@ TestDataReductionProxyParams* TestDataReductionProxyConfig::test_params() { return static_cast<TestDataReductionProxyParams*>(config_values_.get()); } +DataReductionProxyConfigValues* TestDataReductionProxyConfig::config_values() { + return config_values_.get(); +} + void TestDataReductionProxyConfig::SetStateForTest( bool enabled_by_user, bool alternative_enabled_by_user, - bool restricted_by_carrier, - bool at_startup) { + bool restricted_by_carrier) { enabled_by_user_ = enabled_by_user; alternative_enabled_by_user_ = alternative_enabled_by_user; restricted_by_carrier_ = restricted_by_carrier; - UpdateConfigurator(enabled_by_user_, alternative_enabled_by_user_, - restricted_by_carrier_, at_startup); } MockDataReductionProxyConfig::MockDataReductionProxyConfig( - int params_flags, - unsigned int params_definitions, + scoped_ptr<DataReductionProxyConfigValues> config_values, scoped_refptr<base::SingleThreadTaskRunner> task_runner, net::NetLog* net_log, DataReductionProxyConfigurator* configurator, DataReductionProxyEventStore* event_store) - : TestDataReductionProxyConfig( - params_flags, params_definitions, task_runner, net_log, configurator, - event_store) { + : TestDataReductionProxyConfig(config_values.Pass(), + task_runner, + net_log, + configurator, + event_store) { } MockDataReductionProxyConfig::~MockDataReductionProxyConfig() { 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 79c5548..fba88ee 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 @@ -23,6 +23,7 @@ namespace data_reduction_proxy { class DataReductionProxyConfigurator; class DataReductionProxyEventStore; +class DataReductionProxyMutableConfigValues; class TestDataReductionProxyParams; // Test version of |DataReductionProxyConfig|, which uses an underlying @@ -39,6 +40,17 @@ class TestDataReductionProxyConfig : public DataReductionProxyConfig { net::NetLog* net_log, DataReductionProxyConfigurator* configurator, DataReductionProxyEventStore* event_store); + + // Creates a |TestDataReductionProxyConfig| with the provided |config_values|. + // This permits any DataReductionProxyConfigValues to be used (such as + // DataReductionProxyParams or DataReductionProxyMutableConfigValues). + TestDataReductionProxyConfig( + scoped_ptr<DataReductionProxyConfigValues> config_values, + scoped_refptr<base::SingleThreadTaskRunner> task_runner, + net::NetLog* net_log, + DataReductionProxyConfigurator* configurator, + DataReductionProxyEventStore* event_store); + ~TestDataReductionProxyConfig() override; void GetNetworkList(net::NetworkInterfaceList* interfaces, @@ -53,11 +65,14 @@ class TestDataReductionProxyConfig : public DataReductionProxyConfig { // Retrieves the test params being used for the configuration. TestDataReductionProxyParams* test_params(); + // Retrieves the underlying config values. + // TODO(jeremyim): Rationalize with test_params(). + DataReductionProxyConfigValues* config_values(); + // Allows tests to set the internal state. void SetStateForTest(bool enabled_by_user, bool alternative_enabled_by_user, - bool restricted_by_carrier, - bool at_startup); + bool restricted_by_carrier); net::NetworkInterfaceList* interfaces() { return network_interfaces_.get(); @@ -71,10 +86,9 @@ class TestDataReductionProxyConfig : public DataReductionProxyConfig { // testing. class MockDataReductionProxyConfig : public TestDataReductionProxyConfig { public: - // Creates a |MockDataReductionProxyConfig| with the provided |params_flags|. + // Creates a |MockDataReductionProxyConfig|. MockDataReductionProxyConfig( - int params_flags, - unsigned int params_definitions, + scoped_ptr<DataReductionProxyConfigValues> config_values, scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, net::NetLog* net_log, DataReductionProxyConfigurator* configurator, 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 57b79f7..b957ab5 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 @@ -10,9 +10,11 @@ #include "base/single_thread_task_runner.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_bypass_protocol.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h" +#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_delegate.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor.h" +#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_mutable_config_values.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h" @@ -46,12 +48,32 @@ DataReductionProxyIOData::DataReductionProxyIOData( 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())); + bool use_config_client = DataReductionProxyParams::IsConfigClientEnabled(); + DataReductionProxyMutableConfigValues* raw_mutable_config = nullptr; + if (use_config_client) { + scoped_ptr<DataReductionProxyMutableConfigValues> mutable_config = + DataReductionProxyMutableConfigValues::CreateFromParams(io_task_runner_, + params.get()); + raw_mutable_config = mutable_config.get(); + config_.reset(new DataReductionProxyConfig( + io_task_runner_, ui_task_runner_, net_log, mutable_config.Pass(), + configurator_.get(), event_store_.get())); + } else { + config_.reset(new DataReductionProxyConfig( + io_task_runner_, ui_task_runner_, net_log, params.Pass(), + configurator_.get(), event_store_.get())); + } + request_options_.reset(new DataReductionProxyRequestOptions( client_, config_.get(), io_task_runner_)); request_options_->Init(); + + if (use_config_client) { + config_client_.reset(new DataReductionProxyConfigServiceClient( + params.Pass(), GetBackoffPolicy(), request_options_.get(), + raw_mutable_config, config_.get(), io_task_runner_)); + } + proxy_delegate_.reset( new DataReductionProxyDelegate(request_options_.get(), config_.get())); } diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h index 0403c0a..ff0967b 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h @@ -21,6 +21,7 @@ class URLRequestInterceptor; namespace data_reduction_proxy { class DataReductionProxyConfig; +class DataReductionProxyConfigServiceClient; class DataReductionProxyConfigurator; class DataReductionProxyEventStore; class DataReductionProxyService; @@ -150,6 +151,9 @@ class DataReductionProxyIOData { // Constructs credentials suitable for authenticating the client. scoped_ptr<DataReductionProxyRequestOptions> request_options_; + // Requests new Data Reduction Proxy configurations from a remote service. + scoped_ptr<DataReductionProxyConfigServiceClient> config_client_; + // A net log. net::NetLog* net_log_; diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_mutable_config_values.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_mutable_config_values.cc new file mode 100644 index 0000000..cebbdaca --- /dev/null +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_mutable_config_values.cc @@ -0,0 +1,140 @@ +// 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/data_reduction_proxy/core/browser/data_reduction_proxy_mutable_config_values.h" + +#include "base/single_thread_task_runner.h" +#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h" + +namespace data_reduction_proxy { + +scoped_ptr<DataReductionProxyMutableConfigValues> +DataReductionProxyMutableConfigValues::CreateFromParams( + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, + const DataReductionProxyParams* params) { + scoped_ptr<DataReductionProxyMutableConfigValues> config_values( + new DataReductionProxyMutableConfigValues(io_task_runner)); + config_values->promo_allowed_ = params->promo_allowed(); + config_values->holdback_ = params->holdback(); + config_values->allowed_ = params->allowed(); + config_values->fallback_allowed_ = params->fallback_allowed(); + config_values->secure_proxy_check_url_ = params->secure_proxy_check_url(); + return config_values.Pass(); +} + +DataReductionProxyMutableConfigValues::DataReductionProxyMutableConfigValues( + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) + : empty_origin_(), + promo_allowed_(false), + holdback_(false), + allowed_(false), + fallback_allowed_(false), + origin_(empty_origin_), + fallback_origin_(empty_origin_), + io_task_runner_(io_task_runner) { + DCHECK(io_task_runner.get()); +} + +DataReductionProxyMutableConfigValues:: + ~DataReductionProxyMutableConfigValues() { +} + +bool DataReductionProxyMutableConfigValues::promo_allowed() const { + return promo_allowed_; +} + +bool DataReductionProxyMutableConfigValues::holdback() const { + return holdback_; +} + +bool DataReductionProxyMutableConfigValues::allowed() const { + return allowed_; +} + +bool DataReductionProxyMutableConfigValues::fallback_allowed() const { + return fallback_allowed_; +} + +bool DataReductionProxyMutableConfigValues::alternative_allowed() const { + return false; +} + +bool DataReductionProxyMutableConfigValues::alternative_fallback_allowed() + const { + return false; +} + +bool DataReductionProxyMutableConfigValues::UsingHTTPTunnel( + const net::HostPortPair& proxy_server) const { + return false; +} + +bool DataReductionProxyMutableConfigValues::IsDataReductionProxy( + const net::HostPortPair& host_port_pair, + DataReductionProxyTypeInfo* proxy_info) const { + // TODO(jeremyim): Rework as part of ConfigValues interface changes. + if (allowed() && origin().is_valid() && + origin().host_port_pair().Equals(host_port_pair)) { + if (proxy_info) { + proxy_info->proxy_servers.first = origin(); + if (fallback_allowed()) + proxy_info->proxy_servers.second = fallback_origin(); + } + return true; + } + + if (!fallback_allowed() || !fallback_origin().is_valid() || + !fallback_origin().host_port_pair().Equals(host_port_pair)) + return false; + + if (proxy_info) { + proxy_info->proxy_servers.first = fallback_origin(); + proxy_info->proxy_servers.second = net::ProxyServer::FromURI( + std::string(), net::ProxyServer::SCHEME_HTTP); + proxy_info->is_fallback = true; + } + + return true; +} + +const net::ProxyServer& DataReductionProxyMutableConfigValues::origin() const { + DCHECK(io_task_runner_->BelongsToCurrentThread()); + return origin_; +} + +const net::ProxyServer& DataReductionProxyMutableConfigValues::fallback_origin() + const { + DCHECK(io_task_runner_->BelongsToCurrentThread()); + return fallback_origin_; +} + +const net::ProxyServer& DataReductionProxyMutableConfigValues::alt_origin() + const { + return empty_origin_; +} + +const net::ProxyServer& +DataReductionProxyMutableConfigValues::alt_fallback_origin() const { + return empty_origin_; +} + +const net::ProxyServer& DataReductionProxyMutableConfigValues::ssl_origin() + const { + return empty_origin_; +} + +const GURL& DataReductionProxyMutableConfigValues::secure_proxy_check_url() + const { + return secure_proxy_check_url_; +} + +void DataReductionProxyMutableConfigValues::UpdateValues( + const net::ProxyServer& origin, + const net::ProxyServer& fallback_origin) { + DCHECK(io_task_runner_->BelongsToCurrentThread()); + origin_ = origin; + fallback_origin_ = fallback_origin; +} + +} // namespace data_reduction_proxy diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_mutable_config_values.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_mutable_config_values.h new file mode 100644 index 0000000..6897cb9 --- /dev/null +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_mutable_config_values.h @@ -0,0 +1,81 @@ +// 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. + +#ifndef COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_MUTABLE_CONFIG_VALUES_H_ +#define COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_MUTABLE_CONFIG_VALUES_H_ + +#include "base/macros.h" +#include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" +#include "components/data_reduction_proxy/core/common/data_reduction_proxy_config_values.h" +#include "net/proxy/proxy_server.h" +#include "url/gurl.h" + +namespace base { +class SingleThreadTaskRunner; +} + +namespace data_reduction_proxy { + +class DataReductionProxyParams; + +// A |DataReductionProxyConfigValues| which is permitted to change its +// underlying values via the UpdateValues method. +class DataReductionProxyMutableConfigValues + : public DataReductionProxyConfigValues { + public: + // Creates a new |DataReductionProxyMutableConfigValues| using |params| as + // the basis for its initial values. + static scoped_ptr<DataReductionProxyMutableConfigValues> CreateFromParams( + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, + const DataReductionProxyParams* params); + + ~DataReductionProxyMutableConfigValues() override; + + // Updates |origin_| and |fallback_origin_| with the provided values. + // Virtual for testing. + virtual void UpdateValues(const net::ProxyServer& origin, + const net::ProxyServer& fallback_origin); + + // Overrides of |DataReductionProxyConfigValues| + bool promo_allowed() const override; + bool holdback() const override; + bool allowed() const override; + bool fallback_allowed() const override; + bool alternative_allowed() const override; + bool alternative_fallback_allowed() const override; + bool UsingHTTPTunnel(const net::HostPortPair& proxy_server) const override; + bool IsDataReductionProxy( + const net::HostPortPair& host_port_pair, + DataReductionProxyTypeInfo* proxy_info) const override; + const net::ProxyServer& origin() const override; + const net::ProxyServer& fallback_origin() const override; + const net::ProxyServer& alt_origin() const override; + const net::ProxyServer& alt_fallback_origin() const override; + const net::ProxyServer& ssl_origin() const override; + const GURL& secure_proxy_check_url() const override; + + protected: + DataReductionProxyMutableConfigValues( + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner); + + private: + net::ProxyServer empty_origin_; + bool promo_allowed_; + bool holdback_; + bool allowed_; + bool fallback_allowed_; + net::ProxyServer origin_; + net::ProxyServer fallback_origin_; + GURL secure_proxy_check_url_; + + // |io_task_runner_| should be the task runner for running operations on the + // IO thread. + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; + + DISALLOW_COPY_AND_ASSIGN(DataReductionProxyMutableConfigValues); +}; + +} // namespace data_reduction_proxy +#endif // COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_MUTABLE_CONFIG_VALUES_H_ 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 675b05c..1b95890 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 @@ -99,6 +99,7 @@ DataReductionProxyRequestOptions::DataReductionProxyRequestOptions( DataReductionProxyConfig* config, scoped_refptr<base::SingleThreadTaskRunner> network_task_runner) : client_(GetString(client)), + use_assigned_credentials_(false), data_reduction_proxy_config_(config), network_task_runner_(network_task_runner) { GetChromiumBuildAndPatch(ChromiumVersion(), &build_, &patch_); @@ -110,6 +111,7 @@ DataReductionProxyRequestOptions::DataReductionProxyRequestOptions( DataReductionProxyConfig* config, scoped_refptr<base::SingleThreadTaskRunner> network_task_runner) : client_(GetString(client)), + use_assigned_credentials_(false), data_reduction_proxy_config_(config), network_task_runner_(network_task_runner) { GetChromiumBuildAndPatch(version, &build_, &patch_); @@ -227,7 +229,7 @@ void DataReductionProxyRequestOptions::SetHeader( net::HttpRequestHeaders* headers) { base::Time now = Now(); // Authorization credentials must be regenerated if they are expired. - if (now > credentials_expiration_time_) + if (!use_assigned_credentials_ && (now > credentials_expiration_time_)) UpdateCredentials(); UpdateLoFi(); const char kChromeProxyHeader[] = "Chrome-Proxy"; @@ -264,8 +266,6 @@ void DataReductionProxyRequestOptions::ComputeCredentials( } void DataReductionProxyRequestOptions::UpdateCredentials() { - std::string session; - std::string credentials; base::Time now = Now(); ComputeCredentials(now, &session_, &credentials_); credentials_expiration_time_ = now + base::TimeDelta::FromHours(24); @@ -293,6 +293,18 @@ void DataReductionProxyRequestOptions::PopulateConfigResponse( config_parser::TimeToISO8601(expiration_time)); } +void DataReductionProxyRequestOptions::SetCredentials( + const std::string& session, + const std::string& credentials) { + DCHECK(network_task_runner_->BelongsToCurrentThread()); + session_ = session; + credentials_ = credentials; + // Force skipping of credential regeneration. It should be handled by the + // caller. + use_assigned_credentials_ = true; + RegenerateRequestHeaderValue(); +} + std::string DataReductionProxyRequestOptions::GetDefaultKey() const { const base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.h index 5a0b3b0..8d6c289 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.h +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.h @@ -125,6 +125,10 @@ class DataReductionProxyRequestOptions { // Virtualized for testing. virtual void PopulateConfigResponse(base::DictionaryValue* response) const; + // Sets the credentials for sending to the Data Reduction Proxy. + void SetCredentials(const std::string& session, + const std::string& credentials); + protected: void SetHeader(net::HttpRequestHeaders* headers); @@ -211,6 +215,10 @@ class DataReductionProxyRequestOptions { // never used for more than twenty-four hours. base::Time credentials_expiration_time_; + // Whether the authentication headers are sourced by |this| or injected via + // |SetCredentials|. + bool use_assigned_credentials_; + DataReductionProxyConfig* data_reduction_proxy_config_; scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; 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 7e73e60..fe091dc 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 @@ -45,7 +45,7 @@ class DataReductionProxySettingsTest test_context_->pref_service()->SetBoolean(prefs::kDataReductionProxyEnabled, initially_enabled); test_context_->config()->SetStateForTest(initially_enabled, false, - !request_succeeded, false); + !request_succeeded); ExpectSetProxyPrefs(expected_enabled, false, false); settings_->MaybeActivateDataReductionProxy(false); test_context_->RunUntilIdle(); @@ -55,7 +55,7 @@ class DataReductionProxySettingsTest TEST_F(DataReductionProxySettingsTest, TestIsProxyEnabledOrManaged) { settings_->InitPrefMembers(); // The proxy is disabled initially. - test_context_->config()->SetStateForTest(false, false, false, false); + test_context_->config()->SetStateForTest(false, false, false); EXPECT_FALSE(settings_->IsDataReductionProxyEnabled()); EXPECT_FALSE(settings_->IsDataReductionProxyManaged()); @@ -74,7 +74,7 @@ TEST_F(DataReductionProxySettingsTest, TestIsProxyEnabledOrManaged) { TEST_F(DataReductionProxySettingsTest, TestCanUseDataReductionProxy) { settings_->InitPrefMembers(); // The proxy is disabled initially. - test_context_->config()->SetStateForTest(false, false, false, false); + test_context_->config()->SetStateForTest(false, false, false); GURL http_gurl("http://url.com/"); EXPECT_FALSE(settings_->CanUseDataReductionProxy(http_gurl)); @@ -240,7 +240,7 @@ TEST(DataReductionProxySettingsStandaloneTest, TestOnProxyEnabledPrefChange) { .Build(); // The proxy is enabled initially. - drp_test_context->config()->SetStateForTest(true, false, false, true); + drp_test_context->config()->SetStateForTest(true, false, false); drp_test_context->InitSettings(); // The pref is disabled, so correspondingly should be the proxy. @@ -269,7 +269,7 @@ TEST_F(DataReductionProxySettingsTest, TestMaybeActivateDataReductionProxy) { // TODO(bengr): Test enabling/disabling while a secure proxy check is // outstanding. - // The proxy is enabled and unrestructed initially. + // The proxy is enabled and unrestricted initially. // Request succeeded but with bad response, expect proxy to be restricted. CheckMaybeActivateDataReductionProxy(true, true, true, true, false); // Request succeeded with valid response, expect proxy to be unrestricted. diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.cc index e9ea65ee..aae60c3 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.cc +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.cc @@ -6,9 +6,11 @@ #include "base/message_loop/message_loop.h" #include "base/prefs/testing_pref_service.h" +#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator_test_utils.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor.h" +#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_mutable_config_values.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_prefs.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h" @@ -26,6 +28,16 @@ namespace { const char kTestKey[] = "test-key"; +const net::BackoffEntry::Policy kTestBackoffPolicy = { + 0, // num_errors_to_ignore + 10 * 1000, // initial_delay_ms + 2, // multiply_factor + 0, // jitter_factor + 30 * 60 * 1000, // maximum_backoff_ms + -1, // entry_lifetime_ms + true, // always_use_initial_delay +}; + } // namespace namespace data_reduction_proxy { @@ -71,6 +83,82 @@ MockDataReductionProxyRequestOptions::MockDataReductionProxyRequestOptions( MockDataReductionProxyRequestOptions::~MockDataReductionProxyRequestOptions() { } +TestDataReductionProxyConfigServiceClient:: + TestDataReductionProxyConfigServiceClient( + scoped_ptr<DataReductionProxyParams> params, + DataReductionProxyRequestOptions* request_options, + DataReductionProxyMutableConfigValues* config_values, + DataReductionProxyConfig* config, + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) + : DataReductionProxyConfigServiceClient(params.Pass(), + kTestBackoffPolicy, + request_options, + config_values, + config, + io_task_runner), + tick_clock_(base::Time::UnixEpoch()), + test_backoff_entry_(&kTestBackoffPolicy, &tick_clock_) { +} + +TestDataReductionProxyConfigServiceClient:: + ~TestDataReductionProxyConfigServiceClient() { +} + +void TestDataReductionProxyConfigServiceClient::SetNow(const base::Time& time) { + tick_clock_.SetTime(time); +} + +void TestDataReductionProxyConfigServiceClient::SetCustomReleaseTime( + const base::TimeTicks& release_time) { + test_backoff_entry_.SetCustomReleaseTime(release_time); +} + +base::TimeDelta TestDataReductionProxyConfigServiceClient::GetDelay() const { + return config_refresh_timer_.GetCurrentDelay(); +} + +base::Time TestDataReductionProxyConfigServiceClient::Now() const { + return tick_clock_.Now(); +} + +net::BackoffEntry* +TestDataReductionProxyConfigServiceClient::GetBackoffEntry() { + return &test_backoff_entry_; +} + +TestDataReductionProxyConfigServiceClient::TestTickClock::TestTickClock( + const base::Time& initial_time) + : time_(initial_time) { +} + +base::TimeTicks +TestDataReductionProxyConfigServiceClient::TestTickClock::NowTicks() const { + return base::TimeTicks::UnixEpoch() + (time_ - base::Time::UnixEpoch()); +} + +base::Time +TestDataReductionProxyConfigServiceClient::TestTickClock::Now() const { + return time_; +} + +void TestDataReductionProxyConfigServiceClient::TestTickClock::SetTime( + const base::Time& time) { + time_ = time; +} + +TestDataReductionProxyConfigServiceClient::TestBackoffEntry::TestBackoffEntry( + const net::BackoffEntry::Policy* const policy, + const TestTickClock* tick_clock) + : net::BackoffEntry(policy), + tick_clock_(tick_clock) { +} + +base::TimeTicks +TestDataReductionProxyConfigServiceClient::TestBackoffEntry::ImplGetTimeNow() + const { + return tick_clock_->NowTicks(); +} + MockDataReductionProxyService::MockDataReductionProxyService( scoped_ptr<DataReductionProxyStatisticsPrefs> statistics_prefs, DataReductionProxySettings* settings, @@ -84,10 +172,11 @@ MockDataReductionProxyService::~MockDataReductionProxyService() { TestDataReductionProxyIOData::TestDataReductionProxyIOData( scoped_refptr<base::SingleThreadTaskRunner> task_runner, - scoped_ptr<TestDataReductionProxyConfig> config, + scoped_ptr<DataReductionProxyConfig> config, scoped_ptr<DataReductionProxyEventStore> event_store, scoped_ptr<DataReductionProxyRequestOptions> request_options, - scoped_ptr<DataReductionProxyConfigurator> configurator) + scoped_ptr<DataReductionProxyConfigurator> configurator, + scoped_ptr<DataReductionProxyConfigServiceClient> config_client) : DataReductionProxyIOData() { io_task_runner_ = task_runner; ui_task_runner_ = task_runner; @@ -95,6 +184,7 @@ TestDataReductionProxyIOData::TestDataReductionProxyIOData( event_store_ = event_store.Pass(); request_options_ = request_options.Pass(); configurator_ = configurator.Pass(); + config_client_ = config_client.Pass(); io_task_runner_ = task_runner; ui_task_runner_ = task_runner; } @@ -113,6 +203,8 @@ DataReductionProxyTestContext::Builder::Builder() use_test_configurator_(false), use_mock_service_(false), use_mock_request_options_(false), + use_config_client_(false), + use_test_config_client_(false), skip_settings_initialization_(false) { } @@ -174,6 +266,19 @@ DataReductionProxyTestContext::Builder::WithMockRequestOptions() { } DataReductionProxyTestContext::Builder& +DataReductionProxyTestContext::Builder::WithConfigClient() { + use_config_client_ = true; + return *this; +} + +DataReductionProxyTestContext::Builder& +DataReductionProxyTestContext::Builder::WithTestConfigClient() { + use_config_client_ = true; + use_test_config_client_ = true; + return *this; +} + +DataReductionProxyTestContext::Builder& DataReductionProxyTestContext::Builder::SkipSettingsInitialization() { skip_settings_initialization_ = true; return *this; @@ -181,6 +286,8 @@ DataReductionProxyTestContext::Builder::SkipSettingsInitialization() { scoped_ptr<DataReductionProxyTestContext> DataReductionProxyTestContext::Builder::Build() { + // Check for invalid builder combinations. + DCHECK(!(use_mock_config_ && use_config_client_)); scoped_ptr<base::MessageLoopForIO> loop(new base::MessageLoopForIO()); unsigned int test_context_flags = 0; @@ -216,15 +323,29 @@ DataReductionProxyTestContext::Builder::Build() { } scoped_ptr<TestDataReductionProxyConfig> config; - if (use_mock_config_) { + scoped_ptr<DataReductionProxyConfigServiceClient> config_client; + DataReductionProxyMutableConfigValues* raw_mutable_config = nullptr; + scoped_ptr<TestDataReductionProxyParams> params( + new TestDataReductionProxyParams(params_flags_, params_definitions_)); + TestDataReductionProxyParams* raw_params = params.get(); + if (use_config_client_) { + test_context_flags |= USE_CONFIG_CLIENT; + scoped_ptr<DataReductionProxyMutableConfigValues> mutable_config = + DataReductionProxyMutableConfigValues::CreateFromParams(task_runner, + params.get()); + raw_mutable_config = mutable_config.get(); + config.reset(new TestDataReductionProxyConfig( + mutable_config.Pass(), task_runner, net_log.get(), configurator.get(), + event_store.get())); + } else if (use_mock_config_) { test_context_flags |= USE_MOCK_CONFIG; config.reset(new MockDataReductionProxyConfig( - params_flags_, params_definitions_, task_runner, net_log.get(), - configurator.get(), event_store.get())); + params.Pass(), task_runner, net_log.get(), configurator.get(), + event_store.get())); } else { config.reset(new TestDataReductionProxyConfig( - params_flags_, params_definitions_, task_runner, net_log.get(), - configurator.get(), event_store.get())); + params.Pass(), task_runner, net_log.get(), configurator.get(), + event_store.get())); } scoped_ptr<DataReductionProxyRequestOptions> request_options; @@ -237,6 +358,17 @@ DataReductionProxyTestContext::Builder::Build() { client_, config.get(), task_runner)); } + if (use_test_config_client_) { + test_context_flags |= USE_TEST_CONFIG_CLIENT; + config_client.reset(new TestDataReductionProxyConfigServiceClient( + params.Pass(), request_options.get(), raw_mutable_config, config.get(), + task_runner)); + } else if (use_config_client_) { + config_client.reset(new DataReductionProxyConfigServiceClient( + params.Pass(), GetBackoffPolicy(), request_options.get(), + raw_mutable_config, config.get(), task_runner)); + } + scoped_ptr<DataReductionProxySettings> settings( new DataReductionProxySettings()); if (skip_settings_initialization_) @@ -250,14 +382,14 @@ DataReductionProxyTestContext::Builder::Build() { scoped_ptr<TestDataReductionProxyIOData> io_data( new TestDataReductionProxyIOData( task_runner, config.Pass(), event_store.Pass(), - request_options.Pass(), configurator.Pass())); + request_options.Pass(), configurator.Pass(), config_client.Pass())); io_data->InitOnUIThread(pref_service.get()); scoped_ptr<DataReductionProxyTestContext> test_context( new DataReductionProxyTestContext( loop.Pass(), task_runner, pref_service.Pass(), net_log.Pass(), request_context_getter, mock_socket_factory_, io_data.Pass(), - settings.Pass(), test_context_flags)); + settings.Pass(), raw_params, test_context_flags)); if (!skip_settings_initialization_) test_context->InitSettingsWithoutCheck(); @@ -274,6 +406,7 @@ DataReductionProxyTestContext::DataReductionProxyTestContext( net::MockClientSocketFactory* mock_socket_factory, scoped_ptr<TestDataReductionProxyIOData> io_data, scoped_ptr<DataReductionProxySettings> settings, + TestDataReductionProxyParams* params, unsigned int test_context_flags) : test_context_flags_(test_context_flags), loop_(loop.Pass()), @@ -283,7 +416,8 @@ DataReductionProxyTestContext::DataReductionProxyTestContext( request_context_getter_(request_context_getter), mock_socket_factory_(mock_socket_factory), io_data_(io_data.Pass()), - settings_(settings.Pass()) { + settings_(settings.Pass()), + params_(params) { } DataReductionProxyTestContext::~DataReductionProxyTestContext() { @@ -413,6 +547,26 @@ DataReductionProxyTestContext::mock_request_options() const { io_data_->request_options()); } +TestDataReductionProxyConfig* DataReductionProxyTestContext::config() const { + return reinterpret_cast<TestDataReductionProxyConfig*>(io_data_->config()); +} + +DataReductionProxyMutableConfigValues* +DataReductionProxyTestContext::mutable_config_values() { + DCHECK(test_context_flags_ & + DataReductionProxyTestContext::USE_CONFIG_CLIENT); + return reinterpret_cast<DataReductionProxyMutableConfigValues*>( + config()->config_values()); +} + +TestDataReductionProxyConfigServiceClient* +DataReductionProxyTestContext::test_config_client() { + DCHECK(test_context_flags_ & + DataReductionProxyTestContext::USE_TEST_CONFIG_CLIENT); + return reinterpret_cast<TestDataReductionProxyConfigServiceClient*>( + io_data_->config_client()); +} + DataReductionProxyUsageStats::UnreachableCallback DataReductionProxyTestContext::unreachable_callback() const { return base::Bind(&DataReductionProxySettings::SetUnreachable, diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h index 9e0695ef..df1b2c0 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h @@ -12,11 +12,13 @@ #include "base/memory/scoped_ptr.h" #include "base/single_thread_task_runner.h" #include "base/time/time.h" +#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.h" +#include "net/base/backoff_entry.h" #include "net/base/capturing_net_log.h" #include "testing/gmock/include/gmock/gmock.h" @@ -38,12 +40,14 @@ namespace data_reduction_proxy { class DataReductionProxyConfigurator; class DataReductionProxyEventStore; +class DataReductionProxyMutableConfigValues; class DataReductionProxyRequestOptions; class DataReductionProxySettings; class DataReductionProxyStatisticsPrefs; class MockDataReductionProxyConfig; class TestDataReductionProxyConfig; class TestDataReductionProxyConfigurator; +class TestDataReductionProxyParams; // Test version of |DataReductionProxyRequestOptions|. class TestDataReductionProxyRequestOptions @@ -83,6 +87,69 @@ class MockDataReductionProxyRequestOptions void(base::DictionaryValue* response)); }; +// Test version of |DataReductionProxyConfigServiceClient|, which permits +// finely controlling the backoff timer. +class TestDataReductionProxyConfigServiceClient + : public DataReductionProxyConfigServiceClient { + public: + TestDataReductionProxyConfigServiceClient( + scoped_ptr<DataReductionProxyParams> params, + DataReductionProxyRequestOptions* request_options, + DataReductionProxyMutableConfigValues* config_values, + DataReductionProxyConfig* config, + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner); + + ~TestDataReductionProxyConfigServiceClient() override; + + void SetNow(const base::Time& time); + + void SetCustomReleaseTime(const base::TimeTicks& release_time); + + base::TimeDelta GetDelay() const; + + protected: + // Overrides of DataReductionProxyConfigServiceClient + base::Time Now() const override; + net::BackoffEntry* GetBackoffEntry() override; + + private: + // A clock which returns a fixed value in both base::Time and base::TimeTicks. + class TestTickClock { + public: + TestTickClock(const base::Time& initial_time); + + // Returns the current base::TimeTicks + base::TimeTicks NowTicks() const; + + // Returns the current base::Time + base::Time Now() const; + + // Sets the current time. + void SetTime(const base::Time& time); + + private: + base::Time time_; + }; + + // A net::BackoffEntry which uses an injected base::TickClock to control + // the backoff expiration time. + class TestBackoffEntry : public net::BackoffEntry { + public: + TestBackoffEntry(const BackoffEntry::Policy* const policy, + const TestTickClock* tick_clock); + + protected: + // Override of net::BackoffEntry. + base::TimeTicks ImplGetTimeNow() const override; + + private: + const TestTickClock* tick_clock_; + }; + + TestTickClock tick_clock_; + TestBackoffEntry test_backoff_entry_; +}; + // Test version of |DataReductionProxyService|, which permits mocking of various // methods. class MockDataReductionProxyService : public DataReductionProxyService { @@ -105,15 +172,20 @@ class TestDataReductionProxyIOData : public DataReductionProxyIOData { public: TestDataReductionProxyIOData( scoped_refptr<base::SingleThreadTaskRunner> task_runner, - scoped_ptr<TestDataReductionProxyConfig> config, + scoped_ptr<DataReductionProxyConfig> config, scoped_ptr<DataReductionProxyEventStore> event_store, scoped_ptr<DataReductionProxyRequestOptions> request_options, - scoped_ptr<DataReductionProxyConfigurator> configurator); + scoped_ptr<DataReductionProxyConfigurator> configurator, + scoped_ptr<DataReductionProxyConfigServiceClient> config_client); ~TestDataReductionProxyIOData() override; DataReductionProxyConfigurator* configurator() const { return configurator_.get(); } + + DataReductionProxyConfigServiceClient* config_client() const { + return config_client_.get(); + } }; // Builds a test version of the Data Reduction Proxy stack for use in tests. @@ -165,6 +237,13 @@ class DataReductionProxyTestContext { // |DataReductionProxyRequestOptions|. Builder& WithMockRequestOptions(); + // Specifies the use of the |DataReductionProxyConfigServiceClient|. + Builder& WithConfigClient(); + + // Specifies the use of the a |TestDataReductionProxyConfigServiceClient| + // instead of a |DataReductionProxyConfigServiceClient|. + Builder& WithTestConfigClient(); + // Construct, but do not initialize the |DataReductionProxySettings| object. Builder& SkipSettingsInitialization(); @@ -182,6 +261,8 @@ class DataReductionProxyTestContext { bool use_test_configurator_; bool use_mock_service_; bool use_mock_request_options_; + bool use_config_client_; + bool use_test_config_client_; bool skip_settings_initialization_; }; @@ -231,6 +312,17 @@ class DataReductionProxyTestContext { // only be called if built with WithMockRequestOptions. MockDataReductionProxyRequestOptions* mock_request_options() const; + // Returns the underlying |TestDataReductionProxyConfig|. + TestDataReductionProxyConfig* config() const; + + // Returns the underlying |DataReductionProxyMutableConfigValues|. This can + // only be called if built with WithConfigClient. + DataReductionProxyMutableConfigValues* mutable_config_values(); + + // Returns the underlying |TestDataReductionProxyConfigServiceClient|. This + // can only be called if built with WithTestConfigClient. + TestDataReductionProxyConfigServiceClient* test_config_client(); + // Obtains a callback for notifying that the Data Reduction Proxy is no // longer reachable. DataReductionProxyUsageStats::UnreachableCallback @@ -260,10 +352,6 @@ class DataReductionProxyTestContext { return io_data_->configurator(); } - TestDataReductionProxyConfig* config() const { - return reinterpret_cast<TestDataReductionProxyConfig*>(io_data_->config()); - } - TestDataReductionProxyIOData* io_data() const { return io_data_.get(); } @@ -272,6 +360,10 @@ class DataReductionProxyTestContext { return settings_.get(); } + TestDataReductionProxyParams* test_params() const { + return params_; + } + private: enum TestContextOptions { // Permits mocking of the underlying |DataReductionProxyConfig|. @@ -287,6 +379,10 @@ class DataReductionProxyTestContext { USE_MOCK_SERVICE = 0x8, // Permits mocking of the underlying |DataReductionProxyRequestOptions|. USE_MOCK_REQUEST_OPTIONS = 0x10, + // Specifies the use of the |DataReductionProxyConfigServiceClient|. + USE_CONFIG_CLIENT = 0x20, + // Specifies the use of the |TESTDataReductionProxyConfigServiceClient|. + USE_TEST_CONFIG_CLIENT = 0x40, }; DataReductionProxyTestContext( @@ -298,6 +394,7 @@ class DataReductionProxyTestContext { net::MockClientSocketFactory* mock_socket_factory, scoped_ptr<TestDataReductionProxyIOData> io_data, scoped_ptr<DataReductionProxySettings> settings, + TestDataReductionProxyParams* params, unsigned int test_context_flags); void InitSettingsWithoutCheck(); @@ -320,6 +417,8 @@ class DataReductionProxyTestContext { scoped_ptr<TestDataReductionProxyIOData> io_data_; scoped_ptr<DataReductionProxySettings> settings_; + TestDataReductionProxyParams* params_; + DISALLOW_COPY_AND_ASSIGN(DataReductionProxyTestContext); }; diff --git a/components/data_reduction_proxy/core/common/data_reduction_proxy_params.cc b/components/data_reduction_proxy/core/common/data_reduction_proxy_params.cc index 3769f3a..79205a2 100644 --- a/components/data_reduction_proxy/core/common/data_reduction_proxy_params.cc +++ b/components/data_reduction_proxy/core/common/data_reduction_proxy_params.cc @@ -130,6 +130,12 @@ std::string DataReductionProxyParams::GetQuicFieldTrialName() { return kQuicFieldTrial; } +// static +bool DataReductionProxyParams::IsConfigClientEnabled() { + return base::CommandLine::ForCurrentProcess()->HasSwitch( + data_reduction_proxy::switches::kEnableDataReductionProxyConfigClient); +} + void DataReductionProxyParams::EnableQuic(bool enable) { quic_enabled_ = enable; DCHECK(!quic_enabled_ || IsIncludedInQuicFieldTrial()); 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 30c51ff..0f6aea8 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 @@ -113,6 +113,9 @@ class DataReductionProxyParams : public DataReductionProxyConfigValues { static std::string GetQuicFieldTrialName(); + // Returns true if the Data Reduction Proxy config client should be used. + static bool IsConfigClientEnabled(); + // 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 diff --git a/components/data_reduction_proxy/core/common/data_reduction_proxy_switches.cc b/components/data_reduction_proxy/core/common/data_reduction_proxy_switches.cc index bab8af0..2386931 100644 --- a/components/data_reduction_proxy/core/common/data_reduction_proxy_switches.cc +++ b/components/data_reduction_proxy/core/common/data_reduction_proxy_switches.cc @@ -70,5 +70,9 @@ const char kEnableDataReductionProxyBypassWarning[] = const char kClearDataReductionProxyDataSavings[] = "clear-data-reduction-proxy-data-savings"; +// Enable the data reduction proxy config client. +const char kEnableDataReductionProxyConfigClient[] = + "enable-data-reduction-proxy-config-client"; + } // namespace switches } // namespace data_reduction_proxy diff --git a/components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h b/components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h index cd6d08d..1a8f7c0 100644 --- a/components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h +++ b/components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h @@ -28,6 +28,7 @@ extern const char kEnableDataReductionProxyAlt[]; extern const char kEnableDataReductionProxyLoFi[]; extern const char kEnableDataReductionProxyBypassWarning[]; extern const char kClearDataReductionProxyDataSavings[]; +extern const char kEnableDataReductionProxyConfigClient[]; } // namespace switches } // namespace data_reduction_proxy |