| 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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 m_destination2->notify(); | 306 m_destination2->notify(); |
| 307 } | 307 } |
| 308 | 308 |
| 309 Member<BytesConsumer> m_src; | 309 Member<BytesConsumer> m_src; |
| 310 Member<Destination> m_destination1; | 310 Member<Destination> m_destination1; |
| 311 Member<Destination> m_destination2; | 311 Member<Destination> m_destination2; |
| 312 }; | 312 }; |
| 313 | 313 |
| 314 } // namespace | 314 } // namespace |
| 315 | 315 |
| 316 BytesConsumer::Result BytesConsumer::read(char* buffer, size_t size, size_t* rea
dSize) | |
| 317 { | |
| 318 *readSize = 0; | |
| 319 const char* src = nullptr; | |
| 320 size_t available; | |
| 321 Result r = beginRead(&src, &available); | |
| 322 if (r != Result::Ok) | |
| 323 return r; | |
| 324 *readSize = std::min(available, size); | |
| 325 memcpy(buffer, src, *readSize); | |
| 326 auto result = endRead(*readSize); | |
| 327 if (result != BytesConsumer::Result::Ok) | |
| 328 *readSize = 0; | |
| 329 return result; | |
| 330 } | |
| 331 | |
| 332 void BytesConsumer::tee(ExecutionContext* executionContext, BytesConsumer* src,
BytesConsumer** dest1, BytesConsumer** dest2) | 316 void BytesConsumer::tee(ExecutionContext* executionContext, BytesConsumer* src,
BytesConsumer** dest1, BytesConsumer** dest2) |
| 333 { | 317 { |
| 334 RefPtr<BlobDataHandle> blobDataHandle = src->drainAsBlobDataHandle(BlobSizeP
olicy::AllowBlobWithInvalidSize); | 318 RefPtr<BlobDataHandle> blobDataHandle = src->drainAsBlobDataHandle(BlobSizeP
olicy::AllowBlobWithInvalidSize); |
| 335 if (blobDataHandle) { | 319 if (blobDataHandle) { |
| 336 // Register a client in order to be consistent. | 320 // Register a client in order to be consistent. |
| 337 src->setClient(new NoopClient); | 321 src->setClient(new NoopClient); |
| 338 // TODO(yhirano): Do not use FetchBlobDataConsumerHandle. | 322 // TODO(yhirano): Do not use FetchBlobDataConsumerHandle. |
| 339 *dest1 = new BytesConsumerForDataConsumerHandle(executionContext, FetchB
lobDataConsumerHandle::create(executionContext, blobDataHandle)); | 323 *dest1 = new BytesConsumerForDataConsumerHandle(executionContext, FetchB
lobDataConsumerHandle::create(executionContext, blobDataHandle)); |
| 340 *dest2 = new BytesConsumerForDataConsumerHandle(executionContext, FetchB
lobDataConsumerHandle::create(executionContext, blobDataHandle)); | 324 *dest2 = new BytesConsumerForDataConsumerHandle(executionContext, FetchB
lobDataConsumerHandle::create(executionContext, blobDataHandle)); |
| 341 return; | 325 return; |
| 342 } | 326 } |
| 343 | 327 |
| 344 Tee* tee = new Tee(executionContext, src); | 328 Tee* tee = new Tee(executionContext, src); |
| 345 *dest1 = tee->destination1(); | 329 *dest1 = tee->destination1(); |
| 346 *dest2 = tee->destination2(); | 330 *dest2 = tee->destination2(); |
| 347 } | 331 } |
| 348 | 332 |
| 349 } // namespace blink | 333 } // namespace blink |
| OLD | NEW |