| 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/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> |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 // static | 128 // static |
| 129 const int64 Time::kTimeTToMicrosecondsOffset = kWindowsEpochDeltaMicroseconds; | 129 const int64 Time::kTimeTToMicrosecondsOffset = kWindowsEpochDeltaMicroseconds; |
| 130 | 130 |
| 131 // static | 131 // static |
| 132 Time Time::Now() { | 132 Time Time::Now() { |
| 133 return FromCFAbsoluteTime(CFAbsoluteTimeGetCurrent()); | 133 return FromCFAbsoluteTime(CFAbsoluteTimeGetCurrent()); |
| 134 } | 134 } |
| 135 | 135 |
| 136 // static | 136 // static |
| 137 Time Time::FromCFAbsoluteTime(CFAbsoluteTime t) { | 137 Time Time::FromCFAbsoluteTime(CFAbsoluteTime t) { |
| 138 COMPILE_ASSERT(std::numeric_limits<CFAbsoluteTime>::has_infinity, | 138 static_assert(std::numeric_limits<CFAbsoluteTime>::has_infinity, |
| 139 numeric_limits_infinity_is_undefined_when_not_has_infinity); | 139 "CFAbsoluteTime must have an infinity value"); |
| 140 if (t == 0) | 140 if (t == 0) |
| 141 return Time(); // Consider 0 as a null Time. | 141 return Time(); // Consider 0 as a null Time. |
| 142 if (t == std::numeric_limits<CFAbsoluteTime>::infinity()) | 142 if (t == std::numeric_limits<CFAbsoluteTime>::infinity()) |
| 143 return Max(); | 143 return Max(); |
| 144 return Time(static_cast<int64>( | 144 return Time(static_cast<int64>( |
| 145 (t + kCFAbsoluteTimeIntervalSince1970) * kMicrosecondsPerSecond) + | 145 (t + kCFAbsoluteTimeIntervalSince1970) * kMicrosecondsPerSecond) + |
| 146 kWindowsEpochDeltaMicroseconds); | 146 kWindowsEpochDeltaMicroseconds); |
| 147 } | 147 } |
| 148 | 148 |
| 149 CFAbsoluteTime Time::ToCFAbsoluteTime() const { | 149 CFAbsoluteTime Time::ToCFAbsoluteTime() const { |
| 150 COMPILE_ASSERT(std::numeric_limits<CFAbsoluteTime>::has_infinity, | 150 static_assert(std::numeric_limits<CFAbsoluteTime>::has_infinity, |
| 151 numeric_limits_infinity_is_undefined_when_not_has_infinity); | 151 "CFAbsoluteTime must have an infinity value"); |
| 152 if (is_null()) | 152 if (is_null()) |
| 153 return 0; // Consider 0 as a null Time. | 153 return 0; // Consider 0 as a null Time. |
| 154 if (is_max()) | 154 if (is_max()) |
| 155 return std::numeric_limits<CFAbsoluteTime>::infinity(); | 155 return std::numeric_limits<CFAbsoluteTime>::infinity(); |
| 156 return (static_cast<CFAbsoluteTime>(us_ - kWindowsEpochDeltaMicroseconds) / | 156 return (static_cast<CFAbsoluteTime>(us_ - kWindowsEpochDeltaMicroseconds) / |
| 157 kMicrosecondsPerSecond) - kCFAbsoluteTimeIntervalSince1970; | 157 kMicrosecondsPerSecond) - kCFAbsoluteTimeIntervalSince1970; |
| 158 } | 158 } |
| 159 | 159 |
| 160 // static | 160 // static |
| 161 Time Time::NowFromSystemTime() { | 161 Time Time::NowFromSystemTime() { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 bool TimeTicks::IsHighResolution() { | 225 bool TimeTicks::IsHighResolution() { |
| 226 return true; | 226 return true; |
| 227 } | 227 } |
| 228 | 228 |
| 229 // static | 229 // static |
| 230 ThreadTicks ThreadTicks::Now() { | 230 ThreadTicks ThreadTicks::Now() { |
| 231 return ThreadTicks(ComputeThreadTicks()); | 231 return ThreadTicks(ComputeThreadTicks()); |
| 232 } | 232 } |
| 233 | 233 |
| 234 } // namespace base | 234 } // namespace base |
| OLD | NEW |