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

Side by Side Diff: base/time/time_mac.cc

Issue 1824673002: time: Add a static TimeTicks method that returns the underlying clock (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/time/time.h" 5 #include "base/time/time.h"
6 6
7 #include <CoreFoundation/CFDate.h> 7 #include <CoreFoundation/CFDate.h>
8 #include <CoreFoundation/CFTimeZone.h> 8 #include <CoreFoundation/CFTimeZone.h>
9 #include <mach/mach.h> 9 #include <mach/mach.h>
10 #include <mach/mach_time.h> 10 #include <mach/mach_time.h>
11 #include <stddef.h> 11 #include <stddef.h>
12 #include <stdint.h> 12 #include <stdint.h>
13 #include <sys/sysctl.h> 13 #include <sys/sysctl.h>
14 #include <sys/time.h> 14 #include <sys/time.h>
15 #include <sys/types.h> 15 #include <sys/types.h>
16 #include <time.h> 16 #include <time.h>
17 17
18 #include "base/logging.h" 18 #include "base/logging.h"
19 #include "base/mac/mach_logging.h" 19 #include "base/mac/mach_logging.h"
20 #include "base/mac/scoped_cftyperef.h" 20 #include "base/mac/scoped_cftyperef.h"
21 #include "base/mac/scoped_mach_port.h" 21 #include "base/mac/scoped_mach_port.h"
22 #include "base/macros.h" 22 #include "base/macros.h"
23 #include "base/numerics/safe_conversions.h" 23 #include "base/numerics/safe_conversions.h"
24 #include "build/build_config.h" 24 #include "build/build_config.h"
25 25
26 namespace { 26 namespace {
27 27
28 #if defined(OS_IOS)
29 const char* kIOSKernBoottimeClockId =
30 "IOS_CF_ABSOLUTE_TIME_MINUS_KERN_BOOTTIME_MICROS";
31 #else
32 const char* kMacMachClockId = "MAC_MACH_ABSOLUTE_TIME_MICROS";
33 #endif // defined(OS_IOS)
34
28 int64_t ComputeCurrentTicks() { 35 int64_t ComputeCurrentTicks() {
29 #if defined(OS_IOS) 36 #if defined(OS_IOS)
30 // On iOS mach_absolute_time stops while the device is sleeping. Instead use 37 // On iOS mach_absolute_time stops while the device is sleeping. Instead use
31 // now - KERN_BOOTTIME to get a time difference that is not impacted by clock 38 // now - KERN_BOOTTIME to get a time difference that is not impacted by clock
32 // changes. KERN_BOOTTIME will be updated by the system whenever the system 39 // changes. KERN_BOOTTIME will be updated by the system whenever the system
33 // clock change. 40 // clock change.
34 struct timeval boottime; 41 struct timeval boottime;
35 int mib[2] = {CTL_KERN, KERN_BOOTTIME}; 42 int mib[2] = {CTL_KERN, KERN_BOOTTIME};
36 size_t size = sizeof(boottime); 43 size_t size = sizeof(boottime);
37 int kr = sysctl(mib, arraysize(mib), &boottime, &size, NULL, 0); 44 int kr = sysctl(mib, arraysize(mib), &boottime, &size, NULL, 0);
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 TimeTicks TimeTicks::Now() { 237 TimeTicks TimeTicks::Now() {
231 return TimeTicks(ComputeCurrentTicks()); 238 return TimeTicks(ComputeCurrentTicks());
232 } 239 }
233 240
234 // static 241 // static
235 bool TimeTicks::IsHighResolution() { 242 bool TimeTicks::IsHighResolution() {
236 return true; 243 return true;
237 } 244 }
238 245
239 // static 246 // static
247 std::string TimeTicks::ClockId() {
248 #if defined(OS_IOS)
249 return kIOSKernBoottimeClockId;
250 #else
251 return kMacMachClockId;
252 #endif // defined(OS_IOS)
253 }
254
255 // static
240 ThreadTicks ThreadTicks::Now() { 256 ThreadTicks ThreadTicks::Now() {
241 return ThreadTicks(ComputeThreadTicks()); 257 return ThreadTicks(ComputeThreadTicks());
242 } 258 }
243 259
244 } // namespace base 260 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698