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

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: 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, RawPtr<ScheduledAction> action, int timeout, bool singleShot) 54 int DOMTimer::install(ExecutionContext* context, RawPtr<ScheduledAction> action, int timeout, 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); 58 InspectorInstrumentation::scheduleAsyncTask(context, "Timer", action, !singl eShot);
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::didRemoveTimer(context, timeoutID); 66 if (timer)
67 InspectorInstrumentation::cancelAsyncTask(context, timer->m_action);
67 } 68 }
68 69
69 DOMTimer::DOMTimer(ExecutionContext* context, RawPtr<ScheduledAction> action, in t interval, bool singleShot, int timeoutID) 70 DOMTimer::DOMTimer(ExecutionContext* context, RawPtr<ScheduledAction> action, in t interval, bool singleShot, int timeoutID)
70 : SuspendableTimer(context) 71 : SuspendableTimer(context)
71 , m_timeoutID(timeoutID) 72 , m_timeoutID(timeoutID)
72 , m_nestingLevel(context->timers()->timerNestingLevel() + 1) 73 , m_nestingLevel(context->timers()->timerNestingLevel() + 1)
73 , m_action(action) 74 , m_action(action)
74 { 75 {
75 ASSERT(timeoutID > 0); 76 ASSERT(timeoutID > 0);
76 if (shouldForwardUserGesture(interval, m_nestingLevel)) 77 if (shouldForwardUserGesture(interval, m_nestingLevel))
(...skipping 22 matching lines...) Expand all
99 void DOMTimer::fired() 100 void DOMTimer::fired()
100 { 101 {
101 ExecutionContext* context = getExecutionContext(); 102 ExecutionContext* context = getExecutionContext();
102 ASSERT(context); 103 ASSERT(context);
103 context->timers()->setTimerNestingLevel(m_nestingLevel); 104 context->timers()->setTimerNestingLevel(m_nestingLevel);
104 ASSERT(!context->activeDOMObjectsAreSuspended()); 105 ASSERT(!context->activeDOMObjectsAreSuspended());
105 // Only the first execution of a multi-shot timer should get an affirmative user gesture indicator. 106 // Only the first execution of a multi-shot timer should get an affirmative user gesture indicator.
106 UserGestureIndicator gestureIndicator(m_userGestureToken.release()); 107 UserGestureIndicator gestureIndicator(m_userGestureToken.release());
107 108
108 TRACE_EVENT1("devtools.timeline", "TimerFire", "data", InspectorTimerFireEve nt::data(context, m_timeoutID)); 109 TRACE_EVENT1("devtools.timeline", "TimerFire", "data", InspectorTimerFireEve nt::data(context, m_timeoutID));
109 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willFireTi mer(context, m_timeoutID); 110 InspectorInstrumentation::AsyncTask asyncTask(context, m_action.get());
110 111
111 // Simple case for non-one-shot timers. 112 // Simple case for non-one-shot timers.
112 if (isActive()) { 113 if (isActive()) {
113 if (repeatInterval() && repeatInterval() < minimumInterval) { 114 if (repeatInterval() && repeatInterval() < minimumInterval) {
114 m_nestingLevel++; 115 m_nestingLevel++;
115 if (m_nestingLevel >= maxTimerNestingLevel) 116 if (m_nestingLevel >= maxTimerNestingLevel)
116 augmentRepeatInterval(minimumInterval - repeatInterval()); 117 augmentRepeatInterval(minimumInterval - repeatInterval());
117 } 118 }
118 119
119 // No access to member variables after this point, it can delete the tim er. 120 // No access to member variables after this point, it can delete the tim er.
120 m_action->execute(context); 121 m_action->execute(context);
121
122 InspectorInstrumentation::didFireTimer(cookie);
123
124 return; 122 return;
125 } 123 }
126 124
127 RawPtr<DOMTimer> protect(this); 125 RawPtr<DOMTimer> protect(this);
128 126
129 // Unregister the timer from ExecutionContext before executing the action 127 // Unregister the timer from ExecutionContext before executing the action
130 // for one-shot timers. 128 // for one-shot timers.
131 RawPtr<ScheduledAction> action = m_action.release(); 129 RawPtr<ScheduledAction> action = m_action.release();
132 context->timers()->removeTimeoutByID(m_timeoutID); 130 context->timers()->removeTimeoutByID(m_timeoutID);
133 131
134 action->execute(context); 132 action->execute(context);
135 133
136 InspectorInstrumentation::didFireTimer(cookie);
137 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update Counters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::data( )); 134 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update Counters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::data( ));
138 135
139 // ExecutionContext might be already gone when we executed action->execute() . 136 // ExecutionContext might be already gone when we executed action->execute() .
140 if (getExecutionContext()) 137 if (getExecutionContext())
141 getExecutionContext()->timers()->setTimerNestingLevel(0); 138 getExecutionContext()->timers()->setTimerNestingLevel(0);
142 } 139 }
143 140
144 void DOMTimer::stop() 141 void DOMTimer::stop()
145 { 142 {
146 SuspendableTimer::stop(); 143 SuspendableTimer::stop();
147 // Need to release JS objects potentially protected by ScheduledAction 144 // Need to release JS objects potentially protected by ScheduledAction
148 // because they can form circular references back to the ExecutionContext 145 // because they can form circular references back to the ExecutionContext
149 // which will cause a memory leak. 146 // which will cause a memory leak.
150 m_action.clear(); 147 m_action.clear();
151 } 148 }
152 149
153 WebTaskRunner* DOMTimer::timerTaskRunner() const 150 WebTaskRunner* DOMTimer::timerTaskRunner() const
154 { 151 {
155 return getExecutionContext()->timers()->timerTaskRunner(); 152 return getExecutionContext()->timers()->timerTaskRunner();
156 } 153 }
157 154
158 DEFINE_TRACE(DOMTimer) 155 DEFINE_TRACE(DOMTimer)
159 { 156 {
160 visitor->trace(m_action); 157 visitor->trace(m_action);
161 SuspendableTimer::trace(visitor); 158 SuspendableTimer::trace(visitor);
162 } 159 }
163 160
164 } // namespace blink 161 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698