| 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 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 , m_reader(reader) | 344 , m_reader(reader) |
| 345 , m_notifier(client) { } | 345 , m_notifier(client) { } |
| 346 ~ReaderImpl() override { } | 346 ~ReaderImpl() override { } |
| 347 | 347 |
| 348 Result read(void* data, size_t size, Flags flags, size_t* readSize) over
ride | 348 Result read(void* data, size_t size, Flags flags, size_t* readSize) over
ride |
| 349 { | 349 { |
| 350 if (m_readerContext->drained()) | 350 if (m_readerContext->drained()) |
| 351 return Done; | 351 return Done; |
| 352 m_readerContext->ensureStartLoader(); | 352 m_readerContext->ensureStartLoader(); |
| 353 Result r = m_reader->read(data, size, flags, readSize); | 353 Result r = m_reader->read(data, size, flags, readSize); |
| 354 if (r != ShouldWait && !(r == Ok && *readSize == 0)) { | 354 if (!(size == 0 && (r == Ok || r == ShouldWait))) { |
| 355 // We read non-empty data, so we cannot use the blob data | 355 // We read non-empty data, so we cannot use the blob data |
| 356 // handle which represents the whole data. | 356 // handle which represents the whole data. |
| 357 m_readerContext->clearBlobDataHandleForDrain(); | 357 m_readerContext->clearBlobDataHandleForDrain(); |
| 358 } | 358 } |
| 359 return r; | 359 return r; |
| 360 } | 360 } |
| 361 | 361 |
| 362 Result beginRead(const void** buffer, Flags flags, size_t* available) ov
erride | 362 Result beginRead(const void** buffer, Flags flags, size_t* available) ov
erride |
| 363 { | 363 { |
| 364 if (m_readerContext->drained()) | 364 if (m_readerContext->drained()) |
| 365 return Done; | 365 return Done; |
| 366 m_readerContext->ensureStartLoader(); | 366 m_readerContext->ensureStartLoader(); |
| 367 Result r = m_reader->beginRead(buffer, flags, available); | 367 m_readerContext->clearBlobDataHandleForDrain(); |
| 368 if (r != ShouldWait && !(r == Ok && *available == 0)) { | 368 return m_reader->beginRead(buffer, flags, available); |
| 369 // We read non-empty data, so we cannot use the blob data | |
| 370 // handle which represents the whole data. | |
| 371 m_readerContext->clearBlobDataHandleForDrain(); | |
| 372 } | |
| 373 return r; | |
| 374 } | 369 } |
| 375 | 370 |
| 376 Result endRead(size_t readSize) override | 371 Result endRead(size_t readSize) override |
| 377 { | 372 { |
| 378 return m_reader->endRead(readSize); | 373 return m_reader->endRead(readSize); |
| 379 } | 374 } |
| 380 | 375 |
| 381 PassRefPtr<BlobDataHandle> drainAsBlobDataHandle(BlobSizePolicy blobSize
Policy) override | 376 PassRefPtr<BlobDataHandle> drainAsBlobDataHandle(BlobSizePolicy blobSize
Policy) override |
| 382 { | 377 { |
| 383 if (!m_readerContext->m_blobDataHandleForDrain) | 378 if (!m_readerContext->m_blobDataHandleForDrain) |
| 384 return nullptr; | 379 return nullptr; |
| 385 if (blobSizePolicy == DisallowBlobWithInvalidSize && m_readerContext
->m_blobDataHandleForDrain->size() == kuint64max) | 380 if (blobSizePolicy == DisallowBlobWithInvalidSize && m_readerContext
->m_blobDataHandleForDrain->size() == kuint64max) |
| 386 return nullptr; | 381 return nullptr; |
| 387 RefPtr<BlobDataHandle> blobDataHandle = m_readerContext->m_blobDataH
andleForDrain; | 382 RefPtr<BlobDataHandle> blobDataHandle = m_readerContext->m_blobDataH
andleForDrain; |
| 388 m_readerContext->setDrained(); | 383 m_readerContext->setDrained(); |
| 389 m_readerContext->clearBlobDataHandleForDrain(); | 384 m_readerContext->clearBlobDataHandleForDrain(); |
| 390 return blobDataHandle.release(); | 385 return blobDataHandle.release(); |
| 391 } | 386 } |
| 392 | 387 |
| 388 PassRefPtr<FormData> drainAsFormData() override |
| 389 { |
| 390 RefPtr<BlobDataHandle> handle = drainAsBlobDataHandle(AllowBlobWithI
nvalidSize); |
| 391 if (!handle) |
| 392 return nullptr; |
| 393 RefPtr<FormData> formData = FormData::create(); |
| 394 formData->appendBlob(handle->uuid(), handle); |
| 395 return formData.release(); |
| 396 } |
| 397 |
| 393 private: | 398 private: |
| 394 RefPtr<ReaderContext> m_readerContext; | 399 RefPtr<ReaderContext> m_readerContext; |
| 395 OwnPtr<WebDataConsumerHandle::Reader> m_reader; | 400 OwnPtr<WebDataConsumerHandle::Reader> m_reader; |
| 396 NotifyOnReaderCreationHelper m_notifier; | 401 NotifyOnReaderCreationHelper m_notifier; |
| 397 }; | 402 }; |
| 398 | 403 |
| 399 ReaderContext(ExecutionContext* executionContext, PassRefPtr<BlobDataHandle>
blobDataHandle, FetchBlobDataConsumerHandle::LoaderFactory* loaderFactory) | 404 ReaderContext(ExecutionContext* executionContext, PassRefPtr<BlobDataHandle>
blobDataHandle, FetchBlobDataConsumerHandle::LoaderFactory* loaderFactory) |
| 400 : m_blobDataHandleForDrain(blobDataHandle) | 405 : m_blobDataHandleForDrain(blobDataHandle) |
| 401 , m_loaderStarted(false) | 406 , m_loaderStarted(false) |
| 402 , m_drained(false) | 407 , m_drained(false) |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 | 465 |
| 461 return adoptPtr(new FetchBlobDataConsumerHandle(executionContext, blobDataHa
ndle, new DefaultLoaderFactory)); | 466 return adoptPtr(new FetchBlobDataConsumerHandle(executionContext, blobDataHa
ndle, new DefaultLoaderFactory)); |
| 462 } | 467 } |
| 463 | 468 |
| 464 FetchDataConsumerHandle::Reader* FetchBlobDataConsumerHandle::obtainReaderIntern
al(Client* client) | 469 FetchDataConsumerHandle::Reader* FetchBlobDataConsumerHandle::obtainReaderIntern
al(Client* client) |
| 465 { | 470 { |
| 466 return m_readerContext->obtainReader(client).leakPtr(); | 471 return m_readerContext->obtainReader(client).leakPtr(); |
| 467 } | 472 } |
| 468 | 473 |
| 469 } // namespace blink | 474 } // namespace blink |
| OLD | NEW |