| 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/CustomElementMicrotaskRunQueue.h" | |
| 7 | |
| 8 #include "base/bind.h" | |
| 9 #include "sky/engine/core/dom/Microtask.h" | |
| 10 #include "sky/engine/core/dom/custom/CustomElementAsyncImportMicrotaskQueue.h" | |
| 11 #include "sky/engine/core/dom/custom/CustomElementSyncMicrotaskQueue.h" | |
| 12 #include "sky/engine/core/html/imports/HTMLImportLoader.h" | |
| 13 | |
| 14 #include <stdio.h> | |
| 15 | |
| 16 namespace blink { | |
| 17 | |
| 18 CustomElementMicrotaskRunQueue::CustomElementMicrotaskRunQueue() | |
| 19 : m_syncQueue(CustomElementSyncMicrotaskQueue::create()) | |
| 20 , m_asyncQueue(CustomElementAsyncImportMicrotaskQueue::create()) | |
| 21 , m_dispatchIsPending(false) | |
| 22 , m_weakFactory(this) | |
| 23 { | |
| 24 } | |
| 25 | |
| 26 CustomElementMicrotaskRunQueue::~CustomElementMicrotaskRunQueue() | |
| 27 { | |
| 28 } | |
| 29 | |
| 30 void CustomElementMicrotaskRunQueue::enqueue(HTMLImportLoader* parentLoader, Pas
sOwnPtr<CustomElementMicrotaskStep> step, bool importIsSync) | |
| 31 { | |
| 32 if (importIsSync) { | |
| 33 if (parentLoader) | |
| 34 parentLoader->microtaskQueue()->enqueue(step); | |
| 35 else | |
| 36 m_syncQueue->enqueue(step); | |
| 37 } else { | |
| 38 m_asyncQueue->enqueue(step); | |
| 39 } | |
| 40 | |
| 41 requestDispatchIfNeeded(); | |
| 42 } | |
| 43 | |
| 44 void CustomElementMicrotaskRunQueue::requestDispatchIfNeeded() | |
| 45 { | |
| 46 if (m_dispatchIsPending || isEmpty()) | |
| 47 return; | |
| 48 Microtask::enqueueMicrotask(base::Bind(&CustomElementMicrotaskRunQueue::disp
atch, m_weakFactory.GetWeakPtr())); | |
| 49 m_dispatchIsPending = true; | |
| 50 } | |
| 51 | |
| 52 void CustomElementMicrotaskRunQueue::dispatch() | |
| 53 { | |
| 54 m_dispatchIsPending = false; | |
| 55 m_syncQueue->dispatch(); | |
| 56 if (m_syncQueue->isEmpty()) | |
| 57 m_asyncQueue->dispatch(); | |
| 58 } | |
| 59 | |
| 60 bool CustomElementMicrotaskRunQueue::isEmpty() const | |
| 61 { | |
| 62 return m_syncQueue->isEmpty() && m_asyncQueue->isEmpty(); | |
| 63 } | |
| 64 | |
| 65 } // namespace blink | |
| OLD | NEW |