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

Side by Side Diff: third_party/WebKit/Source/core/dom/FrameRequestCallbackCollection.cpp

Issue 2700293002: DevTools: do not use RAII for sync native breakpoints, reuse AsyncTask where possible. (Closed)
Patch Set: same with unused assert removed - assert is trivial Created 3 years, 9 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 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/dom/FrameRequestCallbackCollection.h" 5 #include "core/dom/FrameRequestCallbackCollection.h"
6 6
7 #include "core/dom/FrameRequestCallback.h" 7 #include "core/dom/FrameRequestCallback.h"
8 #include "core/frame/PerformanceMonitor.h" 8 #include "core/frame/PerformanceMonitor.h"
9 #include "core/inspector/InspectorInstrumentation.h" 9 #include "core/inspector/InspectorInstrumentation.h"
10 #include "core/inspector/InspectorTraceEvents.h" 10 #include "core/inspector/InspectorTraceEvents.h"
11 11
12 namespace blink { 12 namespace blink {
13 13
14 FrameRequestCallbackCollection::FrameRequestCallbackCollection( 14 FrameRequestCallbackCollection::FrameRequestCallbackCollection(
15 ExecutionContext* context) 15 ExecutionContext* context)
16 : m_context(context) {} 16 : m_context(context) {}
17 17
18 FrameRequestCallbackCollection::CallbackId 18 FrameRequestCallbackCollection::CallbackId
19 FrameRequestCallbackCollection::registerCallback( 19 FrameRequestCallbackCollection::registerCallback(
20 FrameRequestCallback* callback) { 20 FrameRequestCallback* callback) {
21 FrameRequestCallbackCollection::CallbackId id = ++m_nextCallbackId; 21 FrameRequestCallbackCollection::CallbackId id = ++m_nextCallbackId;
22 callback->m_cancelled = false; 22 callback->m_cancelled = false;
23 callback->m_id = id; 23 callback->m_id = id;
24 m_callbacks.push_back(callback); 24 m_callbacks.push_back(callback);
25 25
26 TRACE_EVENT_INSTANT1("devtools.timeline", "RequestAnimationFrame", 26 TRACE_EVENT_INSTANT1("devtools.timeline", "RequestAnimationFrame",
27 TRACE_EVENT_SCOPE_THREAD, "data", 27 TRACE_EVENT_SCOPE_THREAD, "data",
28 InspectorAnimationFrameEvent::data(m_context, id)); 28 InspectorAnimationFrameEvent::data(m_context, id));
29 InspectorInstrumentation::asyncTaskScheduled( 29 InspectorInstrumentation::asyncTaskScheduledBreakable(
30 m_context, "requestAnimationFrame", callback); 30 m_context, "requestAnimationFrame", callback);
31 InspectorInstrumentation::NativeBreakpoint nativeBreakpoint(
32 m_context, "DOMWindow.requestAnimationFrame", true);
33 return id; 31 return id;
34 } 32 }
35 33
36 void FrameRequestCallbackCollection::cancelCallback(CallbackId id) { 34 void FrameRequestCallbackCollection::cancelCallback(CallbackId id) {
37 for (size_t i = 0; i < m_callbacks.size(); ++i) { 35 for (size_t i = 0; i < m_callbacks.size(); ++i) {
38 if (m_callbacks[i]->m_id == id) { 36 if (m_callbacks[i]->m_id == id) {
39 InspectorInstrumentation::asyncTaskCanceled(m_context, m_callbacks[i]); 37 InspectorInstrumentation::asyncTaskCanceledBreakable(
40 InspectorInstrumentation::NativeBreakpoint nativeBreakpoint( 38 m_context, "cancelAnimationFrame", m_callbacks[i]);
41 m_context, "DOMWindow.cancelAnimationFrame", true);
42 m_callbacks.remove(i); 39 m_callbacks.remove(i);
43 TRACE_EVENT_INSTANT1("devtools.timeline", "CancelAnimationFrame", 40 TRACE_EVENT_INSTANT1("devtools.timeline", "CancelAnimationFrame",
44 TRACE_EVENT_SCOPE_THREAD, "data", 41 TRACE_EVENT_SCOPE_THREAD, "data",
45 InspectorAnimationFrameEvent::data(m_context, id)); 42 InspectorAnimationFrameEvent::data(m_context, id));
46 return; 43 return;
47 } 44 }
48 } 45 }
49 for (const auto& callback : m_callbacksToInvoke) { 46 for (const auto& callback : m_callbacksToInvoke) {
50 if (callback->m_id == id) { 47 if (callback->m_id == id) {
51 InspectorInstrumentation::asyncTaskCanceled(m_context, callback); 48 InspectorInstrumentation::asyncTaskCanceledBreakable(
52 InspectorInstrumentation::NativeBreakpoint nativeBreakpoint( 49 m_context, "cancelAnimationFrame", callback);
53 m_context, "DOMWindow.cancelAnimationFrame", true);
54 TRACE_EVENT_INSTANT1("devtools.timeline", "CancelAnimationFrame", 50 TRACE_EVENT_INSTANT1("devtools.timeline", "CancelAnimationFrame",
55 TRACE_EVENT_SCOPE_THREAD, "data", 51 TRACE_EVENT_SCOPE_THREAD, "data",
56 InspectorAnimationFrameEvent::data(m_context, id)); 52 InspectorAnimationFrameEvent::data(m_context, id));
57 callback->m_cancelled = true; 53 callback->m_cancelled = true;
58 // will be removed at the end of executeCallbacks() 54 // will be removed at the end of executeCallbacks()
59 return; 55 return;
60 } 56 }
61 } 57 }
62 } 58 }
63 59
64 void FrameRequestCallbackCollection::executeCallbacks( 60 void FrameRequestCallbackCollection::executeCallbacks(
65 double highResNowMs, 61 double highResNowMs,
66 double highResNowMsLegacy) { 62 double highResNowMsLegacy) {
67 // First, generate a list of callbacks to consider. Callbacks registered from 63 // First, generate a list of callbacks to consider. Callbacks registered from
68 // this point on are considered only for the "next" frame, not this one. 64 // this point on are considered only for the "next" frame, not this one.
69 DCHECK(m_callbacksToInvoke.isEmpty()); 65 DCHECK(m_callbacksToInvoke.isEmpty());
70 m_callbacksToInvoke.swap(m_callbacks); 66 m_callbacksToInvoke.swap(m_callbacks);
71 67
72 for (const auto& callback : m_callbacksToInvoke) { 68 for (const auto& callback : m_callbacksToInvoke) {
73 if (!callback->m_cancelled) { 69 if (!callback->m_cancelled) {
74 TRACE_EVENT1( 70 TRACE_EVENT1(
75 "devtools.timeline", "FireAnimationFrame", "data", 71 "devtools.timeline", "FireAnimationFrame", "data",
76 InspectorAnimationFrameEvent::data(m_context, callback->m_id)); 72 InspectorAnimationFrameEvent::data(m_context, callback->m_id));
77 InspectorInstrumentation::NativeBreakpoint nativeBreakpoint( 73 InspectorInstrumentation::AsyncTask asyncTask(
78 m_context, "DOMWindow.requestAnimationFrame.callback", false); 74 m_context, callback, "requestAnimationFrame.callback");
79 InspectorInstrumentation::AsyncTask asyncTask(m_context, callback);
80 PerformanceMonitor::HandlerCall handlerCall( 75 PerformanceMonitor::HandlerCall handlerCall(
81 m_context, "requestAnimationFrame", true); 76 m_context, "requestAnimationFrame", true);
82 if (callback->m_useLegacyTimeBase) 77 if (callback->m_useLegacyTimeBase)
83 callback->handleEvent(highResNowMsLegacy); 78 callback->handleEvent(highResNowMsLegacy);
84 else 79 else
85 callback->handleEvent(highResNowMs); 80 callback->handleEvent(highResNowMs);
86 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), 81 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"),
87 "UpdateCounters", TRACE_EVENT_SCOPE_THREAD, "data", 82 "UpdateCounters", TRACE_EVENT_SCOPE_THREAD, "data",
88 InspectorUpdateCountersEvent::data()); 83 InspectorUpdateCountersEvent::data());
89 } 84 }
90 } 85 }
91 86
92 m_callbacksToInvoke.clear(); 87 m_callbacksToInvoke.clear();
93 } 88 }
94 89
95 DEFINE_TRACE(FrameRequestCallbackCollection) { 90 DEFINE_TRACE(FrameRequestCallbackCollection) {
96 visitor->trace(m_callbacks); 91 visitor->trace(m_callbacks);
97 visitor->trace(m_callbacksToInvoke); 92 visitor->trace(m_callbacksToInvoke);
98 visitor->trace(m_context); 93 visitor->trace(m_context);
99 } 94 }
100 95
101 } // namespace blink 96 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/Element.cpp ('k') | third_party/WebKit/Source/core/frame/DOMTimer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698