| OLD | NEW |
| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 bool GenericEventQueue::enqueueEvent(Event* event) { | 51 bool GenericEventQueue::enqueueEvent(Event* event) { |
| 52 if (m_isClosed) | 52 if (m_isClosed) |
| 53 return false; | 53 return false; |
| 54 | 54 |
| 55 if (event->target() == m_owner) | 55 if (event->target() == m_owner) |
| 56 event->setTarget(nullptr); | 56 event->setTarget(nullptr); |
| 57 | 57 |
| 58 TRACE_EVENT_ASYNC_BEGIN1("event", "GenericEventQueue:enqueueEvent", event, | 58 TRACE_EVENT_ASYNC_BEGIN1("event", "GenericEventQueue:enqueueEvent", event, |
| 59 "type", event->type().ascii()); | 59 "type", event->type().ascii()); |
| 60 EventTarget* target = event->target() ? event->target() : m_owner.get(); | 60 EventTarget* target = event->target() ? event->target() : m_owner.get(); |
| 61 InspectorInstrumentation::asyncTaskScheduled(target->getExecutionContext(), | 61 probe::asyncTaskScheduled(target->getExecutionContext(), event->type(), |
| 62 event->type(), event); | 62 event); |
| 63 m_pendingEvents.push_back(event); | 63 m_pendingEvents.push_back(event); |
| 64 | 64 |
| 65 if (!m_timer.isActive()) | 65 if (!m_timer.isActive()) |
| 66 m_timer.startOneShot(0, BLINK_FROM_HERE); | 66 m_timer.startOneShot(0, BLINK_FROM_HERE); |
| 67 | 67 |
| 68 return true; | 68 return true; |
| 69 } | 69 } |
| 70 | 70 |
| 71 bool GenericEventQueue::cancelEvent(Event* event) { | 71 bool GenericEventQueue::cancelEvent(Event* event) { |
| 72 bool found = m_pendingEvents.contains(event); | 72 bool found = m_pendingEvents.contains(event); |
| 73 | 73 |
| 74 if (found) { | 74 if (found) { |
| 75 EventTarget* target = event->target() ? event->target() : m_owner.get(); | 75 EventTarget* target = event->target() ? event->target() : m_owner.get(); |
| 76 InspectorInstrumentation::asyncTaskCanceled(target->getExecutionContext(), | 76 probe::asyncTaskCanceled(target->getExecutionContext(), event); |
| 77 event); | |
| 78 m_pendingEvents.remove(m_pendingEvents.find(event)); | 77 m_pendingEvents.remove(m_pendingEvents.find(event)); |
| 79 TRACE_EVENT_ASYNC_END2("event", "GenericEventQueue:enqueueEvent", event, | 78 TRACE_EVENT_ASYNC_END2("event", "GenericEventQueue:enqueueEvent", event, |
| 80 "type", event->type().ascii(), "status", | 79 "type", event->type().ascii(), "status", |
| 81 "cancelled"); | 80 "cancelled"); |
| 82 } | 81 } |
| 83 | 82 |
| 84 if (m_pendingEvents.isEmpty()) | 83 if (m_pendingEvents.isEmpty()) |
| 85 m_timer.stop(); | 84 m_timer.stop(); |
| 86 | 85 |
| 87 return found; | 86 return found; |
| 88 } | 87 } |
| 89 | 88 |
| 90 void GenericEventQueue::timerFired(TimerBase*) { | 89 void GenericEventQueue::timerFired(TimerBase*) { |
| 91 DCHECK(!m_timer.isActive()); | 90 DCHECK(!m_timer.isActive()); |
| 92 DCHECK(!m_pendingEvents.isEmpty()); | 91 DCHECK(!m_pendingEvents.isEmpty()); |
| 93 | 92 |
| 94 HeapVector<Member<Event>> pendingEvents; | 93 HeapVector<Member<Event>> pendingEvents; |
| 95 m_pendingEvents.swap(pendingEvents); | 94 m_pendingEvents.swap(pendingEvents); |
| 96 | 95 |
| 97 for (const auto& pendingEvent : pendingEvents) { | 96 for (const auto& pendingEvent : pendingEvents) { |
| 98 Event* event = pendingEvent.get(); | 97 Event* event = pendingEvent.get(); |
| 99 EventTarget* target = event->target() ? event->target() : m_owner.get(); | 98 EventTarget* target = event->target() ? event->target() : m_owner.get(); |
| 100 CString type(event->type().ascii()); | 99 CString type(event->type().ascii()); |
| 101 InspectorInstrumentation::AsyncTask asyncTask(target->getExecutionContext(), | 100 probe::AsyncTask asyncTask(target->getExecutionContext(), event); |
| 102 event); | |
| 103 TRACE_EVENT_ASYNC_STEP_INTO1("event", "GenericEventQueue:enqueueEvent", | 101 TRACE_EVENT_ASYNC_STEP_INTO1("event", "GenericEventQueue:enqueueEvent", |
| 104 event, "dispatch", "type", type); | 102 event, "dispatch", "type", type); |
| 105 target->dispatchEvent(pendingEvent); | 103 target->dispatchEvent(pendingEvent); |
| 106 TRACE_EVENT_ASYNC_END1("event", "GenericEventQueue:enqueueEvent", event, | 104 TRACE_EVENT_ASYNC_END1("event", "GenericEventQueue:enqueueEvent", event, |
| 107 "type", type); | 105 "type", type); |
| 108 } | 106 } |
| 109 } | 107 } |
| 110 | 108 |
| 111 void GenericEventQueue::close() { | 109 void GenericEventQueue::close() { |
| 112 m_isClosed = true; | 110 m_isClosed = true; |
| 113 cancelAllEvents(); | 111 cancelAllEvents(); |
| 114 } | 112 } |
| 115 | 113 |
| 116 void GenericEventQueue::cancelAllEvents() { | 114 void GenericEventQueue::cancelAllEvents() { |
| 117 m_timer.stop(); | 115 m_timer.stop(); |
| 118 | 116 |
| 119 for (const auto& pendingEvent : m_pendingEvents) { | 117 for (const auto& pendingEvent : m_pendingEvents) { |
| 120 Event* event = pendingEvent.get(); | 118 Event* event = pendingEvent.get(); |
| 121 TRACE_EVENT_ASYNC_END2("event", "GenericEventQueue:enqueueEvent", event, | 119 TRACE_EVENT_ASYNC_END2("event", "GenericEventQueue:enqueueEvent", event, |
| 122 "type", event->type().ascii(), "status", | 120 "type", event->type().ascii(), "status", |
| 123 "cancelled"); | 121 "cancelled"); |
| 124 EventTarget* target = event->target() ? event->target() : m_owner.get(); | 122 EventTarget* target = event->target() ? event->target() : m_owner.get(); |
| 125 InspectorInstrumentation::asyncTaskCanceled(target->getExecutionContext(), | 123 probe::asyncTaskCanceled(target->getExecutionContext(), event); |
| 126 event); | |
| 127 } | 124 } |
| 128 m_pendingEvents.clear(); | 125 m_pendingEvents.clear(); |
| 129 } | 126 } |
| 130 | 127 |
| 131 bool GenericEventQueue::hasPendingEvents() const { | 128 bool GenericEventQueue::hasPendingEvents() const { |
| 132 return m_pendingEvents.size(); | 129 return m_pendingEvents.size(); |
| 133 } | 130 } |
| 134 | 131 |
| 135 } // namespace blink | 132 } // namespace blink |
| OLD | NEW |