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

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

Issue 2526293002: [wrapper-tracing] Untangle non-trivial mixin ctors (Closed)
Patch Set: s/new BodyStreamBuffer/BodyStreamBuffer::create/ Created 4 years 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/V8ThrowException.h" 9 #include "bindings/core/v8/V8ThrowException.h"
10 #include "core/dom/DOMArrayBuffer.h" 10 #include "core/dom/DOMArrayBuffer.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 FetchDataLoader::Client::trace(visitor); 68 FetchDataLoader::Client::trace(visitor);
69 } 69 }
70 70
71 private: 71 private:
72 void contextDestroyed() override { m_buffer->stopLoading(); } 72 void contextDestroyed() override { m_buffer->stopLoading(); }
73 73
74 Member<BodyStreamBuffer> m_buffer; 74 Member<BodyStreamBuffer> m_buffer;
75 Member<FetchDataLoader::Client> m_client; 75 Member<FetchDataLoader::Client> m_client;
76 }; 76 };
77 77
78 BodyStreamBuffer* BodyStreamBuffer::create(ScriptState* scriptState,
79 BytesConsumer* consumer) {
80 BodyStreamBuffer* buffer = new BodyStreamBuffer(scriptState, consumer);
81
82 ScriptValue readableStream = ReadableStreamOperations::createReadableStream(
83 scriptState, buffer,
84 ReadableStreamOperations::createCountQueuingStrategy(scriptState, 0));
85 DCHECK(!readableStream.isEmpty());
86
87 v8::Local<v8::Value> bodyValue = toV8(buffer, scriptState);
88 DCHECK(!bodyValue.IsEmpty());
89 DCHECK(bodyValue->IsObject());
90 v8::Local<v8::Object> body = bodyValue.As<v8::Object>();
91 V8HiddenValue::setHiddenValue(
92 scriptState, body,
93 V8HiddenValue::internalBodyStream(scriptState->isolate()),
94 readableStream.v8Value());
95
96 buffer->announceClientToConsumer();
97 return buffer;
98 }
99
100 BodyStreamBuffer* BodyStreamBuffer::create(ScriptState* scriptState,
101 ScriptValue stream) {
102 DCHECK(ReadableStreamOperations::isReadableStream(scriptState, stream));
103
104 BodyStreamBuffer* buffer = new BodyStreamBuffer(scriptState, stream);
105
106 v8::Local<v8::Value> bodyValue = toV8(buffer, scriptState);
107 DCHECK(!bodyValue.IsEmpty());
108 DCHECK(bodyValue->IsObject());
109 v8::Local<v8::Object> body = bodyValue.As<v8::Object>();
110 V8HiddenValue::setHiddenValue(
111 scriptState, body,
112 V8HiddenValue::internalBodyStream(scriptState->isolate()),
113 stream.v8Value());
114 return buffer;
115 }
116
117 void BodyStreamBuffer::announceClientToConsumer() {
118 m_consumer->setClient(this);
119 onStateChange();
120 }
121
78 BodyStreamBuffer::BodyStreamBuffer(ScriptState* scriptState, 122 BodyStreamBuffer::BodyStreamBuffer(ScriptState* scriptState,
79 BytesConsumer* consumer) 123 BytesConsumer* consumer)
80 : UnderlyingSourceBase(scriptState), 124 : UnderlyingSourceBase(scriptState),
81 m_scriptState(scriptState), 125 m_scriptState(scriptState),
82 m_consumer(consumer), 126 m_consumer(consumer),
83 m_madeFromReadableStream(false) { 127 m_madeFromReadableStream(false) {}
84 v8::Local<v8::Value> bodyValue = toV8(this, scriptState);
haraken 2016/11/24 23:36:32 Why do we need to move the contents of the constru
Michael Lippautz 2016/11/25 07:21:26 Thanks for the clarification, makes sense.
85 DCHECK(!bodyValue.IsEmpty());
86 DCHECK(bodyValue->IsObject());
87 v8::Local<v8::Object> body = bodyValue.As<v8::Object>();
88
89 ScriptValue readableStream = ReadableStreamOperations::createReadableStream(
90 scriptState, this,
91 ReadableStreamOperations::createCountQueuingStrategy(scriptState, 0));
92 DCHECK(!readableStream.isEmpty());
93 V8HiddenValue::setHiddenValue(
94 scriptState, body,
95 V8HiddenValue::internalBodyStream(scriptState->isolate()),
96 readableStream.v8Value());
97 m_consumer->setClient(this);
98 onStateChange();
99 }
100 128
101 BodyStreamBuffer::BodyStreamBuffer(ScriptState* scriptState, ScriptValue stream) 129 BodyStreamBuffer::BodyStreamBuffer(ScriptState* scriptState, ScriptValue stream)
102 : UnderlyingSourceBase(scriptState), 130 : UnderlyingSourceBase(scriptState),
103 m_scriptState(scriptState), 131 m_scriptState(scriptState),
104 m_madeFromReadableStream(true) { 132 m_madeFromReadableStream(true) {}
105 DCHECK(ReadableStreamOperations::isReadableStream(scriptState, stream));
106 v8::Local<v8::Value> bodyValue = toV8(this, scriptState);
107 DCHECK(!bodyValue.IsEmpty());
108 DCHECK(bodyValue->IsObject());
109 v8::Local<v8::Object> body = bodyValue.As<v8::Object>();
110
111 V8HiddenValue::setHiddenValue(
112 scriptState, body,
113 V8HiddenValue::internalBodyStream(scriptState->isolate()),
114 stream.v8Value());
115 }
116 133
117 ScriptValue BodyStreamBuffer::stream() { 134 ScriptValue BodyStreamBuffer::stream() {
118 ScriptState::Scope scope(m_scriptState.get()); 135 ScriptState::Scope scope(m_scriptState.get());
119 v8::Local<v8::Value> bodyValue = toV8(this, m_scriptState.get()); 136 v8::Local<v8::Value> bodyValue = toV8(this, m_scriptState.get());
120 DCHECK(!bodyValue.IsEmpty()); 137 DCHECK(!bodyValue.IsEmpty());
121 DCHECK(bodyValue->IsObject()); 138 DCHECK(bodyValue->IsObject());
122 v8::Local<v8::Object> body = bodyValue.As<v8::Object>(); 139 v8::Local<v8::Object> body = bodyValue.As<v8::Object>();
123 return ScriptValue( 140 return ScriptValue(
124 m_scriptState.get(), 141 m_scriptState.get(),
125 V8HiddenValue::getHiddenValue( 142 V8HiddenValue::getHiddenValue(
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 BodyStreamBuffer** branch2) { 194 BodyStreamBuffer** branch2) {
178 DCHECK(!isStreamLocked()); 195 DCHECK(!isStreamLocked());
179 DCHECK(!isStreamDisturbed()); 196 DCHECK(!isStreamDisturbed());
180 *branch1 = nullptr; 197 *branch1 = nullptr;
181 *branch2 = nullptr; 198 *branch2 = nullptr;
182 199
183 if (m_madeFromReadableStream) { 200 if (m_madeFromReadableStream) {
184 ScriptValue stream1, stream2; 201 ScriptValue stream1, stream2;
185 ReadableStreamOperations::tee(m_scriptState.get(), stream(), &stream1, 202 ReadableStreamOperations::tee(m_scriptState.get(), stream(), &stream1,
186 &stream2); 203 &stream2);
187 *branch1 = new BodyStreamBuffer(m_scriptState.get(), stream1); 204 *branch1 = BodyStreamBuffer::create(m_scriptState.get(), stream1);
188 *branch2 = new BodyStreamBuffer(m_scriptState.get(), stream2); 205 *branch2 = BodyStreamBuffer::create(m_scriptState.get(), stream2);
189 return; 206 return;
190 } 207 }
191 BytesConsumer* dest1 = nullptr; 208 BytesConsumer* dest1 = nullptr;
192 BytesConsumer* dest2 = nullptr; 209 BytesConsumer* dest2 = nullptr;
193 BytesConsumer::tee(m_scriptState->getExecutionContext(), releaseHandle(), 210 BytesConsumer::tee(m_scriptState->getExecutionContext(), releaseHandle(),
194 &dest1, &dest2); 211 &dest1, &dest2);
195 *branch1 = new BodyStreamBuffer(m_scriptState.get(), dest1); 212 *branch1 = BodyStreamBuffer::create(m_scriptState.get(), dest1);
196 *branch2 = new BodyStreamBuffer(m_scriptState.get(), dest2); 213 *branch2 = BodyStreamBuffer::create(m_scriptState.get(), dest2);
197 } 214 }
198 215
199 ScriptPromise BodyStreamBuffer::pull(ScriptState* scriptState) { 216 ScriptPromise BodyStreamBuffer::pull(ScriptState* scriptState) {
200 ASSERT(scriptState == m_scriptState.get()); 217 ASSERT(scriptState == m_scriptState.get());
201 if (m_streamNeedsMore) 218 if (m_streamNeedsMore)
202 return ScriptPromise::castUndefined(scriptState); 219 return ScriptPromise::castUndefined(scriptState);
203 m_streamNeedsMore = true; 220 m_streamNeedsMore = true;
204 processData(); 221 processData();
205 return ScriptPromise::castUndefined(scriptState); 222 return ScriptPromise::castUndefined(scriptState);
206 } 223 }
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 } 401 }
385 if (isErrored) 402 if (isErrored)
386 return BytesConsumer::createErrored(BytesConsumer::Error("error")); 403 return BytesConsumer::createErrored(BytesConsumer::Error("error"));
387 404
388 DCHECK(consumer); 405 DCHECK(consumer);
389 consumer->clearClient(); 406 consumer->clearClient();
390 return consumer; 407 return consumer;
391 } 408 }
392 409
393 } // namespace blink 410 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698