Chromium Code Reviews| 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 // Returns the current value of the performance counter. | 102 // Returns the current value of the performance counter. |
| 103 uint64_t QPCNowRaw() { | 103 uint64_t QPCNowRaw() { |
| 104 LARGE_INTEGER perf_counter_now = {}; | 104 LARGE_INTEGER perf_counter_now = {}; |
| 105 // According to the MSDN documentation for QueryPerformanceCounter(), this | 105 // According to the MSDN documentation for QueryPerformanceCounter(), this |
| 106 // will never fail on systems that run XP or later. | 106 // will never fail on systems that run XP or later. |
| 107 // https://msdn.microsoft.com/library/windows/desktop/ms644904.aspx | 107 // https://msdn.microsoft.com/library/windows/desktop/ms644904.aspx |
| 108 ::QueryPerformanceCounter(&perf_counter_now); | 108 ::QueryPerformanceCounter(&perf_counter_now); |
| 109 return perf_counter_now.QuadPart; | 109 return perf_counter_now.QuadPart; |
| 110 } | 110 } |
| 111 | 111 |
| 112 // Maximum size of the | |
| 113 const int kMaxWinWordSize = 65535; | |
|
mmenke
2016/10/18 15:04:50
This should just be std::numeric_limits<WORD>::max
| |
| 114 | |
| 112 } // namespace | 115 } // namespace |
| 113 | 116 |
| 114 // Time ----------------------------------------------------------------------- | 117 // Time ----------------------------------------------------------------------- |
| 115 | 118 |
| 116 // The internal representation of Time uses FILETIME, whose epoch is 1601-01-01 | 119 // The internal representation of Time uses FILETIME, whose epoch is 1601-01-01 |
| 117 // 00:00:00 UTC. ((1970-1601)*365+89)*24*60*60*1000*1000, where 89 is the | 120 // 00:00:00 UTC. ((1970-1601)*365+89)*24*60*60*1000*1000, where 89 is the |
| 118 // number of leap year days between 1601 and 1970: (1970-1601)/4 excluding | 121 // number of leap year days between 1601 and 1970: (1970-1601)/4 excluding |
| 119 // 1700, 1800, and 1900. | 122 // 1700, 1800, and 1900. |
| 120 // static | 123 // static |
| 121 const int64_t Time::kTimeTToMicrosecondsOffset = INT64_C(11644473600000000); | 124 const int64_t Time::kTimeTToMicrosecondsOffset = INT64_C(11644473600000000); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 } | 232 } |
| 230 | 233 |
| 231 // static | 234 // static |
| 232 bool Time::IsHighResolutionTimerInUse() { | 235 bool Time::IsHighResolutionTimerInUse() { |
| 233 base::AutoLock lock(g_high_res_lock.Get()); | 236 base::AutoLock lock(g_high_res_lock.Get()); |
| 234 return g_high_res_timer_enabled && g_high_res_timer_count > 0; | 237 return g_high_res_timer_enabled && g_high_res_timer_count > 0; |
| 235 } | 238 } |
| 236 | 239 |
| 237 // static | 240 // static |
| 238 bool Time::FromExploded(bool is_local, const Exploded& exploded, Time* time) { | 241 bool Time::FromExploded(bool is_local, const Exploded& exploded, Time* time) { |
| 242 // Windows WORD has size of 2 bytes. Thus, maximum value that can be | |
| 243 // stored is 65535. If it is not possible to cast to WORD without an overflow, | |
| 244 // just return an error. | |
| 245 if (exploded.year > kMaxWinWordSize) { | |
|
miu
2016/10/18 19:55:13
Suggestion:
if (exploded.year > std::numeric_li
maksims (do not use this acc)
2016/10/19 16:41:04
Yes. Removed
| |
| 246 *time = Time(0); | |
| 247 return false; | |
| 248 } | |
| 249 | |
| 239 // Create the system struct representing our exploded time. It will either be | 250 // Create the system struct representing our exploded time. It will either be |
| 240 // in local time or UTC. | 251 // in local time or UTC. |
| 241 SYSTEMTIME st; | 252 SYSTEMTIME st; |
| 242 st.wYear = static_cast<WORD>(exploded.year); | 253 st.wYear = static_cast<WORD>(exploded.year); |
| 243 st.wMonth = static_cast<WORD>(exploded.month); | 254 st.wMonth = static_cast<WORD>(exploded.month); |
| 244 st.wDayOfWeek = static_cast<WORD>(exploded.day_of_week); | 255 st.wDayOfWeek = static_cast<WORD>(exploded.day_of_week); |
| 245 st.wDay = static_cast<WORD>(exploded.day_of_month); | 256 st.wDay = static_cast<WORD>(exploded.day_of_month); |
| 246 st.wHour = static_cast<WORD>(exploded.hour); | 257 st.wHour = static_cast<WORD>(exploded.hour); |
| 247 st.wMinute = static_cast<WORD>(exploded.minute); | 258 st.wMinute = static_cast<WORD>(exploded.minute); |
| 248 st.wSecond = static_cast<WORD>(exploded.second); | 259 st.wSecond = static_cast<WORD>(exploded.second); |
| 249 st.wMilliseconds = static_cast<WORD>(exploded.millisecond); | 260 st.wMilliseconds = static_cast<WORD>(exploded.millisecond); |
|
mmenke
2016/10/18 15:04:50
Seems like this should be:
if (!SafeConvertToWord
maksims (do not use this acc)
2016/10/19 16:41:04
Done.
| |
| 250 | 261 |
| 251 FILETIME ft; | 262 FILETIME ft; |
| 252 bool success = true; | 263 bool success = true; |
| 253 // Ensure that it's in UTC. | 264 // Ensure that it's in UTC. |
| 254 if (is_local) { | 265 if (is_local) { |
| 255 SYSTEMTIME utc_st; | 266 SYSTEMTIME utc_st; |
| 256 success = TzSpecificLocalTimeToSystemTime(nullptr, &st, &utc_st) && | 267 success = TzSpecificLocalTimeToSystemTime(nullptr, &st, &utc_st) && |
| 257 SystemTimeToFileTime(&utc_st, &ft); | 268 SystemTimeToFileTime(&utc_st, &ft); |
| 258 } else { | 269 } else { |
| 259 success = !!SystemTimeToFileTime(&st, &ft); | 270 success = !!SystemTimeToFileTime(&st, &ft); |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 630 TimeTicks TimeTicks::FromQPCValue(LONGLONG qpc_value) { | 641 TimeTicks TimeTicks::FromQPCValue(LONGLONG qpc_value) { |
| 631 return TimeTicks() + QPCValueToTimeDelta(qpc_value); | 642 return TimeTicks() + QPCValueToTimeDelta(qpc_value); |
| 632 } | 643 } |
| 633 | 644 |
| 634 // TimeDelta ------------------------------------------------------------------ | 645 // TimeDelta ------------------------------------------------------------------ |
| 635 | 646 |
| 636 // static | 647 // static |
| 637 TimeDelta TimeDelta::FromQPCValue(LONGLONG qpc_value) { | 648 TimeDelta TimeDelta::FromQPCValue(LONGLONG qpc_value) { |
| 638 return QPCValueToTimeDelta(qpc_value); | 649 return QPCValueToTimeDelta(qpc_value); |
| 639 } | 650 } |
| OLD | NEW |