| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 * | 24 * |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #include "config.h" | 27 #include "config.h" |
| 28 #include "core/frame/SuspendableTimer.h" | 28 #include "core/frame/SuspendableTimer.h" |
| 29 | 29 |
| 30 namespace blink { | 30 namespace blink { |
| 31 | 31 |
| 32 namespace { |
| 33 // The lowest value returned by TimerBase::nextUnalignedFireInterval is 0.0 |
| 34 const double kNextFireIntervalInvalid = -1.0; |
| 35 } |
| 36 |
| 32 SuspendableTimer::SuspendableTimer(ExecutionContext* context) | 37 SuspendableTimer::SuspendableTimer(ExecutionContext* context) |
| 33 : ActiveDOMObject(context) | 38 : ActiveDOMObject(context) |
| 34 , m_nextFireInterval(0) | 39 , m_nextFireInterval(kNextFireIntervalInvalid) |
| 35 , m_repeatInterval(0) | 40 , m_repeatInterval(0) |
| 36 , m_active(false) | |
| 37 #if ENABLE(ASSERT) | 41 #if ENABLE(ASSERT) |
| 38 , m_suspended(false) | 42 , m_suspended(false) |
| 39 #endif | 43 #endif |
| 40 { | 44 { |
| 41 } | 45 } |
| 42 | 46 |
| 43 SuspendableTimer::~SuspendableTimer() | 47 SuspendableTimer::~SuspendableTimer() |
| 44 { | 48 { |
| 45 } | 49 } |
| 46 | 50 |
| 47 bool SuspendableTimer::hasPendingActivity() const | 51 bool SuspendableTimer::hasPendingActivity() const |
| 48 { | 52 { |
| 49 return isActive(); | 53 return isActive(); |
| 50 } | 54 } |
| 51 | 55 |
| 52 void SuspendableTimer::stop() | 56 void SuspendableTimer::stop() |
| 53 { | 57 { |
| 58 m_nextFireInterval = kNextFireIntervalInvalid; |
| 54 TimerBase::stop(); | 59 TimerBase::stop(); |
| 55 } | 60 } |
| 56 | 61 |
| 57 void SuspendableTimer::suspend() | 62 void SuspendableTimer::suspend() |
| 58 { | 63 { |
| 59 #if ENABLE(ASSERT) | 64 #if ENABLE(ASSERT) |
| 60 ASSERT(!m_suspended); | 65 ASSERT(!m_suspended); |
| 61 m_suspended = true; | 66 m_suspended = true; |
| 62 #endif | 67 #endif |
| 63 m_active = isActive(); | 68 if (isActive()) { |
| 64 if (m_active) { | |
| 65 m_nextFireInterval = nextUnalignedFireInterval(); | 69 m_nextFireInterval = nextUnalignedFireInterval(); |
| 70 ASSERT(m_nextFireInterval >= 0.0); |
| 66 m_repeatInterval = repeatInterval(); | 71 m_repeatInterval = repeatInterval(); |
| 67 TimerBase::stop(); | 72 TimerBase::stop(); |
| 68 } | 73 } |
| 69 } | 74 } |
| 70 | 75 |
| 71 void SuspendableTimer::resume() | 76 void SuspendableTimer::resume() |
| 72 { | 77 { |
| 73 #if ENABLE(ASSERT) | 78 #if ENABLE(ASSERT) |
| 74 ASSERT(m_suspended); | 79 ASSERT(m_suspended); |
| 75 m_suspended = false; | 80 m_suspended = false; |
| 76 #endif | 81 #endif |
| 77 // FIXME: FROM_HERE is wrong here. | 82 if (m_nextFireInterval >= 0.0) { |
| 78 if (m_active) | 83 // start() was called before, therefore location() is already set. |
| 79 start(m_nextFireInterval, m_repeatInterval, FROM_HERE); | 84 // m_nextFireInterval is only set in suspend() if the Timer was active. |
| 85 start(m_nextFireInterval, m_repeatInterval, location()); |
| 86 m_nextFireInterval = kNextFireIntervalInvalid; |
| 87 } |
| 80 } | 88 } |
| 81 | 89 |
| 82 } // namespace blink | 90 } // namespace blink |
| OLD | NEW |