| 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 | 5 |
| 6 // Windows Timer Primer | 6 // Windows Timer Primer |
| 7 // | 7 // |
| 8 // A good article: http://www.ddj.com/windows/184416651 | 8 // A good article: http://www.ddj.com/windows/184416651 |
| 9 // A good mozilla bug: http://bugzilla.mozilla.org/show_bug.cgi?id=363258 | 9 // A good mozilla bug: http://bugzilla.mozilla.org/show_bug.cgi?id=363258 |
| 10 // | 10 // |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 bool SafeConvertToWord(int in, WORD* out) { | 114 bool SafeConvertToWord(int in, WORD* out) { |
| 115 base::CheckedNumeric<WORD> result = in; | 115 base::CheckedNumeric<WORD> result = in; |
| 116 *out = result.ValueOrDefault(std::numeric_limits<WORD>::max()); | 116 *out = result.ValueOrDefault(std::numeric_limits<WORD>::max()); |
| 117 return result.IsValid(); | 117 return result.IsValid(); |
| 118 } | 118 } |
| 119 | 119 |
| 120 } // namespace | 120 } // namespace |
| 121 | 121 |
| 122 // Time ----------------------------------------------------------------------- | 122 // Time ----------------------------------------------------------------------- |
| 123 | 123 |
| 124 // The internal representation of Time uses FILETIME, whose epoch is 1601-01-01 | |
| 125 // 00:00:00 UTC. ((1970-1601)*365+89)*24*60*60*1000*1000, where 89 is the | |
| 126 // number of leap year days between 1601 and 1970: (1970-1601)/4 excluding | |
| 127 // 1700, 1800, and 1900. | |
| 128 // static | |
| 129 const int64_t Time::kTimeTToMicrosecondsOffset = INT64_C(11644473600000000); | |
| 130 | |
| 131 // static | 124 // static |
| 132 Time Time::Now() { | 125 Time Time::Now() { |
| 133 if (initial_time == 0) | 126 if (initial_time == 0) |
| 134 InitializeClock(); | 127 InitializeClock(); |
| 135 | 128 |
| 136 // We implement time using the high-resolution timers so that we can get | 129 // We implement time using the high-resolution timers so that we can get |
| 137 // timeouts which are smaller than 10-15ms. If we just used | 130 // timeouts which are smaller than 10-15ms. If we just used |
| 138 // CurrentWallclockMicroseconds(), we'd have the less-granular timer. | 131 // CurrentWallclockMicroseconds(), we'd have the less-granular timer. |
| 139 // | 132 // |
| 140 // To make this work, we initialize the clock (initial_time) and the | 133 // To make this work, we initialize the clock (initial_time) and the |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 TimeTicks TimeTicks::FromQPCValue(LONGLONG qpc_value) { | 668 TimeTicks TimeTicks::FromQPCValue(LONGLONG qpc_value) { |
| 676 return TimeTicks() + QPCValueToTimeDelta(qpc_value); | 669 return TimeTicks() + QPCValueToTimeDelta(qpc_value); |
| 677 } | 670 } |
| 678 | 671 |
| 679 // TimeDelta ------------------------------------------------------------------ | 672 // TimeDelta ------------------------------------------------------------------ |
| 680 | 673 |
| 681 // static | 674 // static |
| 682 TimeDelta TimeDelta::FromQPCValue(LONGLONG qpc_value) { | 675 TimeDelta TimeDelta::FromQPCValue(LONGLONG qpc_value) { |
| 683 return QPCValueToTimeDelta(qpc_value); | 676 return QPCValueToTimeDelta(qpc_value); |
| 684 } | 677 } |
| OLD | NEW |