OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 | 119 |
120 // Calculate the time elapsed since we started our timer | 120 // Calculate the time elapsed since we started our timer |
121 TimeDelta elapsed = ticks - initial_ticks; | 121 TimeDelta elapsed = ticks - initial_ticks; |
122 | 122 |
123 // Check if enough time has elapsed that we need to resync the clock. | 123 // Check if enough time has elapsed that we need to resync the clock. |
124 if (elapsed.InMilliseconds() > kMaxMillisecondsToAvoidDrift) { | 124 if (elapsed.InMilliseconds() > kMaxMillisecondsToAvoidDrift) { |
125 InitializeClock(); | 125 InitializeClock(); |
126 continue; | 126 continue; |
127 } | 127 } |
128 | 128 |
129 return elapsed + initial_time; | 129 return Time(elapsed + initial_time); |
130 } | 130 } |
131 } | 131 } |
132 | 132 |
133 // static | 133 // static |
| 134 Time Time::NowFromSystemTime() { |
| 135 // Force resync. |
| 136 InitializeClock(); |
| 137 return Time(initial_time); |
| 138 } |
| 139 |
| 140 // static |
134 Time Time::FromFileTime(FILETIME ft) { | 141 Time Time::FromFileTime(FILETIME ft) { |
135 return Time(FileTimeToMicroseconds(ft)); | 142 return Time(FileTimeToMicroseconds(ft)); |
136 } | 143 } |
137 | 144 |
138 FILETIME Time::ToFileTime() const { | 145 FILETIME Time::ToFileTime() const { |
139 FILETIME utc_ft; | 146 FILETIME utc_ft; |
140 MicrosecondsToFileTime(us_, &utc_ft); | 147 MicrosecondsToFileTime(us_, &utc_ft); |
141 return utc_ft; | 148 return utc_ft; |
142 } | 149 } |
143 | 150 |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 | 395 |
389 // static | 396 // static |
390 TimeTicks TimeTicks::Now() { | 397 TimeTicks TimeTicks::Now() { |
391 return TimeTicks() + Singleton<NowSingleton>::get()->Now(); | 398 return TimeTicks() + Singleton<NowSingleton>::get()->Now(); |
392 } | 399 } |
393 | 400 |
394 // static | 401 // static |
395 TimeTicks TimeTicks::HighResNow() { | 402 TimeTicks TimeTicks::HighResNow() { |
396 return TimeTicks() + Singleton<HighResNowSingleton>::get()->Now(); | 403 return TimeTicks() + Singleton<HighResNowSingleton>::get()->Now(); |
397 } | 404 } |
OLD | NEW |