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

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

Issue 2392823002: Remove create[Done|UnexpectedError]DataConsumerHandle (Closed)
Patch Set: fix 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"
16 #include "modules/fetch/DataConsumerHandleUtil.h"
17 #include "modules/fetch/ReadableStreamBytesConsumer.h" 15 #include "modules/fetch/ReadableStreamBytesConsumer.h"
18 #include "platform/blob/BlobData.h" 16 #include "platform/blob/BlobData.h"
19 #include "platform/network/EncodedFormData.h" 17 #include "platform/network/EncodedFormData.h"
20 #include <memory> 18 #include <memory>
21 19
22 namespace blink { 20 namespace blink {
23 21
24 class BodyStreamBuffer::LoaderClient final 22 class BodyStreamBuffer::LoaderClient final
25 : public GarbageCollectedFinalized<LoaderClient>, 23 : public GarbageCollectedFinalized<LoaderClient>,
26 public ActiveDOMObject, 24 public ActiveDOMObject,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 FetchDataLoader::Client::trace(visitor); 67 FetchDataLoader::Client::trace(visitor);
70 } 68 }
71 69
72 private: 70 private:
73 void stop() override { m_buffer->stopLoading(); } 71 void stop() override { m_buffer->stopLoading(); }
74 72
75 Member<BodyStreamBuffer> m_buffer; 73 Member<BodyStreamBuffer> m_buffer;
76 Member<FetchDataLoader::Client> m_client; 74 Member<FetchDataLoader::Client> m_client;
77 }; 75 };
78 76
79 BodyStreamBuffer::BodyStreamBuffer(
80 ScriptState* scriptState,
81 std::unique_ptr<FetchDataConsumerHandle> handle)
82 : BodyStreamBuffer(scriptState,
83 new BytesConsumerForDataConsumerHandle(
84 scriptState->getExecutionContext(),
85 std::move(handle))) {}
86
87 BodyStreamBuffer::BodyStreamBuffer(ScriptState* scriptState, 77 BodyStreamBuffer::BodyStreamBuffer(ScriptState* scriptState,
88 BytesConsumer* consumer) 78 BytesConsumer* consumer)
89 : UnderlyingSourceBase(scriptState), 79 : UnderlyingSourceBase(scriptState),
90 m_scriptState(scriptState), 80 m_scriptState(scriptState),
91 m_consumer(consumer), 81 m_consumer(consumer),
92 m_madeFromReadableStream(false) { 82 m_madeFromReadableStream(false) {
93 v8::Local<v8::Value> bodyValue = toV8(this, scriptState); 83 v8::Local<v8::Value> bodyValue = toV8(this, scriptState);
94 DCHECK(!bodyValue.IsEmpty()); 84 DCHECK(!bodyValue.IsEmpty());
95 DCHECK(bodyValue->IsObject()); 85 DCHECK(bodyValue->IsObject());
96 v8::Local<v8::Object> body = bodyValue.As<v8::Object>(); 86 v8::Local<v8::Object> body = bodyValue.As<v8::Object>();
97 87
98 ScriptValue readableStream = ReadableStreamOperations::createReadableStream( 88 ScriptValue readableStream = ReadableStreamOperations::createReadableStream(
99 scriptState, this, 89 scriptState, this,
100 ReadableStreamOperations::createCountQueuingStrategy(scriptState, 0)); 90 ReadableStreamOperations::createCountQueuingStrategy(scriptState, 0));
101 DCHECK(!readableStream.isEmpty()); 91 DCHECK(!readableStream.isEmpty());
102 V8HiddenValue::setHiddenValue( 92 V8HiddenValue::setHiddenValue(
103 scriptState, body, 93 scriptState, body,
104 V8HiddenValue::internalBodyStream(scriptState->isolate()), 94 V8HiddenValue::internalBodyStream(scriptState->isolate()),
105 readableStream.v8Value()); 95 readableStream.v8Value());
106 m_consumer->setClient(this); 96 m_consumer->setClient(this);
97 onStateChange();
107 } 98 }
108 99
109 BodyStreamBuffer::BodyStreamBuffer(ScriptState* scriptState, ScriptValue stream) 100 BodyStreamBuffer::BodyStreamBuffer(ScriptState* scriptState, ScriptValue stream)
110 : UnderlyingSourceBase(scriptState), 101 : UnderlyingSourceBase(scriptState),
111 m_scriptState(scriptState), 102 m_scriptState(scriptState),
112 m_madeFromReadableStream(true) { 103 m_madeFromReadableStream(true) {
113 DCHECK(ReadableStreamOperations::isReadableStream(scriptState, stream)); 104 DCHECK(ReadableStreamOperations::isReadableStream(scriptState, stream));
114 v8::Local<v8::Value> bodyValue = toV8(this, scriptState); 105 v8::Local<v8::Value> bodyValue = toV8(this, scriptState);
115 DCHECK(!bodyValue.IsEmpty()); 106 DCHECK(!bodyValue.IsEmpty());
116 DCHECK(bodyValue->IsObject()); 107 DCHECK(bodyValue->IsObject());
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 // We need to call these before calling closeAndLockAndDisturb. 368 // We need to call these before calling closeAndLockAndDisturb.
378 const bool isClosed = isStreamClosed(); 369 const bool isClosed = isStreamClosed();
379 const bool isErrored = isStreamErrored(); 370 const bool isErrored = isStreamErrored();
380 BytesConsumer* consumer = m_consumer.release(); 371 BytesConsumer* consumer = m_consumer.release();
381 372
382 closeAndLockAndDisturb(); 373 closeAndLockAndDisturb();
383 374
384 if (isClosed) { 375 if (isClosed) {
385 // Note that the stream cannot be "draining", because it doesn't have 376 // Note that the stream cannot be "draining", because it doesn't have
386 // the internal buffer. 377 // the internal buffer.
387 return new BytesConsumerForDataConsumerHandle( 378 return BytesConsumer::createClosed();
388 m_scriptState->getExecutionContext(),
389 createFetchDataConsumerHandleFromWebHandle(
390 createDoneDataConsumerHandle()));
391 } 379 }
392 if (isErrored) 380 if (isErrored)
393 return new BytesConsumerForDataConsumerHandle( 381 return BytesConsumer::createErrored(BytesConsumer::Error("error"));
394 m_scriptState->getExecutionContext(),
395 createFetchDataConsumerHandleFromWebHandle(
396 createUnexpectedErrorDataConsumerHandle()));
397 382
398 DCHECK(consumer); 383 DCHECK(consumer);
399 consumer->clearClient(); 384 consumer->clearClient();
400 return consumer; 385 return consumer;
401 } 386 }
402 387
403 } // namespace blink 388 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698