| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/BytesConsumer.h" | 5 #include "modules/fetch/BytesConsumer.h" |
| 6 | 6 |
| 7 #include "core/dom/ExecutionContext.h" | 7 #include "core/dom/ExecutionContext.h" |
| 8 #include "core/dom/TaskRunnerHelper.h" | 8 #include "core/dom/TaskRunnerHelper.h" |
| 9 #include "modules/fetch/BytesConsumerForDataConsumerHandle.h" | 9 #include "modules/fetch/BytesConsumerForDataConsumerHandle.h" |
| 10 #include "modules/fetch/FetchBlobDataConsumerHandle.h" | 10 #include "modules/fetch/FetchBlobDataConsumerHandle.h" |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 BytesConsumer::Result BytesConsumer::read(char* buffer, size_t size, size_t* rea
dSize) | 316 BytesConsumer::Result BytesConsumer::read(char* buffer, size_t size, size_t* rea
dSize) |
| 317 { | 317 { |
| 318 *readSize = 0; | 318 *readSize = 0; |
| 319 const char* src = nullptr; | 319 const char* src = nullptr; |
| 320 size_t available; | 320 size_t available; |
| 321 Result r = beginRead(&src, &available); | 321 Result r = beginRead(&src, &available); |
| 322 if (r != Result::Ok) | 322 if (r != Result::Ok) |
| 323 return r; | 323 return r; |
| 324 *readSize = std::min(available, size); | 324 *readSize = std::min(available, size); |
| 325 memcpy(buffer, src, *readSize); | 325 memcpy(buffer, src, *readSize); |
| 326 return endRead(*readSize); | 326 auto result = endRead(*readSize); |
| 327 if (result != BytesConsumer::Result::Ok) |
| 328 *readSize = 0; |
| 329 return result; |
| 327 } | 330 } |
| 328 | 331 |
| 329 void BytesConsumer::tee(ExecutionContext* executionContext, BytesConsumer* src,
BytesConsumer** dest1, BytesConsumer** dest2) | 332 void BytesConsumer::tee(ExecutionContext* executionContext, BytesConsumer* src,
BytesConsumer** dest1, BytesConsumer** dest2) |
| 330 { | 333 { |
| 331 RefPtr<BlobDataHandle> blobDataHandle = src->drainAsBlobDataHandle(BlobSizeP
olicy::AllowBlobWithInvalidSize); | 334 RefPtr<BlobDataHandle> blobDataHandle = src->drainAsBlobDataHandle(BlobSizeP
olicy::AllowBlobWithInvalidSize); |
| 332 if (blobDataHandle) { | 335 if (blobDataHandle) { |
| 333 // Register a client in order to be consistent. | 336 // Register a client in order to be consistent. |
| 334 src->setClient(new NoopClient); | 337 src->setClient(new NoopClient); |
| 335 // TODO(yhirano): Do not use FetchBlobDataConsumerHandle. | 338 // TODO(yhirano): Do not use FetchBlobDataConsumerHandle. |
| 336 *dest1 = new BytesConsumerForDataConsumerHandle(executionContext, FetchB
lobDataConsumerHandle::create(executionContext, blobDataHandle)); | 339 *dest1 = new BytesConsumerForDataConsumerHandle(executionContext, FetchB
lobDataConsumerHandle::create(executionContext, blobDataHandle)); |
| 337 *dest2 = new BytesConsumerForDataConsumerHandle(executionContext, FetchB
lobDataConsumerHandle::create(executionContext, blobDataHandle)); | 340 *dest2 = new BytesConsumerForDataConsumerHandle(executionContext, FetchB
lobDataConsumerHandle::create(executionContext, blobDataHandle)); |
| 338 return; | 341 return; |
| 339 } | 342 } |
| 340 | 343 |
| 341 Tee* tee = new Tee(executionContext, src); | 344 Tee* tee = new Tee(executionContext, src); |
| 342 *dest1 = tee->destination1(); | 345 *dest1 = tee->destination1(); |
| 343 *dest2 = tee->destination2(); | 346 *dest2 = tee->destination2(); |
| 344 } | 347 } |
| 345 | 348 |
| 346 } // namespace blink | 349 } // namespace blink |
| OLD | NEW |