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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 | 90 |
91 WebTaskRunner* TimerBase::timerTaskRunner() const | 91 WebTaskRunner* TimerBase::timerTaskRunner() const |
92 { | 92 { |
93 return m_webTaskRunner; | 93 return m_webTaskRunner; |
94 } | 94 } |
95 | 95 |
96 void TimerBase::setNextFireTime(double now, double delay) | 96 void TimerBase::setNextFireTime(double now, double delay) |
97 { | 97 { |
98 ASSERT(m_thread == currentThread()); | 98 ASSERT(m_thread == currentThread()); |
99 | 99 |
100 double newTime = now + delay; | 100 m_nextFireTime = now + delay; |
| 101 if (m_cancellableTimerTask) |
| 102 m_cancellableTimerTask->cancel(); |
| 103 m_cancellableTimerTask = new CancellableTimerTask(this); |
101 | 104 |
102 if (m_nextFireTime != newTime) { | 105 double delayMs = 1000.0 * delay; |
103 m_nextFireTime = newTime; | 106 timerTaskRunner()->postDelayedTask(m_location, m_cancellableTimerTask, delay
Ms); |
104 if (m_cancellableTimerTask) | |
105 m_cancellableTimerTask->cancel(); | |
106 m_cancellableTimerTask = new CancellableTimerTask(this); | |
107 | |
108 double delayMs = 1000.0 * (newTime - now); | |
109 timerTaskRunner()->postDelayedTask(m_location, m_cancellableTimerTask, d
elayMs); | |
110 } | |
111 } | 107 } |
112 | 108 |
113 NO_LAZY_SWEEP_SANITIZE_ADDRESS | 109 NO_LAZY_SWEEP_SANITIZE_ADDRESS |
114 void TimerBase::runInternal() | 110 void TimerBase::runInternal() |
115 { | 111 { |
116 if (!canFire()) | 112 if (!canFire()) |
117 return; | 113 return; |
118 | 114 |
119 TRACE_EVENT0("blink", "TimerBase::run"); | 115 TRACE_EVENT0("blink", "TimerBase::run"); |
120 #if DCHECK_IS_ON() | 116 #if DCHECK_IS_ON() |
121 DCHECK_EQ(m_thread, currentThread()) << "Timer posted by " << m_location.fun
ction_name() << " " << m_location.file_name() << " was run on a different thread
"; | 117 DCHECK_EQ(m_thread, currentThread()) << "Timer posted by " << m_location.fun
ction_name() << " " << m_location.file_name() << " was run on a different thread
"; |
122 #endif | 118 #endif |
123 TRACE_EVENT_SET_SAMPLING_STATE("blink", "BlinkInternal"); | 119 TRACE_EVENT_SET_SAMPLING_STATE("blink", "BlinkInternal"); |
124 | 120 |
125 if (m_repeatInterval) { | 121 if (m_repeatInterval) { |
126 double now = timerMonotonicallyIncreasingTime(); | 122 double now = timerMonotonicallyIncreasingTime(); |
127 // This computation should be drift free, and it will cope if we miss a
beat, | 123 // This computation should be drift free, and it will cope if we miss a
beat, |
128 // which can easily happen if the thread is busy. It will also cope if
we get | 124 // which can easily happen if the thread is busy. It will also cope if
we get |
129 // called slightly before m_unalignedNextFireTime, which can happen due
to lack | 125 // called slightly before m_unalignedNextFireTime, which can happen due
to lack |
130 // of timer precision. | 126 // of timer precision. |
131 double intervalToNextFireTime = m_repeatInterval - fmod(now - m_nextFire
Time, m_repeatInterval); | 127 double intervalToNextFireTime = m_repeatInterval - fmod(now - m_nextFire
Time, m_repeatInterval); |
132 setNextFireTime(timerMonotonicallyIncreasingTime(), intervalToNextFireTi
me); | 128 setNextFireTime(now, intervalToNextFireTime); |
133 } else { | 129 } else { |
134 m_nextFireTime = 0; | 130 m_nextFireTime = 0; |
135 } | 131 } |
136 fired(); | 132 fired(); |
137 TRACE_EVENT_SET_SAMPLING_STATE("blink", "Sleeping"); | 133 TRACE_EVENT_SET_SAMPLING_STATE("blink", "Sleeping"); |
138 } | 134 } |
139 | 135 |
140 bool TimerBase::Comparator::operator()(const TimerBase* a, const TimerBase* b) c
onst | 136 bool TimerBase::Comparator::operator()(const TimerBase* a, const TimerBase* b) c
onst |
141 { | 137 { |
142 return a->m_nextFireTime < b->m_nextFireTime; | 138 return a->m_nextFireTime < b->m_nextFireTime; |
143 } | 139 } |
144 | 140 |
145 // static | 141 // static |
146 WebTaskRunner* TimerBase::UnthrottledWebTaskRunner() | 142 WebTaskRunner* TimerBase::UnthrottledWebTaskRunner() |
147 { | 143 { |
148 return Platform::current()->currentThread()->getWebTaskRunner(); | 144 return Platform::current()->currentThread()->getWebTaskRunner(); |
149 } | 145 } |
150 | 146 |
151 double TimerBase::timerMonotonicallyIncreasingTime() const | 147 double TimerBase::timerMonotonicallyIncreasingTime() const |
152 { | 148 { |
153 return timerTaskRunner()->monotonicallyIncreasingVirtualTimeSeconds(); | 149 return timerTaskRunner()->monotonicallyIncreasingVirtualTimeSeconds(); |
154 } | 150 } |
155 | 151 |
156 } // namespace blink | 152 } // namespace blink |
OLD | NEW |