Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: third_party/WebKit/Source/core/frame/DOMTimer.cpp

Issue 2713613003: Revert of DevTools: do not use RAII for sync native breakpoints, reuse AsyncTask where possible. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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);
67 return timeoutID; 69 return timeoutID;
68 } 70 }
69 71
70 void DOMTimer::removeByID(ExecutionContext* context, int timeoutID) { 72 void DOMTimer::removeByID(ExecutionContext* context, int timeoutID) {
71 DOMTimer* timer = context->timers()->removeTimeoutByID(timeoutID); 73 DOMTimer* timer = context->timers()->removeTimeoutByID(timeoutID);
72 TRACE_EVENT_INSTANT1("devtools.timeline", "TimerRemove", 74 TRACE_EVENT_INSTANT1("devtools.timeline", "TimerRemove",
73 TRACE_EVENT_SCOPE_THREAD, "data", 75 TRACE_EVENT_SCOPE_THREAD, "data",
74 InspectorTimerRemoveEvent::data(context, timeoutID)); 76 InspectorTimerRemoveEvent::data(context, timeoutID));
77 InspectorInstrumentation::NativeBreakpoint nativeBreakpoint(
78 context, "clearTimer", true);
75 // Eagerly unregister as ExecutionContext observer. 79 // Eagerly unregister as ExecutionContext observer.
76 if (timer) 80 if (timer)
77 timer->clearContext(); 81 timer->clearContext();
78 } 82 }
79 83
80 DOMTimer::DOMTimer(ExecutionContext* context, 84 DOMTimer::DOMTimer(ExecutionContext* context,
81 ScheduledAction* action, 85 ScheduledAction* action,
82 int interval, 86 int interval,
83 bool singleShot, 87 bool singleShot,
84 int timeoutID) 88 int timeoutID)
85 : SuspendableTimer(context, TaskType::Timer), 89 : SuspendableTimer(context, TaskType::Timer),
86 m_timeoutID(timeoutID), 90 m_timeoutID(timeoutID),
87 m_nestingLevel(context->timers()->timerNestingLevel() + 1), 91 m_nestingLevel(context->timers()->timerNestingLevel() + 1),
88 m_action(action) { 92 m_action(action) {
89 ASSERT(timeoutID > 0); 93 ASSERT(timeoutID > 0);
90 if (shouldForwardUserGesture(interval, m_nestingLevel)) { 94 if (shouldForwardUserGesture(interval, m_nestingLevel)) {
91 // Thread safe because shouldForwardUserGesture will only return true if 95 // Thread safe because shouldForwardUserGesture will only return true if
92 // execution is on the the main thread. 96 // execution is on the the main thread.
93 m_userGestureToken = UserGestureIndicator::currentToken(); 97 m_userGestureToken = UserGestureIndicator::currentToken();
94 } 98 }
95 99
100 InspectorInstrumentation::asyncTaskScheduled(
101 context, singleShot ? "setTimeout" : "setInterval", this, !singleShot);
102
96 double intervalMilliseconds = 103 double intervalMilliseconds =
97 std::max(oneMillisecond, interval * oneMillisecond); 104 std::max(oneMillisecond, interval * oneMillisecond);
98 if (intervalMilliseconds < minimumInterval && 105 if (intervalMilliseconds < minimumInterval &&
99 m_nestingLevel >= maxTimerNestingLevel) 106 m_nestingLevel >= maxTimerNestingLevel)
100 intervalMilliseconds = minimumInterval; 107 intervalMilliseconds = minimumInterval;
101 if (singleShot) 108 if (singleShot)
102 startOneShot(intervalMilliseconds, BLINK_FROM_HERE); 109 startOneShot(intervalMilliseconds, BLINK_FROM_HERE);
103 else 110 else
104 startRepeating(intervalMilliseconds, BLINK_FROM_HERE); 111 startRepeating(intervalMilliseconds, BLINK_FROM_HERE);
105
106 suspendIfNeeded();
107 InspectorInstrumentation::asyncTaskScheduledBreakable(
108 context, singleShot ? "setTimeout" : "setInterval", this, !singleShot);
109 } 112 }
110 113
111 DOMTimer::~DOMTimer() { 114 DOMTimer::~DOMTimer() {
112 if (m_action) 115 if (m_action)
113 m_action->dispose(); 116 m_action->dispose();
114 } 117 }
115 118
116 void DOMTimer::stop() { 119 void DOMTimer::stop() {
117 InspectorInstrumentation::asyncTaskCanceledBreakable( 120 InspectorInstrumentation::asyncTaskCanceled(getExecutionContext(), this);
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::AsyncTask asyncTask(context, this, "timerFired"); 148 InspectorInstrumentation::NativeBreakpoint nativeBreakpoint(
149 context, "timerFired", false);
150 InspectorInstrumentation::AsyncTask asyncTask(context, this);
149 151
150 // Simple case for non-one-shot timers. 152 // Simple case for non-one-shot timers.
151 if (isActive()) { 153 if (isActive()) {
152 if (repeatInterval() && repeatInterval() < minimumInterval) { 154 if (repeatInterval() && repeatInterval() < minimumInterval) {
153 m_nestingLevel++; 155 m_nestingLevel++;
154 if (m_nestingLevel >= maxTimerNestingLevel) 156 if (m_nestingLevel >= maxTimerNestingLevel)
155 augmentRepeatInterval(minimumInterval - repeatInterval()); 157 augmentRepeatInterval(minimumInterval - repeatInterval());
156 } 158 }
157 159
158 // No access to member variables after this point, it can delete the timer. 160 // No access to member variables after this point, it can delete the timer.
(...skipping 30 matching lines...) Expand all
189 RefPtr<WebTaskRunner> DOMTimer::timerTaskRunner() const { 191 RefPtr<WebTaskRunner> DOMTimer::timerTaskRunner() const {
190 return getExecutionContext()->timers()->timerTaskRunner(); 192 return getExecutionContext()->timers()->timerTaskRunner();
191 } 193 }
192 194
193 DEFINE_TRACE(DOMTimer) { 195 DEFINE_TRACE(DOMTimer) {
194 visitor->trace(m_action); 196 visitor->trace(m_action);
195 SuspendableTimer::trace(visitor); 197 SuspendableTimer::trace(visitor);
196 } 198 }
197 199
198 } // namespace blink 200 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698