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

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

Issue 1857713004: DevTools: simplify the async instrumentation harness. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: same with scriptpromiseresolver Created 4 years, 8 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 { 48 {
49 return UserGestureIndicator::processingUserGesture() 49 return UserGestureIndicator::processingUserGesture()
50 && interval <= maxIntervalForUserGestureForwarding 50 && interval <= maxIntervalForUserGestureForwarding
51 && nestingLevel == 1; // Gestures should not be forwarded to nested time rs. 51 && nestingLevel == 1; // Gestures should not be forwarded to nested time rs.
52 } 52 }
53 53
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::didInstallTimer(context, timeoutID, timeout, singl eShot);
59 return timeoutID; 58 return timeoutID;
60 } 59 }
61 60
62 void DOMTimer::removeByID(ExecutionContext* context, int timeoutID) 61 void DOMTimer::removeByID(ExecutionContext* context, int timeoutID)
63 { 62 {
64 context->timers()->removeTimeoutByID(timeoutID); 63 DOMTimer* timer = context->timers()->removeTimeoutByID(timeoutID);
65 TRACE_EVENT_INSTANT1("devtools.timeline", "TimerRemove", TRACE_EVENT_SCOPE_T HREAD, "data", InspectorTimerRemoveEvent::data(context, timeoutID)); 64 TRACE_EVENT_INSTANT1("devtools.timeline", "TimerRemove", TRACE_EVENT_SCOPE_T HREAD, "data", InspectorTimerRemoveEvent::data(context, timeoutID));
66 InspectorInstrumentation::didRemoveTimer(context, timeoutID); 65 if (timer)
66 InspectorInstrumentation::cancelAsyncTask(context, timer->m_action);
67 } 67 }
68 68
69 DOMTimer::DOMTimer(ExecutionContext* context, ScheduledAction* action, int inter val, bool singleShot, int timeoutID) 69 DOMTimer::DOMTimer(ExecutionContext* context, ScheduledAction* action, int inter val, bool singleShot, int timeoutID)
70 : SuspendableTimer(context) 70 : SuspendableTimer(context)
71 , m_timeoutID(timeoutID) 71 , m_timeoutID(timeoutID)
72 , m_nestingLevel(context->timers()->timerNestingLevel() + 1) 72 , m_nestingLevel(context->timers()->timerNestingLevel() + 1)
73 , m_action(action) 73 , m_action(action)
74 { 74 {
75 ASSERT(timeoutID > 0); 75 ASSERT(timeoutID > 0);
76 if (shouldForwardUserGesture(interval, m_nestingLevel)) 76 if (shouldForwardUserGesture(interval, m_nestingLevel))
77 m_userGestureToken = UserGestureIndicator::currentToken(); 77 m_userGestureToken = UserGestureIndicator::currentToken();
78 78
79 InspectorInstrumentation::scheduleAsyncTask(context, singleShot ? "setTimeou t" : "setInterval", action, !singleShot);
80
79 double intervalMilliseconds = std::max(oneMillisecond, interval * oneMillise cond); 81 double intervalMilliseconds = std::max(oneMillisecond, interval * oneMillise cond);
80 if (intervalMilliseconds < minimumInterval && m_nestingLevel >= maxTimerNest ingLevel) 82 if (intervalMilliseconds < minimumInterval && m_nestingLevel >= maxTimerNest ingLevel)
81 intervalMilliseconds = minimumInterval; 83 intervalMilliseconds = minimumInterval;
82 if (singleShot) 84 if (singleShot)
83 startOneShot(intervalMilliseconds, BLINK_FROM_HERE); 85 startOneShot(intervalMilliseconds, BLINK_FROM_HERE);
84 else 86 else
85 startRepeating(intervalMilliseconds, BLINK_FROM_HERE); 87 startRepeating(intervalMilliseconds, BLINK_FROM_HERE);
86 } 88 }
87 89
88 DOMTimer::~DOMTimer() 90 DOMTimer::~DOMTimer()
(...skipping 10 matching lines...) Expand all
99 void DOMTimer::fired() 101 void DOMTimer::fired()
100 { 102 {
101 ExecutionContext* context = getExecutionContext(); 103 ExecutionContext* context = getExecutionContext();
102 ASSERT(context); 104 ASSERT(context);
103 context->timers()->setTimerNestingLevel(m_nestingLevel); 105 context->timers()->setTimerNestingLevel(m_nestingLevel);
104 ASSERT(!context->activeDOMObjectsAreSuspended()); 106 ASSERT(!context->activeDOMObjectsAreSuspended());
105 // Only the first execution of a multi-shot timer should get an affirmative user gesture indicator. 107 // Only the first execution of a multi-shot timer should get an affirmative user gesture indicator.
106 UserGestureIndicator gestureIndicator(m_userGestureToken.release()); 108 UserGestureIndicator gestureIndicator(m_userGestureToken.release());
107 109
108 TRACE_EVENT1("devtools.timeline", "TimerFire", "data", InspectorTimerFireEve nt::data(context, m_timeoutID)); 110 TRACE_EVENT1("devtools.timeline", "TimerFire", "data", InspectorTimerFireEve nt::data(context, m_timeoutID));
109 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willFireTi mer(context, m_timeoutID); 111 InspectorInstrumentation::AsyncTask asyncTask(context, m_action.get());
110 112
111 // Simple case for non-one-shot timers. 113 // Simple case for non-one-shot timers.
112 if (isActive()) { 114 if (isActive()) {
113 if (repeatInterval() && repeatInterval() < minimumInterval) { 115 if (repeatInterval() && repeatInterval() < minimumInterval) {
114 m_nestingLevel++; 116 m_nestingLevel++;
115 if (m_nestingLevel >= maxTimerNestingLevel) 117 if (m_nestingLevel >= maxTimerNestingLevel)
116 augmentRepeatInterval(minimumInterval - repeatInterval()); 118 augmentRepeatInterval(minimumInterval - repeatInterval());
117 } 119 }
118 120
119 // No access to member variables after this point, it can delete the tim er. 121 // No access to member variables after this point, it can delete the tim er.
120 m_action->execute(context); 122 m_action->execute(context);
121
122 InspectorInstrumentation::didFireTimer(cookie);
123
124 return; 123 return;
125 } 124 }
126 125
127 // Unregister the timer from ExecutionContext before executing the action 126 // Unregister the timer from ExecutionContext before executing the action
128 // for one-shot timers. 127 // for one-shot timers.
129 ScheduledAction* action = m_action.release(); 128 ScheduledAction* action = m_action.release();
130 context->timers()->removeTimeoutByID(m_timeoutID); 129 context->timers()->removeTimeoutByID(m_timeoutID);
131 130
132 action->execute(context); 131 action->execute(context);
133 132
134 InspectorInstrumentation::didFireTimer(cookie);
135 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update Counters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::data( )); 133 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update Counters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::data( ));
136 134
137 // ExecutionContext might be already gone when we executed action->execute() . 135 // ExecutionContext might be already gone when we executed action->execute() .
138 if (getExecutionContext()) 136 if (getExecutionContext())
139 getExecutionContext()->timers()->setTimerNestingLevel(0); 137 getExecutionContext()->timers()->setTimerNestingLevel(0);
140 } 138 }
141 139
142 void DOMTimer::stop() 140 void DOMTimer::stop()
143 { 141 {
144 SuspendableTimer::stop(); 142 SuspendableTimer::stop();
145 // Need to release JS objects potentially protected by ScheduledAction 143 // Need to release JS objects potentially protected by ScheduledAction
146 // because they can form circular references back to the ExecutionContext 144 // because they can form circular references back to the ExecutionContext
147 // which will cause a memory leak. 145 // which will cause a memory leak.
148 m_action.clear(); 146 m_action.clear();
149 } 147 }
150 148
151 WebTaskRunner* DOMTimer::timerTaskRunner() const 149 WebTaskRunner* DOMTimer::timerTaskRunner() const
152 { 150 {
153 return getExecutionContext()->timers()->timerTaskRunner(); 151 return getExecutionContext()->timers()->timerTaskRunner();
154 } 152 }
155 153
156 DEFINE_TRACE(DOMTimer) 154 DEFINE_TRACE(DOMTimer)
157 { 155 {
158 visitor->trace(m_action); 156 visitor->trace(m_action);
159 SuspendableTimer::trace(visitor); 157 SuspendableTimer::trace(visitor);
160 } 158 }
161 159
162 } // namespace blink 160 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698