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

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

Issue 2671213003: BodyStreamBuffer should take care the case where endRead returns Done (Closed)
Patch Set: fix Created 3 years, 10 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 | « third_party/WebKit/LayoutTests/http/tests/fetch/script-tests/response.js ('k') | no next file » | 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 "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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 auto result = m_consumer->beginRead(&buffer, &available); 309 auto result = m_consumer->beginRead(&buffer, &available);
310 if (result == BytesConsumer::Result::ShouldWait) 310 if (result == BytesConsumer::Result::ShouldWait)
311 return; 311 return;
312 DOMUint8Array* array = nullptr; 312 DOMUint8Array* array = nullptr;
313 if (result == BytesConsumer::Result::Ok) { 313 if (result == BytesConsumer::Result::Ok) {
314 array = DOMUint8Array::create( 314 array = DOMUint8Array::create(
315 reinterpret_cast<const unsigned char*>(buffer), available); 315 reinterpret_cast<const unsigned char*>(buffer), available);
316 result = m_consumer->endRead(available); 316 result = m_consumer->endRead(available);
317 } 317 }
318 switch (result) { 318 switch (result) {
319 case BytesConsumer::Result::Ok: { 319 case BytesConsumer::Result::Ok:
320 DCHECK(array); 320 case BytesConsumer::Result::Done:
321 // Clear m_streamNeedsMore in order to detect a pull call. 321 if (array) {
322 m_streamNeedsMore = false; 322 // Clear m_streamNeedsMore in order to detect a pull call.
323 controller()->enqueue(array); 323 m_streamNeedsMore = false;
324 controller()->enqueue(array);
325 }
326 if (result == BytesConsumer::Result::Done) {
327 close();
328 return;
329 }
324 // If m_streamNeedsMore is true, it means that pull is called and 330 // If m_streamNeedsMore is true, it means that pull is called and
325 // the stream needs more data even if the desired size is not 331 // the stream needs more data even if the desired size is not
326 // positive. 332 // positive.
327 if (!m_streamNeedsMore) 333 if (!m_streamNeedsMore)
328 m_streamNeedsMore = controller()->desiredSize() > 0; 334 m_streamNeedsMore = controller()->desiredSize() > 0;
329 break; 335 break;
330 }
331 case BytesConsumer::Result::ShouldWait: 336 case BytesConsumer::Result::ShouldWait:
332 NOTREACHED(); 337 NOTREACHED();
333 return; 338 return;
334 case BytesConsumer::Result::Done:
335 close();
336 return;
337 case BytesConsumer::Result::Error: 339 case BytesConsumer::Result::Error:
338 error(); 340 error();
339 return; 341 return;
340 } 342 }
341 } 343 }
342 } 344 }
343 345
344 void BodyStreamBuffer::endLoading() { 346 void BodyStreamBuffer::endLoading() {
345 ASSERT(m_loader); 347 ASSERT(m_loader);
346 m_loader = nullptr; 348 m_loader = nullptr;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 } 386 }
385 if (isErrored) 387 if (isErrored)
386 return BytesConsumer::createErrored(BytesConsumer::Error("error")); 388 return BytesConsumer::createErrored(BytesConsumer::Error("error"));
387 389
388 DCHECK(consumer); 390 DCHECK(consumer);
389 consumer->clearClient(); 391 consumer->clearClient();
390 return consumer; 392 return consumer;
391 } 393 }
392 394
393 } // namespace blink 395 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/http/tests/fetch/script-tests/response.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698