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 |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 #include <cfloat> | |
31 | |
30 namespace blink { | 32 namespace blink { |
31 | 33 |
34 namespace { | |
35 const double kNextFireIntervalInvalid = -DBL_MAX; | |
João Eiras
2014/10/17 16:04:10
m_nextFireInterval could be zero for the case of s
Mike West
2014/10/18 09:06:42
Hrm. This kills some of the elegance of the previo
| |
36 } | |
37 | |
32 SuspendableTimer::SuspendableTimer(ExecutionContext* context) | 38 SuspendableTimer::SuspendableTimer(ExecutionContext* context) |
33 : ActiveDOMObject(context) | 39 : ActiveDOMObject(context) |
34 , m_nextFireInterval(0) | 40 , m_nextFireInterval(kNextFireIntervalInvalid) |
35 , m_repeatInterval(0) | 41 , m_repeatInterval(0) |
36 , m_active(false) | |
37 #if ENABLE(ASSERT) | 42 #if ENABLE(ASSERT) |
38 , m_suspended(false) | 43 , m_suspended(false) |
39 #endif | 44 #endif |
40 { | 45 { |
41 } | 46 } |
42 | 47 |
43 SuspendableTimer::~SuspendableTimer() | 48 SuspendableTimer::~SuspendableTimer() |
44 { | 49 { |
45 } | 50 } |
46 | 51 |
47 bool SuspendableTimer::hasPendingActivity() const | 52 bool SuspendableTimer::hasPendingActivity() const |
48 { | 53 { |
49 return isActive(); | 54 return isActive(); |
50 } | 55 } |
51 | 56 |
52 void SuspendableTimer::stop() | 57 void SuspendableTimer::stop() |
53 { | 58 { |
59 m_nextFireInterval = kNextFireIntervalInvalid; | |
54 TimerBase::stop(); | 60 TimerBase::stop(); |
55 } | 61 } |
56 | 62 |
57 void SuspendableTimer::suspend() | 63 void SuspendableTimer::suspend() |
58 { | 64 { |
59 #if ENABLE(ASSERT) | 65 #if ENABLE(ASSERT) |
60 ASSERT(!m_suspended); | 66 ASSERT(!m_suspended); |
61 m_suspended = true; | 67 m_suspended = true; |
62 #endif | 68 #endif |
63 m_active = isActive(); | 69 if (isActive()) { |
64 if (m_active) { | |
65 m_nextFireInterval = nextUnalignedFireInterval(); | 70 m_nextFireInterval = nextUnalignedFireInterval(); |
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 > kNextFireIntervalInvalid) { |
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 |