OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef DOMTimerCoordinator_h | 5 #ifndef DOMTimerCoordinator_h |
6 #define DOMTimerCoordinator_h | 6 #define DOMTimerCoordinator_h |
7 | 7 |
8 #include "core/frame/DOMTimer.h" | |
9 #include "platform/heap/Handle.h" | 8 #include "platform/heap/Handle.h" |
10 #include "wtf/Noncopyable.h" | 9 #include "wtf/Noncopyable.h" |
11 #include "wtf/PassOwnPtr.h" | 10 #include "wtf/PassOwnPtr.h" |
12 | 11 |
13 namespace blink { | 12 namespace blink { |
14 | 13 |
15 class DOMTimer; | 14 class DOMTimer; |
16 class ExecutionContext; | 15 class ExecutionContext; |
17 class ScheduledAction; | 16 class ScheduledAction; |
18 | 17 |
19 // Maintains a set of DOMTimers for a given page or | 18 // Maintains a set of DOMTimers for a given page or |
20 // worker. DOMTimerCoordinator assigns IDs to timers; these IDs are | 19 // worker. DOMTimerCoordinator assigns IDs to timers; these IDs are |
21 // the ones returned to web authors from setTimeout or setInterval. It | 20 // the ones returned to web authors from setTimeout or setInterval. It |
22 // also tracks recursive creation or iterative scheduling of timers, | 21 // also tracks recursive creation or iterative scheduling of timers, |
23 // which is used as a signal for throttling repetitive timers. | 22 // which is used as a signal for throttling repetitive timers. |
24 class DOMTimerCoordinator { | 23 class DOMTimerCoordinator { |
25 DISALLOW_ALLOCATION(); | 24 DISALLOW_ALLOCATION(); |
26 WTF_MAKE_NONCOPYABLE(DOMTimerCoordinator); | 25 WTF_MAKE_NONCOPYABLE(DOMTimerCoordinator); |
27 public: | 26 public: |
28 DOMTimerCoordinator(); | 27 DOMTimerCoordinator(); |
29 | 28 |
30 // Creates and installs a new timer. Returns the assigned ID. | 29 // Creates and installs a new timer. Returns the assigned ID. |
31 int installNewTimeout(ExecutionContext*, PassOwnPtr<ScheduledAction>, int ti
meout, bool singleShot); | 30 int installNewTimeout(ExecutionContext*, PassOwnPtrWillBeRawPtr<ScheduledAct
ion>, int timeout, bool singleShot); |
32 | 31 |
33 // Removes and disposes the timer with the specified ID, if any. This may | 32 // Removes and disposes the timer with the specified ID, if any. This may |
34 // destroy the timer. | 33 // destroy the timer. |
35 void removeTimeoutByID(int id); | 34 void removeTimeoutByID(int id); |
36 | 35 |
37 // Notifies registered timers that | 36 // Notifies registered timers that |
38 // ExecutionContext::timerAlignmentInterval has changed so that | 37 // ExecutionContext::timerAlignmentInterval has changed so that |
39 // timers can adjust their schedule to the new alignment interval. | 38 // timers can adjust their schedule to the new alignment interval. |
40 void didChangeTimerAlignmentInterval(); | 39 void didChangeTimerAlignmentInterval(); |
41 | 40 |
42 // Timers created during the execution of other timers, and | 41 // Timers created during the execution of other timers, and |
43 // repeating timers, are throttled. Timer nesting level tracks the | 42 // repeating timers, are throttled. Timer nesting level tracks the |
44 // number of linked timers or repetitions of a timer. See | 43 // number of linked timers or repetitions of a timer. See |
45 // https://html.spec.whatwg.org/#timers | 44 // https://html.spec.whatwg.org/#timers |
46 int timerNestingLevel() { return m_timerNestingLevel; } | 45 int timerNestingLevel() { return m_timerNestingLevel; } |
47 | 46 |
48 // Sets the timer nesting level. Set when a timer executes so that | 47 // Sets the timer nesting level. Set when a timer executes so that |
49 // any timers created while the timer is executing will incur a | 48 // any timers created while the timer is executing will incur a |
50 // deeper timer nesting level, see DOMTimer::DOMTimer. | 49 // deeper timer nesting level, see DOMTimer::DOMTimer. |
51 void setTimerNestingLevel(int level) { m_timerNestingLevel = level; } | 50 void setTimerNestingLevel(int level) { m_timerNestingLevel = level; } |
52 | 51 |
53 void trace(Visitor*); // Oilpan. | 52 void trace(Visitor*); // Oilpan. |
54 | 53 |
55 private: | 54 private: |
56 int nextID(); | 55 int nextID(); |
57 | 56 |
58 typedef WillBeHeapHashMap<int, RefPtrWillBeMember<DOMTimer> > TimeoutMap; | 57 using TimeoutMap = WillBeHeapHashMap<int, RefPtrWillBeMember<DOMTimer>>; |
59 TimeoutMap m_timers; | 58 TimeoutMap m_timers; |
60 | 59 |
61 int m_circularSequentialID; | 60 int m_circularSequentialID; |
62 int m_timerNestingLevel; | 61 int m_timerNestingLevel; |
63 }; | 62 }; |
64 | 63 |
65 } // namespace blink | 64 } // namespace blink |
66 | 65 |
67 #endif // DOMTimerCoordinator_h | 66 #endif // DOMTimerCoordinator_h |
OLD | NEW |