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

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

Issue 2365853002: Implement ReadableStreamBytesConsumer (Closed)
Patch Set: git cl format Created 4 years, 2 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 #include "modules/fetch/BodyStreamBuffer.h" 5 #include "modules/fetch/BodyStreamBuffer.h"
6 6
7 #include "bindings/core/v8/ScriptState.h" 7 #include "bindings/core/v8/ScriptState.h"
8 #include "bindings/core/v8/V8HiddenValue.h" 8 #include "bindings/core/v8/V8HiddenValue.h"
9 #include "core/dom/DOMArrayBuffer.h" 9 #include "core/dom/DOMArrayBuffer.h"
10 #include "core/dom/DOMTypedArray.h" 10 #include "core/dom/DOMTypedArray.h"
11 #include "core/dom/ExceptionCode.h" 11 #include "core/dom/ExceptionCode.h"
12 #include "core/streams/ReadableStreamController.h" 12 #include "core/streams/ReadableStreamController.h"
13 #include "core/streams/ReadableStreamOperations.h" 13 #include "core/streams/ReadableStreamOperations.h"
14 #include "modules/fetch/Body.h" 14 #include "modules/fetch/Body.h"
15 #include "modules/fetch/BytesConsumerForDataConsumerHandle.h" 15 #include "modules/fetch/BytesConsumerForDataConsumerHandle.h"
16 #include "modules/fetch/DataConsumerHandleUtil.h" 16 #include "modules/fetch/DataConsumerHandleUtil.h"
17 #include "modules/fetch/ReadableStreamDataConsumerHandle.h" 17 #include "modules/fetch/ReadableStreamBytesConsumer.h"
18 #include "platform/blob/BlobData.h" 18 #include "platform/blob/BlobData.h"
19 #include "platform/network/EncodedFormData.h" 19 #include "platform/network/EncodedFormData.h"
20 #include <memory> 20 #include <memory>
21 21
22 namespace blink { 22 namespace blink {
23 23
24 class BodyStreamBuffer::LoaderClient final 24 class BodyStreamBuffer::LoaderClient final
25 : public GarbageCollectedFinalized<LoaderClient>, 25 : public GarbageCollectedFinalized<LoaderClient>,
26 public ActiveDOMObject, 26 public ActiveDOMObject,
27 public FetchDataLoader::Client { 27 public FetchDataLoader::Client {
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 ScriptState::Scope scope(m_scriptState.get()); 365 ScriptState::Scope scope(m_scriptState.get());
366 // We need to have |reader| alive by some means (as written in 366 // We need to have |reader| alive by some means (as written in
367 // ReadableStreamDataConsumerHandle). Based on the following facts 367 // ReadableStreamDataConsumerHandle). Based on the following facts
368 // - This function is used only from tee and startLoading. 368 // - This function is used only from tee and startLoading.
369 // - This branch cannot be taken when called from tee. 369 // - This branch cannot be taken when called from tee.
370 // - startLoading makes hasPendingActivity return true while loading. 370 // - startLoading makes hasPendingActivity return true while loading.
371 // , we don't need to keep the reader explicitly. 371 // , we don't need to keep the reader explicitly.
372 NonThrowableExceptionState exceptionState; 372 NonThrowableExceptionState exceptionState;
373 ScriptValue reader = ReadableStreamOperations::getReader( 373 ScriptValue reader = ReadableStreamOperations::getReader(
374 m_scriptState.get(), stream(), exceptionState); 374 m_scriptState.get(), stream(), exceptionState);
375 return new BytesConsumerForDataConsumerHandle( 375 return new ReadableStreamBytesConsumer(m_scriptState.get(), reader);
376 m_scriptState->getExecutionContext(),
377 ReadableStreamDataConsumerHandle::create(m_scriptState.get(), reader));
378 } 376 }
379 // We need to call these before calling closeAndLockAndDisturb. 377 // We need to call these before calling closeAndLockAndDisturb.
380 const bool isClosed = isStreamClosed(); 378 const bool isClosed = isStreamClosed();
381 const bool isErrored = isStreamErrored(); 379 const bool isErrored = isStreamErrored();
382 BytesConsumer* consumer = m_consumer.release(); 380 BytesConsumer* consumer = m_consumer.release();
383 381
384 closeAndLockAndDisturb(); 382 closeAndLockAndDisturb();
385 383
386 if (isClosed) { 384 if (isClosed) {
387 // Note that the stream cannot be "draining", because it doesn't have 385 // Note that the stream cannot be "draining", because it doesn't have
388 // the internal buffer. 386 // the internal buffer.
389 return new BytesConsumerForDataConsumerHandle( 387 return new BytesConsumerForDataConsumerHandle(
390 m_scriptState->getExecutionContext(), 388 m_scriptState->getExecutionContext(),
391 createFetchDataConsumerHandleFromWebHandle( 389 createFetchDataConsumerHandleFromWebHandle(
392 createDoneDataConsumerHandle())); 390 createDoneDataConsumerHandle()));
393 } 391 }
394 if (isErrored) 392 if (isErrored)
395 return new BytesConsumerForDataConsumerHandle( 393 return new BytesConsumerForDataConsumerHandle(
396 m_scriptState->getExecutionContext(), 394 m_scriptState->getExecutionContext(),
397 createFetchDataConsumerHandleFromWebHandle( 395 createFetchDataConsumerHandleFromWebHandle(
398 createUnexpectedErrorDataConsumerHandle())); 396 createUnexpectedErrorDataConsumerHandle()));
399 397
400 DCHECK(consumer); 398 DCHECK(consumer);
401 consumer->clearClient(); 399 consumer->clearClient();
402 return consumer; 400 return consumer;
403 } 401 }
404 402
405 } // namespace blink 403 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698