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

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

Issue 528373003: Make CustomElementSchedular static (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Removed empty BUG= line Created 6 years, 3 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
« no previous file with comments | « Source/core/dom/custom/CustomElementScheduler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "core/dom/custom/CustomElementProcessingStack.h" 42 #include "core/dom/custom/CustomElementProcessingStack.h"
43 #include "core/dom/custom/CustomElementRegistrationContext.h" 43 #include "core/dom/custom/CustomElementRegistrationContext.h"
44 #include "core/dom/custom/CustomElementSyncMicrotaskQueue.h" 44 #include "core/dom/custom/CustomElementSyncMicrotaskQueue.h"
45 #include "core/html/imports/HTMLImportChild.h" 45 #include "core/html/imports/HTMLImportChild.h"
46 #include "core/html/imports/HTMLImportsController.h" 46 #include "core/html/imports/HTMLImportsController.h"
47 47
48 namespace blink { 48 namespace blink {
49 49
50 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(CustomElementScheduler) 50 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(CustomElementScheduler)
51 51
52 // FIXME: Consider moving the element's callback queue to ElementRareData.
53 typedef WillBeHeapHashMap<RawPtrWillBeMember<Element>, OwnPtrWillBeMember<Custom ElementCallbackQueue> > ElementCallbackQueueMap;
54
55 static ElementCallbackQueueMap& callbackQueues()
56 {
57 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<ElementCallbackQueueMap>, map, (a doptPtrWillBeNoop(new ElementCallbackQueueMap())));
58 return *map;
59 }
60
61 static CustomElementCallbackQueue& ensureCallbackQueue(PassRefPtrWillBeRawPtr<El ement> element)
62 {
63 ElementCallbackQueueMap::ValueType* it = callbackQueues().add(element.get(), nullptr).storedValue;
64 if (!it->value)
65 it->value = CustomElementCallbackQueue::create(element);
66 return *it->value.get();
67 }
68
69 // Finds or creates the callback queue for element.
70 static CustomElementCallbackQueue& scheduleCallbackQueue(PassRefPtrWillBeRawPtr< Element> passElement)
71 {
72 RefPtrWillBeRawPtr<Element> element(passElement);
73
74 CustomElementCallbackQueue& callbackQueue = ensureCallbackQueue(element);
75 if (callbackQueue.inCreatedCallback()) {
76 // Don't move it. Authors use the createdCallback like a
77 // constructor. By not moving it, the createdCallback
78 // completes before any other callbacks are entered for this
79 // element.
80 return callbackQueue;
81 }
82
83 if (CustomElementProcessingStack::inCallbackDeliveryScope()) {
84 // The processing stack is active.
85 CustomElementProcessingStack::instance().enqueue(&callbackQueue);
86 return callbackQueue;
87 }
88
89 CustomElementMicrotaskDispatcher::instance().enqueue(&callbackQueue);
90 return callbackQueue;
91 }
92
52 void CustomElementScheduler::scheduleCallback(PassRefPtr<CustomElementLifecycleC allbacks> callbacks, PassRefPtrWillBeRawPtr<Element> element, CustomElementLifec ycleCallbacks::CallbackType type) 93 void CustomElementScheduler::scheduleCallback(PassRefPtr<CustomElementLifecycleC allbacks> callbacks, PassRefPtrWillBeRawPtr<Element> element, CustomElementLifec ycleCallbacks::CallbackType type)
53 { 94 {
54 ASSERT(type != CustomElementLifecycleCallbacks::AttributeChangedCallback); 95 ASSERT(type != CustomElementLifecycleCallbacks::AttributeChangedCallback);
55 96
56 if (!callbacks->hasCallback(type)) 97 if (!callbacks->hasCallback(type))
57 return; 98 return;
58 99
59 CustomElementCallbackQueue& queue = instance().schedule(element); 100 CustomElementCallbackQueue& queue = scheduleCallbackQueue(element);
60 queue.append(CustomElementCallbackInvocation::createInvocation(callbacks, ty pe)); 101 queue.append(CustomElementCallbackInvocation::createInvocation(callbacks, ty pe));
61 } 102 }
62 103
63 void CustomElementScheduler::scheduleAttributeChangedCallback(PassRefPtr<CustomE lementLifecycleCallbacks> callbacks, PassRefPtrWillBeRawPtr<Element> element, co nst AtomicString& name, const AtomicString& oldValue, const AtomicString& newVal ue) 104 void CustomElementScheduler::scheduleAttributeChangedCallback(PassRefPtr<CustomE lementLifecycleCallbacks> callbacks, PassRefPtrWillBeRawPtr<Element> element, co nst AtomicString& name, const AtomicString& oldValue, const AtomicString& newVal ue)
64 { 105 {
65 if (!callbacks->hasCallback(CustomElementLifecycleCallbacks::AttributeChange dCallback)) 106 if (!callbacks->hasCallback(CustomElementLifecycleCallbacks::AttributeChange dCallback))
66 return; 107 return;
67 108
68 CustomElementCallbackQueue& queue = instance().schedule(element); 109 CustomElementCallbackQueue& queue = scheduleCallbackQueue(element);
69 queue.append(CustomElementCallbackInvocation::createAttributeChangedInvocati on(callbacks, name, oldValue, newValue)); 110 queue.append(CustomElementCallbackInvocation::createAttributeChangedInvocati on(callbacks, name, oldValue, newValue));
70 } 111 }
71 112
72 void CustomElementScheduler::resolveOrScheduleResolution(PassRefPtrWillBeRawPtr< CustomElementRegistrationContext> context, PassRefPtrWillBeRawPtr<Element> eleme nt, const CustomElementDescriptor& descriptor) 113 void CustomElementScheduler::resolveOrScheduleResolution(PassRefPtrWillBeRawPtr< CustomElementRegistrationContext> context, PassRefPtrWillBeRawPtr<Element> eleme nt, const CustomElementDescriptor& descriptor)
73 { 114 {
74 if (CustomElementProcessingStack::inCallbackDeliveryScope()) { 115 if (CustomElementProcessingStack::inCallbackDeliveryScope()) {
75 context->resolve(element.get(), descriptor); 116 context->resolve(element.get(), descriptor);
76 return; 117 return;
77 } 118 }
78 119
(...skipping 14 matching lines...) Expand all
93 enqueueMicrotaskStep(*(import->parent()->document()), step.release(), import ->isSync()); 134 enqueueMicrotaskStep(*(import->parent()->document()), step.release(), import ->isSync());
94 return rawStep; 135 return rawStep;
95 } 136 }
96 137
97 void CustomElementScheduler::enqueueMicrotaskStep(Document& document, PassOwnPtr WillBeRawPtr<CustomElementMicrotaskStep> step, bool importIsSync) 138 void CustomElementScheduler::enqueueMicrotaskStep(Document& document, PassOwnPtr WillBeRawPtr<CustomElementMicrotaskStep> step, bool importIsSync)
98 { 139 {
99 Document& master = document.importsController() ? *(document.importsControll er()->master()) : document; 140 Document& master = document.importsController() ? *(document.importsControll er()->master()) : document;
100 master.customElementMicrotaskRunQueue()->enqueue(document.importLoader(), st ep, importIsSync); 141 master.customElementMicrotaskRunQueue()->enqueue(document.importLoader(), st ep, importIsSync);
101 } 142 }
102 143
103 CustomElementScheduler& CustomElementScheduler::instance()
104 {
105 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<CustomElementScheduler>, instance , (adoptPtrWillBeNoop (new CustomElementScheduler())));
106 return *instance;
107 }
108
109 CustomElementCallbackQueue& CustomElementScheduler::ensureCallbackQueue(PassRefP trWillBeRawPtr<Element> element)
110 {
111 ElementCallbackQueueMap::ValueType* it = m_elementCallbackQueueMap.add(eleme nt.get(), nullptr).storedValue;
112 if (!it->value)
113 it->value = CustomElementCallbackQueue::create(element);
114 return *it->value.get();
115 }
116 144
117 void CustomElementScheduler::callbackDispatcherDidFinish() 145 void CustomElementScheduler::callbackDispatcherDidFinish()
118 { 146 {
119 if (CustomElementMicrotaskDispatcher::instance().elementQueueIsEmpty()) 147 if (CustomElementMicrotaskDispatcher::instance().elementQueueIsEmpty())
120 instance().clearElementCallbackQueueMap(); 148 callbackQueues().clear();
121 } 149 }
122 150
123 void CustomElementScheduler::microtaskDispatcherDidFinish() 151 void CustomElementScheduler::microtaskDispatcherDidFinish()
124 { 152 {
125 ASSERT(!CustomElementProcessingStack::inCallbackDeliveryScope()); 153 ASSERT(!CustomElementProcessingStack::inCallbackDeliveryScope());
126 instance().clearElementCallbackQueueMap(); 154 callbackQueues().clear();
127 }
128
129 void CustomElementScheduler::clearElementCallbackQueueMap()
130 {
131 ElementCallbackQueueMap emptyMap;
132 m_elementCallbackQueueMap.swap(emptyMap);
133 }
134
135 // Finds or creates the callback queue for element.
136 CustomElementCallbackQueue& CustomElementScheduler::schedule(PassRefPtrWillBeRaw Ptr<Element> passElement)
137 {
138 RefPtrWillBeRawPtr<Element> element(passElement);
139
140 CustomElementCallbackQueue& callbackQueue = ensureCallbackQueue(element);
141 if (callbackQueue.inCreatedCallback()) {
142 // Don't move it. Authors use the createdCallback like a
143 // constructor. By not moving it, the createdCallback
144 // completes before any other callbacks are entered for this
145 // element.
146 return callbackQueue;
147 }
148
149 if (CustomElementProcessingStack::inCallbackDeliveryScope()) {
150 // The processing stack is active.
151 CustomElementProcessingStack::instance().enqueue(&callbackQueue);
152 return callbackQueue;
153 }
154
155 CustomElementMicrotaskDispatcher::instance().enqueue(&callbackQueue);
156 return callbackQueue;
157 }
158
159 void CustomElementScheduler::trace(Visitor* visitor)
160 {
161 #if ENABLE(OILPAN)
162 visitor->trace(m_elementCallbackQueueMap);
163 #endif
164 } 155 }
165 156
166 } // namespace blink 157 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/dom/custom/CustomElementScheduler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698