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
[email protected]

Review URL: https://codereview.chromium.org/1076853003

Cr-Commit-Position: refs/heads/master@{#325865}
diff --git a/components/domain_reliability/util.h b/components/domain_reliability/util.h
index 4256b05..832e2fc 100644
--- a/components/domain_reliability/util.h
+++ b/components/domain_reliability/util.h
@@ -10,11 +10,12 @@
 #include "base/callback_forward.h"
 #include "base/compiler_specific.h"
 #include "base/memory/scoped_ptr.h"
+#include "base/time/clock.h"
+#include "base/time/tick_clock.h"
 #include "base/time/time.h"
 #include "base/tracked_objects.h"
 #include "components/domain_reliability/domain_reliability_export.h"
 #include "components/domain_reliability/uploader.h"
-#include "net/base/backoff_entry.h"
 #include "net/http/http_response_info.h"
 #include "net/url_request/url_request_status.h"
 
@@ -51,7 +52,8 @@
 // Mockable wrapper around TimeTicks::Now and Timer. Mock version is in
 // test_util.h.
 // TODO(ttuttle): Rename to Time{Provider,Source,?}.
-class DOMAIN_RELIABILITY_EXPORT MockableTime {
+class DOMAIN_RELIABILITY_EXPORT MockableTime : public base::Clock,
+                                               public base::TickClock {
  public:
   // Mockable wrapper around (a subset of) base::Timer.
   class DOMAIN_RELIABILITY_EXPORT Timer {
@@ -68,12 +70,13 @@
     Timer();
   };
 
-  virtual ~MockableTime();
+  ~MockableTime() override;
 
-  // Returns base::Time::Now() or a mocked version thereof.
-  virtual base::Time Now() = 0;
-  // Returns base::TimeTicks::Now() or a mocked version thereof.
-  virtual base::TimeTicks NowTicks() = 0;
+  // Clock impl; returns base::Time::Now() or a mocked version thereof.
+  base::Time Now() override = 0;
+  // TickClock impl; returns base::TimeTicks::Now() or a mocked version thereof.
+  base::TimeTicks NowTicks() override = 0;
+
   // Returns a new Timer, or a mocked version thereof.
   virtual scoped_ptr<MockableTime::Timer> CreateTimer() = 0;
 
@@ -98,21 +101,6 @@
   scoped_ptr<MockableTime::Timer> CreateTimer() override;
 };
 
-// A subclass of BackoffEntry that uses a MockableTime to keep track of time.
-class MockableTimeBackoffEntry : public net::BackoffEntry {
- public:
-  MockableTimeBackoffEntry(const net::BackoffEntry::Policy* const policy,
-                           MockableTime* time);
-
-  ~MockableTimeBackoffEntry() override;
-
- protected:
-  base::TimeTicks ImplGetTimeNow() const override;
-
- private:
-  MockableTime* time_;
-};
-
 }  // namespace domain_reliability
 
 #endif  // COMPONENTS_DOMAIN_RELIABILITY_UTIL_H_