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 #include "config.h" | 5 #include "config.h" |
6 #include "core/frame/DOMTimerCoordinator.h" | 6 #include "core/frame/DOMTimerCoordinator.h" |
7 | 7 |
8 #include "core/dom/ExecutionContext.h" | 8 #include "core/dom/ExecutionContext.h" |
9 #include "core/frame/DOMTimer.h" | 9 #include "core/frame/DOMTimer.h" |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... |
35 { | 35 { |
36 if (timeoutID <= 0) | 36 if (timeoutID <= 0) |
37 return; | 37 return; |
38 | 38 |
39 if (DOMTimer* removedTimer = m_timers.get(timeoutID)) | 39 if (DOMTimer* removedTimer = m_timers.get(timeoutID)) |
40 removedTimer->disposeTimer(); | 40 removedTimer->disposeTimer(); |
41 | 41 |
42 m_timers.remove(timeoutID); | 42 m_timers.remove(timeoutID); |
43 } | 43 } |
44 | 44 |
45 void DOMTimerCoordinator::didChangeTimerAlignmentInterval() | |
46 { | |
47 // Reschedule timers in increasing order of desired run time to maintain the
ir relative order. | |
48 // TODO(skyostil): Move timer alignment into the scheduler. | |
49 WillBeHeapVector<RawPtrWillBeMember<DOMTimer>> timers; | |
50 timers.reserveCapacity(m_timers.size()); | |
51 for (TimeoutMap::iterator iter = m_timers.begin(); iter != m_timers.end(); +
+iter) | |
52 timers.append(iter->value.get()); | |
53 std::sort(timers.begin(), timers.end(), TimerBase::Comparator()); | |
54 double now = monotonicallyIncreasingTime(); | |
55 for (DOMTimer* timer : timers) | |
56 timer->didChangeAlignmentInterval(now); | |
57 } | |
58 | |
59 DEFINE_TRACE(DOMTimerCoordinator) | 45 DEFINE_TRACE(DOMTimerCoordinator) |
60 { | 46 { |
61 #if ENABLE(OILPAN) | 47 #if ENABLE(OILPAN) |
62 visitor->trace(m_timers); | 48 visitor->trace(m_timers); |
63 #endif | 49 #endif |
64 } | 50 } |
65 | 51 |
66 int DOMTimerCoordinator::nextID() | 52 int DOMTimerCoordinator::nextID() |
67 { | 53 { |
68 while (true) { | 54 while (true) { |
69 ++m_circularSequentialID; | 55 ++m_circularSequentialID; |
70 | 56 |
71 if (m_circularSequentialID <= 0) | 57 if (m_circularSequentialID <= 0) |
72 m_circularSequentialID = 1; | 58 m_circularSequentialID = 1; |
73 | 59 |
74 if (!m_timers.contains(m_circularSequentialID)) | 60 if (!m_timers.contains(m_circularSequentialID)) |
75 return m_circularSequentialID; | 61 return m_circularSequentialID; |
76 } | 62 } |
77 } | 63 } |
78 | 64 |
79 void DOMTimerCoordinator::setTimerTaskRunner(PassOwnPtr<WebTaskRunner> timerTask
Runner) | 65 void DOMTimerCoordinator::setTimerTaskRunner(PassOwnPtr<WebTaskRunner> timerTask
Runner) |
80 { | 66 { |
81 m_timerTaskRunner = timerTaskRunner; | 67 m_timerTaskRunner = timerTaskRunner; |
82 } | 68 } |
83 | 69 |
84 } // namespace blink | 70 } // namespace blink |
OLD | NEW |