| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "sky/engine/config.h" | |
| 6 #include "sky/engine/core/dom/custom/CustomElementMicrotaskDispatcher.h" | |
| 7 | |
| 8 #include "base/bind.h" | |
| 9 #include "sky/engine/core/dom/Microtask.h" | |
| 10 #include "sky/engine/core/dom/custom/CustomElementCallbackQueue.h" | |
| 11 #include "sky/engine/core/dom/custom/CustomElementMicrotaskImportStep.h" | |
| 12 #include "sky/engine/core/dom/custom/CustomElementProcessingStack.h" | |
| 13 #include "sky/engine/core/dom/custom/CustomElementScheduler.h" | |
| 14 #include "sky/engine/wtf/MainThread.h" | |
| 15 | |
| 16 namespace blink { | |
| 17 | |
| 18 static const CustomElementCallbackQueue::ElementQueueId kMicrotaskQueueId = 0; | |
| 19 | |
| 20 CustomElementMicrotaskDispatcher::CustomElementMicrotaskDispatcher() | |
| 21 : m_hasScheduledMicrotask(false) | |
| 22 , m_phase(Quiescent) | |
| 23 { | |
| 24 } | |
| 25 | |
| 26 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(CustomElementMicrotaskDispatcher) | |
| 27 | |
| 28 CustomElementMicrotaskDispatcher& CustomElementMicrotaskDispatcher::instance() | |
| 29 { | |
| 30 DEFINE_STATIC_LOCAL(OwnPtr<CustomElementMicrotaskDispatcher>, instance, (ado
ptPtr(new CustomElementMicrotaskDispatcher()))); | |
| 31 return *instance; | |
| 32 } | |
| 33 | |
| 34 void CustomElementMicrotaskDispatcher::enqueue(CustomElementCallbackQueue* queue
) | |
| 35 { | |
| 36 ensureMicrotaskScheduledForElementQueue(); | |
| 37 queue->setOwner(kMicrotaskQueueId); | |
| 38 m_elements.append(queue); | |
| 39 } | |
| 40 | |
| 41 void CustomElementMicrotaskDispatcher::ensureMicrotaskScheduledForElementQueue() | |
| 42 { | |
| 43 ASSERT(m_phase == Quiescent || m_phase == Resolving); | |
| 44 ensureMicrotaskScheduled(); | |
| 45 } | |
| 46 | |
| 47 void CustomElementMicrotaskDispatcher::ensureMicrotaskScheduled() | |
| 48 { | |
| 49 if (!m_hasScheduledMicrotask) { | |
| 50 Microtask::enqueueMicrotask(base::Bind(&dispatch)); | |
| 51 m_hasScheduledMicrotask = true; | |
| 52 } | |
| 53 } | |
| 54 | |
| 55 void CustomElementMicrotaskDispatcher::dispatch() | |
| 56 { | |
| 57 instance().doDispatch(); | |
| 58 } | |
| 59 | |
| 60 void CustomElementMicrotaskDispatcher::doDispatch() | |
| 61 { | |
| 62 ASSERT(isMainThread()); | |
| 63 | |
| 64 ASSERT(m_phase == Quiescent && m_hasScheduledMicrotask); | |
| 65 m_hasScheduledMicrotask = false; | |
| 66 | |
| 67 // Finishing microtask work deletes all | |
| 68 // CustomElementCallbackQueues. Being in a callback delivery scope | |
| 69 // implies those queues could still be in use. | |
| 70 ASSERT_WITH_SECURITY_IMPLICATION(!CustomElementProcessingStack::inCallbackDe
liveryScope()); | |
| 71 | |
| 72 m_phase = Resolving; | |
| 73 | |
| 74 m_phase = DispatchingCallbacks; | |
| 75 for (Vector<RawPtr<CustomElementCallbackQueue> >::iterator it = m_elements.b
egin(); it != m_elements.end(); ++it) { | |
| 76 // Created callback may enqueue an attached callback. | |
| 77 CustomElementProcessingStack::CallbackDeliveryScope scope; | |
| 78 (*it)->processInElementQueue(kMicrotaskQueueId); | |
| 79 } | |
| 80 | |
| 81 m_elements.clear(); | |
| 82 CustomElementScheduler::microtaskDispatcherDidFinish(); | |
| 83 m_phase = Quiescent; | |
| 84 } | |
| 85 | |
| 86 } // namespace blink | |
| OLD | NEW |