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

Side by Side Diff: Source/core/streams/ReadableStreamImpl.h

Issue 1233173002: Have ScriptPromiseResolver on the Oilpan heap always. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: fix webusb ScriptPromiseResolver usage Created 5 years, 4 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
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 #ifndef ReadableStreamImpl_h 5 #ifndef ReadableStreamImpl_h
6 #define ReadableStreamImpl_h 6 #define ReadableStreamImpl_h
7 7
8 #include "bindings/core/v8/ExceptionState.h" 8 #include "bindings/core/v8/ExceptionState.h"
9 #include "bindings/core/v8/ScriptPromise.h" 9 #include "bindings/core/v8/ScriptPromise.h"
10 #include "bindings/core/v8/ScriptPromiseResolver.h" 10 #include "bindings/core/v8/ScriptPromiseResolver.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 111
112 // This function is intended to be used by internal code to withdraw 112 // This function is intended to be used by internal code to withdraw
113 // queued data. This pulls all data from this stream's queue, but 113 // queued data. This pulls all data from this stream's queue, but
114 // ReadableStream public APIs can work with the behavior (i.e. it behaves 114 // ReadableStream public APIs can work with the behavior (i.e. it behaves
115 // as if multiple read-one-buffer calls were made). 115 // as if multiple read-one-buffer calls were made).
116 void readInternal(Deque<std::pair<typename ChunkTypeTraits::HoldType, size_t >>& queue); 116 void readInternal(Deque<std::pair<typename ChunkTypeTraits::HoldType, size_t >>& queue);
117 117
118 DEFINE_INLINE_VIRTUAL_TRACE() 118 DEFINE_INLINE_VIRTUAL_TRACE()
119 { 119 {
120 visitor->trace(m_strategy); 120 visitor->trace(m_strategy);
121 #if ENABLE(OILPAN)
122 visitor->trace(m_pendingReads); 121 visitor->trace(m_pendingReads);
123 #endif
124 ReadableStream::trace(visitor); 122 ReadableStream::trace(visitor);
125 } 123 }
126 124
127 private: 125 private:
128 #if ENABLE(OILPAN)
129 using PendingReads = HeapDeque<Member<ScriptPromiseResolver>>; 126 using PendingReads = HeapDeque<Member<ScriptPromiseResolver>>;
130 #else
131 using PendingReads = Deque<RefPtr<ScriptPromiseResolver>>;
132 #endif
133 127
134 // ReadableStream methods 128 // ReadableStream methods
135 bool isQueueEmpty() const override { return m_queue.isEmpty(); } 129 bool isQueueEmpty() const override { return m_queue.isEmpty(); }
136 void clearQueue() override 130 void clearQueue() override
137 { 131 {
138 m_queue.clear(); 132 m_queue.clear();
139 m_totalQueueSize = 0; 133 m_totalQueueSize = 0;
140 } 134 }
141 135
142 void resolveAllPendingReadsAsDone() override 136 void resolveAllPendingReadsAsDone() override
143 { 137 {
144 for (auto& resolver : m_pendingReads) { 138 for (auto& resolver : m_pendingReads) {
145 ScriptState::Scope scope(resolver->scriptState()); 139 ScriptState* scriptState = resolver->scriptState();
146 resolver->resolve(v8IteratorResultDone(resolver->scriptState())); 140 if (!scriptState->contextIsValid())
141 continue;
142 ScriptState::Scope scope(scriptState);
143 resolver->resolve(v8IteratorResultDone(scriptState));
147 } 144 }
148 m_pendingReads.clear(); 145 m_pendingReads.clear();
149 } 146 }
150 147
151 void rejectAllPendingReads(DOMException* reason) override 148 void rejectAllPendingReads(DOMException* reason) override
152 { 149 {
153 for (auto& resolver : m_pendingReads) 150 for (auto& resolver : m_pendingReads)
154 resolver->reject(reason); 151 resolver->reject(reason);
155 m_pendingReads.clear(); 152 m_pendingReads.clear();
156 } 153 }
(...skipping 16 matching lines...) Expand all
173 size_t size = m_strategy->size(chunk, this); 170 size_t size = m_strategy->size(chunk, this);
174 if (!enqueuePreliminaryCheck()) 171 if (!enqueuePreliminaryCheck())
175 return false; 172 return false;
176 173
177 if (m_pendingReads.isEmpty()) { 174 if (m_pendingReads.isEmpty()) {
178 m_queue.append(std::make_pair(chunk, size)); 175 m_queue.append(std::make_pair(chunk, size));
179 m_totalQueueSize += size; 176 m_totalQueueSize += size;
180 return enqueuePostAction(); 177 return enqueuePostAction();
181 } 178 }
182 179
183 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = m_pendingReads.takeFirs t(); 180 ScriptPromiseResolver* resolver = m_pendingReads.takeFirst();
184 ScriptState* scriptState = resolver->scriptState(); 181 ScriptState* scriptState = resolver->scriptState();
182 if (!scriptState->contextIsValid())
183 return false;
185 ScriptState::Scope scope(scriptState); 184 ScriptState::Scope scope(scriptState);
186 resolver->resolve(v8IteratorResult(scriptState, chunk)); 185 resolver->resolve(v8IteratorResult(scriptState, chunk));
187 return enqueuePostAction(); 186 return enqueuePostAction();
188 } 187 }
189 188
190 template <typename ChunkTypeTraits> 189 template <typename ChunkTypeTraits>
191 ScriptPromise ReadableStreamImpl<ChunkTypeTraits>::read(ScriptState* scriptState ) 190 ScriptPromise ReadableStreamImpl<ChunkTypeTraits>::read(ScriptState* scriptState )
192 { 191 {
193 ASSERT(stateInternal() == Readable); 192 ASSERT(stateInternal() == Readable);
194 if (m_queue.isEmpty()) { 193 if (m_queue.isEmpty()) {
(...skipping 22 matching lines...) Expand all
217 ASSERT(queue.isEmpty()); 216 ASSERT(queue.isEmpty());
218 217
219 queue.swap(m_queue); 218 queue.swap(m_queue);
220 m_totalQueueSize = 0; 219 m_totalQueueSize = 0;
221 readInternalPostAction(); 220 readInternalPostAction();
222 } 221 }
223 222
224 } // namespace blink 223 } // namespace blink
225 224
226 #endif // ReadableStreamImpl_h 225 #endif // ReadableStreamImpl_h
OLDNEW
« no previous file with comments | « Source/core/imagebitmap/ImageBitmapFactories.cpp ('k') | Source/core/streams/ReadableStreamReader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698