| 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 Time Time::FromExploded(bool is_local, const Exploded& exploded) { | 238 bool Time::FromExploded(bool is_local, const Exploded& exploded, Time* time) { |
| 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(NULL, &st, &utc_st) && | 256 success = TzSpecificLocalTimeToSystemTime(nullptr, &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 NOTREACHED() << "Unable to convert time"; | 263 *time = Time(0); |
| 264 return Time(0); | 264 return false; |
| 265 } | 265 } |
| 266 return Time(FileTimeToMicroseconds(ft)); | 266 |
| 267 *time = Time(FileTimeToMicroseconds(ft)); |
| 268 return true; |
| 267 } | 269 } |
| 268 | 270 |
| 269 void Time::Explode(bool is_local, Exploded* exploded) const { | 271 void Time::Explode(bool is_local, Exploded* exploded) const { |
| 270 if (us_ < 0LL) { | 272 if (us_ < 0LL) { |
| 271 // We are not able to convert it to FILETIME. | 273 // We are not able to convert it to FILETIME. |
| 272 ZeroMemory(exploded, sizeof(*exploded)); | 274 ZeroMemory(exploded, sizeof(*exploded)); |
| 273 return; | 275 return; |
| 274 } | 276 } |
| 275 | 277 |
| 276 // FILETIME in UTC. | 278 // FILETIME in UTC. |
| 277 FILETIME utc_ft; | 279 FILETIME utc_ft; |
| 278 MicrosecondsToFileTime(us_, &utc_ft); | 280 MicrosecondsToFileTime(us_, &utc_ft); |
| 279 | 281 |
| 280 // FILETIME in local time if necessary. | 282 // FILETIME in local time if necessary. |
| 281 bool success = true; | 283 bool success = true; |
| 282 // FILETIME in SYSTEMTIME (exploded). | 284 // FILETIME in SYSTEMTIME (exploded). |
| 283 SYSTEMTIME st = {0}; | 285 SYSTEMTIME st = {0}; |
| 284 if (is_local) { | 286 if (is_local) { |
| 285 SYSTEMTIME utc_st; | 287 SYSTEMTIME utc_st; |
| 286 // We don't use FileTimeToLocalFileTime here, since it uses the current | 288 // We don't use FileTimeToLocalFileTime here, since it uses the current |
| 287 // settings for the time zone and daylight saving time. Therefore, if it is | 289 // settings for the time zone and daylight saving time. Therefore, if it is |
| 288 // daylight saving time, it will take daylight saving time into account, | 290 // daylight saving time, it will take daylight saving time into account, |
| 289 // even if the time you are converting is in standard time. | 291 // even if the time you are converting is in standard time. |
| 290 success = FileTimeToSystemTime(&utc_ft, &utc_st) && | 292 success = FileTimeToSystemTime(&utc_ft, &utc_st) && |
| 291 SystemTimeToTzSpecificLocalTime(NULL, &utc_st, &st); | 293 SystemTimeToTzSpecificLocalTime(nullptr, &utc_st, &st); |
| 292 } else { | 294 } else { |
| 293 success = !!FileTimeToSystemTime(&utc_ft, &st); | 295 success = !!FileTimeToSystemTime(&utc_ft, &st); |
| 294 } | 296 } |
| 295 | 297 |
| 296 if (!success) { | 298 if (!success) { |
| 297 NOTREACHED() << "Unable to convert time, don't know why"; | 299 NOTREACHED() << "Unable to convert time, don't know why"; |
| 298 ZeroMemory(exploded, sizeof(*exploded)); | 300 ZeroMemory(exploded, sizeof(*exploded)); |
| 299 return; | 301 return; |
| 300 } | 302 } |
| 301 | 303 |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 TimeTicks TimeTicks::FromQPCValue(LONGLONG qpc_value) { | 610 TimeTicks TimeTicks::FromQPCValue(LONGLONG qpc_value) { |
| 609 return TimeTicks() + QPCValueToTimeDelta(qpc_value); | 611 return TimeTicks() + QPCValueToTimeDelta(qpc_value); |
| 610 } | 612 } |
| 611 | 613 |
| 612 // TimeDelta ------------------------------------------------------------------ | 614 // TimeDelta ------------------------------------------------------------------ |
| 613 | 615 |
| 614 // static | 616 // static |
| 615 TimeDelta TimeDelta::FromQPCValue(LONGLONG qpc_value) { | 617 TimeDelta TimeDelta::FromQPCValue(LONGLONG qpc_value) { |
| 616 return QPCValueToTimeDelta(qpc_value); | 618 return QPCValueToTimeDelta(qpc_value); |
| 617 } | 619 } |
| OLD | NEW |