Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Unified Diff: net/base/backoff_entry.h

Issue 1076853003: Refactor net::BackoffEntry to not require subclassing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address pneubeck's review comments Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « google_apis/gcm/engine/connection_factory_impl_unittest.cc ('k') | net/base/backoff_entry.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/backoff_entry.h
diff --git a/net/base/backoff_entry.h b/net/base/backoff_entry.h
index d8f03d3476b7add5f83a17f66e7f34f15f7ec198..dbc7488b7a4bd8005b5d699da8158d3a5459685c 100644
--- a/net/base/backoff_entry.h
+++ b/net/base/backoff_entry.h
@@ -9,6 +9,10 @@
#include "base/time/time.h"
#include "net/base/net_export.h"
+namespace base {
+class TickClock;
+}
+
namespace net {
// Provides the core logic needed for randomized exponential back-off
@@ -57,7 +61,11 @@ class NET_EXPORT BackoffEntry : NON_EXPORTED_BASE(public base::NonThreadSafe) {
// Lifetime of policy must enclose lifetime of BackoffEntry. The
// pointer must be valid but is not dereferenced during construction.
- explicit BackoffEntry(const Policy* const policy);
+ explicit BackoffEntry(const Policy* policy);
+ // Lifetime of policy and clock must enclose lifetime of BackoffEntry.
+ // |policy| pointer must be valid but isn't dereferenced during construction.
+ // |clock| pointer may be null.
+ BackoffEntry(const Policy* policy, base::TickClock* clock);
virtual ~BackoffEntry();
// Inform this item that a request for the network resource it is
@@ -90,14 +98,13 @@ class NET_EXPORT BackoffEntry : NON_EXPORTED_BASE(public base::NonThreadSafe) {
// Returns the failure count for this entry.
int failure_count() const { return failure_count_; }
- protected:
- // Equivalent to TimeTicks::Now(), virtual so unit tests can override.
- virtual base::TimeTicks ImplGetTimeNow() const;
-
private:
// Calculates when requests should again be allowed through.
base::TimeTicks CalculateReleaseTime() const;
+ // Equivalent to TimeTicks::Now(), using clock_ if provided.
+ base::TimeTicks GetTimeTicksNow() const;
+
// Timestamp calculated by the exponential back-off algorithm at which we are
// allowed to start sending requests again.
base::TimeTicks exponential_backoff_release_time_;
@@ -105,7 +112,9 @@ class NET_EXPORT BackoffEntry : NON_EXPORTED_BASE(public base::NonThreadSafe) {
// Counts request errors; decremented on success.
int failure_count_;
- const Policy* const policy_;
+ const Policy* const policy_; // Not owned.
+
+ base::TickClock* const clock_; // Not owned.
DISALLOW_COPY_AND_ASSIGN(BackoffEntry);
};
« no previous file with comments | « google_apis/gcm/engine/connection_factory_impl_unittest.cc ('k') | net/base/backoff_entry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698