OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/dom/custom/CustomElementMicrotaskRunQueue.h" | 5 #include "core/dom/custom/CustomElementMicrotaskRunQueue.h" |
6 | 6 |
7 #include "bindings/core/v8/Microtask.h" | 7 #include "bindings/core/v8/Microtask.h" |
8 #include "core/dom/custom/CustomElementAsyncImportMicrotaskQueue.h" | 8 #include "core/dom/custom/CustomElementAsyncImportMicrotaskQueue.h" |
9 #include "core/dom/custom/CustomElementSyncMicrotaskQueue.h" | 9 #include "core/dom/custom/CustomElementSyncMicrotaskQueue.h" |
10 #include "core/html/imports/HTMLImportLoader.h" | 10 #include "core/html/imports/HTMLImportLoader.h" |
11 | 11 |
12 namespace blink { | 12 namespace blink { |
13 | 13 |
14 CustomElementMicrotaskRunQueue::CustomElementMicrotaskRunQueue() | 14 CustomElementMicrotaskRunQueue::CustomElementMicrotaskRunQueue() |
15 : m_syncQueue(CustomElementSyncMicrotaskQueue::create()) | 15 : m_syncQueue(CustomElementSyncMicrotaskQueue::create()) |
16 , m_asyncQueue(CustomElementAsyncImportMicrotaskQueue::create()) | 16 , m_asyncQueue(CustomElementAsyncImportMicrotaskQueue::create()) |
17 , m_dispatchIsPending(false) | 17 , m_dispatchIsPending(false) |
18 #if !ENABLE(OILPAN) | |
19 , m_weakFactory(this) | |
20 #endif | |
21 { | 18 { |
22 } | 19 } |
23 | 20 |
24 void CustomElementMicrotaskRunQueue::enqueue(HTMLImportLoader* parentLoader, Cus
tomElementMicrotaskStep* step, bool importIsSync) | 21 void CustomElementMicrotaskRunQueue::enqueue(HTMLImportLoader* parentLoader, Cus
tomElementMicrotaskStep* step, bool importIsSync) |
25 { | 22 { |
26 if (importIsSync) { | 23 if (importIsSync) { |
27 if (parentLoader) | 24 if (parentLoader) |
28 parentLoader->microtaskQueue()->enqueue(step); | 25 parentLoader->microtaskQueue()->enqueue(step); |
29 else | 26 else |
30 m_syncQueue->enqueue(step); | 27 m_syncQueue->enqueue(step); |
31 } else { | 28 } else { |
32 m_asyncQueue->enqueue(step); | 29 m_asyncQueue->enqueue(step); |
33 } | 30 } |
34 | 31 |
35 requestDispatchIfNeeded(); | 32 requestDispatchIfNeeded(); |
36 } | 33 } |
37 | 34 |
38 void CustomElementMicrotaskRunQueue::requestDispatchIfNeeded() | 35 void CustomElementMicrotaskRunQueue::requestDispatchIfNeeded() |
39 { | 36 { |
40 if (m_dispatchIsPending || isEmpty()) | 37 if (m_dispatchIsPending || isEmpty()) |
41 return; | 38 return; |
42 #if ENABLE(OILPAN) | |
43 Microtask::enqueueMicrotask(WTF::bind(&CustomElementMicrotaskRunQueue::dispa
tch, WeakPersistentThisPointer<CustomElementMicrotaskRunQueue>(this))); | 39 Microtask::enqueueMicrotask(WTF::bind(&CustomElementMicrotaskRunQueue::dispa
tch, WeakPersistentThisPointer<CustomElementMicrotaskRunQueue>(this))); |
44 #else | |
45 Microtask::enqueueMicrotask(WTF::bind(&CustomElementMicrotaskRunQueue::dispa
tch, m_weakFactory.createWeakPtr())); | |
46 #endif | |
47 m_dispatchIsPending = true; | 40 m_dispatchIsPending = true; |
48 } | 41 } |
49 | 42 |
50 DEFINE_TRACE(CustomElementMicrotaskRunQueue) | 43 DEFINE_TRACE(CustomElementMicrotaskRunQueue) |
51 { | 44 { |
52 visitor->trace(m_syncQueue); | 45 visitor->trace(m_syncQueue); |
53 visitor->trace(m_asyncQueue); | 46 visitor->trace(m_asyncQueue); |
54 } | 47 } |
55 | 48 |
56 void CustomElementMicrotaskRunQueue::dispatch() | 49 void CustomElementMicrotaskRunQueue::dispatch() |
57 { | 50 { |
58 m_dispatchIsPending = false; | 51 m_dispatchIsPending = false; |
59 m_syncQueue->dispatch(); | 52 m_syncQueue->dispatch(); |
60 if (m_syncQueue->isEmpty()) | 53 if (m_syncQueue->isEmpty()) |
61 m_asyncQueue->dispatch(); | 54 m_asyncQueue->dispatch(); |
62 } | 55 } |
63 | 56 |
64 bool CustomElementMicrotaskRunQueue::isEmpty() const | 57 bool CustomElementMicrotaskRunQueue::isEmpty() const |
65 { | 58 { |
66 return m_syncQueue->isEmpty() && m_asyncQueue->isEmpty(); | 59 return m_syncQueue->isEmpty() && m_asyncQueue->isEmpty(); |
67 } | 60 } |
68 | 61 |
69 } // namespace blink | 62 } // namespace blink |
OLD | NEW |