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

Side by Side Diff: third_party/WebKit/Source/modules/fetch/ReadableStreamDataConsumerHandle.cpp

Issue 2177243002: Use per-frame TaskRunner instead of thread's default in DataConsumerHandle (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@data_consumer_handle_unique_ptr
Patch Set: update Created 4 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "modules/fetch/ReadableStreamDataConsumerHandle.h" 5 #include "modules/fetch/ReadableStreamDataConsumerHandle.h"
6 6
7 #include "bindings/core/v8/ExceptionState.h" 7 #include "bindings/core/v8/ExceptionState.h"
8 #include "bindings/core/v8/ScopedPersistent.h" 8 #include "bindings/core/v8/ScopedPersistent.h"
9 #include "bindings/core/v8/ScriptFunction.h" 9 #include "bindings/core/v8/ScriptFunction.h"
10 #include "bindings/core/v8/ScriptState.h" 10 #include "bindings/core/v8/ScriptState.h"
11 #include "bindings/core/v8/ScriptValue.h" 11 #include "bindings/core/v8/ScriptValue.h"
12 #include "bindings/core/v8/V8BindingMacros.h" 12 #include "bindings/core/v8/V8BindingMacros.h"
13 #include "bindings/core/v8/V8IteratorResultValue.h" 13 #include "bindings/core/v8/V8IteratorResultValue.h"
14 #include "bindings/core/v8/V8Uint8Array.h" 14 #include "bindings/core/v8/V8Uint8Array.h"
15 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" 15 #include "bindings/core/v8/WorkerOrWorkletScriptController.h"
16 #include "core/dom/DOMTypedArray.h" 16 #include "core/dom/DOMTypedArray.h"
17 #include "core/dom/TaskRunnerHelper.h"
17 #include "core/streams/ReadableStreamOperations.h" 18 #include "core/streams/ReadableStreamOperations.h"
18 #include "core/workers/WorkerGlobalScope.h" 19 #include "core/workers/WorkerGlobalScope.h"
19 #include "public/platform/Platform.h" 20 #include "public/platform/Platform.h"
20 #include "public/platform/WebTaskRunner.h" 21 #include "public/platform/WebTaskRunner.h"
21 #include "public/platform/WebThread.h" 22 #include "public/platform/WebThread.h"
22 #include "public/platform/WebTraceLocation.h" 23 #include "public/platform/WebTraceLocation.h"
23 #include "wtf/Assertions.h" 24 #include "wtf/Assertions.h"
24 #include "wtf/Functional.h" 25 #include "wtf/Functional.h"
25 #include "wtf/RefCounted.h" 26 #include "wtf/RefCounted.h"
26 #include <algorithm> 27 #include <algorithm>
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 235
235 void notify() 236 void notify()
236 { 237 {
237 if (!m_client) 238 if (!m_client)
238 return; 239 return;
239 m_client->didGetReadable(); 240 m_client->didGetReadable();
240 } 241 }
241 242
242 void notifyLater() 243 void notifyLater()
243 { 244 {
244 ASSERT(m_client); 245 if (!m_client)
245 Platform::current()->currentThread()->getWebTaskRunner()->postTask(BLINK _FROM_HERE, WTF::bind(&ReadingContext::notify, PassRefPtr<ReadingContext>(this)) ); 246 return;
247 TaskRunnerHelper::getUnthrottledTaskRunner(m_scriptState.get())->postTas k(BLINK_FROM_HERE, WTF::bind(&ReadingContext::notify, PassRefPtr<ReadingContext> (this)));
246 } 248 }
247 249
248 private: 250 private:
249 ReadingContext(ScriptState* scriptState, ScriptValue streamReader) 251 ReadingContext(ScriptState* scriptState, ScriptValue streamReader)
250 : m_reader(scriptState->isolate(), streamReader.v8Value()) 252 : m_reader(scriptState->isolate(), streamReader.v8Value())
251 , m_scriptState(scriptState) 253 , m_scriptState(scriptState)
252 , m_client(nullptr) 254 , m_client(nullptr)
253 , m_pendingOffset(0) 255 , m_pendingOffset(0)
254 , m_isReading(false) 256 , m_isReading(false)
255 , m_isDone(false) 257 , m_isDone(false)
256 , m_hasError(false) 258 , m_hasError(false)
257 { 259 {
258 m_reader.setWeak(this, &ReadingContext::onCollected); 260 m_reader.setWeak(this, &ReadingContext::onCollected);
259 } 261 }
260 262
261 void onCollected() 263 void onCollected()
262 { 264 {
263 m_reader.clear(); 265 m_reader.clear();
264 if (m_isDone || m_hasError) 266 if (m_isDone || m_hasError)
265 return; 267 return;
266 m_hasError = true; 268 m_hasError = true;
267 if (m_client) 269 notifyLater();
268 notifyLater();
269 } 270 }
270 271
271 static void onCollected(const v8::WeakCallbackInfo<ReadableStreamDataConsume rHandle::ReadingContext>& data) 272 static void onCollected(const v8::WeakCallbackInfo<ReadableStreamDataConsume rHandle::ReadingContext>& data)
272 { 273 {
273 data.GetParameter()->onCollected(); 274 data.GetParameter()->onCollected();
274 } 275 }
275 276
276 // |m_reader| is a weak persistent. It should be kept alive by someone 277 // |m_reader| is a weak persistent. It should be kept alive by someone
277 // outside of ReadableStreamDataConsumerHandle. 278 // outside of ReadableStreamDataConsumerHandle.
278 // Holding a ScopedPersistent here is safe in terms of cross-world wrapper 279 // Holding a ScopedPersistent here is safe in terms of cross-world wrapper
(...skipping 13 matching lines...) Expand all
292 { 293 {
293 } 294 }
294 ReadableStreamDataConsumerHandle::~ReadableStreamDataConsumerHandle() = default; 295 ReadableStreamDataConsumerHandle::~ReadableStreamDataConsumerHandle() = default;
295 296
296 std::unique_ptr<FetchDataConsumerHandle::Reader> ReadableStreamDataConsumerHandl e::obtainFetchDataReader(Client* client) 297 std::unique_ptr<FetchDataConsumerHandle::Reader> ReadableStreamDataConsumerHandl e::obtainFetchDataReader(Client* client)
297 { 298 {
298 return WTF::wrapUnique(new ReadingContext::ReaderImpl(m_readingContext, clie nt)); 299 return WTF::wrapUnique(new ReadingContext::ReaderImpl(m_readingContext, clie nt));
299 } 300 }
300 301
301 } // namespace blink 302 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698