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

Side by Side Diff: third_party/WebKit/Source/core/events/DOMWindowEventQueue.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) 2010 Google Inc. All Rights Reserved. 2 * Copyright (C) 2010 Google 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 visitor->trace(m_queuedEvents); 80 visitor->trace(m_queuedEvents);
81 EventQueue::trace(visitor); 81 EventQueue::trace(visitor);
82 } 82 }
83 83
84 bool DOMWindowEventQueue::enqueueEvent(Event* event) 84 bool DOMWindowEventQueue::enqueueEvent(Event* event)
85 { 85 {
86 if (m_isClosed) 86 if (m_isClosed)
87 return false; 87 return false;
88 88
89 ASSERT(event->target()); 89 ASSERT(event->target());
90 InspectorInstrumentation::didEnqueueEvent(event->target(), event); 90 InspectorInstrumentation::asyncTaskScheduled(event->target()->getExecutionCo ntext(), event->type(), event);
91 91
92 bool wasAdded = m_queuedEvents.add(event).isNewEntry; 92 bool wasAdded = m_queuedEvents.add(event).isNewEntry;
93 ASSERT_UNUSED(wasAdded, wasAdded); // It should not have already been in the list. 93 ASSERT_UNUSED(wasAdded, wasAdded); // It should not have already been in the list.
94 94
95 if (!m_pendingEventTimer->isActive()) 95 if (!m_pendingEventTimer->isActive())
96 m_pendingEventTimer->startOneShot(0, BLINK_FROM_HERE); 96 m_pendingEventTimer->startOneShot(0, BLINK_FROM_HERE);
97 97
98 return true; 98 return true;
99 } 99 }
100 100
101 bool DOMWindowEventQueue::cancelEvent(Event* event) 101 bool DOMWindowEventQueue::cancelEvent(Event* event)
102 { 102 {
103 HeapListHashSet<Member<Event>, 16>::iterator it = m_queuedEvents.find(event) ; 103 HeapListHashSet<Member<Event>, 16>::iterator it = m_queuedEvents.find(event) ;
104 bool found = it != m_queuedEvents.end(); 104 bool found = it != m_queuedEvents.end();
105 if (found) { 105 if (found) {
106 InspectorInstrumentation::didRemoveEvent(event->target(), event); 106 InspectorInstrumentation::asyncTaskCanceled(event->target()->getExecutio nContext(), event);
107 m_queuedEvents.remove(it); 107 m_queuedEvents.remove(it);
108 } 108 }
109 if (m_queuedEvents.isEmpty()) 109 if (m_queuedEvents.isEmpty())
110 m_pendingEventTimer->stop(); 110 m_pendingEventTimer->stop();
111 return found; 111 return found;
112 } 112 }
113 113
114 void DOMWindowEventQueue::close() 114 void DOMWindowEventQueue::close()
115 { 115 {
116 m_isClosed = true; 116 m_isClosed = true;
117 m_pendingEventTimer->stop(); 117 m_pendingEventTimer->stop();
118 if (InspectorInstrumentation::hasFrontends()) { 118 if (InspectorInstrumentation::hasFrontends()) {
119 for (const auto& queuedEvent : m_queuedEvents) { 119 for (const auto& queuedEvent : m_queuedEvents) {
120 Event* event = queuedEvent; 120 if (queuedEvent)
121 if (event) 121 InspectorInstrumentation::asyncTaskCanceled(queuedEvent->target( )->getExecutionContext(), queuedEvent);
122 InspectorInstrumentation::didRemoveEvent(event->target(), event) ;
123 } 122 }
124 } 123 }
125 m_queuedEvents.clear(); 124 m_queuedEvents.clear();
126 } 125 }
127 126
128 void DOMWindowEventQueue::pendingEventTimerFired() 127 void DOMWindowEventQueue::pendingEventTimerFired()
129 { 128 {
130 ASSERT(!m_pendingEventTimer->isActive()); 129 ASSERT(!m_pendingEventTimer->isActive());
131 ASSERT(!m_queuedEvents.isEmpty()); 130 ASSERT(!m_queuedEvents.isEmpty());
132 131
133 // Insert a marker for where we should stop. 132 // Insert a marker for where we should stop.
134 ASSERT(!m_queuedEvents.contains(nullptr)); 133 ASSERT(!m_queuedEvents.contains(nullptr));
135 bool wasAdded = m_queuedEvents.add(nullptr).isNewEntry; 134 bool wasAdded = m_queuedEvents.add(nullptr).isNewEntry;
136 ASSERT_UNUSED(wasAdded, wasAdded); // It should not have already been in the list. 135 ASSERT_UNUSED(wasAdded, wasAdded); // It should not have already been in the list.
137 136
138 while (!m_queuedEvents.isEmpty()) { 137 while (!m_queuedEvents.isEmpty()) {
139 HeapListHashSet<Member<Event>, 16>::iterator iter = m_queuedEvents.begin (); 138 HeapListHashSet<Member<Event>, 16>::iterator iter = m_queuedEvents.begin ();
140 Event* event = *iter; 139 Event* event = *iter;
141 m_queuedEvents.remove(iter); 140 m_queuedEvents.remove(iter);
142 if (!event) 141 if (!event)
143 break; 142 break;
144 dispatchEvent(event); 143 dispatchEvent(event);
145 InspectorInstrumentation::didRemoveEvent(event->target(), event);
146 } 144 }
147 } 145 }
148 146
149 void DOMWindowEventQueue::dispatchEvent(Event* event) 147 void DOMWindowEventQueue::dispatchEvent(Event* event)
150 { 148 {
151 EventTarget* eventTarget = event->target(); 149 EventTarget* eventTarget = event->target();
150 InspectorInstrumentation::AsyncTask asyncTask(eventTarget->getExecutionConte xt(), event);
152 if (eventTarget->toDOMWindow()) 151 if (eventTarget->toDOMWindow())
153 eventTarget->toDOMWindow()->dispatchEvent(event, nullptr); 152 eventTarget->toDOMWindow()->dispatchEvent(event, nullptr);
154 else 153 else
155 eventTarget->dispatchEvent(event); 154 eventTarget->dispatchEvent(event);
156 } 155 }
157 156
158 } // namespace blink 157 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698