| 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 // number of leap year days between 1601 and 1970: (1970-1601)/4 excluding | 96 // number of leap year days between 1601 and 1970: (1970-1601)/4 excluding |
| 97 // 1700, 1800, and 1900. | 97 // 1700, 1800, and 1900. |
| 98 // static | 98 // static |
| 99 const int64 Time::kTimeTToMicrosecondsOffset = GG_INT64_C(11644473600000000); | 99 const int64 Time::kTimeTToMicrosecondsOffset = GG_INT64_C(11644473600000000); |
| 100 | 100 |
| 101 bool Time::high_resolution_timer_enabled_ = false; | 101 bool Time::high_resolution_timer_enabled_ = false; |
| 102 int Time::high_resolution_timer_activated_ = 0; | 102 int Time::high_resolution_timer_activated_ = 0; |
| 103 | 103 |
| 104 // static | 104 // static |
| 105 Time Time::Now() { | 105 Time Time::Now() { |
| 106 if (TimeFactory::instance()) |
| 107 return TimeFactory::instance()->TimeNow(); |
| 108 |
| 106 if (initial_time == 0) | 109 if (initial_time == 0) |
| 107 InitializeClock(); | 110 InitializeClock(); |
| 108 | 111 |
| 109 // We implement time using the high-resolution timers so that we can get | 112 // We implement time using the high-resolution timers so that we can get |
| 110 // timeouts which are smaller than 10-15ms. If we just used | 113 // timeouts which are smaller than 10-15ms. If we just used |
| 111 // CurrentWallclockMicroseconds(), we'd have the less-granular timer. | 114 // CurrentWallclockMicroseconds(), we'd have the less-granular timer. |
| 112 // | 115 // |
| 113 // To make this work, we initialize the clock (initial_time) and the | 116 // To make this work, we initialize the clock (initial_time) and the |
| 114 // counter (initial_ctr). To compute the initial time, we can check | 117 // counter (initial_ctr). To compute the initial time, we can check |
| 115 // the number of ticks that have elapsed, and compute the delta. | 118 // the number of ticks that have elapsed, and compute the delta. |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 // static | 447 // static |
| 445 TimeTicks::TickFunctionType TimeTicks::SetMockTickFunction( | 448 TimeTicks::TickFunctionType TimeTicks::SetMockTickFunction( |
| 446 TickFunctionType ticker) { | 449 TickFunctionType ticker) { |
| 447 TickFunctionType old = tick_function; | 450 TickFunctionType old = tick_function; |
| 448 tick_function = ticker; | 451 tick_function = ticker; |
| 449 return old; | 452 return old; |
| 450 } | 453 } |
| 451 | 454 |
| 452 // static | 455 // static |
| 453 TimeTicks TimeTicks::Now() { | 456 TimeTicks TimeTicks::Now() { |
| 457 if (TimeFactory::instance()) |
| 458 return TimeFactory::instance()->TimeTicksNow(); |
| 459 |
| 454 return TimeTicks() + RolloverProtectedNow(); | 460 return TimeTicks() + RolloverProtectedNow(); |
| 455 } | 461 } |
| 456 | 462 |
| 457 // static | 463 // static |
| 458 TimeTicks TimeTicks::HighResNow() { | 464 TimeTicks TimeTicks::HighResNow() { |
| 459 return TimeTicks() + HighResNowSingleton::GetInstance()->Now(); | 465 return TimeTicks() + HighResNowSingleton::GetInstance()->Now(); |
| 460 } | 466 } |
| 461 | 467 |
| 462 // static | 468 // static |
| 463 TimeTicks TimeTicks::NowFromSystemTraceTime() { | 469 TimeTicks TimeTicks::NowFromSystemTraceTime() { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 480 return HighResNowSingleton::GetInstance()->IsUsingHighResClock(); | 486 return HighResNowSingleton::GetInstance()->IsUsingHighResClock(); |
| 481 } | 487 } |
| 482 | 488 |
| 483 // TimeDelta ------------------------------------------------------------------ | 489 // TimeDelta ------------------------------------------------------------------ |
| 484 | 490 |
| 485 // static | 491 // static |
| 486 TimeDelta TimeDelta::FromQPCValue(LONGLONG qpc_value) { | 492 TimeDelta TimeDelta::FromQPCValue(LONGLONG qpc_value) { |
| 487 return TimeDelta( | 493 return TimeDelta( |
| 488 HighResNowSingleton::GetInstance()->QPCValueToMicroseconds(qpc_value)); | 494 HighResNowSingleton::GetInstance()->QPCValueToMicroseconds(qpc_value)); |
| 489 } | 495 } |
| OLD | NEW |