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