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

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

Issue 2351643004: BytesConsumer::endRead can return Done (Closed)
Patch Set: fix Created 4 years, 3 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/fetch/BytesConsumer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 m_consumer = nullptr; 304 m_consumer = nullptr;
305 } 305 }
306 } 306 }
307 307
308 void BodyStreamBuffer::processData() 308 void BodyStreamBuffer::processData()
309 { 309 {
310 DCHECK(m_consumer); 310 DCHECK(m_consumer);
311 while (m_streamNeedsMore) { 311 while (m_streamNeedsMore) {
312 const char* buffer = nullptr; 312 const char* buffer = nullptr;
313 size_t available = 0; 313 size_t available = 0;
314 314 auto result = m_consumer->beginRead(&buffer, &available);
315 switch (m_consumer->beginRead(&buffer, &available)) { 315 if (result == BytesConsumer::Result::ShouldWait)
316 return;
317 DOMUint8Array* array = nullptr;
318 if (result == BytesConsumer::Result::Ok) {
319 array = DOMUint8Array::create(reinterpret_cast<const unsigned char*> (buffer), available);
320 result = m_consumer->endRead(available);
321 }
322 switch (result) {
316 case BytesConsumer::Result::Ok: { 323 case BytesConsumer::Result::Ok: {
317 DOMUint8Array* array = DOMUint8Array::create(reinterpret_cast<const unsigned char*>(buffer), available); 324 DCHECK(array);
318 if (m_consumer->endRead(available) != BytesConsumer::Result::Ok) {
319 error();
320 return;
321 }
322 // Clear m_streamNeedsMore in order to detect a pull call. 325 // Clear m_streamNeedsMore in order to detect a pull call.
323 m_streamNeedsMore = false; 326 m_streamNeedsMore = false;
324 controller()->enqueue(array); 327 controller()->enqueue(array);
325 // If m_streamNeedsMore is true, it means that pull is called and 328 // If m_streamNeedsMore is true, it means that pull is called and
326 // the stream needs more data even if the desired size is not 329 // the stream needs more data even if the desired size is not
327 // positive. 330 // positive.
328 if (!m_streamNeedsMore) 331 if (!m_streamNeedsMore)
329 m_streamNeedsMore = controller()->desiredSize() > 0; 332 m_streamNeedsMore = controller()->desiredSize() > 0;
330 break; 333 break;
331 } 334 }
332 case BytesConsumer::Result::ShouldWait: 335 case BytesConsumer::Result::ShouldWait:
336 NOTREACHED();
333 return; 337 return;
334 case BytesConsumer::Result::Done: 338 case BytesConsumer::Result::Done:
335 close(); 339 close();
336 return; 340 return;
337 case BytesConsumer::Result::Error: 341 case BytesConsumer::Result::Error:
338 error(); 342 error();
339 return; 343 return;
340 } 344 }
341 } 345 }
342 } 346 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 } 390 }
387 if (isErrored) 391 if (isErrored)
388 return new BytesConsumerForDataConsumerHandle(m_scriptState->getExecutio nContext(), createFetchDataConsumerHandleFromWebHandle(createUnexpectedErrorData ConsumerHandle())); 392 return new BytesConsumerForDataConsumerHandle(m_scriptState->getExecutio nContext(), createFetchDataConsumerHandleFromWebHandle(createUnexpectedErrorData ConsumerHandle()));
389 393
390 DCHECK(consumer); 394 DCHECK(consumer);
391 consumer->clearClient(); 395 consumer->clearClient();
392 return consumer; 396 return consumer;
393 } 397 }
394 398
395 } // namespace blink 399 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/fetch/BytesConsumer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698