Chromium Code Reviews| 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" | |
| 9 #include "core/dom/custom/CustomElementCallbackDispatcher.h" | 10 #include "core/dom/custom/CustomElementCallbackDispatcher.h" |
| 10 #include "core/dom/custom/CustomElementCallbackQueue.h" | 11 #include "core/dom/custom/CustomElementCallbackQueue.h" |
| 11 #include "core/dom/custom/CustomElementMicrotaskImportStep.h" | 12 #include "core/dom/custom/CustomElementMicrotaskImportStep.h" |
| 12 #include "core/dom/custom/CustomElementMicrotaskQueue.h" | 13 #include "core/dom/custom/CustomElementMicrotaskQueue.h" |
| 13 #include "core/dom/custom/CustomElementScheduler.h" | 14 #include "core/dom/custom/CustomElementScheduler.h" |
| 14 #include "core/html/imports/HTMLImportLoader.h" | 15 #include "core/html/imports/HTMLImportLoader.h" |
| 15 #include "wtf/MainThread.h" | 16 #include "wtf/MainThread.h" |
| 16 | 17 |
| 17 namespace WebCore { | 18 namespace WebCore { |
| 18 | 19 |
| 19 static const CustomElementCallbackQueue::ElementQueueId kMicrotaskQueueId = 0; | 20 static const CustomElementCallbackQueue::ElementQueueId kMicrotaskQueueId = 0; |
| 20 | 21 |
| 21 CustomElementMicrotaskDispatcher::CustomElementMicrotaskDispatcher() | 22 CustomElementMicrotaskDispatcher::CustomElementMicrotaskDispatcher() |
| 22 : m_hasScheduledMicrotask(false) | 23 : m_hasScheduledMicrotask(false) |
| 23 , m_phase(Quiescent) | 24 , m_phase(Quiescent) |
| 24 , m_resolutionAndImports(CustomElementMicrotaskQueue::create()) | 25 , m_resolutionAndImports(CustomElementMicrotaskQueue::create()) |
| 26 , m_asyncImports(CustomElementAsyncImportMicrotaskQueue::create()) | |
| 25 { | 27 { |
| 26 } | 28 } |
| 27 | 29 |
| 30 CustomElementMicrotaskDispatcher::~CustomElementMicrotaskDispatcher() | |
| 31 { | |
| 32 } | |
| 33 | |
| 28 CustomElementMicrotaskDispatcher& CustomElementMicrotaskDispatcher::instance() | 34 CustomElementMicrotaskDispatcher& CustomElementMicrotaskDispatcher::instance() |
| 29 { | 35 { |
| 30 DEFINE_STATIC_LOCAL(CustomElementMicrotaskDispatcher, instance, ()); | 36 DEFINE_STATIC_LOCAL(CustomElementMicrotaskDispatcher, instance, ()); |
| 31 return instance; | 37 return instance; |
| 32 } | 38 } |
| 33 | 39 |
| 34 void CustomElementMicrotaskDispatcher::enqueue(HTMLImportLoader* importLoader, P assOwnPtr<CustomElementMicrotaskStep> step) | 40 void CustomElementMicrotaskDispatcher::enqueue(HTMLImportLoader* importLoader, P assOwnPtr<CustomElementMicrotaskStep> step) |
| 35 { | 41 { |
| 36 ASSERT(m_phase == Quiescent || m_phase == DispatchingCallbacks); | 42 ASSERT(m_phase == Quiescent || m_phase == DispatchingCallbacks); |
| 37 ensureMicrotaskScheduled(); | 43 ensureMicrotaskScheduled(); |
| 38 if (importLoader) | 44 if (importLoader) |
| 39 importLoader->microtaskQueue()->enqueue(step); | 45 importLoader->microtaskQueue()->enqueue(step); |
| 40 else | 46 else |
| 41 m_resolutionAndImports->enqueue(step); | 47 m_resolutionAndImports->enqueue(step); |
| 42 } | 48 } |
| 43 | 49 |
| 44 void CustomElementMicrotaskDispatcher::enqueue(CustomElementCallbackQueue* queue ) | 50 void CustomElementMicrotaskDispatcher::enqueue(CustomElementCallbackQueue* queue ) |
| 45 { | 51 { |
| 46 ASSERT(m_phase == Quiescent || m_phase == Resolving); | 52 ASSERT(m_phase == Quiescent || m_phase == Resolving); |
| 47 ensureMicrotaskScheduled(); | 53 ensureMicrotaskScheduled(); |
| 48 queue->setOwner(kMicrotaskQueueId); | 54 queue->setOwner(kMicrotaskQueueId); |
| 49 m_elements.append(queue); | 55 m_elements.append(queue); |
| 50 } | 56 } |
| 51 | 57 |
| 58 void CustomElementMicrotaskDispatcher::enqueueAsyncImportStep(PassOwnPtr<CustomE lementMicrotaskImportStep> step) | |
| 59 { | |
| 60 ASSERT(m_phase == Quiescent || m_phase == DispatchingCallbacks); | |
|
dominicc (has gone to gerrit)
2014/05/25 23:55:10
Can we refactor to eliminate the duplication of th
Hajime Morrita
2014/05/27 21:12:47
Done. Made some rearrangement around signature and
| |
| 61 ensureMicrotaskScheduled(); | |
| 62 m_asyncImports->enqueue(step); | |
| 63 } | |
| 64 | |
| 52 void CustomElementMicrotaskDispatcher::importDidFinish(CustomElementMicrotaskImp ortStep* step) | 65 void CustomElementMicrotaskDispatcher::importDidFinish(CustomElementMicrotaskImp ortStep* step) |
| 53 { | 66 { |
| 54 ASSERT(m_phase == Quiescent || m_phase == DispatchingCallbacks); | 67 ASSERT(m_phase == Quiescent || m_phase == DispatchingCallbacks); |
| 55 ensureMicrotaskScheduled(); | 68 ensureMicrotaskScheduled(); |
| 56 } | 69 } |
| 57 | 70 |
| 58 void CustomElementMicrotaskDispatcher::ensureMicrotaskScheduled() | 71 void CustomElementMicrotaskDispatcher::ensureMicrotaskScheduled() |
| 59 { | 72 { |
| 60 if (!m_hasScheduledMicrotask) { | 73 if (!m_hasScheduledMicrotask) { |
| 61 Microtask::enqueueMicrotask(WTF::bind(&dispatch)); | 74 Microtask::enqueueMicrotask(WTF::bind(&dispatch)); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 75 ASSERT(m_phase == Quiescent && m_hasScheduledMicrotask); | 88 ASSERT(m_phase == Quiescent && m_hasScheduledMicrotask); |
| 76 m_hasScheduledMicrotask = false; | 89 m_hasScheduledMicrotask = false; |
| 77 | 90 |
| 78 // Finishing microtask work deletes all | 91 // Finishing microtask work deletes all |
| 79 // CustomElementCallbackQueues. Being in a callback delivery scope | 92 // CustomElementCallbackQueues. Being in a callback delivery scope |
| 80 // implies those queues could still be in use. | 93 // implies those queues could still be in use. |
| 81 ASSERT_WITH_SECURITY_IMPLICATION(!CustomElementCallbackDispatcher::inCallbac kDeliveryScope()); | 94 ASSERT_WITH_SECURITY_IMPLICATION(!CustomElementCallbackDispatcher::inCallbac kDeliveryScope()); |
| 82 | 95 |
| 83 m_phase = Resolving; | 96 m_phase = Resolving; |
| 84 m_resolutionAndImports->dispatch(); | 97 m_resolutionAndImports->dispatch(); |
| 98 if (m_resolutionAndImports->isEmpty()) | |
| 99 m_asyncImports->dispatch(); | |
|
dominicc (has gone to gerrit)
2014/05/25 23:55:10
Could we dispatch these anyway? WDYT?
Hajime Morrita
2014/05/27 21:12:47
That makes some tests fail.
Async imports don't bl
dominicc (has gone to gerrit)
2014/05/27 23:41:25
I remembered this in the middle of the night last
| |
| 85 | 100 |
| 86 m_phase = DispatchingCallbacks; | 101 m_phase = DispatchingCallbacks; |
| 87 for (Vector<CustomElementCallbackQueue*>::iterator it = m_elements.begin();i t != m_elements.end(); ++it) { | 102 for (Vector<CustomElementCallbackQueue*>::iterator it = m_elements.begin();i t != m_elements.end(); ++it) { |
| 88 // Created callback may enqueue an attached callback. | 103 // Created callback may enqueue an attached callback. |
| 89 CustomElementCallbackDispatcher::CallbackDeliveryScope scope; | 104 CustomElementCallbackDispatcher::CallbackDeliveryScope scope; |
| 90 (*it)->processInElementQueue(kMicrotaskQueueId); | 105 (*it)->processInElementQueue(kMicrotaskQueueId); |
| 91 } | 106 } |
| 92 | 107 |
| 93 m_elements.clear(); | 108 m_elements.clear(); |
| 94 CustomElementScheduler::microtaskDispatcherDidFinish(); | 109 CustomElementScheduler::microtaskDispatcherDidFinish(); |
| 95 m_phase = Quiescent; | 110 m_phase = Quiescent; |
| 96 } | 111 } |
| 97 | 112 |
| 98 #if !defined(NDEBUG) | 113 #if !defined(NDEBUG) |
| 99 void CustomElementMicrotaskDispatcher::show() | 114 void CustomElementMicrotaskDispatcher::show() |
| 100 { | 115 { |
| 101 fprintf(stderr, "Dispatcher:\n"); | 116 fprintf(stderr, "Dispatcher:\n"); |
| 102 m_resolutionAndImports->show(1); | 117 fprintf(stderr, " Sync:\n"); |
| 118 m_resolutionAndImports->show(3); | |
| 119 fprintf(stderr, " Async:\n"); | |
| 120 m_asyncImports->show(3); | |
| 121 | |
| 103 } | 122 } |
| 104 #endif | 123 #endif |
| 105 | 124 |
| 106 } // namespace WebCore | 125 } // namespace WebCore |
| 107 | 126 |
| 108 #if !defined(NDEBUG) | 127 #if !defined(NDEBUG) |
| 109 void showCEMD() | 128 void showCEMD() |
| 110 { | 129 { |
| 111 WebCore::CustomElementMicrotaskDispatcher::instance().show(); | 130 WebCore::CustomElementMicrotaskDispatcher::instance().show(); |
| 112 } | 131 } |
| 113 #endif | 132 #endif |
| OLD | NEW |