| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2009 Google Inc. All rights reserved. | 3 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 ASSERT(m_webTaskRunner); | 51 ASSERT(m_webTaskRunner); |
| 52 } | 52 } |
| 53 | 53 |
| 54 TimerBase::~TimerBase() { | 54 TimerBase::~TimerBase() { |
| 55 stop(); | 55 stop(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void TimerBase::start(double nextFireInterval, | 58 void TimerBase::start(double nextFireInterval, |
| 59 double repeatInterval, | 59 double repeatInterval, |
| 60 const WebTraceLocation& caller) { | 60 const WebTraceLocation& caller) { |
| 61 ASSERT(m_thread == currentThread()); | 61 DCHECK(m_thread == currentThread()); |
| 62 | 62 |
| 63 m_location = caller; | 63 m_location = caller; |
| 64 m_repeatInterval = repeatInterval; | 64 m_repeatInterval = repeatInterval; |
| 65 setNextFireTime(timerMonotonicallyIncreasingTime(), nextFireInterval); | 65 setNextFireTime(timerMonotonicallyIncreasingTime(), nextFireInterval); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void TimerBase::stop() { | 68 void TimerBase::stop() { |
| 69 ASSERT(m_thread == currentThread()); | 69 DCHECK(m_thread == currentThread()); |
| 70 | 70 |
| 71 m_repeatInterval = 0; | 71 m_repeatInterval = 0; |
| 72 m_nextFireTime = 0; | 72 m_nextFireTime = 0; |
| 73 m_weakPtrFactory.revokeAll(); | 73 m_weakPtrFactory.revokeAll(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 double TimerBase::nextFireInterval() const { | 76 double TimerBase::nextFireInterval() const { |
| 77 ASSERT(isActive()); | 77 ASSERT(isActive()); |
| 78 double current = timerMonotonicallyIncreasingTime(); | 78 double current = timerMonotonicallyIncreasingTime(); |
| 79 if (m_nextFireTime < current) | 79 if (m_nextFireTime < current) |
| 80 return 0; | 80 return 0; |
| 81 return m_nextFireTime - current; | 81 return m_nextFireTime - current; |
| 82 } | 82 } |
| 83 | 83 |
| 84 // static | 84 // static |
| 85 WebTaskRunner* TimerBase::getTimerTaskRunner() { | 85 WebTaskRunner* TimerBase::getTimerTaskRunner() { |
| 86 return Platform::current()->currentThread()->scheduler()->timerTaskRunner(); | 86 return Platform::current()->currentThread()->scheduler()->timerTaskRunner(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 // static | 89 // static |
| 90 WebTaskRunner* TimerBase::getUnthrottledTaskRunner() { | 90 WebTaskRunner* TimerBase::getUnthrottledTaskRunner() { |
| 91 return Platform::current()->currentThread()->getWebTaskRunner(); | 91 return Platform::current()->currentThread()->getWebTaskRunner(); |
| 92 } | 92 } |
| 93 | 93 |
| 94 WebTaskRunner* TimerBase::timerTaskRunner() const { | 94 WebTaskRunner* TimerBase::timerTaskRunner() const { |
| 95 return m_webTaskRunner.get(); | 95 return m_webTaskRunner.get(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 void TimerBase::setNextFireTime(double now, double delay) { | 98 void TimerBase::setNextFireTime(double now, double delay) { |
| 99 ASSERT(m_thread == currentThread()); | 99 DCHECK(m_thread == currentThread()); |
| 100 | 100 |
| 101 double newTime = now + delay; | 101 double newTime = now + delay; |
| 102 | 102 |
| 103 if (m_nextFireTime != newTime) { | 103 if (m_nextFireTime != newTime) { |
| 104 m_nextFireTime = newTime; | 104 m_nextFireTime = newTime; |
| 105 | 105 |
| 106 // Cancel any previously posted task. | 106 // Cancel any previously posted task. |
| 107 m_weakPtrFactory.revokeAll(); | 107 m_weakPtrFactory.revokeAll(); |
| 108 | 108 |
| 109 double delayMs = 1000.0 * (newTime - now); | 109 double delayMs = 1000.0 * (newTime - now); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 const TimerBase* b) const { | 147 const TimerBase* b) const { |
| 148 return a->m_nextFireTime < b->m_nextFireTime; | 148 return a->m_nextFireTime < b->m_nextFireTime; |
| 149 } | 149 } |
| 150 | 150 |
| 151 // static | 151 // static |
| 152 double TimerBase::timerMonotonicallyIncreasingTime() const { | 152 double TimerBase::timerMonotonicallyIncreasingTime() const { |
| 153 return timerTaskRunner()->monotonicallyIncreasingVirtualTimeSeconds(); | 153 return timerTaskRunner()->monotonicallyIncreasingVirtualTimeSeconds(); |
| 154 } | 154 } |
| 155 | 155 |
| 156 } // namespace blink | 156 } // namespace blink |
| OLD | NEW |