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 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 return (period == kMinTimerIntervalHighResMs); | 228 return (period == kMinTimerIntervalHighResMs); |
229 } | 229 } |
230 | 230 |
231 // static | 231 // static |
232 bool Time::IsHighResolutionTimerInUse() { | 232 bool Time::IsHighResolutionTimerInUse() { |
233 base::AutoLock lock(g_high_res_lock.Get()); | 233 base::AutoLock lock(g_high_res_lock.Get()); |
234 return g_high_res_timer_enabled && g_high_res_timer_count > 0; | 234 return g_high_res_timer_enabled && g_high_res_timer_count > 0; |
235 } | 235 } |
236 | 236 |
237 // static | 237 // static |
238 bool Time::FromExploded(bool is_local, const Exploded& exploded, Time* time) { | 238 Time Time::FromExploded(bool is_local, const Exploded& exploded) { |
239 // Create the system struct representing our exploded time. It will either be | 239 // Create the system struct representing our exploded time. It will either be |
240 // in local time or UTC. | 240 // in local time or UTC. |
241 SYSTEMTIME st; | 241 SYSTEMTIME st; |
242 st.wYear = static_cast<WORD>(exploded.year); | 242 st.wYear = static_cast<WORD>(exploded.year); |
243 st.wMonth = static_cast<WORD>(exploded.month); | 243 st.wMonth = static_cast<WORD>(exploded.month); |
244 st.wDayOfWeek = static_cast<WORD>(exploded.day_of_week); | 244 st.wDayOfWeek = static_cast<WORD>(exploded.day_of_week); |
245 st.wDay = static_cast<WORD>(exploded.day_of_month); | 245 st.wDay = static_cast<WORD>(exploded.day_of_month); |
246 st.wHour = static_cast<WORD>(exploded.hour); | 246 st.wHour = static_cast<WORD>(exploded.hour); |
247 st.wMinute = static_cast<WORD>(exploded.minute); | 247 st.wMinute = static_cast<WORD>(exploded.minute); |
248 st.wSecond = static_cast<WORD>(exploded.second); | 248 st.wSecond = static_cast<WORD>(exploded.second); |
249 st.wMilliseconds = static_cast<WORD>(exploded.millisecond); | 249 st.wMilliseconds = static_cast<WORD>(exploded.millisecond); |
250 | 250 |
251 FILETIME ft; | 251 FILETIME ft; |
252 bool success = true; | 252 bool success = true; |
253 // Ensure that it's in UTC. | 253 // Ensure that it's in UTC. |
254 if (is_local) { | 254 if (is_local) { |
255 SYSTEMTIME utc_st; | 255 SYSTEMTIME utc_st; |
256 success = TzSpecificLocalTimeToSystemTime(nullptr, &st, &utc_st) && | 256 success = TzSpecificLocalTimeToSystemTime(NULL, &st, &utc_st) && |
257 SystemTimeToFileTime(&utc_st, &ft); | 257 SystemTimeToFileTime(&utc_st, &ft); |
258 } else { | 258 } else { |
259 success = !!SystemTimeToFileTime(&st, &ft); | 259 success = !!SystemTimeToFileTime(&st, &ft); |
260 } | 260 } |
261 | 261 |
262 if (!success) { | 262 if (!success) { |
263 *time = Time(0); | 263 NOTREACHED() << "Unable to convert time"; |
264 return false; | 264 return Time(0); |
265 } | 265 } |
266 | 266 return Time(FileTimeToMicroseconds(ft)); |
267 *time = Time(FileTimeToMicroseconds(ft)); | |
268 return true; | |
269 } | 267 } |
270 | 268 |
271 void Time::Explode(bool is_local, Exploded* exploded) const { | 269 void Time::Explode(bool is_local, Exploded* exploded) const { |
272 if (us_ < 0LL) { | 270 if (us_ < 0LL) { |
273 // We are not able to convert it to FILETIME. | 271 // We are not able to convert it to FILETIME. |
274 ZeroMemory(exploded, sizeof(*exploded)); | 272 ZeroMemory(exploded, sizeof(*exploded)); |
275 return; | 273 return; |
276 } | 274 } |
277 | 275 |
278 // FILETIME in UTC. | 276 // FILETIME in UTC. |
279 FILETIME utc_ft; | 277 FILETIME utc_ft; |
280 MicrosecondsToFileTime(us_, &utc_ft); | 278 MicrosecondsToFileTime(us_, &utc_ft); |
281 | 279 |
282 // FILETIME in local time if necessary. | 280 // FILETIME in local time if necessary. |
283 bool success = true; | 281 bool success = true; |
284 // FILETIME in SYSTEMTIME (exploded). | 282 // FILETIME in SYSTEMTIME (exploded). |
285 SYSTEMTIME st = {0}; | 283 SYSTEMTIME st = {0}; |
286 if (is_local) { | 284 if (is_local) { |
287 SYSTEMTIME utc_st; | 285 SYSTEMTIME utc_st; |
288 // We don't use FileTimeToLocalFileTime here, since it uses the current | 286 // We don't use FileTimeToLocalFileTime here, since it uses the current |
289 // settings for the time zone and daylight saving time. Therefore, if it is | 287 // settings for the time zone and daylight saving time. Therefore, if it is |
290 // daylight saving time, it will take daylight saving time into account, | 288 // daylight saving time, it will take daylight saving time into account, |
291 // even if the time you are converting is in standard time. | 289 // even if the time you are converting is in standard time. |
292 success = FileTimeToSystemTime(&utc_ft, &utc_st) && | 290 success = FileTimeToSystemTime(&utc_ft, &utc_st) && |
293 SystemTimeToTzSpecificLocalTime(nullptr, &utc_st, &st); | 291 SystemTimeToTzSpecificLocalTime(NULL, &utc_st, &st); |
294 } else { | 292 } else { |
295 success = !!FileTimeToSystemTime(&utc_ft, &st); | 293 success = !!FileTimeToSystemTime(&utc_ft, &st); |
296 } | 294 } |
297 | 295 |
298 if (!success) { | 296 if (!success) { |
299 NOTREACHED() << "Unable to convert time, don't know why"; | 297 NOTREACHED() << "Unable to convert time, don't know why"; |
300 ZeroMemory(exploded, sizeof(*exploded)); | 298 ZeroMemory(exploded, sizeof(*exploded)); |
301 return; | 299 return; |
302 } | 300 } |
303 | 301 |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 TimeTicks TimeTicks::FromQPCValue(LONGLONG qpc_value) { | 608 TimeTicks TimeTicks::FromQPCValue(LONGLONG qpc_value) { |
611 return TimeTicks() + QPCValueToTimeDelta(qpc_value); | 609 return TimeTicks() + QPCValueToTimeDelta(qpc_value); |
612 } | 610 } |
613 | 611 |
614 // TimeDelta ------------------------------------------------------------------ | 612 // TimeDelta ------------------------------------------------------------------ |
615 | 613 |
616 // static | 614 // static |
617 TimeDelta TimeDelta::FromQPCValue(LONGLONG qpc_value) { | 615 TimeDelta TimeDelta::FromQPCValue(LONGLONG qpc_value) { |
618 return QPCValueToTimeDelta(qpc_value); | 616 return QPCValueToTimeDelta(qpc_value); |
619 } | 617 } |
OLD | NEW |