OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/child/web_data_consumer_handle_impl.h" | 5 #include "content/child/web_data_consumer_handle_impl.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 #include <utility> | 10 #include <utility> |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 size_t size, | 49 size_t size, |
50 Flags flags, | 50 Flags flags, |
51 size_t* read_size) { | 51 size_t* read_size) { |
52 // We need this variable definition to avoid a link error. | 52 // We need this variable definition to avoid a link error. |
53 const Flags kNone = FlagNone; | 53 const Flags kNone = FlagNone; |
54 DCHECK_EQ(flags, kNone); | 54 DCHECK_EQ(flags, kNone); |
55 DCHECK_LE(size, std::numeric_limits<uint32_t>::max()); | 55 DCHECK_LE(size, std::numeric_limits<uint32_t>::max()); |
56 | 56 |
57 *read_size = 0; | 57 *read_size = 0; |
58 | 58 |
| 59 if (!size) { |
| 60 // Even if there is unread data available, mojo::ReadDataRaw() returns |
| 61 // FAILED_PRECONDITION when |size| is 0 and the producer handle was closed. |
| 62 // But in this case, WebDataConsumerHandle::Reader::read() must return Ok. |
| 63 // So we use mojo::Wait() with 0 deadline to check whether readable or not. |
| 64 return HandleReadResult(mojo::Wait( |
| 65 context_->handle().get(), MOJO_HANDLE_SIGNAL_READABLE, 0, nullptr)); |
| 66 } |
| 67 |
59 uint32_t size_to_pass = size; | 68 uint32_t size_to_pass = size; |
60 MojoReadDataFlags flags_to_pass = MOJO_READ_DATA_FLAG_NONE; | 69 MojoReadDataFlags flags_to_pass = MOJO_READ_DATA_FLAG_NONE; |
61 MojoResult rv = mojo::ReadDataRaw(context_->handle().get(), data, | 70 MojoResult rv = mojo::ReadDataRaw(context_->handle().get(), data, |
62 &size_to_pass, flags_to_pass); | 71 &size_to_pass, flags_to_pass); |
63 if (rv == MOJO_RESULT_OK) | 72 if (rv == MOJO_RESULT_OK) |
64 *read_size = size_to_pass; | 73 *read_size = size_to_pass; |
65 | 74 |
66 return HandleReadResult(rv); | 75 return HandleReadResult(rv); |
67 } | 76 } |
68 | 77 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 std::unique_ptr<blink::WebDataConsumerHandle::Reader> | 138 std::unique_ptr<blink::WebDataConsumerHandle::Reader> |
130 WebDataConsumerHandleImpl::obtainReader(Client* client) { | 139 WebDataConsumerHandleImpl::obtainReader(Client* client) { |
131 return base::WrapUnique(new ReaderImpl(context_, client)); | 140 return base::WrapUnique(new ReaderImpl(context_, client)); |
132 } | 141 } |
133 | 142 |
134 const char* WebDataConsumerHandleImpl::debugName() const { | 143 const char* WebDataConsumerHandleImpl::debugName() const { |
135 return "WebDataConsumerHandleImpl"; | 144 return "WebDataConsumerHandleImpl"; |
136 } | 145 } |
137 | 146 |
138 } // namespace content | 147 } // namespace content |
OLD | NEW |