Index: base/time.h |
diff --git a/base/time.h b/base/time.h |
index 78d7456b68ae273c3bf27e8aaf93cd3742efe02c..e2aeacede779c7e89d2a986c6007ac07e8efbabc 100644 |
--- a/base/time.h |
+++ b/base/time.h |
@@ -17,6 +17,9 @@ |
// Time::Now() may actually decrease or jump). But note that TimeTicks may |
// "stand still", for example if the computer suspended. |
// |
+// TimeFactory can be used to override values returned by Time::Now and |
+// TimeTicks::Now for test purposes. |
+// |
// These classes are represented as only a 64-bit value, so they can be |
// efficiently passed by value. |
@@ -638,6 +641,25 @@ inline TimeTicks TimeDelta::operator+(TimeTicks t) const { |
return TimeTicks(t.ticks_ + delta_); |
} |
+// TimeFactory ---------------------------------------------------------------- |
+ |
+// This class should be subclassed to provide test values for Time::Now and |
+// TimeTicks::Now. Subclass instance should register itself by setting |
+// |instance_| fields. |
+class BASE_EXPORT TimeFactory { |
+ public: |
+ // Substitutes value for Time::Now(). |
+ virtual Time TimeNow() = 0; |
+ // Substitutes value for TimeTicks::Now() |
+ virtual TimeTicks TimeTicksNow() = 0; |
+ |
+ // Returns instance of |TimeFactory|. If null, system time routines are used. |
+ static TimeFactory* instance() { return instance_; } |
+ protected: |
+ // Implementation of TimeFactory (set by implementing subclasses). |
+ static TimeFactory* instance_; |
+}; |
+ |
} // namespace base |
#endif // BASE_TIME_H_ |