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

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

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

Powered by Google App Engine
This is Rietveld 408576698