| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_resource_base.h" | 5 #include "ppapi/proxy/udp_socket_resource_base.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cstring> | 8 #include <cstring> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 NOTREACHED(); | 84 NOTREACHED(); |
| 85 return PP_ERROR_BADARGUMENT; | 85 return PP_ERROR_BADARGUMENT; |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 | 88 |
| 89 Call<PpapiPluginMsg_UDPSocket_SetOptionReply>( | 89 Call<PpapiPluginMsg_UDPSocket_SetOptionReply>( |
| 90 BROWSER, | 90 BROWSER, |
| 91 PpapiHostMsg_UDPSocket_SetOption(name, option_data), | 91 PpapiHostMsg_UDPSocket_SetOption(name, option_data), |
| 92 base::Bind(&UDPSocketResourceBase::OnPluginMsgSetOptionReply, | 92 base::Bind(&UDPSocketResourceBase::OnPluginMsgSetOptionReply, |
| 93 base::Unretained(this), | 93 base::Unretained(this), |
| 94 callback)); | 94 callback), |
| 95 callback); |
| 95 return PP_OK_COMPLETIONPENDING; | 96 return PP_OK_COMPLETIONPENDING; |
| 96 } | 97 } |
| 97 | 98 |
| 98 int32_t UDPSocketResourceBase::BindImpl( | 99 int32_t UDPSocketResourceBase::BindImpl( |
| 99 const PP_NetAddress_Private* addr, | 100 const PP_NetAddress_Private* addr, |
| 100 scoped_refptr<TrackedCallback> callback) { | 101 scoped_refptr<TrackedCallback> callback) { |
| 101 if (!addr) | 102 if (!addr) |
| 102 return PP_ERROR_BADARGUMENT; | 103 return PP_ERROR_BADARGUMENT; |
| 103 if (bound_ || closed_) | 104 if (bound_ || closed_) |
| 104 return PP_ERROR_FAILED; | 105 return PP_ERROR_FAILED; |
| 105 if (TrackedCallback::IsPending(bind_callback_)) | 106 if (TrackedCallback::IsPending(bind_callback_)) |
| 106 return PP_ERROR_INPROGRESS; | 107 return PP_ERROR_INPROGRESS; |
| 107 | 108 |
| 108 bind_callback_ = callback; | 109 bind_callback_ = callback; |
| 109 | 110 |
| 110 // Send the request, the browser will call us back via BindReply. | 111 // Send the request, the browser will call us back via BindReply. |
| 111 Call<PpapiPluginMsg_UDPSocket_BindReply>( | 112 Call<PpapiPluginMsg_UDPSocket_BindReply>( |
| 112 BROWSER, | 113 BROWSER, |
| 113 PpapiHostMsg_UDPSocket_Bind(*addr), | 114 PpapiHostMsg_UDPSocket_Bind(*addr), |
| 114 base::Bind(&UDPSocketResourceBase::OnPluginMsgBindReply, | 115 base::Bind(&UDPSocketResourceBase::OnPluginMsgBindReply, |
| 115 base::Unretained(this))); | 116 base::Unretained(this)), |
| 117 callback); |
| 116 return PP_OK_COMPLETIONPENDING; | 118 return PP_OK_COMPLETIONPENDING; |
| 117 } | 119 } |
| 118 | 120 |
| 119 PP_Bool UDPSocketResourceBase::GetBoundAddressImpl( | 121 PP_Bool UDPSocketResourceBase::GetBoundAddressImpl( |
| 120 PP_NetAddress_Private* addr) { | 122 PP_NetAddress_Private* addr) { |
| 121 if (!addr || !bound_ || closed_) | 123 if (!addr || !bound_ || closed_) |
| 122 return PP_FALSE; | 124 return PP_FALSE; |
| 123 | 125 |
| 124 *addr = bound_addr_; | 126 *addr = bound_addr_; |
| 125 return PP_TRUE; | 127 return PP_TRUE; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 139 | 141 |
| 140 read_buffer_ = buffer; | 142 read_buffer_ = buffer; |
| 141 bytes_to_read_ = std::min(num_bytes, kMaxReadSize); | 143 bytes_to_read_ = std::min(num_bytes, kMaxReadSize); |
| 142 recvfrom_callback_ = callback; | 144 recvfrom_callback_ = callback; |
| 143 | 145 |
| 144 // Send the request, the browser will call us back via RecvFromReply. | 146 // Send the request, the browser will call us back via RecvFromReply. |
| 145 Call<PpapiPluginMsg_UDPSocket_RecvFromReply>( | 147 Call<PpapiPluginMsg_UDPSocket_RecvFromReply>( |
| 146 BROWSER, | 148 BROWSER, |
| 147 PpapiHostMsg_UDPSocket_RecvFrom(bytes_to_read_), | 149 PpapiHostMsg_UDPSocket_RecvFrom(bytes_to_read_), |
| 148 base::Bind(&UDPSocketResourceBase::OnPluginMsgRecvFromReply, | 150 base::Bind(&UDPSocketResourceBase::OnPluginMsgRecvFromReply, |
| 149 base::Unretained(this), addr)); | 151 base::Unretained(this), addr), |
| 152 callback); |
| 150 return PP_OK_COMPLETIONPENDING; | 153 return PP_OK_COMPLETIONPENDING; |
| 151 } | 154 } |
| 152 | 155 |
| 153 PP_Bool UDPSocketResourceBase::GetRecvFromAddressImpl( | 156 PP_Bool UDPSocketResourceBase::GetRecvFromAddressImpl( |
| 154 PP_NetAddress_Private* addr) { | 157 PP_NetAddress_Private* addr) { |
| 155 if (!addr) | 158 if (!addr) |
| 156 return PP_FALSE; | 159 return PP_FALSE; |
| 157 *addr = recvfrom_addr_; | 160 *addr = recvfrom_addr_; |
| 158 return PP_TRUE; | 161 return PP_TRUE; |
| 159 } | 162 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 173 if (num_bytes > kMaxWriteSize) | 176 if (num_bytes > kMaxWriteSize) |
| 174 num_bytes = kMaxWriteSize; | 177 num_bytes = kMaxWriteSize; |
| 175 | 178 |
| 176 sendto_callback_ = callback; | 179 sendto_callback_ = callback; |
| 177 | 180 |
| 178 // Send the request, the browser will call us back via SendToReply. | 181 // Send the request, the browser will call us back via SendToReply. |
| 179 Call<PpapiPluginMsg_UDPSocket_SendToReply>( | 182 Call<PpapiPluginMsg_UDPSocket_SendToReply>( |
| 180 BROWSER, | 183 BROWSER, |
| 181 PpapiHostMsg_UDPSocket_SendTo(std::string(buffer, num_bytes), *addr), | 184 PpapiHostMsg_UDPSocket_SendTo(std::string(buffer, num_bytes), *addr), |
| 182 base::Bind(&UDPSocketResourceBase::OnPluginMsgSendToReply, | 185 base::Bind(&UDPSocketResourceBase::OnPluginMsgSendToReply, |
| 183 base::Unretained(this))); | 186 base::Unretained(this)), |
| 187 callback); |
| 184 return PP_OK_COMPLETIONPENDING; | 188 return PP_OK_COMPLETIONPENDING; |
| 185 } | 189 } |
| 186 | 190 |
| 187 void UDPSocketResourceBase::CloseImpl() { | 191 void UDPSocketResourceBase::CloseImpl() { |
| 188 if(closed_) | 192 if(closed_) |
| 189 return; | 193 return; |
| 190 | 194 |
| 191 bound_ = false; | 195 bound_ = false; |
| 192 closed_ = true; | 196 closed_ = true; |
| 193 | 197 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 } | 286 } |
| 283 | 287 |
| 284 void UDPSocketResourceBase::RunCallback(scoped_refptr<TrackedCallback> callback, | 288 void UDPSocketResourceBase::RunCallback(scoped_refptr<TrackedCallback> callback, |
| 285 int32_t pp_result) { | 289 int32_t pp_result) { |
| 286 callback->Run(ConvertNetworkAPIErrorForCompatibility(pp_result, | 290 callback->Run(ConvertNetworkAPIErrorForCompatibility(pp_result, |
| 287 private_api_)); | 291 private_api_)); |
| 288 } | 292 } |
| 289 | 293 |
| 290 } // namespace proxy | 294 } // namespace proxy |
| 291 } // namespace ppapi | 295 } // namespace ppapi |
| OLD | NEW |