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