Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license | |
| 5 * that can be found in the LICENSE file in the root of the source | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 | |
| 11 #ifndef WEBRTC_BASE_FAKETIME_H_ | |
| 12 #define WEBRTC_BASE_FAKETIME_H_ | |
| 13 | |
| 14 #include "webrtc/base/checks.h" | |
| 15 #include "webrtc/base/timeutils.h" | |
| 16 | |
| 17 namespace rtc { | |
| 18 namespace test { | |
| 19 class FakeTime : public FakeTimeInterface { | |
| 20 public: | |
| 21 explicit FakeTime(uint64_t start_time) : current_time_ns_(start_time) {} | |
| 22 uint64_t TimeNanos() override { | |
| 23 rtc::CritScope cs(&time_lock_); | |
| 24 return current_time_ns_; | |
| 25 } | |
| 26 void AdvanceTime(uint64_t interval) { | |
| 27 rtc::CritScope cs(&time_lock_); | |
| 28 current_time_ns_ += interval; | |
| 29 } | |
| 30 private: | |
| 31 CriticalSection time_lock_; | |
| 32 uint64_t current_time_ns_ GUARDED_BY(time_lock_); | |
| 33 }; | |
| 34 | |
| 35 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
| |
| 36 public: | |
| 37 explicit ScopedFakeTime(uint64_t start_time) : FakeTime(start_time) { | |
| 38 rtc::test::SetFakeTime(this); | |
| 39 } | |
| 40 ScopedFakeTime() : ScopedFakeTime(rtc::TimeNanos()) {} | |
| 41 | |
| 42 ~ScopedFakeTime() { | |
| 43 rtc::test::SetFakeTime(nullptr); | |
| 44 } | |
| 45 }; | |
| 46 | |
| 47 } // namespace test | |
| 48 } // namespace rtc | |
| 49 | |
| 50 #endif // WEBRTC_BASE_FAKETIME_H_ | |
| OLD | NEW |