| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 int DOMTimer::install(ExecutionContext* context, ScheduledAction* action, int ti
meout, bool singleShot) | 54 int DOMTimer::install(ExecutionContext* context, ScheduledAction* action, int ti
meout, bool singleShot) |
| 55 { | 55 { |
| 56 int timeoutID = context->timers()->installNewTimeout(context, action, timeou
t, singleShot); | 56 int timeoutID = context->timers()->installNewTimeout(context, action, timeou
t, singleShot); |
| 57 TRACE_EVENT_INSTANT1("devtools.timeline", "TimerInstall", TRACE_EVENT_SCOPE_
THREAD, "data", InspectorTimerInstallEvent::data(context, timeoutID, timeout, si
ngleShot)); | 57 TRACE_EVENT_INSTANT1("devtools.timeline", "TimerInstall", TRACE_EVENT_SCOPE_
THREAD, "data", InspectorTimerInstallEvent::data(context, timeoutID, timeout, si
ngleShot)); |
| 58 InspectorInstrumentation::NativeBreakpoint nativeBreakpoint(context, "setTim
er", true); | 58 InspectorInstrumentation::NativeBreakpoint nativeBreakpoint(context, "setTim
er", true); |
| 59 return timeoutID; | 59 return timeoutID; |
| 60 } | 60 } |
| 61 | 61 |
| 62 void DOMTimer::removeByID(ExecutionContext* context, int timeoutID) | 62 void DOMTimer::removeByID(ExecutionContext* context, int timeoutID) |
| 63 { | 63 { |
| 64 context->timers()->removeTimeoutByID(timeoutID); | 64 DOMTimer* timer = context->timers()->removeTimeoutByID(timeoutID); |
| 65 TRACE_EVENT_INSTANT1("devtools.timeline", "TimerRemove", TRACE_EVENT_SCOPE_T
HREAD, "data", InspectorTimerRemoveEvent::data(context, timeoutID)); | 65 TRACE_EVENT_INSTANT1("devtools.timeline", "TimerRemove", TRACE_EVENT_SCOPE_T
HREAD, "data", InspectorTimerRemoveEvent::data(context, timeoutID)); |
| 66 InspectorInstrumentation::NativeBreakpoint nativeBreakpoint(context, "clearT
imer", true); | 66 InspectorInstrumentation::NativeBreakpoint nativeBreakpoint(context, "clearT
imer", true); |
| 67 // Eagerly unregister as ExecutionContext observer. |
| 68 if (timer) |
| 69 timer->clearContext(); |
| 67 } | 70 } |
| 68 | 71 |
| 69 DOMTimer::DOMTimer(ExecutionContext* context, ScheduledAction* action, int inter
val, bool singleShot, int timeoutID) | 72 DOMTimer::DOMTimer(ExecutionContext* context, ScheduledAction* action, int inter
val, bool singleShot, int timeoutID) |
| 70 : SuspendableTimer(context) | 73 : SuspendableTimer(context) |
| 71 , m_timeoutID(timeoutID) | 74 , m_timeoutID(timeoutID) |
| 72 , m_nestingLevel(context->timers()->timerNestingLevel() + 1) | 75 , m_nestingLevel(context->timers()->timerNestingLevel() + 1) |
| 73 , m_action(action) | 76 , m_action(action) |
| 74 { | 77 { |
| 75 ASSERT(timeoutID > 0); | 78 ASSERT(timeoutID > 0); |
| 76 if (shouldForwardUserGesture(interval, m_nestingLevel)) | 79 if (shouldForwardUserGesture(interval, m_nestingLevel)) |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 // Unregister the timer from ExecutionContext before executing the action | 130 // Unregister the timer from ExecutionContext before executing the action |
| 128 // for one-shot timers. | 131 // for one-shot timers. |
| 129 ScheduledAction* action = m_action.release(); | 132 ScheduledAction* action = m_action.release(); |
| 130 context->timers()->removeTimeoutByID(m_timeoutID); | 133 context->timers()->removeTimeoutByID(m_timeoutID); |
| 131 | 134 |
| 132 action->execute(context); | 135 action->execute(context); |
| 133 | 136 |
| 134 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update
Counters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::data(
)); | 137 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update
Counters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::data(
)); |
| 135 | 138 |
| 136 // ExecutionContext might be already gone when we executed action->execute()
. | 139 // ExecutionContext might be already gone when we executed action->execute()
. |
| 137 if (getExecutionContext()) | 140 ExecutionContext* executionContext = getExecutionContext(); |
| 138 getExecutionContext()->timers()->setTimerNestingLevel(0); | 141 if (!executionContext) |
| 142 return; |
| 143 |
| 144 executionContext->timers()->setTimerNestingLevel(0); |
| 145 // Eagerly unregister as ExecutionContext observer. |
| 146 clearContext(); |
| 139 } | 147 } |
| 140 | 148 |
| 141 void DOMTimer::stop() | 149 void DOMTimer::stop() |
| 142 { | 150 { |
| 143 InspectorInstrumentation::asyncTaskCanceled(getExecutionContext(), this); | 151 InspectorInstrumentation::asyncTaskCanceled(getExecutionContext(), this); |
| 144 SuspendableTimer::stop(); | 152 SuspendableTimer::stop(); |
| 145 // Need to release JS objects potentially protected by ScheduledAction | 153 // Need to release JS objects potentially protected by ScheduledAction |
| 146 // because they can form circular references back to the ExecutionContext | 154 // because they can form circular references back to the ExecutionContext |
| 147 // which will cause a memory leak. | 155 // which will cause a memory leak. |
| 148 m_action.clear(); | 156 m_action.clear(); |
| 149 } | 157 } |
| 150 | 158 |
| 151 WebTaskRunner* DOMTimer::timerTaskRunner() const | 159 WebTaskRunner* DOMTimer::timerTaskRunner() const |
| 152 { | 160 { |
| 153 return getExecutionContext()->timers()->timerTaskRunner(); | 161 return getExecutionContext()->timers()->timerTaskRunner(); |
| 154 } | 162 } |
| 155 | 163 |
| 156 DEFINE_TRACE(DOMTimer) | 164 DEFINE_TRACE(DOMTimer) |
| 157 { | 165 { |
| 158 visitor->trace(m_action); | 166 visitor->trace(m_action); |
| 159 SuspendableTimer::trace(visitor); | 167 SuspendableTimer::trace(visitor); |
| 160 } | 168 } |
| 161 | 169 |
| 162 } // namespace blink | 170 } // namespace blink |
| OLD | NEW |