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

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

Issue 2700293002: DevTools: do not use RAII for sync native breakpoints, reuse AsyncTask where possible. (Closed)
Patch Set: Introduce progress monitor 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);
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) {
77 InspectorInstrumentation::asyncTaskCanceledBreakable(context,
78 "clearTimeout", timer);
81 timer->clearContext(); 79 timer->clearContext();
80 }
82 } 81 }
83 82
84 DOMTimer::DOMTimer(ExecutionContext* context, 83 DOMTimer::DOMTimer(ExecutionContext* context,
85 ScheduledAction* action, 84 ScheduledAction* action,
86 int interval, 85 int interval,
87 bool singleShot, 86 bool singleShot,
88 int timeoutID) 87 int timeoutID)
89 : SuspendableTimer(context, TaskType::Timer), 88 : SuspendableTimer(context, TaskType::Timer),
90 m_timeoutID(timeoutID), 89 m_timeoutID(timeoutID),
91 m_nestingLevel(context->timers()->timerNestingLevel() + 1), 90 m_nestingLevel(context->timers()->timerNestingLevel() + 1),
92 m_action(action) { 91 m_action(action) {
93 ASSERT(timeoutID > 0); 92 ASSERT(timeoutID > 0);
94 if (shouldForwardUserGesture(interval, m_nestingLevel)) { 93 if (shouldForwardUserGesture(interval, m_nestingLevel)) {
95 // Thread safe because shouldForwardUserGesture will only return true if 94 // Thread safe because shouldForwardUserGesture will only return true if
96 // execution is on the the main thread. 95 // execution is on the the main thread.
97 m_userGestureToken = UserGestureIndicator::currentToken(); 96 m_userGestureToken = UserGestureIndicator::currentToken();
98 } 97 }
99 98
100 InspectorInstrumentation::asyncTaskScheduled( 99 InspectorInstrumentation::asyncTaskScheduledBreakable(context, "setTimeout",
alph 2017/02/21 20:13:58 what happenned to setInterval?
101 context, singleShot ? "setTimeout" : "setInterval", this, !singleShot); 100 this, !singleShot);
102 101
103 double intervalMilliseconds = 102 double intervalMilliseconds =
104 std::max(oneMillisecond, interval * oneMillisecond); 103 std::max(oneMillisecond, interval * oneMillisecond);
105 if (intervalMilliseconds < minimumInterval && 104 if (intervalMilliseconds < minimumInterval &&
106 m_nestingLevel >= maxTimerNestingLevel) 105 m_nestingLevel >= maxTimerNestingLevel)
107 intervalMilliseconds = minimumInterval; 106 intervalMilliseconds = minimumInterval;
108 if (singleShot) 107 if (singleShot)
109 startOneShot(intervalMilliseconds, BLINK_FROM_HERE); 108 startOneShot(intervalMilliseconds, BLINK_FROM_HERE);
110 else 109 else
111 startRepeating(intervalMilliseconds, BLINK_FROM_HERE); 110 startRepeating(intervalMilliseconds, BLINK_FROM_HERE);
(...skipping 26 matching lines...) Expand all
138 context->timers()->setTimerNestingLevel(m_nestingLevel); 137 context->timers()->setTimerNestingLevel(m_nestingLevel);
139 DCHECK(!context->isContextSuspended()); 138 DCHECK(!context->isContextSuspended());
140 // Only the first execution of a multi-shot timer should get an affirmative 139 // Only the first execution of a multi-shot timer should get an affirmative
141 // user gesture indicator. 140 // user gesture indicator.
142 UserGestureIndicator gestureIndicator(std::move(m_userGestureToken)); 141 UserGestureIndicator gestureIndicator(std::move(m_userGestureToken));
143 142
144 TRACE_EVENT1("devtools.timeline", "TimerFire", "data", 143 TRACE_EVENT1("devtools.timeline", "TimerFire", "data",
145 InspectorTimerFireEvent::data(context, m_timeoutID)); 144 InspectorTimerFireEvent::data(context, m_timeoutID));
146 PerformanceMonitor::HandlerCall handlerCall( 145 PerformanceMonitor::HandlerCall handlerCall(
147 context, repeatInterval() ? "setInterval" : "setTimeout", true); 146 context, repeatInterval() ? "setInterval" : "setTimeout", true);
148 InspectorInstrumentation::NativeBreakpoint nativeBreakpoint( 147 InspectorInstrumentation::AsyncTask asyncTask(context, this, "timerFired");
149 context, "timerFired", false);
150 InspectorInstrumentation::AsyncTask asyncTask(context, this);
151 148
152 // Simple case for non-one-shot timers. 149 // Simple case for non-one-shot timers.
153 if (isActive()) { 150 if (isActive()) {
154 if (repeatInterval() && repeatInterval() < minimumInterval) { 151 if (repeatInterval() && repeatInterval() < minimumInterval) {
155 m_nestingLevel++; 152 m_nestingLevel++;
156 if (m_nestingLevel >= maxTimerNestingLevel) 153 if (m_nestingLevel >= maxTimerNestingLevel)
157 augmentRepeatInterval(minimumInterval - repeatInterval()); 154 augmentRepeatInterval(minimumInterval - repeatInterval());
158 } 155 }
159 156
160 // No access to member variables after this point, it can delete the timer. 157 // No access to member variables after this point, it can delete the timer.
(...skipping 30 matching lines...) Expand all
191 RefPtr<WebTaskRunner> DOMTimer::timerTaskRunner() const { 188 RefPtr<WebTaskRunner> DOMTimer::timerTaskRunner() const {
192 return getExecutionContext()->timers()->timerTaskRunner(); 189 return getExecutionContext()->timers()->timerTaskRunner();
193 } 190 }
194 191
195 DEFINE_TRACE(DOMTimer) { 192 DEFINE_TRACE(DOMTimer) {
196 visitor->trace(m_action); 193 visitor->trace(m_action);
197 SuspendableTimer::trace(visitor); 194 SuspendableTimer::trace(visitor);
198 } 195 }
199 196
200 } // namespace blink 197 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698