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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 // the smallest possible interval timer. | 45 // the smallest possible interval timer. |
46 static const double minimumInterval = 0.004; | 46 static const double minimumInterval = 0.004; |
47 | 47 |
48 static inline bool shouldForwardUserGesture(int interval, int nestingLevel) | 48 static inline bool shouldForwardUserGesture(int interval, int nestingLevel) |
49 { | 49 { |
50 return UserGestureIndicator::processingUserGesture() | 50 return UserGestureIndicator::processingUserGesture() |
51 && interval <= maxIntervalForUserGestureForwarding | 51 && interval <= maxIntervalForUserGestureForwarding |
52 && nestingLevel == 1; // Gestures should not be forwarded to nested time
rs. | 52 && nestingLevel == 1; // Gestures should not be forwarded to nested time
rs. |
53 } | 53 } |
54 | 54 |
| 55 double DOMTimer::hiddenPageAlignmentInterval() |
| 56 { |
| 57 // Timers on hidden pages are aligned so that they fire once per |
| 58 // second at most. |
| 59 return 1.0; |
| 60 } |
| 61 |
| 62 double DOMTimer::visiblePageAlignmentInterval() |
| 63 { |
| 64 // Alignment does not apply to timers on visible pages. |
| 65 return 0; |
| 66 } |
| 67 |
55 int DOMTimer::install(ExecutionContext* context, PassOwnPtrWillBeRawPtr<Schedule
dAction> action, int timeout, bool singleShot) | 68 int DOMTimer::install(ExecutionContext* context, PassOwnPtrWillBeRawPtr<Schedule
dAction> action, int timeout, bool singleShot) |
56 { | 69 { |
57 int timeoutID = context->timers()->installNewTimeout(context, action, timeou
t, singleShot); | 70 int timeoutID = context->timers()->installNewTimeout(context, action, timeou
t, singleShot); |
58 TRACE_EVENT_INSTANT1("devtools.timeline", "TimerInstall", TRACE_EVENT_SCOPE_
THREAD, "data", InspectorTimerInstallEvent::data(context, timeoutID, timeout, si
ngleShot)); | 71 TRACE_EVENT_INSTANT1("devtools.timeline", "TimerInstall", TRACE_EVENT_SCOPE_
THREAD, "data", InspectorTimerInstallEvent::data(context, timeoutID, timeout, si
ngleShot)); |
59 InspectorInstrumentation::didInstallTimer(context, timeoutID, timeout, singl
eShot); | 72 InspectorInstrumentation::didInstallTimer(context, timeoutID, timeout, singl
eShot); |
60 return timeoutID; | 73 return timeoutID; |
61 } | 74 } |
62 | 75 |
63 void DOMTimer::removeByID(ExecutionContext* context, int timeoutID) | 76 void DOMTimer::removeByID(ExecutionContext* context, int timeoutID) |
64 { | 77 { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 | 157 |
145 void DOMTimer::stop() | 158 void DOMTimer::stop() |
146 { | 159 { |
147 SuspendableTimer::stop(); | 160 SuspendableTimer::stop(); |
148 // Need to release JS objects potentially protected by ScheduledAction | 161 // Need to release JS objects potentially protected by ScheduledAction |
149 // because they can form circular references back to the ExecutionContext | 162 // because they can form circular references back to the ExecutionContext |
150 // which will cause a memory leak. | 163 // which will cause a memory leak. |
151 m_action.clear(); | 164 m_action.clear(); |
152 } | 165 } |
153 | 166 |
| 167 double DOMTimer::alignedFireTime(double fireTime) const |
| 168 { |
| 169 double alignmentInterval = executionContext()->timerAlignmentInterval(); |
| 170 if (alignmentInterval) { |
| 171 double currentTime = monotonicallyIncreasingTime(); |
| 172 if (fireTime <= currentTime) |
| 173 return fireTime; |
| 174 |
| 175 // When a repeating timer is scheduled for exactly the |
| 176 // background page alignment interval, because it's impossible |
| 177 // for the timer to be rescheduled instantaneously, it misses |
| 178 // every other fire time. Avoid this by looking at the next |
| 179 // fire time rounded both down and up. |
| 180 |
| 181 double alignedTimeRoundedDown = floor(fireTime / alignmentInterval) * al
ignmentInterval; |
| 182 double alignedTimeRoundedUp = ceil(fireTime / alignmentInterval) * align
mentInterval; |
| 183 |
| 184 // If the version rounded down is in the past, discard it |
| 185 // immediately. |
| 186 |
| 187 if (alignedTimeRoundedDown <= currentTime) |
| 188 return alignedTimeRoundedUp; |
| 189 |
| 190 // Only use the rounded-down time if it's within a certain |
| 191 // tolerance of the fire time. This avoids speeding up timers |
| 192 // on background pages in the common case. |
| 193 |
| 194 if (fireTime - alignedTimeRoundedDown < minimumInterval) |
| 195 return alignedTimeRoundedDown; |
| 196 |
| 197 return alignedTimeRoundedUp; |
| 198 } |
| 199 |
| 200 return fireTime; |
| 201 } |
| 202 |
154 WebTaskRunner* DOMTimer::timerTaskRunner() | 203 WebTaskRunner* DOMTimer::timerTaskRunner() |
155 { | 204 { |
156 return executionContext()->timers()->timerTaskRunner(); | 205 return executionContext()->timers()->timerTaskRunner(); |
157 } | 206 } |
158 | 207 |
159 DEFINE_TRACE(DOMTimer) | 208 DEFINE_TRACE(DOMTimer) |
160 { | 209 { |
161 visitor->trace(m_action); | 210 visitor->trace(m_action); |
162 SuspendableTimer::trace(visitor); | 211 SuspendableTimer::trace(visitor); |
163 } | 212 } |
164 | 213 |
165 } // namespace blink | 214 } // namespace blink |
OLD | NEW |