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

Side by Side Diff: third_party/WebKit/Source/core/events/GenericEventQueue.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) 2012 Victor Carbune (victor@rosedu.org) 2 * Copyright (C) 2012 Victor Carbune (victor@rosedu.org)
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 56
57 bool GenericEventQueue::enqueueEvent(Event* event) 57 bool GenericEventQueue::enqueueEvent(Event* event)
58 { 58 {
59 if (m_isClosed) 59 if (m_isClosed)
60 return false; 60 return false;
61 61
62 if (event->target() == m_owner) 62 if (event->target() == m_owner)
63 event->setTarget(nullptr); 63 event->setTarget(nullptr);
64 64
65 TRACE_EVENT_ASYNC_BEGIN1("event", "GenericEventQueue:enqueueEvent", event, " type", event->type().ascii()); 65 TRACE_EVENT_ASYNC_BEGIN1("event", "GenericEventQueue:enqueueEvent", event, " type", event->type().ascii());
66 InspectorInstrumentation::didEnqueueEvent(event->target() ? event->target() : m_owner.get(), event); 66 InspectorInstrumentation::scheduleAsyncTask(event->target()->getExecutionCon text(), "Generic event", event);
67 m_pendingEvents.append(event); 67 m_pendingEvents.append(event);
68 68
69 if (!m_timer.isActive()) 69 if (!m_timer.isActive())
70 m_timer.startOneShot(0, BLINK_FROM_HERE); 70 m_timer.startOneShot(0, BLINK_FROM_HERE);
71 71
72 return true; 72 return true;
73 } 73 }
74 74
75 bool GenericEventQueue::cancelEvent(Event* event) 75 bool GenericEventQueue::cancelEvent(Event* event)
76 { 76 {
77 bool found = m_pendingEvents.contains(event); 77 bool found = m_pendingEvents.contains(event);
78 78
79 if (found) { 79 if (found) {
80 InspectorInstrumentation::didRemoveEvent(event->target() ? event->target () : m_owner.get(), event); 80 InspectorInstrumentation::cancelAsyncTask(event->target()->getExecutionC ontext(), event);
81 m_pendingEvents.remove(m_pendingEvents.find(event)); 81 m_pendingEvents.remove(m_pendingEvents.find(event));
82 TRACE_EVENT_ASYNC_END2("event", "GenericEventQueue:enqueueEvent", event, "type", event->type().ascii(), "status", "cancelled"); 82 TRACE_EVENT_ASYNC_END2("event", "GenericEventQueue:enqueueEvent", event, "type", event->type().ascii(), "status", "cancelled");
83 } 83 }
84 84
85 if (m_pendingEvents.isEmpty()) 85 if (m_pendingEvents.isEmpty())
86 m_timer.stop(); 86 m_timer.stop();
87 87
88 return found; 88 return found;
89 } 89 }
90 90
91 void GenericEventQueue::timerFired(Timer<GenericEventQueue>*) 91 void GenericEventQueue::timerFired(Timer<GenericEventQueue>*)
92 { 92 {
93 ASSERT(!m_timer.isActive()); 93 ASSERT(!m_timer.isActive());
94 ASSERT(!m_pendingEvents.isEmpty()); 94 ASSERT(!m_pendingEvents.isEmpty());
95 95
96 HeapVector<Member<Event>> pendingEvents; 96 HeapVector<Member<Event>> pendingEvents;
97 m_pendingEvents.swap(pendingEvents); 97 m_pendingEvents.swap(pendingEvents);
98 98
99 for (const auto& pendingEvent : pendingEvents) { 99 for (const auto& pendingEvent : pendingEvents) {
100 Event* event = pendingEvent.get(); 100 Event* event = pendingEvent.get();
101 EventTarget* target = event->target() ? event->target() : m_owner.get(); 101 EventTarget* target = event->target() ? event->target() : m_owner.get();
102 CString type(event->type().ascii()); 102 CString type(event->type().ascii());
103 InspectorInstrumentation::AsyncTask asyncTask(target->getExecutionContex t(), event);
103 TRACE_EVENT_ASYNC_STEP_INTO1("event", "GenericEventQueue:enqueueEvent", event, "dispatch", "type", type); 104 TRACE_EVENT_ASYNC_STEP_INTO1("event", "GenericEventQueue:enqueueEvent", event, "dispatch", "type", type);
104 target->dispatchEvent(pendingEvent); 105 target->dispatchEvent(pendingEvent);
105 TRACE_EVENT_ASYNC_END1("event", "GenericEventQueue:enqueueEvent", event, "type", type); 106 TRACE_EVENT_ASYNC_END1("event", "GenericEventQueue:enqueueEvent", event, "type", type);
106 InspectorInstrumentation::didRemoveEvent(target, event);
107 } 107 }
108 } 108 }
109 109
110 void GenericEventQueue::close() 110 void GenericEventQueue::close()
111 { 111 {
112 m_isClosed = true; 112 m_isClosed = true;
113 cancelAllEvents(); 113 cancelAllEvents();
114 } 114 }
115 115
116 void GenericEventQueue::cancelAllEvents() 116 void GenericEventQueue::cancelAllEvents()
117 { 117 {
118 m_timer.stop(); 118 m_timer.stop();
119 119
120 for (const auto& pendingEvent : m_pendingEvents) { 120 for (const auto& pendingEvent : m_pendingEvents) {
121 Event* event = pendingEvent.get(); 121 Event* event = pendingEvent.get();
122 TRACE_EVENT_ASYNC_END2("event", "GenericEventQueue:enqueueEvent", event, "type", event->type().ascii(), "status", "cancelled"); 122 TRACE_EVENT_ASYNC_END2("event", "GenericEventQueue:enqueueEvent", event, "type", event->type().ascii(), "status", "cancelled");
123 InspectorInstrumentation::didRemoveEvent(event->target() ? event->target () : m_owner.get(), event); 123 InspectorInstrumentation::cancelAsyncTask(event->target()->getExecutionC ontext(), event);
124 } 124 }
125 m_pendingEvents.clear(); 125 m_pendingEvents.clear();
126 } 126 }
127 127
128 bool GenericEventQueue::hasPendingEvents() const 128 bool GenericEventQueue::hasPendingEvents() const
129 { 129 {
130 return m_pendingEvents.size(); 130 return m_pendingEvents.size();
131 } 131 }
132 132
133 } // namespace blink 133 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698