Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(600)

Unified Diff: Source/core/dom/custom/CustomElementMicrotaskQueue.cpp

Issue 334253005: Custom Elements: Encapsulates Async and Sync Queues into one class. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/dom/custom/CustomElementMicrotaskQueue.cpp
diff --git a/Source/core/dom/custom/CustomElementMicrotaskQueue.cpp b/Source/core/dom/custom/CustomElementMicrotaskQueue.cpp
index ad0e287e2ce9f0496e3c2a0a4e04379eddb03b5c..1ae313aff5f892e3bd28eb2f1c675801de334916 100644
--- a/Source/core/dom/custom/CustomElementMicrotaskQueue.cpp
+++ b/Source/core/dom/custom/CustomElementMicrotaskQueue.cpp
@@ -31,88 +31,54 @@
#include "config.h"
#include "core/dom/custom/CustomElementMicrotaskQueue.h"
-#include "core/dom/custom/CustomElementCallbackDispatcher.h"
+#include "core/dom/custom/CustomElementMicrotaskImportStep.h"
+#include "core/html/imports/HTMLImportLoader.h"
namespace WebCore {
-class MicrotaskQueueInvocationScope {
-public:
-#if defined(NDEBUG)
- explicit MicrotaskQueueInvocationScope(CustomElementMicrotaskQueueBase*) { }
-#else
- explicit MicrotaskQueueInvocationScope(CustomElementMicrotaskQueueBase* queue)
- : m_parent(s_top)
- , m_queue(queue)
- {
- s_top = this;
- ASSERT(m_queue->isEmpty() || !hasReenter());
- }
-
- ~MicrotaskQueueInvocationScope()
- {
- s_top = m_parent;
- }
-
-private:
- bool hasReenter() const
- {
- for (MicrotaskQueueInvocationScope* scope = this->m_parent; scope; scope = scope->m_parent) {
- if (scope->m_queue == m_queue)
- return true;
- }
-
- return false;
- }
-
- MicrotaskQueueInvocationScope* m_parent;
- CustomElementMicrotaskQueueBase* m_queue;
-
- static MicrotaskQueueInvocationScope* s_top;
-#endif
-};
-
-#if !defined(NDEBUG)
-MicrotaskQueueInvocationScope* MicrotaskQueueInvocationScope::s_top = 0;
-#endif
-
-void CustomElementMicrotaskQueueBase::dispatch()
+CustomElementMicrotaskQueue::CustomElementMicrotaskQueue()
+ : m_syncQueue(CustomElementSyncMicrotaskQueue::create())
+ , m_asyncQueue(CustomElementAsyncImportMicrotaskQueue::create())
{
- MicrotaskQueueInvocationScope scope(this);
- doDispatch();
}
-void CustomElementMicrotaskQueueBase::trace(Visitor* visitor)
+void CustomElementMicrotaskQueue::enqueue(HTMLImportLoader* parentLoader, PassOwnPtrWillBeRawPtr<CustomElementMicrotaskStep> step)
{
- visitor->trace(m_queue);
+ if (parentLoader)
+ parentLoader->microtaskQueue()->enqueue(step);
+ else
+ m_syncQueue->enqueue(step);
}
-#if !defined(NDEBUG)
-void CustomElementMicrotaskQueueBase::show(unsigned indent)
+void CustomElementMicrotaskQueue::enqueue(HTMLImportLoader* parentLoader, PassOwnPtrWillBeRawPtr<CustomElementMicrotaskImportStep> step, bool importIsSync)
{
- for (unsigned q = 0; q < m_queue.size(); ++q) {
- if (m_queue[q])
- m_queue[q]->show(indent);
- else
- fprintf(stderr, "%*snull\n", indent, "");
- }
+ if (importIsSync)
+ enqueue(parentLoader, PassOwnPtrWillBeRawPtr<CustomElementMicrotaskStep>(step));
+ else
+ m_asyncQueue->enqueue(step);
}
-#endif
-void CustomElementMicrotaskQueue::enqueue(PassOwnPtrWillBeRawPtr<CustomElementMicrotaskStep> step)
+void CustomElementMicrotaskQueue::dispatch()
{
- m_queue.append(step);
+ m_syncQueue->dispatch();
+ if (m_syncQueue->isEmpty())
+ m_asyncQueue->dispatch();
}
-void CustomElementMicrotaskQueue::doDispatch()
+void CustomElementMicrotaskQueue::trace(Visitor* visitor)
{
- unsigned i;
-
- for (i = 0; i < m_queue.size(); ++i) {
- if (CustomElementMicrotaskStep::Processing == m_queue[i]->process())
- break;
- }
+ visitor->trace(m_syncQueue);
+ visitor->trace(m_asyncQueue);
+}
- m_queue.remove(0, i);
+#if !defined(NDEBUG)
+void CustomElementMicrotaskQueue::show(unsigned indent)
+{
+ fprintf(stderr, "%*sSync:\n", indent, "");
+ m_syncQueue->show(indent + 1);
+ fprintf(stderr, "%*sAsync:\n", indent, "");
+ m_asyncQueue->show(indent + 1);
}
+#endif
} // namespace WebCore

Powered by Google App Engine
This is Rietveld 408576698