| 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 29 matching lines...) Expand all Loading... |
| 40 static const int maxTimerNestingLevel = 5; | 40 static const int maxTimerNestingLevel = 5; |
| 41 static const double oneMillisecond = 0.001; | 41 static const double oneMillisecond = 0.001; |
| 42 // Chromium uses a minimum timer interval of 4ms. We'd like to go | 42 // Chromium uses a minimum timer interval of 4ms. We'd like to go |
| 43 // lower; however, there are poorly coded websites out there which do | 43 // lower; however, there are poorly coded websites out there which do |
| 44 // create CPU-spinning loops. Using 4ms prevents the CPU from | 44 // create CPU-spinning loops. Using 4ms prevents the CPU from |
| 45 // spinning too busily and provides a balance between CPU spinning and | 45 // spinning too busily and provides a balance between CPU spinning and |
| 46 // the smallest possible interval timer. | 46 // the smallest possible interval timer. |
| 47 static const double minimumInterval = 0.004; | 47 static const double minimumInterval = 0.004; |
| 48 | 48 |
| 49 static inline bool shouldForwardUserGesture(int interval, int nestingLevel) { | 49 static inline bool shouldForwardUserGesture(int interval, int nestingLevel) { |
| 50 return UserGestureIndicator::processingUserGesture() && | 50 return UserGestureIndicator::processingUserGestureThreadSafe() && |
| 51 interval <= maxIntervalForUserGestureForwarding && | 51 interval <= maxIntervalForUserGestureForwarding && |
| 52 nestingLevel == | 52 nestingLevel == |
| 53 1; // Gestures should not be forwarded to nested timers. | 53 1; // Gestures should not be forwarded to nested timers. |
| 54 } | 54 } |
| 55 | 55 |
| 56 int DOMTimer::install(ExecutionContext* context, | 56 int DOMTimer::install(ExecutionContext* context, |
| 57 ScheduledAction* action, | 57 ScheduledAction* action, |
| 58 int timeout, | 58 int timeout, |
| 59 bool singleShot) { | 59 bool singleShot) { |
| 60 int timeoutID = context->timers()->installNewTimeout(context, action, timeout, | 60 int timeoutID = context->timers()->installNewTimeout(context, action, timeout, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 83 DOMTimer::DOMTimer(ExecutionContext* context, | 83 DOMTimer::DOMTimer(ExecutionContext* context, |
| 84 ScheduledAction* action, | 84 ScheduledAction* action, |
| 85 int interval, | 85 int interval, |
| 86 bool singleShot, | 86 bool singleShot, |
| 87 int timeoutID) | 87 int timeoutID) |
| 88 : SuspendableTimer(context), | 88 : SuspendableTimer(context), |
| 89 m_timeoutID(timeoutID), | 89 m_timeoutID(timeoutID), |
| 90 m_nestingLevel(context->timers()->timerNestingLevel() + 1), | 90 m_nestingLevel(context->timers()->timerNestingLevel() + 1), |
| 91 m_action(action) { | 91 m_action(action) { |
| 92 ASSERT(timeoutID > 0); | 92 ASSERT(timeoutID > 0); |
| 93 if (shouldForwardUserGesture(interval, m_nestingLevel)) | 93 if (shouldForwardUserGesture(interval, m_nestingLevel)) { |
| 94 // Thread safe because shouldForwardUserGesture will only return true if |
| 95 // execution is on the the main thread. |
| 94 m_userGestureToken = UserGestureIndicator::currentToken(); | 96 m_userGestureToken = UserGestureIndicator::currentToken(); |
| 97 } |
| 95 | 98 |
| 96 InspectorInstrumentation::asyncTaskScheduled( | 99 InspectorInstrumentation::asyncTaskScheduled( |
| 97 context, singleShot ? "setTimeout" : "setInterval", this, !singleShot); | 100 context, singleShot ? "setTimeout" : "setInterval", this, !singleShot); |
| 98 | 101 |
| 99 double intervalMilliseconds = | 102 double intervalMilliseconds = |
| 100 std::max(oneMillisecond, interval * oneMillisecond); | 103 std::max(oneMillisecond, interval * oneMillisecond); |
| 101 if (intervalMilliseconds < minimumInterval && | 104 if (intervalMilliseconds < minimumInterval && |
| 102 m_nestingLevel >= maxTimerNestingLevel) | 105 m_nestingLevel >= maxTimerNestingLevel) |
| 103 intervalMilliseconds = minimumInterval; | 106 intervalMilliseconds = minimumInterval; |
| 104 if (singleShot) | 107 if (singleShot) |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 WebTaskRunner* DOMTimer::timerTaskRunner() const { | 187 WebTaskRunner* DOMTimer::timerTaskRunner() const { |
| 185 return getExecutionContext()->timers()->timerTaskRunner(); | 188 return getExecutionContext()->timers()->timerTaskRunner(); |
| 186 } | 189 } |
| 187 | 190 |
| 188 DEFINE_TRACE(DOMTimer) { | 191 DEFINE_TRACE(DOMTimer) { |
| 189 visitor->trace(m_action); | 192 visitor->trace(m_action); |
| 190 SuspendableTimer::trace(visitor); | 193 SuspendableTimer::trace(visitor); |
| 191 } | 194 } |
| 192 | 195 |
| 193 } // namespace blink | 196 } // namespace blink |
| OLD | NEW |