| 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 "ppapi/proxy/udp_socket_filter.h" | 5 #include "ppapi/proxy/udp_socket_filter.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cstring> | 8 #include <cstring> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "ppapi/c/pp_errors.h" | 13 #include "ppapi/c/pp_errors.h" |
| 14 #include "ppapi/proxy/error_conversion.h" | 14 #include "ppapi/proxy/error_conversion.h" |
| 15 #include "ppapi/proxy/plugin_globals.h" | 15 #include "ppapi/proxy/plugin_globals.h" |
| 16 #include "ppapi/proxy/ppapi_messages.h" | 16 #include "ppapi/proxy/ppapi_messages.h" |
| 17 #include "ppapi/proxy/udp_socket_resource_constants.h" |
| 17 #include "ppapi/thunk/enter.h" | 18 #include "ppapi/thunk/enter.h" |
| 18 #include "ppapi/thunk/resource_creation_api.h" | 19 #include "ppapi/thunk/resource_creation_api.h" |
| 19 | 20 |
| 20 namespace ppapi { | 21 namespace ppapi { |
| 21 namespace proxy { | 22 namespace proxy { |
| 22 | 23 |
| 23 const int32_t UDPSocketFilter::kMaxReadSize = 128 * 1024; | |
| 24 const int32_t UDPSocketFilter::kMaxReceiveBufferSize = | |
| 25 1024 * UDPSocketFilter::kMaxReadSize; | |
| 26 const size_t UDPSocketFilter::kPluginReceiveBufferSlots = 32u; | |
| 27 | |
| 28 namespace { | 24 namespace { |
| 29 | 25 |
| 30 int32_t SetRecvFromOutput(PP_Instance pp_instance, | 26 int32_t SetRecvFromOutput(PP_Instance pp_instance, |
| 31 const std::unique_ptr<std::string>& data, | 27 const std::unique_ptr<std::string>& data, |
| 32 const PP_NetAddress_Private& addr, | 28 const PP_NetAddress_Private& addr, |
| 33 char* output_buffer, | 29 char* output_buffer, |
| 34 int32_t num_bytes, | 30 int32_t num_bytes, |
| 35 PP_Resource* output_addr, | 31 PP_Resource* output_addr, |
| 36 int32_t browser_result) { | 32 int32_t browser_result) { |
| 37 ProxyLock::AssertAcquired(); | 33 ProxyLock::AssertAcquired(); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 UDPSocketFilter::RecvQueue::~RecvQueue() { | 145 UDPSocketFilter::RecvQueue::~RecvQueue() { |
| 150 if (TrackedCallback::IsPending(recvfrom_callback_)) | 146 if (TrackedCallback::IsPending(recvfrom_callback_)) |
| 151 recvfrom_callback_->PostAbort(); | 147 recvfrom_callback_->PostAbort(); |
| 152 } | 148 } |
| 153 | 149 |
| 154 void UDPSocketFilter::RecvQueue::DataReceivedOnIOThread( | 150 void UDPSocketFilter::RecvQueue::DataReceivedOnIOThread( |
| 155 int32_t result, | 151 int32_t result, |
| 156 const std::string& data, | 152 const std::string& data, |
| 157 const PP_NetAddress_Private& addr) { | 153 const PP_NetAddress_Private& addr) { |
| 158 DCHECK(PluginGlobals::Get()->ipc_task_runner()->RunsTasksOnCurrentThread()); | 154 DCHECK(PluginGlobals::Get()->ipc_task_runner()->RunsTasksOnCurrentThread()); |
| 159 DCHECK_LT(recv_buffers_.size(), UDPSocketFilter::kPluginReceiveBufferSlots); | 155 DCHECK_LT(recv_buffers_.size(), |
| 156 UDPSocketResourceConstants::kPluginReceiveBufferSlots); |
| 160 | 157 |
| 161 if (!TrackedCallback::IsPending(recvfrom_callback_) || !read_buffer_) { | 158 if (!TrackedCallback::IsPending(recvfrom_callback_) || !read_buffer_) { |
| 162 recv_buffers_.push(RecvBuffer()); | 159 recv_buffers_.push(RecvBuffer()); |
| 163 RecvBuffer& back = recv_buffers_.back(); | 160 RecvBuffer& back = recv_buffers_.back(); |
| 164 back.result = result; | 161 back.result = result; |
| 165 back.data = data; | 162 back.data = data; |
| 166 back.addr = addr; | 163 back.addr = addr; |
| 167 return; | 164 return; |
| 168 } | 165 } |
| 169 DCHECK_EQ(recv_buffers_.size(), 0u); | 166 DCHECK_EQ(recv_buffers_.size(), 0u); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 PP_Resource* addr_out, | 206 PP_Resource* addr_out, |
| 210 const scoped_refptr<TrackedCallback>& callback) { | 207 const scoped_refptr<TrackedCallback>& callback) { |
| 211 ProxyLock::AssertAcquired(); | 208 ProxyLock::AssertAcquired(); |
| 212 if (!buffer_out || num_bytes <= 0) | 209 if (!buffer_out || num_bytes <= 0) |
| 213 return PP_ERROR_BADARGUMENT; | 210 return PP_ERROR_BADARGUMENT; |
| 214 if (TrackedCallback::IsPending(recvfrom_callback_)) | 211 if (TrackedCallback::IsPending(recvfrom_callback_)) |
| 215 return PP_ERROR_INPROGRESS; | 212 return PP_ERROR_INPROGRESS; |
| 216 | 213 |
| 217 if (recv_buffers_.empty()) { | 214 if (recv_buffers_.empty()) { |
| 218 read_buffer_ = buffer_out; | 215 read_buffer_ = buffer_out; |
| 219 bytes_to_read_ = std::min(num_bytes, UDPSocketFilter::kMaxReadSize); | 216 bytes_to_read_ = |
| 217 std::min(num_bytes, UDPSocketResourceConstants::kMaxReadSize); |
| 220 recvfrom_addr_resource_ = addr_out; | 218 recvfrom_addr_resource_ = addr_out; |
| 221 recvfrom_callback_ = callback; | 219 recvfrom_callback_ = callback; |
| 222 return PP_OK_COMPLETIONPENDING; | 220 return PP_OK_COMPLETIONPENDING; |
| 223 } else { | 221 } else { |
| 224 RecvBuffer& front = recv_buffers_.front(); | 222 RecvBuffer& front = recv_buffers_.front(); |
| 225 | 223 |
| 226 if (static_cast<size_t>(num_bytes) < front.data.size()) | 224 if (static_cast<size_t>(num_bytes) < front.data.size()) |
| 227 return PP_ERROR_MESSAGE_TOO_BIG; | 225 return PP_ERROR_MESSAGE_TOO_BIG; |
| 228 | 226 |
| 229 int32_t result = static_cast<int32_t>(front.data.size()); | 227 int32_t result = static_cast<int32_t>(front.data.size()); |
| 230 std::unique_ptr<std::string> data_to_pass(new std::string); | 228 std::unique_ptr<std::string> data_to_pass(new std::string); |
| 231 data_to_pass->swap(front.data); | 229 data_to_pass->swap(front.data); |
| 232 SetRecvFromOutput(pp_instance_, std::move(data_to_pass), front.addr, | 230 SetRecvFromOutput(pp_instance_, std::move(data_to_pass), front.addr, |
| 233 buffer_out, num_bytes, addr_out, PP_OK); | 231 buffer_out, num_bytes, addr_out, PP_OK); |
| 234 last_recvfrom_addr_ = front.addr; | 232 last_recvfrom_addr_ = front.addr; |
| 235 recv_buffers_.pop(); | 233 recv_buffers_.pop(); |
| 236 slot_available_callback_.Run(); | 234 slot_available_callback_.Run(); |
| 237 | 235 |
| 238 return result; | 236 return result; |
| 239 } | 237 } |
| 240 } | 238 } |
| 241 | 239 |
| 242 PP_NetAddress_Private UDPSocketFilter::RecvQueue::GetLastAddrPrivate() const { | 240 PP_NetAddress_Private UDPSocketFilter::RecvQueue::GetLastAddrPrivate() const { |
| 243 CHECK(private_api_); | 241 CHECK(private_api_); |
| 244 return last_recvfrom_addr_; | 242 return last_recvfrom_addr_; |
| 245 } | 243 } |
| 246 | 244 |
| 247 } // namespace proxy | 245 } // namespace proxy |
| 248 } // namespace ppapi | 246 } // namespace ppapi |
| OLD | NEW |