OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "config.h" | 5 #include "config.h" |
6 #include "modules/fetch/FetchBlobDataConsumerHandle.h" | 6 #include "modules/fetch/FetchBlobDataConsumerHandle.h" |
7 | 7 |
8 #include "core/dom/ActiveDOMObject.h" | 8 #include "core/dom/ActiveDOMObject.h" |
9 #include "core/dom/CrossThreadTask.h" | 9 #include "core/dom/CrossThreadTask.h" |
10 #include "core/dom/ExecutionContext.h" | 10 #include "core/dom/ExecutionContext.h" |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 , m_reader(reader) | 356 , m_reader(reader) |
357 , m_notifier(client) { } | 357 , m_notifier(client) { } |
358 ~ReaderImpl() override { } | 358 ~ReaderImpl() override { } |
359 | 359 |
360 Result read(void* data, size_t size, Flags flags, size_t* readSize) over
ride | 360 Result read(void* data, size_t size, Flags flags, size_t* readSize) over
ride |
361 { | 361 { |
362 if (m_readerContext->drained()) | 362 if (m_readerContext->drained()) |
363 return Done; | 363 return Done; |
364 m_readerContext->ensureStartLoader(); | 364 m_readerContext->ensureStartLoader(); |
365 Result r = m_reader->read(data, size, flags, readSize); | 365 Result r = m_reader->read(data, size, flags, readSize); |
366 if (r != ShouldWait) { | 366 if (r != ShouldWait && !(r == Ok && *readSize == 0)) { |
367 // We read non-empty data, so we cannot use the blob data | 367 // We read non-empty data, so we cannot use the blob data |
368 // handle which represents the whole data. | 368 // handle which represents the whole data. |
369 m_readerContext->clearBlobDataHandleForDrain(); | 369 m_readerContext->clearBlobDataHandleForDrain(); |
370 } | 370 } |
371 return r; | 371 return r; |
372 } | 372 } |
373 | 373 |
374 Result beginRead(const void** buffer, Flags flags, size_t* available) ov
erride | 374 Result beginRead(const void** buffer, Flags flags, size_t* available) ov
erride |
375 { | 375 { |
376 if (m_readerContext->drained()) | 376 if (m_readerContext->drained()) |
377 return Done; | 377 return Done; |
378 m_readerContext->ensureStartLoader(); | 378 m_readerContext->ensureStartLoader(); |
379 Result r = m_reader->beginRead(buffer, flags, available); | 379 Result r = m_reader->beginRead(buffer, flags, available); |
380 if (r != ShouldWait) { | 380 if (r != ShouldWait && !(r == Ok && *available == 0)) { |
381 // We read non-empty data, so we cannot use the blob data | 381 // We read non-empty data, so we cannot use the blob data |
382 // handle which represents the whole data. | 382 // handle which represents the whole data. |
383 m_readerContext->clearBlobDataHandleForDrain(); | 383 m_readerContext->clearBlobDataHandleForDrain(); |
384 } | 384 } |
385 return r; | 385 return r; |
386 } | 386 } |
387 | 387 |
388 Result endRead(size_t readSize) override | 388 Result endRead(size_t readSize) override |
389 { | 389 { |
390 return m_reader->endRead(readSize); | 390 return m_reader->endRead(readSize); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 | 471 |
472 return adoptPtr(new FetchBlobDataConsumerHandle(executionContext, blobDataHa
ndle, new DefaultLoaderFactory)); | 472 return adoptPtr(new FetchBlobDataConsumerHandle(executionContext, blobDataHa
ndle, new DefaultLoaderFactory)); |
473 } | 473 } |
474 | 474 |
475 FetchDataConsumerHandle::Reader* FetchBlobDataConsumerHandle::obtainReaderIntern
al(Client* client) | 475 FetchDataConsumerHandle::Reader* FetchBlobDataConsumerHandle::obtainReaderIntern
al(Client* client) |
476 { | 476 { |
477 return m_readerContext->obtainReader(client).leakPtr(); | 477 return m_readerContext->obtainReader(client).leakPtr(); |
478 } | 478 } |
479 | 479 |
480 } // namespace blink | 480 } // namespace blink |
OLD | NEW |