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

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: Fix ConnectionFactoryImplTest 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
Index: net/base/backoff_entry.h
diff --git a/net/base/backoff_entry.h b/net/base/backoff_entry.h
index d8f03d3476b7add5f83a17f66e7f34f15f7ec198..640fbfa192cf6844aa549874cfa00f59c556a9a7 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
@@ -58,6 +62,7 @@ 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);
+ BackoffEntry(const Policy* const policy, base::TickClock* clock);
virtual ~BackoffEntry();
// Inform this item that a request for the network resource it is
@@ -90,14 +95,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_;
@@ -107,6 +111,8 @@ class NET_EXPORT BackoffEntry : NON_EXPORTED_BASE(public base::NonThreadSafe) {
const Policy* const policy_;
+ base::TickClock* clock_; // Not owned.
+
DISALLOW_COPY_AND_ASSIGN(BackoffEntry);
};

Powered by Google App Engine
This is Rietveld 408576698