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

Unified Diff: webrtc/base/faketime.h

Issue 2016863003: Implemented ScopedFakeTime, faking rtc::TimeNanos. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Addressed comments. 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/base_tests.gyp ('k') | webrtc/base/timeutils.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/faketime.h
diff --git a/webrtc/base/faketime.h b/webrtc/base/faketime.h
new file mode 100644
index 0000000000000000000000000000000000000000..a45a2d7a99db1ea24c804b77f229b5d2a9f0a8af
--- /dev/null
+++ b/webrtc/base/faketime.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2009 The WebRTC Project Authors. All rights reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef WEBRTC_BASE_FAKETIME_H_
+#define WEBRTC_BASE_FAKETIME_H_
+
+#include "webrtc/base/checks.h"
+#include "webrtc/base/timeutils.h"
+
+namespace rtc {
+namespace test {
+class FakeTime : public FakeTimeInterface {
+ public:
+ explicit FakeTime(uint64_t start_time) : current_time_ns_(start_time) {}
+ uint64_t TimeNanos() override {
+ rtc::CritScope cs(&time_lock_);
+ return current_time_ns_;
+ }
+ void AdvanceTime(uint64_t interval) {
+ rtc::CritScope cs(&time_lock_);
+ current_time_ns_ += interval;
+ }
+ private:
+ CriticalSection time_lock_;
+ uint64_t current_time_ns_ GUARDED_BY(time_lock_);
+};
+
+class ScopedFakeTime : public FakeTime {
pthatcher1 2016/06/03 00:34:45 Have you seen FakeClock in fakeclock.h? It looks *
nisse-webrtc 2016/06/03 11:40:07 It look very similar indeed. Great minds think ali
Taylor Brandstetter 2016/06/03 16:30:16 Aside from FakeTime taking a time in its construct
+ public:
+ explicit ScopedFakeTime(uint64_t start_time) : FakeTime(start_time) {
+ rtc::test::SetFakeTime(this);
+ }
+ ScopedFakeTime() : ScopedFakeTime(rtc::TimeNanos()) {}
+
+ ~ScopedFakeTime() {
+ rtc::test::SetFakeTime(nullptr);
+ }
+};
+
+} // namespace test
+} // namespace rtc
+
+#endif // WEBRTC_BASE_FAKETIME_H_
« no previous file with comments | « webrtc/base/base_tests.gyp ('k') | webrtc/base/timeutils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698