OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 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 12 matching lines...) Expand all Loading... |
23 #endif | 23 #endif |
24 #include <windows.h> | 24 #include <windows.h> |
25 #include <mmsystem.h> | 25 #include <mmsystem.h> |
26 #endif | 26 #endif |
27 | 27 |
28 #include "webrtc/base/checks.h" | 28 #include "webrtc/base/checks.h" |
29 #include "webrtc/base/timeutils.h" | 29 #include "webrtc/base/timeutils.h" |
30 | 30 |
31 namespace rtc { | 31 namespace rtc { |
32 | 32 |
| 33 namespace test { |
| 34 |
| 35 namespace { |
| 36 FakeTimeInterface* g_fake_time = nullptr; |
| 37 } // Anonymous |
| 38 |
| 39 void SetFakeTime(FakeTimeInterface* fake_time) { |
| 40 // Allow setting g_fake_time non-null only if old value is null. |
| 41 if (fake_time) |
| 42 RTC_CHECK(!g_fake_time); |
| 43 |
| 44 g_fake_time = fake_time; |
| 45 } |
| 46 |
| 47 } // namespace test |
| 48 |
33 uint64_t TimeNanos() { | 49 uint64_t TimeNanos() { |
| 50 if (test::g_fake_time) |
| 51 return test::g_fake_time->TimeNanos(); |
| 52 |
34 int64_t ticks = 0; | 53 int64_t ticks = 0; |
35 #if defined(WEBRTC_MAC) | 54 #if defined(WEBRTC_MAC) |
36 static mach_timebase_info_data_t timebase; | 55 static mach_timebase_info_data_t timebase; |
37 if (timebase.denom == 0) { | 56 if (timebase.denom == 0) { |
38 // Get the timebase if this is the first time we run. | 57 // Get the timebase if this is the first time we run. |
39 // Recommended by Apple's QA1398. | 58 // Recommended by Apple's QA1398. |
40 if (mach_timebase_info(&timebase) != KERN_SUCCESS) { | 59 if (mach_timebase_info(&timebase) != KERN_SUCCESS) { |
41 RTC_DCHECK(false); | 60 RTC_DCHECK(false); |
42 } | 61 } |
43 } | 62 } |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 if (expiry_in_leap_year && month <= 2 - 1) // |month| is zero based. | 180 if (expiry_in_leap_year && month <= 2 - 1) // |month| is zero based. |
162 day -= 1; | 181 day -= 1; |
163 | 182 |
164 // Combine all variables into seconds from 1970-01-01 00:00 (except |month| | 183 // Combine all variables into seconds from 1970-01-01 00:00 (except |month| |
165 // which was accumulated into |day| above). | 184 // which was accumulated into |day| above). |
166 return (((static_cast<int64_t> | 185 return (((static_cast<int64_t> |
167 (year - 1970) * 365 + day) * 24 + hour) * 60 + min) * 60 + sec; | 186 (year - 1970) * 365 + day) * 24 + hour) * 60 + min) * 60 + sec; |
168 } | 187 } |
169 | 188 |
170 } // namespace rtc | 189 } // namespace rtc |
OLD | NEW |