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

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: Fixing compile warning. Created 4 years, 6 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
« no previous file with comments | « webrtc/base/timedelta.h ('k') | webrtc/base/timeutils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // TODO(honghaiz): Define a type for the time value specifically. 32 // TODO(honghaiz): Define a type for the time value specifically.
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 //
42 // Does not transfer ownership of the clock.
43 // SetClock(nullptr) should be called before the ClockInterface is deleted.
44 //
45 // This method is not thread-safe; it should only be used when no other thread
46 // is running (for example, at the start/end of a unit test, or start/end of
47 // main()).
48 //
49 // TODO(deadbeef): Instead of having functions that access this global
50 // ClockInterface, we may want to pass the ClockInterface into everything
51 // that uses it, eliminating the need for a global variable and this function.
52 void SetClock(ClockInterface* clock);
53
34 // Returns the current time in milliseconds in 32 bits. 54 // Returns the current time in milliseconds in 32 bits.
35 uint32_t Time32(); 55 uint32_t Time32();
36 56
37 // Returns the current time in milliseconds in 64 bits. 57 // Returns the current time in milliseconds in 64 bits.
38 int64_t TimeMillis(); 58 int64_t TimeMillis();
39 // Deprecated. Do not use this in any new code. 59 // Deprecated. Do not use this in any new code.
40 inline int64_t Time() { 60 inline int64_t Time() {
41 return TimeMillis(); 61 return TimeMillis();
42 } 62 }
43 63
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 }; 97 };
78 98
79 // Convert from std::tm, which is relative to 1900-01-01 00:00 to number of 99 // Convert from std::tm, which is relative to 1900-01-01 00:00 to number of
80 // seconds from 1970-01-01 00:00 ("epoch"). Don't return time_t since that 100 // seconds from 1970-01-01 00:00 ("epoch"). Don't return time_t since that
81 // is still 32 bits on many systems. 101 // is still 32 bits on many systems.
82 int64_t TmToSeconds(const std::tm& tm); 102 int64_t TmToSeconds(const std::tm& tm);
83 103
84 } // namespace rtc 104 } // namespace rtc
85 105
86 #endif // WEBRTC_BASE_TIMEUTILS_H_ 106 #endif // WEBRTC_BASE_TIMEUTILS_H_
OLDNEW
« 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