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 #ifndef CustomElementMicrotaskDispatcher_h 6 #define CustomElementMicrotaskDispatcher_h 7 8 #include "platform/heap/Handle.h" 9 #include "wtf/Noncopyable.h" 10 #include "wtf/PassOwnPtr.h" 11 #include "wtf/Vector.h" 12 13 namespace WebCore { 14 15 class CustomElementCallbackQueue; 16 class CustomElementMicrotaskImportStep; 17 class CustomElementMicrotaskStep; 18 class CustomElementMicrotaskStepDispatcher; 19 class HTMLImportLoader; 20 21 class CustomElementMicrotaskDispatcher FINAL : public NoBaseWillBeGarbageCollected<CustomElementMicrotaskDispatcher> { 22 WTF_MAKE_NONCOPYABLE(CustomElementMicrotaskDispatcher); 23 DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(CustomElementMicrotaskDispatcher); 24 public: 25 static CustomElementMicrotaskDispatcher& instance(); 26 27 void enqueue(HTMLImportLoader* parentLoader, PassOwnPtrWillBeRawPtr<CustomElementMicrotaskStep>); 28 void enqueue(HTMLImportLoader* parentLoader, PassOwnPtrWillBeRawPtr<CustomElementMicrotaskImportStep>, bool importIsSync); 29 30 void enqueue(CustomElementCallbackQueue*); 31 32 33 void importDidFinish(CustomElementMicrotaskImportStep*); 34 35 bool elementQueueIsEmpty() { return m_elements.isEmpty(); } 36 37 void trace(Visitor*); 38 39 #if !defined(NDEBUG) 40 void show(); 41 #endif 42 43 private: 44 CustomElementMicrotaskDispatcher(); 45 46 void ensureMicrotaskScheduledForElementQueue(); 47 void ensureMicrotaskScheduledForMicrotaskSteps(); 48 void ensureMicrotaskScheduled(); 49 50 static void dispatch(); 51 void doDispatch(); 52 53 bool m_hasScheduledMicrotask; 54 enum { 55 Quiescent, 56 Resolving, 57 DispatchingCallbacks 58 } m_phase; 59 60 RefPtrWillBeMember<CustomElementMicrotaskStepDispatcher> m_steps; 61 WillBeHeapVector<RawPtrWillBeMember<CustomElementCallbackQueue> > m_elements; 62 }; 63 64 } 65 66 #if !defined(NDEBUG) 67 void showCEMD(); 68 #endif 69 70 #endif // CustomElementMicrotaskDispatcher_h 71