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

Unified Diff: webrtc/base/timeutils.h

Issue 1895933003: Adding the ability to use a simulated clock for unit tests. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixing compile warning. Created 4 years, 7 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 | « webrtc/base/timedelta.h ('k') | webrtc/base/timeutils.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/timeutils.h
diff --git a/webrtc/base/timeutils.h b/webrtc/base/timeutils.h
index 222d5c26e4774efc568736bd2f9fcfa417978ed1..78ebacee38df5087737de039fa20a6e8c485c9f6 100644
--- a/webrtc/base/timeutils.h
+++ b/webrtc/base/timeutils.h
@@ -31,6 +31,26 @@ static const int64_t kNumNanosecsPerMicrosec =
// TODO(honghaiz): Define a type for the time value specifically.
+class ClockInterface {
+ public:
+ virtual ~ClockInterface() {}
+ virtual uint64_t TimeNanos() const = 0;
+};
+
+// Sets the global source of time. This is useful mainly for unit tests.
+//
+// Does not transfer ownership of the clock.
+// SetClock(nullptr) should be called before the ClockInterface is deleted.
+//
+// This method is not thread-safe; it should only be used when no other thread
+// is running (for example, at the start/end of a unit test, or start/end of
+// main()).
+//
+// TODO(deadbeef): Instead of having functions that access this global
+// ClockInterface, we may want to pass the ClockInterface into everything
+// that uses it, eliminating the need for a global variable and this function.
+void SetClock(ClockInterface* clock);
+
// Returns the current time in milliseconds in 32 bits.
uint32_t Time32();
« no previous file with comments | « webrtc/base/timedelta.h ('k') | webrtc/base/timeutils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698