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

Side by Side Diff: webrtc/base/timeutils.cc

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 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 14 matching lines...) Expand all
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 const uint32_t HALF = 0x80000000; 33 const uint32_t HALF = 0x80000000;
34 34
35 ClockInterface* clock_ = nullptr;
36
37 void SetClock(ClockInterface* clock) {
38 clock_ = clock;
39 }
40
35 uint64_t TimeNanos() { 41 uint64_t TimeNanos() {
42 if (clock_) {
juberti2 2016/04/25 20:18:23 Do we need to mention that this is unsynchronized?
Taylor Brandstetter 2016/04/26 01:22:32 I mention in timeutils.h that SetClock (which is t
43 return clock_->TimeNanos();
44 }
36 int64_t ticks = 0; 45 int64_t ticks = 0;
37 #if defined(WEBRTC_MAC) 46 #if defined(WEBRTC_MAC)
juberti2 2016/04/25 20:18:23 Should we factor this into a real clock implementa
Taylor Brandstetter 2016/04/26 01:22:32 Done.
38 static mach_timebase_info_data_t timebase; 47 static mach_timebase_info_data_t timebase;
39 if (timebase.denom == 0) { 48 if (timebase.denom == 0) {
40 // Get the timebase if this is the first time we run. 49 // Get the timebase if this is the first time we run.
41 // Recommended by Apple's QA1398. 50 // Recommended by Apple's QA1398.
42 if (mach_timebase_info(&timebase) != KERN_SUCCESS) { 51 if (mach_timebase_info(&timebase) != KERN_SUCCESS) {
43 RTC_DCHECK(false); 52 RTC_DCHECK(false);
44 } 53 }
45 } 54 }
46 // Use timebase to convert absolute time tick units into nanoseconds. 55 // Use timebase to convert absolute time tick units into nanoseconds.
47 ticks = mach_absolute_time() * timebase.numer / timebase.denom; 56 ticks = mach_absolute_time() * timebase.numer / timebase.denom;
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 if (expiry_in_leap_year && month <= 2 - 1) // |month| is zero based. 183 if (expiry_in_leap_year && month <= 2 - 1) // |month| is zero based.
175 day -= 1; 184 day -= 1;
176 185
177 // Combine all variables into seconds from 1970-01-01 00:00 (except |month| 186 // Combine all variables into seconds from 1970-01-01 00:00 (except |month|
178 // which was accumulated into |day| above). 187 // which was accumulated into |day| above).
179 return (((static_cast<int64_t> 188 return (((static_cast<int64_t>
180 (year - 1970) * 365 + day) * 24 + hour) * 60 + min) * 60 + sec; 189 (year - 1970) * 365 + day) * 24 + hour) * 60 + min) * 60 + sec;
181 } 190 }
182 191
183 } // namespace rtc 192 } // namespace rtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698