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

Side by Side 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: Created 4 years, 8 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2005 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2005 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 13 matching lines...) Expand all
24 24
25 static const int64_t kNumMicrosecsPerMillisec = 25 static const int64_t kNumMicrosecsPerMillisec =
26 kNumMicrosecsPerSec / kNumMillisecsPerSec; 26 kNumMicrosecsPerSec / kNumMillisecsPerSec;
27 static const int64_t kNumNanosecsPerMillisec = 27 static const int64_t kNumNanosecsPerMillisec =
28 kNumNanosecsPerSec / kNumMillisecsPerSec; 28 kNumNanosecsPerSec / kNumMillisecsPerSec;
29 static const int64_t kNumNanosecsPerMicrosec = 29 static const int64_t kNumNanosecsPerMicrosec =
30 kNumNanosecsPerSec / kNumMicrosecsPerSec; 30 kNumNanosecsPerSec / kNumMicrosecsPerSec;
31 31
32 typedef uint32_t TimeStamp; 32 typedef uint32_t TimeStamp;
33 33
34 class ClockInterface {
35 public:
36 virtual ~ClockInterface() {}
37 virtual uint64_t TimeNanos() const = 0;
38 };
39
40 // Sets the global source of time. This is useful mainly for unit tests.
41 // SetClock(nullptr) should be called before the ClockInterface is deleted.
42 // This method is not thread-safe; it should only be used when no other thread
43 // is running (for example, at the start/end of a unit test, or start/end of
44 // main()).
45 void SetClock(ClockInterface* clock);
46
34 // Returns the current time in milliseconds in 32 bits. 47 // Returns the current time in milliseconds in 32 bits.
35 uint32_t Time32(); 48 uint32_t Time32();
36 49
37 // Returns the current time in milliseconds in 64 bits. 50 // Returns the current time in milliseconds in 64 bits.
38 int64_t Time64(); 51 int64_t Time64();
39 52
40 // Returns the current time in milliseconds. 53 // Returns the current time in milliseconds.
41 // TODO(honghaiz): Returns Time64 once majority of the webrtc code migrates to 54 // TODO(honghaiz): Returns Time64 once majority of the webrtc code migrates to
42 // 64-bit timestamp. 55 // 64-bit timestamp.
43 inline uint32_t Time() { 56 inline uint32_t Time() {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 }; 108 };
96 109
97 // Convert from std::tm, which is relative to 1900-01-01 00:00 to number of 110 // Convert from std::tm, which is relative to 1900-01-01 00:00 to number of
98 // seconds from 1970-01-01 00:00 ("epoch"). Don't return time_t since that 111 // seconds from 1970-01-01 00:00 ("epoch"). Don't return time_t since that
99 // is still 32 bits on many systems. 112 // is still 32 bits on many systems.
100 int64_t TmToSeconds(const std::tm& tm); 113 int64_t TmToSeconds(const std::tm& tm);
101 114
102 } // namespace rtc 115 } // namespace rtc
103 116
104 #endif // WEBRTC_BASE_TIMEUTILS_H_ 117 #endif // WEBRTC_BASE_TIMEUTILS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698