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

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

Issue 2080623002: Revert "Remove OwnPtr from Blink." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 "bindings/core/v8/WorkerOrWorkletScriptController.h" 9 #include "bindings/core/v8/WorkerOrWorkletScriptController.h"
10 #include "core/dom/DOMArrayBuffer.h" 10 #include "core/dom/DOMArrayBuffer.h"
11 #include "core/dom/DOMTypedArray.h" 11 #include "core/dom/DOMTypedArray.h"
12 #include "core/dom/ExceptionCode.h" 12 #include "core/dom/ExceptionCode.h"
13 #include "core/streams/ReadableStreamController.h" 13 #include "core/streams/ReadableStreamController.h"
14 #include "core/streams/ReadableStreamOperations.h" 14 #include "core/streams/ReadableStreamOperations.h"
15 #include "core/workers/WorkerGlobalScope.h" 15 #include "core/workers/WorkerGlobalScope.h"
16 #include "modules/fetch/Body.h" 16 #include "modules/fetch/Body.h"
17 #include "modules/fetch/DataConsumerHandleUtil.h" 17 #include "modules/fetch/DataConsumerHandleUtil.h"
18 #include "modules/fetch/DataConsumerTee.h" 18 #include "modules/fetch/DataConsumerTee.h"
19 #include "modules/fetch/ReadableStreamDataConsumerHandle.h" 19 #include "modules/fetch/ReadableStreamDataConsumerHandle.h"
20 #include "platform/RuntimeEnabledFeatures.h" 20 #include "platform/RuntimeEnabledFeatures.h"
21 #include "platform/blob/BlobData.h" 21 #include "platform/blob/BlobData.h"
22 #include "platform/network/EncodedFormData.h" 22 #include "platform/network/EncodedFormData.h"
23 #include <memory>
24 23
25 namespace blink { 24 namespace blink {
26 25
27 namespace { 26 namespace {
28 27
29 bool isTerminating(ScriptState* scriptState) 28 bool isTerminating(ScriptState* scriptState)
30 { 29 {
31 ExecutionContext* executionContext = scriptState->getExecutionContext(); 30 ExecutionContext* executionContext = scriptState->getExecutionContext();
32 if (!executionContext) 31 if (!executionContext)
33 return true; 32 return true;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 private: 90 private:
92 void stop() override 91 void stop() override
93 { 92 {
94 m_buffer->stopLoading(); 93 m_buffer->stopLoading();
95 } 94 }
96 95
97 Member<BodyStreamBuffer> m_buffer; 96 Member<BodyStreamBuffer> m_buffer;
98 Member<FetchDataLoader::Client> m_client; 97 Member<FetchDataLoader::Client> m_client;
99 }; 98 };
100 99
101 BodyStreamBuffer::BodyStreamBuffer(ScriptState* scriptState, std::unique_ptr<Fet chDataConsumerHandle> handle) 100 BodyStreamBuffer::BodyStreamBuffer(ScriptState* scriptState, PassOwnPtr<FetchDat aConsumerHandle> handle)
102 : UnderlyingSourceBase(scriptState) 101 : UnderlyingSourceBase(scriptState)
103 , m_scriptState(scriptState) 102 , m_scriptState(scriptState)
104 , m_handle(std::move(handle)) 103 , m_handle(std::move(handle))
105 , m_reader(m_handle->obtainReader(this)) 104 , m_reader(m_handle->obtainReader(this))
106 , m_madeFromReadableStream(false) 105 , m_madeFromReadableStream(false)
107 { 106 {
108 if (RuntimeEnabledFeatures::responseBodyWithV8ExtraStreamEnabled()) { 107 if (RuntimeEnabledFeatures::responseBodyWithV8ExtraStreamEnabled()) {
109 ScriptState::Scope scope(scriptState); 108 ScriptState::Scope scope(scriptState);
110 if (isTerminating(scriptState)) { 109 if (isTerminating(scriptState)) {
111 m_reader = nullptr; 110 m_reader = nullptr;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 closeAndLockAndDisturb(); 207 closeAndLockAndDisturb();
209 return formData.release(); 208 return formData.release();
210 } 209 }
211 return nullptr; 210 return nullptr;
212 } 211 }
213 212
214 void BodyStreamBuffer::startLoading(FetchDataLoader* loader, FetchDataLoader::Cl ient* client) 213 void BodyStreamBuffer::startLoading(FetchDataLoader* loader, FetchDataLoader::Cl ient* client)
215 { 214 {
216 ASSERT(!m_loader); 215 ASSERT(!m_loader);
217 ASSERT(m_scriptState->contextIsValid()); 216 ASSERT(m_scriptState->contextIsValid());
218 std::unique_ptr<FetchDataConsumerHandle> handle = releaseHandle(); 217 OwnPtr<FetchDataConsumerHandle> handle = releaseHandle();
219 m_loader = loader; 218 m_loader = loader;
220 loader->start(handle.get(), new LoaderClient(m_scriptState->getExecutionCont ext(), this, client)); 219 loader->start(handle.get(), new LoaderClient(m_scriptState->getExecutionCont ext(), this, client));
221 } 220 }
222 221
223 void BodyStreamBuffer::tee(BodyStreamBuffer** branch1, BodyStreamBuffer** branch 2) 222 void BodyStreamBuffer::tee(BodyStreamBuffer** branch1, BodyStreamBuffer** branch 2)
224 { 223 {
225 DCHECK(!isStreamLocked()); 224 DCHECK(!isStreamLocked());
226 DCHECK(!isStreamDisturbed()); 225 DCHECK(!isStreamDisturbed());
227 *branch1 = nullptr; 226 *branch1 = nullptr;
228 *branch2 = nullptr; 227 *branch2 = nullptr;
229 228
230 if (m_madeFromReadableStream) { 229 if (m_madeFromReadableStream) {
231 ScriptState::Scope scope(m_scriptState.get()); 230 ScriptState::Scope scope(m_scriptState.get());
232 ScriptValue stream1, stream2; 231 ScriptValue stream1, stream2;
233 ReadableStreamOperations::tee(m_scriptState.get(), stream(), &stream1, & stream2); 232 ReadableStreamOperations::tee(m_scriptState.get(), stream(), &stream1, & stream2);
234 *branch1 = new BodyStreamBuffer(m_scriptState.get(), stream1); 233 *branch1 = new BodyStreamBuffer(m_scriptState.get(), stream1);
235 *branch2 = new BodyStreamBuffer(m_scriptState.get(), stream2); 234 *branch2 = new BodyStreamBuffer(m_scriptState.get(), stream2);
236 return; 235 return;
237 } 236 }
238 std::unique_ptr<FetchDataConsumerHandle> handle = releaseHandle(); 237 OwnPtr<FetchDataConsumerHandle> handle = releaseHandle();
239 std::unique_ptr<FetchDataConsumerHandle> handle1, handle2; 238 OwnPtr<FetchDataConsumerHandle> handle1, handle2;
240 DataConsumerTee::create(m_scriptState->getExecutionContext(), std::move(hand le), &handle1, &handle2); 239 DataConsumerTee::create(m_scriptState->getExecutionContext(), std::move(hand le), &handle1, &handle2);
241 *branch1 = new BodyStreamBuffer(m_scriptState.get(), std::move(handle1)); 240 *branch1 = new BodyStreamBuffer(m_scriptState.get(), std::move(handle1));
242 *branch2 = new BodyStreamBuffer(m_scriptState.get(), std::move(handle2)); 241 *branch2 = new BodyStreamBuffer(m_scriptState.get(), std::move(handle2));
243 } 242 }
244 243
245 void BodyStreamBuffer::pullSource() 244 void BodyStreamBuffer::pullSource()
246 { 245 {
247 ASSERT(!m_streamNeedsMore); 246 ASSERT(!m_streamNeedsMore);
248 m_streamNeedsMore = true; 247 m_streamNeedsMore = true;
249 processData(); 248 processData();
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 } 442 }
444 443
445 void BodyStreamBuffer::stopLoading() 444 void BodyStreamBuffer::stopLoading()
446 { 445 {
447 if (!m_loader) 446 if (!m_loader)
448 return; 447 return;
449 m_loader->cancel(); 448 m_loader->cancel();
450 m_loader = nullptr; 449 m_loader = nullptr;
451 } 450 }
452 451
453 std::unique_ptr<FetchDataConsumerHandle> BodyStreamBuffer::releaseHandle() 452 PassOwnPtr<FetchDataConsumerHandle> BodyStreamBuffer::releaseHandle()
454 { 453 {
455 DCHECK(!isStreamLocked()); 454 DCHECK(!isStreamLocked());
456 DCHECK(!isStreamDisturbed()); 455 DCHECK(!isStreamDisturbed());
457 456
458 if (m_madeFromReadableStream) { 457 if (m_madeFromReadableStream) {
459 ScriptState::Scope scope(m_scriptState.get()); 458 ScriptState::Scope scope(m_scriptState.get());
460 // We need to have |reader| alive by some means (as written in 459 // We need to have |reader| alive by some means (as written in
461 // ReadableStreamDataConsumerHandle). Based on the following facts 460 // ReadableStreamDataConsumerHandle). Based on the following facts
462 // - This function is used only from tee and startLoading. 461 // - This function is used only from tee and startLoading.
463 // - This branch cannot be taken when called from tee. 462 // - This branch cannot be taken when called from tee.
464 // - startLoading makes hasPendingActivity return true while loading. 463 // - startLoading makes hasPendingActivity return true while loading.
465 // , we don't need to keep the reader explicitly. 464 // , we don't need to keep the reader explicitly.
466 NonThrowableExceptionState exceptionState; 465 NonThrowableExceptionState exceptionState;
467 ScriptValue reader = ReadableStreamOperations::getReader(m_scriptState.g et(), stream(), exceptionState); 466 ScriptValue reader = ReadableStreamOperations::getReader(m_scriptState.g et(), stream(), exceptionState);
468 return ReadableStreamDataConsumerHandle::create(m_scriptState.get(), rea der); 467 return ReadableStreamDataConsumerHandle::create(m_scriptState.get(), rea der);
469 } 468 }
470 // We need to call these before calling closeAndLockAndDisturb. 469 // We need to call these before calling closeAndLockAndDisturb.
471 const bool isClosed = isStreamClosed(); 470 const bool isClosed = isStreamClosed();
472 const bool isErrored = isStreamErrored(); 471 const bool isErrored = isStreamErrored();
473 std::unique_ptr<FetchDataConsumerHandle> handle = std::move(m_handle); 472 OwnPtr<FetchDataConsumerHandle> handle = std::move(m_handle);
474 473
475 closeAndLockAndDisturb(); 474 closeAndLockAndDisturb();
476 475
477 if (isClosed) { 476 if (isClosed) {
478 // Note that the stream cannot be "draining", because it doesn't have 477 // Note that the stream cannot be "draining", because it doesn't have
479 // the internal buffer. 478 // the internal buffer.
480 return createFetchDataConsumerHandleFromWebHandle(createDoneDataConsumer Handle()); 479 return createFetchDataConsumerHandleFromWebHandle(createDoneDataConsumer Handle());
481 } 480 }
482 if (isErrored) 481 if (isErrored)
483 return createFetchDataConsumerHandleFromWebHandle(createUnexpectedErrorD ataConsumerHandle()); 482 return createFetchDataConsumerHandleFromWebHandle(createUnexpectedErrorD ataConsumerHandle());
484 483
485 DCHECK(handle); 484 DCHECK(handle);
486 return handle; 485 return handle;
487 } 486 }
488 487
489 } // namespace blink 488 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698