diff options
author | johnme <johnme@chromium.org> | 2015-04-20 10:06:20 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-20 17:06:21 +0000 |
commit | dce40c39e0d44436283fbc43fa9b708153dd04e6 (patch) | |
tree | c680a23267bba048f057cddf9d04a2cb2e099e61 /components/data_reduction_proxy | |
parent | 32be343ac9b22aa66d645aed4c701f127072aaab (diff) | |
download | chromium_src-dce40c39e0d44436283fbc43fa9b708153dd04e6.zip chromium_src-dce40c39e0d44436283fbc43fa9b708153dd04e6.tar.gz chromium_src-dce40c39e0d44436283fbc43fa9b708153dd04e6.tar.bz2 |
Refactor net::BackoffEntry to not require subclassing
Before this patch, net::BackoffEntry had a virtual ImplGetTimeNow method
that tests etc would override to change what time is considered "now".
As suggested by rsleevi in https://codereview.chromium.org/1023473003,
this patch removes that method, and instead makes net::BackoffEntry
accept a base::TickClock in the constructor, to allow overriding the
time without subclassing.
(this will allow future changes to net::BackoffEntry without the
fragile base class problem)
Accordingly, I've removed all subclasses of BackoffEntry, and made them
pass TickClocks instead; in most cases this has been a nice
simplification.
BUG=465399
TBR=stevenjb@chromium.org
Review URL: https://codereview.chromium.org/1076853003
Cr-Commit-Position: refs/heads/master@{#325865}
Diffstat (limited to 'components/data_reduction_proxy')
4 files changed, 14 insertions, 40 deletions
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 f8e3d9e..af4c571 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 @@ -156,7 +156,7 @@ void DataReductionProxyConfigServiceClient::SetConfigRefreshTimer( &DataReductionProxyConfigServiceClient::RetrieveConfig); } -base::Time DataReductionProxyConfigServiceClient::Now() const { +base::Time DataReductionProxyConfigServiceClient::Now() { return base::Time::Now(); } 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 e51ea83..8487829 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 @@ -61,7 +61,7 @@ class DataReductionProxyConfigServiceClient { // Returns the current time. // Virtual for testing. - virtual base::Time Now() const; + virtual base::Time Now(); // Constructs a synthetic response based on |params_|. // Virtual for testing. 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 7aff4be..b3c9c4a 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 @@ -113,7 +113,7 @@ base::TimeDelta TestDataReductionProxyConfigServiceClient::GetDelay() const { return config_refresh_timer_.GetCurrentDelay(); } -base::Time TestDataReductionProxyConfigServiceClient::Now() const { +base::Time TestDataReductionProxyConfigServiceClient::Now() { return tick_clock_.Now(); } @@ -128,12 +128,12 @@ TestDataReductionProxyConfigServiceClient::TestTickClock::TestTickClock( } base::TimeTicks -TestDataReductionProxyConfigServiceClient::TestTickClock::NowTicks() const { +TestDataReductionProxyConfigServiceClient::TestTickClock::NowTicks() { return base::TimeTicks::UnixEpoch() + (time_ - base::Time::UnixEpoch()); } base::Time -TestDataReductionProxyConfigServiceClient::TestTickClock::Now() const { +TestDataReductionProxyConfigServiceClient::TestTickClock::Now() { return time_; } @@ -142,19 +142,6 @@ void TestDataReductionProxyConfigServiceClient::TestTickClock::SetTime( 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<DataReductionProxyCompressionStats> compression_stats, DataReductionProxySettings* settings, 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 c7be2e4..b1d29d2 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 @@ -11,6 +11,8 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/single_thread_task_runner.h" +#include "base/time/clock.h" +#include "base/time/tick_clock.h" #include "base/time/time.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_bypass_stats.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.h" @@ -104,20 +106,20 @@ class TestDataReductionProxyConfigServiceClient protected: // Overrides of DataReductionProxyConfigServiceClient - base::Time Now() const override; + base::Time Now() override; net::BackoffEntry* GetBackoffEntry() override; private: // A clock which returns a fixed value in both base::Time and base::TimeTicks. - class TestTickClock { + class TestTickClock : public base::Clock, public base::TickClock { public: TestTickClock(const base::Time& initial_time); - // Returns the current base::TimeTicks - base::TimeTicks NowTicks() const; + // base::TickClock implementation. + base::TimeTicks NowTicks() override; - // Returns the current base::Time - base::Time Now() const; + // base::Clock implementation. + base::Time Now() override; // Sets the current time. void SetTime(const base::Time& time); @@ -126,23 +128,8 @@ class TestDataReductionProxyConfigServiceClient 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_; + net::BackoffEntry test_backoff_entry_; }; // Test version of |DataReductionProxyService|, which permits mocking of various |