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

Side by Side Diff: Source/core/dom/custom/CustomElementMicrotaskDispatcher.cpp

Issue 288323004: HTML Imports: Get rid of needsProcessOrStop() from dom/custom/ (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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 willOrDidEnqueueStep();
dominicc (has gone to gerrit) 2014/05/27 23:41:25 Thanks for fighting duplication.
37 ensureMicrotaskScheduled();
38 if (importLoader) 43 if (importLoader)
39 importLoader->microtaskQueue()->enqueue(step); 44 importLoader->microtaskQueue()->enqueue(step);
40 else 45 else
41 m_resolutionAndImports->enqueue(step); 46 m_resolutionAndImports->enqueue(step);
42 } 47 }
43 48
49 void CustomElementMicrotaskDispatcher::enqueue(HTMLImportLoader* importLoader, P assOwnPtr<CustomElementMicrotaskImportStep> step)
50 {
51 willOrDidEnqueueStep();
52 if (step->isSync())
dominicc (has gone to gerrit) 2014/05/27 23:41:25 Very neat; I love it.
53 enqueue(importLoader, PassOwnPtr<CustomElementMicrotaskStep>(step));
54 else
55 m_asyncImports->enqueue(step);
56 }
57
44 void CustomElementMicrotaskDispatcher::enqueue(CustomElementCallbackQueue* queue ) 58 void CustomElementMicrotaskDispatcher::enqueue(CustomElementCallbackQueue* queue )
45 { 59 {
46 ASSERT(m_phase == Quiescent || m_phase == Resolving); 60 ASSERT(m_phase == Quiescent || m_phase == Resolving);
47 ensureMicrotaskScheduled(); 61 ensureMicrotaskScheduled();
48 queue->setOwner(kMicrotaskQueueId); 62 queue->setOwner(kMicrotaskQueueId);
49 m_elements.append(queue); 63 m_elements.append(queue);
50 } 64 }
51 65
52 void CustomElementMicrotaskDispatcher::importDidFinish(CustomElementMicrotaskImp ortStep* step) 66 void CustomElementMicrotaskDispatcher::importDidFinish(CustomElementMicrotaskImp ortStep* step)
53 { 67 {
68 willOrDidEnqueueStep();
dominicc (has gone to gerrit) 2014/05/27 23:41:25 Think willOrDidEnqueueStep is mis-named, because i
Hajime Morrita 2014/05/28 00:41:37 Agreed. I just did't came up with any better name.
dominicc (has gone to gerrit) 2014/05/28 01:41:34 OK. Can you extract the two lines from enqueue(Cus
69 }
70
71 void CustomElementMicrotaskDispatcher::willOrDidEnqueueStep()
72 {
54 ASSERT(m_phase == Quiescent || m_phase == DispatchingCallbacks); 73 ASSERT(m_phase == Quiescent || m_phase == DispatchingCallbacks);
55 ensureMicrotaskScheduled(); 74 ensureMicrotaskScheduled();
56 } 75 }
57 76
58 void CustomElementMicrotaskDispatcher::ensureMicrotaskScheduled() 77 void CustomElementMicrotaskDispatcher::ensureMicrotaskScheduled()
59 { 78 {
60 if (!m_hasScheduledMicrotask) { 79 if (!m_hasScheduledMicrotask) {
61 Microtask::enqueueMicrotask(WTF::bind(&dispatch)); 80 Microtask::enqueueMicrotask(WTF::bind(&dispatch));
62 m_hasScheduledMicrotask = true; 81 m_hasScheduledMicrotask = true;
63 } 82 }
(...skipping 11 matching lines...) Expand all
75 ASSERT(m_phase == Quiescent && m_hasScheduledMicrotask); 94 ASSERT(m_phase == Quiescent && m_hasScheduledMicrotask);
76 m_hasScheduledMicrotask = false; 95 m_hasScheduledMicrotask = false;
77 96
78 // Finishing microtask work deletes all 97 // Finishing microtask work deletes all
79 // CustomElementCallbackQueues. Being in a callback delivery scope 98 // CustomElementCallbackQueues. Being in a callback delivery scope
80 // implies those queues could still be in use. 99 // implies those queues could still be in use.
81 ASSERT_WITH_SECURITY_IMPLICATION(!CustomElementCallbackDispatcher::inCallbac kDeliveryScope()); 100 ASSERT_WITH_SECURITY_IMPLICATION(!CustomElementCallbackDispatcher::inCallbac kDeliveryScope());
82 101
83 m_phase = Resolving; 102 m_phase = Resolving;
84 m_resolutionAndImports->dispatch(); 103 m_resolutionAndImports->dispatch();
104 if (m_resolutionAndImports->isEmpty())
105 m_asyncImports->dispatch();
85 106
86 m_phase = DispatchingCallbacks; 107 m_phase = DispatchingCallbacks;
87 for (Vector<CustomElementCallbackQueue*>::iterator it = m_elements.begin();i t != m_elements.end(); ++it) { 108 for (Vector<CustomElementCallbackQueue*>::iterator it = m_elements.begin();i t != m_elements.end(); ++it) {
88 // Created callback may enqueue an attached callback. 109 // Created callback may enqueue an attached callback.
89 CustomElementCallbackDispatcher::CallbackDeliveryScope scope; 110 CustomElementCallbackDispatcher::CallbackDeliveryScope scope;
90 (*it)->processInElementQueue(kMicrotaskQueueId); 111 (*it)->processInElementQueue(kMicrotaskQueueId);
91 } 112 }
92 113
93 m_elements.clear(); 114 m_elements.clear();
94 CustomElementScheduler::microtaskDispatcherDidFinish(); 115 CustomElementScheduler::microtaskDispatcherDidFinish();
95 m_phase = Quiescent; 116 m_phase = Quiescent;
96 } 117 }
97 118
98 #if !defined(NDEBUG) 119 #if !defined(NDEBUG)
99 void CustomElementMicrotaskDispatcher::show() 120 void CustomElementMicrotaskDispatcher::show()
100 { 121 {
101 fprintf(stderr, "Dispatcher:\n"); 122 fprintf(stderr, "Dispatcher:\n");
102 m_resolutionAndImports->show(1); 123 fprintf(stderr, " Sync:\n");
124 m_resolutionAndImports->show(3);
125 fprintf(stderr, " Async:\n");
126 m_asyncImports->show(3);
127
103 } 128 }
104 #endif 129 #endif
105 130
106 } // namespace WebCore 131 } // namespace WebCore
107 132
108 #if !defined(NDEBUG) 133 #if !defined(NDEBUG)
109 void showCEMD() 134 void showCEMD()
110 { 135 {
111 WebCore::CustomElementMicrotaskDispatcher::instance().show(); 136 WebCore::CustomElementMicrotaskDispatcher::instance().show();
112 } 137 }
113 #endif 138 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698