| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 int DOMTimer::install(ExecutionContext* context, | 57 int DOMTimer::install(ExecutionContext* context, |
| 58 ScheduledAction* action, | 58 ScheduledAction* action, |
| 59 int timeout, | 59 int timeout, |
| 60 bool singleShot) { | 60 bool singleShot) { |
| 61 int timeoutID = context->timers()->installNewTimeout(context, action, timeout, | 61 int timeoutID = context->timers()->installNewTimeout(context, action, timeout, |
| 62 singleShot); | 62 singleShot); |
| 63 TRACE_EVENT_INSTANT1("devtools.timeline", "TimerInstall", | 63 TRACE_EVENT_INSTANT1("devtools.timeline", "TimerInstall", |
| 64 TRACE_EVENT_SCOPE_THREAD, "data", | 64 TRACE_EVENT_SCOPE_THREAD, "data", |
| 65 InspectorTimerInstallEvent::data(context, timeoutID, | 65 InspectorTimerInstallEvent::data(context, timeoutID, |
| 66 timeout, singleShot)); | 66 timeout, singleShot)); |
| 67 InspectorInstrumentation::NativeBreakpoint nativeBreakpoint(context, | |
| 68 "setTimer", true); | |
| 69 return timeoutID; | 67 return timeoutID; |
| 70 } | 68 } |
| 71 | 69 |
| 72 void DOMTimer::removeByID(ExecutionContext* context, int timeoutID) { | 70 void DOMTimer::removeByID(ExecutionContext* context, int timeoutID) { |
| 73 DOMTimer* timer = context->timers()->removeTimeoutByID(timeoutID); | 71 DOMTimer* timer = context->timers()->removeTimeoutByID(timeoutID); |
| 74 TRACE_EVENT_INSTANT1("devtools.timeline", "TimerRemove", | 72 TRACE_EVENT_INSTANT1("devtools.timeline", "TimerRemove", |
| 75 TRACE_EVENT_SCOPE_THREAD, "data", | 73 TRACE_EVENT_SCOPE_THREAD, "data", |
| 76 InspectorTimerRemoveEvent::data(context, timeoutID)); | 74 InspectorTimerRemoveEvent::data(context, timeoutID)); |
| 77 InspectorInstrumentation::NativeBreakpoint nativeBreakpoint( | |
| 78 context, "clearTimer", true); | |
| 79 // Eagerly unregister as ExecutionContext observer. | 75 // Eagerly unregister as ExecutionContext observer. |
| 80 if (timer) | 76 if (timer) |
| 81 timer->clearContext(); | 77 timer->clearContext(); |
| 82 } | 78 } |
| 83 | 79 |
| 84 DOMTimer::DOMTimer(ExecutionContext* context, | 80 DOMTimer::DOMTimer(ExecutionContext* context, |
| 85 ScheduledAction* action, | 81 ScheduledAction* action, |
| 86 int interval, | 82 int interval, |
| 87 bool singleShot, | 83 bool singleShot, |
| 88 int timeoutID) | 84 int timeoutID) |
| 89 : SuspendableTimer(context, TaskType::Timer), | 85 : SuspendableTimer(context, TaskType::Timer), |
| 90 m_timeoutID(timeoutID), | 86 m_timeoutID(timeoutID), |
| 91 m_nestingLevel(context->timers()->timerNestingLevel() + 1), | 87 m_nestingLevel(context->timers()->timerNestingLevel() + 1), |
| 92 m_action(action) { | 88 m_action(action) { |
| 93 ASSERT(timeoutID > 0); | 89 ASSERT(timeoutID > 0); |
| 94 if (shouldForwardUserGesture(interval, m_nestingLevel)) { | 90 if (shouldForwardUserGesture(interval, m_nestingLevel)) { |
| 95 // Thread safe because shouldForwardUserGesture will only return true if | 91 // Thread safe because shouldForwardUserGesture will only return true if |
| 96 // execution is on the the main thread. | 92 // execution is on the the main thread. |
| 97 m_userGestureToken = UserGestureIndicator::currentToken(); | 93 m_userGestureToken = UserGestureIndicator::currentToken(); |
| 98 } | 94 } |
| 99 | 95 |
| 100 InspectorInstrumentation::asyncTaskScheduled( | |
| 101 context, singleShot ? "setTimeout" : "setInterval", this, !singleShot); | |
| 102 | |
| 103 double intervalMilliseconds = | 96 double intervalMilliseconds = |
| 104 std::max(oneMillisecond, interval * oneMillisecond); | 97 std::max(oneMillisecond, interval * oneMillisecond); |
| 105 if (intervalMilliseconds < minimumInterval && | 98 if (intervalMilliseconds < minimumInterval && |
| 106 m_nestingLevel >= maxTimerNestingLevel) | 99 m_nestingLevel >= maxTimerNestingLevel) |
| 107 intervalMilliseconds = minimumInterval; | 100 intervalMilliseconds = minimumInterval; |
| 108 if (singleShot) | 101 if (singleShot) |
| 109 startOneShot(intervalMilliseconds, BLINK_FROM_HERE); | 102 startOneShot(intervalMilliseconds, BLINK_FROM_HERE); |
| 110 else | 103 else |
| 111 startRepeating(intervalMilliseconds, BLINK_FROM_HERE); | 104 startRepeating(intervalMilliseconds, BLINK_FROM_HERE); |
| 105 |
| 106 suspendIfNeeded(); |
| 107 InspectorInstrumentation::asyncTaskScheduledBreakable( |
| 108 context, singleShot ? "setTimeout" : "setInterval", this, !singleShot); |
| 112 } | 109 } |
| 113 | 110 |
| 114 DOMTimer::~DOMTimer() { | 111 DOMTimer::~DOMTimer() { |
| 115 if (m_action) | 112 if (m_action) |
| 116 m_action->dispose(); | 113 m_action->dispose(); |
| 117 } | 114 } |
| 118 | 115 |
| 119 void DOMTimer::stop() { | 116 void DOMTimer::stop() { |
| 120 InspectorInstrumentation::asyncTaskCanceled(getExecutionContext(), this); | 117 InspectorInstrumentation::asyncTaskCanceledBreakable( |
| 118 getExecutionContext(), |
| 119 repeatInterval() ? "clearInterval" : "clearTimeout", this); |
| 120 |
| 121 m_userGestureToken = nullptr; | 121 m_userGestureToken = nullptr; |
| 122 // Need to release JS objects potentially protected by ScheduledAction | 122 // Need to release JS objects potentially protected by ScheduledAction |
| 123 // because they can form circular references back to the ExecutionContext | 123 // because they can form circular references back to the ExecutionContext |
| 124 // which will cause a memory leak. | 124 // which will cause a memory leak. |
| 125 if (m_action) | 125 if (m_action) |
| 126 m_action->dispose(); | 126 m_action->dispose(); |
| 127 m_action = nullptr; | 127 m_action = nullptr; |
| 128 SuspendableTimer::stop(); | 128 SuspendableTimer::stop(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 void DOMTimer::contextDestroyed(ExecutionContext*) { | 131 void DOMTimer::contextDestroyed(ExecutionContext*) { |
| 132 stop(); | 132 stop(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 void DOMTimer::fired() { | 135 void DOMTimer::fired() { |
| 136 ExecutionContext* context = getExecutionContext(); | 136 ExecutionContext* context = getExecutionContext(); |
| 137 ASSERT(context); | 137 ASSERT(context); |
| 138 context->timers()->setTimerNestingLevel(m_nestingLevel); | 138 context->timers()->setTimerNestingLevel(m_nestingLevel); |
| 139 DCHECK(!context->isContextSuspended()); | 139 DCHECK(!context->isContextSuspended()); |
| 140 // Only the first execution of a multi-shot timer should get an affirmative | 140 // Only the first execution of a multi-shot timer should get an affirmative |
| 141 // user gesture indicator. | 141 // user gesture indicator. |
| 142 UserGestureIndicator gestureIndicator(std::move(m_userGestureToken)); | 142 UserGestureIndicator gestureIndicator(std::move(m_userGestureToken)); |
| 143 | 143 |
| 144 TRACE_EVENT1("devtools.timeline", "TimerFire", "data", | 144 TRACE_EVENT1("devtools.timeline", "TimerFire", "data", |
| 145 InspectorTimerFireEvent::data(context, m_timeoutID)); | 145 InspectorTimerFireEvent::data(context, m_timeoutID)); |
| 146 PerformanceMonitor::HandlerCall handlerCall( | 146 PerformanceMonitor::HandlerCall handlerCall( |
| 147 context, repeatInterval() ? "setInterval" : "setTimeout", true); | 147 context, repeatInterval() ? "setInterval" : "setTimeout", true); |
| 148 InspectorInstrumentation::NativeBreakpoint nativeBreakpoint( | 148 InspectorInstrumentation::AsyncTask asyncTask(context, this, "timerFired"); |
| 149 context, "timerFired", false); | |
| 150 InspectorInstrumentation::AsyncTask asyncTask(context, this); | |
| 151 | 149 |
| 152 // Simple case for non-one-shot timers. | 150 // Simple case for non-one-shot timers. |
| 153 if (isActive()) { | 151 if (isActive()) { |
| 154 if (repeatInterval() && repeatInterval() < minimumInterval) { | 152 if (repeatInterval() && repeatInterval() < minimumInterval) { |
| 155 m_nestingLevel++; | 153 m_nestingLevel++; |
| 156 if (m_nestingLevel >= maxTimerNestingLevel) | 154 if (m_nestingLevel >= maxTimerNestingLevel) |
| 157 augmentRepeatInterval(minimumInterval - repeatInterval()); | 155 augmentRepeatInterval(minimumInterval - repeatInterval()); |
| 158 } | 156 } |
| 159 | 157 |
| 160 // No access to member variables after this point, it can delete the timer. | 158 // No access to member variables after this point, it can delete the timer. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 191 RefPtr<WebTaskRunner> DOMTimer::timerTaskRunner() const { | 189 RefPtr<WebTaskRunner> DOMTimer::timerTaskRunner() const { |
| 192 return getExecutionContext()->timers()->timerTaskRunner(); | 190 return getExecutionContext()->timers()->timerTaskRunner(); |
| 193 } | 191 } |
| 194 | 192 |
| 195 DEFINE_TRACE(DOMTimer) { | 193 DEFINE_TRACE(DOMTimer) { |
| 196 visitor->trace(m_action); | 194 visitor->trace(m_action); |
| 197 SuspendableTimer::trace(visitor); | 195 SuspendableTimer::trace(visitor); |
| 198 } | 196 } |
| 199 | 197 |
| 200 } // namespace blink | 198 } // namespace blink |
| OLD | NEW |