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 "config.h" | 5 #include "config.h" |
6 #include "core/dom/custom/CustomElementMicrotaskDispatcher.h" | 6 #include "core/dom/custom/CustomElementMicrotaskDispatcher.h" |
7 | 7 |
8 #include "core/dom/Microtask.h" | 8 #include "core/dom/Microtask.h" |
9 #include "core/dom/custom/CustomElementAsyncImportMicrotaskQueue.h" | |
10 #include "core/dom/custom/CustomElementCallbackDispatcher.h" | 9 #include "core/dom/custom/CustomElementCallbackDispatcher.h" |
11 #include "core/dom/custom/CustomElementCallbackQueue.h" | 10 #include "core/dom/custom/CustomElementCallbackQueue.h" |
12 #include "core/dom/custom/CustomElementMicrotaskImportStep.h" | 11 #include "core/dom/custom/CustomElementMicrotaskImportStep.h" |
13 #include "core/dom/custom/CustomElementMicrotaskQueue.h" | 12 #include "core/dom/custom/CustomElementPendingMicrotaskSet.h" |
14 #include "core/dom/custom/CustomElementScheduler.h" | 13 #include "core/dom/custom/CustomElementScheduler.h" |
15 #include "core/html/imports/HTMLImportLoader.h" | |
16 #include "wtf/MainThread.h" | 14 #include "wtf/MainThread.h" |
17 | 15 |
18 namespace WebCore { | 16 namespace WebCore { |
19 | 17 |
20 static const CustomElementCallbackQueue::ElementQueueId kMicrotaskQueueId = 0; | 18 static const CustomElementCallbackQueue::ElementQueueId kMicrotaskQueueId = 0; |
21 | 19 |
22 CustomElementMicrotaskDispatcher::CustomElementMicrotaskDispatcher() | 20 CustomElementMicrotaskDispatcher::CustomElementMicrotaskDispatcher() |
23 : m_hasScheduledMicrotask(false) | 21 : m_hasScheduledMicrotask(false) |
24 , m_phase(Quiescent) | 22 , m_phase(Quiescent) |
25 , m_resolutionAndImports(CustomElementMicrotaskQueue::create()) | 23 , m_resolutionAndImports(CustomElementPendingMicrotaskSet::create()) |
26 , m_asyncImports(CustomElementAsyncImportMicrotaskQueue::create()) | |
27 { | 24 { |
28 } | 25 } |
29 | 26 |
30 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(CustomElementMicrotaskDispatcher) | 27 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(CustomElementMicrotaskDispatcher) |
31 | 28 |
32 CustomElementMicrotaskDispatcher& CustomElementMicrotaskDispatcher::instance() | 29 CustomElementMicrotaskDispatcher& CustomElementMicrotaskDispatcher::instance() |
33 { | 30 { |
34 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<CustomElementMicrotaskDispatcher> , instance, (adoptPtrWillBeNoop(new CustomElementMicrotaskDispatcher()))); | 31 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<CustomElementMicrotaskDispatcher> , instance, (adoptPtrWillBeNoop(new CustomElementMicrotaskDispatcher()))); |
35 return *instance; | 32 return *instance; |
36 } | 33 } |
37 | 34 |
38 void CustomElementMicrotaskDispatcher::enqueue(HTMLImportLoader* parentLoader, P assOwnPtrWillBeRawPtr<CustomElementMicrotaskStep> step) | 35 void CustomElementMicrotaskDispatcher::enqueue(HTMLImportLoader* parentLoader, P assOwnPtrWillBeRawPtr<CustomElementMicrotaskStep> step) |
39 { | 36 { |
40 ensureMicrotaskScheduledForMicrotaskSteps(); | 37 ensureMicrotaskScheduledForMicrotaskSteps(); |
41 if (parentLoader) | 38 m_resolutionAndImports->enqueue(parentLoader, step); |
dominicc (has gone to gerrit)
2014/06/18 00:11:27
I guess if it is a set this method should be add a
| |
42 parentLoader->microtaskQueue()->enqueue(step); | |
43 else | |
44 m_resolutionAndImports->enqueue(step); | |
45 } | 39 } |
46 | 40 |
47 void CustomElementMicrotaskDispatcher::enqueue(HTMLImportLoader* parentLoader, P assOwnPtrWillBeRawPtr<CustomElementMicrotaskImportStep> step, bool importIsSync) | 41 void CustomElementMicrotaskDispatcher::enqueue(HTMLImportLoader* parentLoader, P assOwnPtrWillBeRawPtr<CustomElementMicrotaskImportStep> step, bool importIsSync) |
48 { | 42 { |
49 ensureMicrotaskScheduledForMicrotaskSteps(); | 43 ensureMicrotaskScheduledForMicrotaskSteps(); |
50 if (importIsSync) | 44 m_resolutionAndImports->enqueue(parentLoader, step, importIsSync); |
51 enqueue(parentLoader, PassOwnPtrWillBeRawPtr<CustomElementMicrotaskStep> (step)); | |
52 else | |
53 m_asyncImports->enqueue(step); | |
54 } | 45 } |
55 | 46 |
56 void CustomElementMicrotaskDispatcher::enqueue(CustomElementCallbackQueue* queue ) | 47 void CustomElementMicrotaskDispatcher::enqueue(CustomElementCallbackQueue* queue ) |
57 { | 48 { |
58 ensureMicrotaskScheduledForElementQueue(); | 49 ensureMicrotaskScheduledForElementQueue(); |
59 queue->setOwner(kMicrotaskQueueId); | 50 queue->setOwner(kMicrotaskQueueId); |
60 m_elements.append(queue); | 51 m_elements.append(queue); |
61 } | 52 } |
62 | 53 |
63 void CustomElementMicrotaskDispatcher::importDidFinish(CustomElementMicrotaskImp ortStep* step) | 54 void CustomElementMicrotaskDispatcher::importDidFinish(CustomElementMicrotaskImp ortStep* step) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 ASSERT(m_phase == Quiescent && m_hasScheduledMicrotask); | 88 ASSERT(m_phase == Quiescent && m_hasScheduledMicrotask); |
98 m_hasScheduledMicrotask = false; | 89 m_hasScheduledMicrotask = false; |
99 | 90 |
100 // Finishing microtask work deletes all | 91 // Finishing microtask work deletes all |
101 // CustomElementCallbackQueues. Being in a callback delivery scope | 92 // CustomElementCallbackQueues. Being in a callback delivery scope |
102 // implies those queues could still be in use. | 93 // implies those queues could still be in use. |
103 ASSERT_WITH_SECURITY_IMPLICATION(!CustomElementCallbackDispatcher::inCallbac kDeliveryScope()); | 94 ASSERT_WITH_SECURITY_IMPLICATION(!CustomElementCallbackDispatcher::inCallbac kDeliveryScope()); |
104 | 95 |
105 m_phase = Resolving; | 96 m_phase = Resolving; |
106 m_resolutionAndImports->dispatch(); | 97 m_resolutionAndImports->dispatch(); |
107 if (m_resolutionAndImports->isEmpty()) | |
108 m_asyncImports->dispatch(); | |
109 | 98 |
110 m_phase = DispatchingCallbacks; | 99 m_phase = DispatchingCallbacks; |
111 for (WillBeHeapVector<RawPtrWillBeMember<CustomElementCallbackQueue> >::iter ator it = m_elements.begin(); it != m_elements.end(); ++it) { | 100 for (WillBeHeapVector<RawPtrWillBeMember<CustomElementCallbackQueue> >::iter ator it = m_elements.begin(); it != m_elements.end(); ++it) { |
112 // Created callback may enqueue an attached callback. | 101 // Created callback may enqueue an attached callback. |
113 CustomElementCallbackDispatcher::CallbackDeliveryScope scope; | 102 CustomElementCallbackDispatcher::CallbackDeliveryScope scope; |
114 (*it)->processInElementQueue(kMicrotaskQueueId); | 103 (*it)->processInElementQueue(kMicrotaskQueueId); |
115 } | 104 } |
116 | 105 |
117 m_elements.clear(); | 106 m_elements.clear(); |
118 CustomElementScheduler::microtaskDispatcherDidFinish(); | 107 CustomElementScheduler::microtaskDispatcherDidFinish(); |
119 m_phase = Quiescent; | 108 m_phase = Quiescent; |
120 } | 109 } |
121 | 110 |
122 void CustomElementMicrotaskDispatcher::trace(Visitor* visitor) | 111 void CustomElementMicrotaskDispatcher::trace(Visitor* visitor) |
123 { | 112 { |
124 visitor->trace(m_resolutionAndImports); | 113 visitor->trace(m_resolutionAndImports); |
125 visitor->trace(m_asyncImports); | |
126 #if ENABLE(OILPAN) | 114 #if ENABLE(OILPAN) |
127 visitor->trace(m_elements); | 115 visitor->trace(m_elements); |
128 #endif | 116 #endif |
129 } | 117 } |
130 | 118 |
131 #if !defined(NDEBUG) | 119 #if !defined(NDEBUG) |
132 void CustomElementMicrotaskDispatcher::show() | 120 void CustomElementMicrotaskDispatcher::show() |
133 { | 121 { |
134 fprintf(stderr, "Dispatcher:\n"); | 122 m_resolutionAndImports->show(2); |
135 fprintf(stderr, " Sync:\n"); | |
136 m_resolutionAndImports->show(3); | |
137 fprintf(stderr, " Async:\n"); | |
138 m_asyncImports->show(3); | |
139 | 123 |
140 } | 124 } |
141 #endif | 125 #endif |
142 | 126 |
143 } // namespace WebCore | 127 } // namespace WebCore |
144 | 128 |
145 #if !defined(NDEBUG) | 129 #if !defined(NDEBUG) |
146 void showCEMD() | 130 void showCEMD() |
147 { | 131 { |
148 WebCore::CustomElementMicrotaskDispatcher::instance().show(); | 132 WebCore::CustomElementMicrotaskDispatcher::instance().show(); |
149 } | 133 } |
150 #endif | 134 #endif |
OLD | NEW |