| 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 "public/platform/WebDataConsumerHandle.h" | 5 #include "public/platform/WebDataConsumerHandle.h" |
| 6 | 6 |
| 7 #include "platform/heap/Handle.h" | 7 #include "platform/heap/Handle.h" |
| 8 #include "wtf/PtrUtil.h" | 8 #include "wtf/PtrUtil.h" |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <string.h> | 11 #include <string.h> |
| 12 | 12 |
| 13 namespace blink { | 13 namespace blink { |
| 14 | 14 |
| 15 WebDataConsumerHandle::WebDataConsumerHandle() | 15 WebDataConsumerHandle::WebDataConsumerHandle() |
| 16 { | 16 { |
| 17 ASSERT(ThreadState::current()); | 17 ASSERT(ThreadState::current()); |
| 18 } | 18 } |
| 19 | 19 |
| 20 WebDataConsumerHandle::~WebDataConsumerHandle() | 20 WebDataConsumerHandle::~WebDataConsumerHandle() |
| 21 { | 21 { |
| 22 ASSERT(ThreadState::current()); | 22 ASSERT(ThreadState::current()); |
| 23 } | 23 } |
| 24 | 24 |
| 25 std::unique_ptr<WebDataConsumerHandle::Reader> WebDataConsumerHandle::obtainRead
er(WebDataConsumerHandle::Client* client) | |
| 26 { | |
| 27 ASSERT(ThreadState::current()); | |
| 28 return wrapUnique(obtainReaderInternal(client)); | |
| 29 } | |
| 30 | |
| 31 WebDataConsumerHandle::Result WebDataConsumerHandle::Reader::read(void* data, si
ze_t size, Flags flags, size_t* readSize) | 25 WebDataConsumerHandle::Result WebDataConsumerHandle::Reader::read(void* data, si
ze_t size, Flags flags, size_t* readSize) |
| 32 { | 26 { |
| 33 *readSize = 0; | 27 *readSize = 0; |
| 34 const void* src = nullptr; | 28 const void* src = nullptr; |
| 35 size_t available; | 29 size_t available; |
| 36 Result r = beginRead(&src, flags, &available); | 30 Result r = beginRead(&src, flags, &available); |
| 37 if (r != WebDataConsumerHandle::Ok) | 31 if (r != WebDataConsumerHandle::Ok) |
| 38 return r; | 32 return r; |
| 39 *readSize = std::min(available, size); | 33 *readSize = std::min(available, size); |
| 40 memcpy(data, src, *readSize); | 34 memcpy(data, src, *readSize); |
| 41 return endRead(*readSize); | 35 return endRead(*readSize); |
| 42 } | 36 } |
| 43 | 37 |
| 44 } // namespace blink | 38 } // namespace blink |
| 45 | |
| OLD | NEW |