OLD | NEW |
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.h" | 5 #include "base/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_time.h> | 9 #include <mach/mach_time.h> |
10 #include <sys/time.h> | 10 #include <sys/time.h> |
(...skipping 29 matching lines...) Expand all Loading... |
40 const int64 Time::kWindowsEpochDeltaMicroseconds = | 40 const int64 Time::kWindowsEpochDeltaMicroseconds = |
41 kWindowsEpochDeltaSeconds * Time::kMicrosecondsPerSecond; | 41 kWindowsEpochDeltaSeconds * Time::kMicrosecondsPerSecond; |
42 | 42 |
43 // Some functions in time.cc use time_t directly, so we provide an offset | 43 // Some functions in time.cc use time_t directly, so we provide an offset |
44 // to convert from time_t (Unix epoch) and internal (Windows epoch). | 44 // to convert from time_t (Unix epoch) and internal (Windows epoch). |
45 // static | 45 // static |
46 const int64 Time::kTimeTToMicrosecondsOffset = kWindowsEpochDeltaMicroseconds; | 46 const int64 Time::kTimeTToMicrosecondsOffset = kWindowsEpochDeltaMicroseconds; |
47 | 47 |
48 // static | 48 // static |
49 Time Time::Now() { | 49 Time Time::Now() { |
| 50 if (TimeFactory::instance()) |
| 51 return TimeFactory::instance()->TimeNow(); |
50 return FromCFAbsoluteTime(CFAbsoluteTimeGetCurrent()); | 52 return FromCFAbsoluteTime(CFAbsoluteTimeGetCurrent()); |
51 } | 53 } |
52 | 54 |
53 // static | 55 // static |
54 Time Time::FromCFAbsoluteTime(CFAbsoluteTime t) { | 56 Time Time::FromCFAbsoluteTime(CFAbsoluteTime t) { |
55 if (t == 0) | 57 if (t == 0) |
56 return Time(); // Consider 0 as a null Time. | 58 return Time(); // Consider 0 as a null Time. |
57 if (t == std::numeric_limits<CFAbsoluteTime>::max()) | 59 if (t == std::numeric_limits<CFAbsoluteTime>::max()) |
58 return Max(); | 60 return Max(); |
59 return Time(static_cast<int64>( | 61 return Time(static_cast<int64>( |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 exploded->millisecond = | 126 exploded->millisecond = |
125 (microsecond >= 0) ? microsecond / kMicrosecondsPerMillisecond : | 127 (microsecond >= 0) ? microsecond / kMicrosecondsPerMillisecond : |
126 (microsecond - kMicrosecondsPerMillisecond + 1) / | 128 (microsecond - kMicrosecondsPerMillisecond + 1) / |
127 kMicrosecondsPerMillisecond; | 129 kMicrosecondsPerMillisecond; |
128 } | 130 } |
129 | 131 |
130 // TimeTicks ------------------------------------------------------------------ | 132 // TimeTicks ------------------------------------------------------------------ |
131 | 133 |
132 // static | 134 // static |
133 TimeTicks TimeTicks::Now() { | 135 TimeTicks TimeTicks::Now() { |
| 136 if (TimeFactory::instance()) |
| 137 return TimeFactory::instance()->TimeTicksNow(); |
| 138 |
134 uint64_t absolute_micro; | 139 uint64_t absolute_micro; |
135 | 140 |
136 static mach_timebase_info_data_t timebase_info; | 141 static mach_timebase_info_data_t timebase_info; |
137 if (timebase_info.denom == 0) { | 142 if (timebase_info.denom == 0) { |
138 // Zero-initialization of statics guarantees that denom will be 0 before | 143 // Zero-initialization of statics guarantees that denom will be 0 before |
139 // calling mach_timebase_info. mach_timebase_info will never set denom to | 144 // calling mach_timebase_info. mach_timebase_info will never set denom to |
140 // 0 as that would be invalid, so the zero-check can be used to determine | 145 // 0 as that would be invalid, so the zero-check can be used to determine |
141 // whether mach_timebase_info has already been called. This is | 146 // whether mach_timebase_info has already been called. This is |
142 // recommended by Apple's QA1398. | 147 // recommended by Apple's QA1398. |
143 kern_return_t kr = mach_timebase_info(&timebase_info); | 148 kern_return_t kr = mach_timebase_info(&timebase_info); |
(...skipping 20 matching lines...) Expand all Loading... |
164 TimeTicks TimeTicks::HighResNow() { | 169 TimeTicks TimeTicks::HighResNow() { |
165 return Now(); | 170 return Now(); |
166 } | 171 } |
167 | 172 |
168 // static | 173 // static |
169 TimeTicks TimeTicks::NowFromSystemTraceTime() { | 174 TimeTicks TimeTicks::NowFromSystemTraceTime() { |
170 return HighResNow(); | 175 return HighResNow(); |
171 } | 176 } |
172 | 177 |
173 } // namespace base | 178 } // namespace base |
OLD | NEW |