| 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 | |
| 68 int DOMTimer::install(ExecutionContext* context, PassOwnPtrWillBeRawPtr<Schedule
dAction> action, int timeout, bool singleShot) | 55 int DOMTimer::install(ExecutionContext* context, PassOwnPtrWillBeRawPtr<Schedule
dAction> action, int timeout, bool singleShot) |
| 69 { | 56 { |
| 70 int timeoutID = context->timers()->installNewTimeout(context, action, timeou
t, singleShot); | 57 int timeoutID = context->timers()->installNewTimeout(context, action, timeou
t, singleShot); |
| 71 TRACE_EVENT_INSTANT1("devtools.timeline", "TimerInstall", TRACE_EVENT_SCOPE_
THREAD, "data", InspectorTimerInstallEvent::data(context, timeoutID, timeout, si
ngleShot)); | 58 TRACE_EVENT_INSTANT1("devtools.timeline", "TimerInstall", TRACE_EVENT_SCOPE_
THREAD, "data", InspectorTimerInstallEvent::data(context, timeoutID, timeout, si
ngleShot)); |
| 72 InspectorInstrumentation::didInstallTimer(context, timeoutID, timeout, singl
eShot); | 59 InspectorInstrumentation::didInstallTimer(context, timeoutID, timeout, singl
eShot); |
| 73 return timeoutID; | 60 return timeoutID; |
| 74 } | 61 } |
| 75 | 62 |
| 76 void DOMTimer::removeByID(ExecutionContext* context, int timeoutID) | 63 void DOMTimer::removeByID(ExecutionContext* context, int timeoutID) |
| 77 { | 64 { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 | 144 |
| 158 void DOMTimer::stop() | 145 void DOMTimer::stop() |
| 159 { | 146 { |
| 160 SuspendableTimer::stop(); | 147 SuspendableTimer::stop(); |
| 161 // Need to release JS objects potentially protected by ScheduledAction | 148 // Need to release JS objects potentially protected by ScheduledAction |
| 162 // because they can form circular references back to the ExecutionContext | 149 // because they can form circular references back to the ExecutionContext |
| 163 // which will cause a memory leak. | 150 // which will cause a memory leak. |
| 164 m_action.clear(); | 151 m_action.clear(); |
| 165 } | 152 } |
| 166 | 153 |
| 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 | |
| 203 WebTaskRunner* DOMTimer::timerTaskRunner() | 154 WebTaskRunner* DOMTimer::timerTaskRunner() |
| 204 { | 155 { |
| 205 return executionContext()->timers()->timerTaskRunner(); | 156 return executionContext()->timers()->timerTaskRunner(); |
| 206 } | 157 } |
| 207 | 158 |
| 208 DEFINE_TRACE(DOMTimer) | 159 DEFINE_TRACE(DOMTimer) |
| 209 { | 160 { |
| 210 visitor->trace(m_action); | 161 visitor->trace(m_action); |
| 211 SuspendableTimer::trace(visitor); | 162 SuspendableTimer::trace(visitor); |
| 212 } | 163 } |
| 213 | 164 |
| 214 } // namespace blink | 165 } // namespace blink |
| OLD | NEW |