| 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/tcp_socket_resource_base.h" | 5 #include "ppapi/proxy/tcp_socket_resource_base.h" |
| 6 | 6 |
| 7 #include <cstring> | 7 #include <cstring> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "ppapi/c/pp_bool.h" | 12 #include "ppapi/c/pp_bool.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/ppapi_messages.h" | 15 #include "ppapi/proxy/ppapi_messages.h" |
| 16 #include "ppapi/proxy/tcp_socket_resource_constants.h" |
| 16 #include "ppapi/shared_impl/ppapi_globals.h" | 17 #include "ppapi/shared_impl/ppapi_globals.h" |
| 17 #include "ppapi/shared_impl/private/ppb_x509_certificate_private_shared.h" | 18 #include "ppapi/shared_impl/private/ppb_x509_certificate_private_shared.h" |
| 18 #include "ppapi/shared_impl/socket_option_data.h" | 19 #include "ppapi/shared_impl/socket_option_data.h" |
| 19 #include "ppapi/shared_impl/var.h" | 20 #include "ppapi/shared_impl/var.h" |
| 20 #include "ppapi/shared_impl/var_tracker.h" | 21 #include "ppapi/shared_impl/var_tracker.h" |
| 21 #include "ppapi/thunk/enter.h" | 22 #include "ppapi/thunk/enter.h" |
| 22 #include "ppapi/thunk/ppb_x509_certificate_private_api.h" | 23 #include "ppapi/thunk/ppb_x509_certificate_private_api.h" |
| 23 | 24 |
| 24 namespace ppapi { | 25 namespace ppapi { |
| 25 namespace proxy { | 26 namespace proxy { |
| 26 | 27 |
| 27 const int32_t TCPSocketResourceBase::kMaxReadSize = 1024 * 1024; | |
| 28 const int32_t TCPSocketResourceBase::kMaxWriteSize = 1024 * 1024; | |
| 29 const int32_t TCPSocketResourceBase::kMaxSendBufferSize = | |
| 30 1024 * TCPSocketResourceBase::kMaxWriteSize; | |
| 31 const int32_t TCPSocketResourceBase::kMaxReceiveBufferSize = | |
| 32 1024 * TCPSocketResourceBase::kMaxReadSize; | |
| 33 | |
| 34 TCPSocketResourceBase::TCPSocketResourceBase(Connection connection, | 28 TCPSocketResourceBase::TCPSocketResourceBase(Connection connection, |
| 35 PP_Instance instance, | 29 PP_Instance instance, |
| 36 TCPSocketVersion version) | 30 TCPSocketVersion version) |
| 37 : PluginResource(connection, instance), | 31 : PluginResource(connection, instance), |
| 38 state_(TCPSocketState::INITIAL), | 32 state_(TCPSocketState::INITIAL), |
| 39 read_buffer_(NULL), | 33 read_buffer_(NULL), |
| 40 bytes_to_read_(-1), | 34 bytes_to_read_(-1), |
| 41 accepted_tcp_socket_(NULL), | 35 accepted_tcp_socket_(NULL), |
| 42 version_(version) { | 36 version_(version) { |
| 43 local_addr_.size = 0; | 37 local_addr_.size = 0; |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 scoped_refptr<TrackedCallback> callback) { | 199 scoped_refptr<TrackedCallback> callback) { |
| 206 if (!buffer || bytes_to_read <= 0) | 200 if (!buffer || bytes_to_read <= 0) |
| 207 return PP_ERROR_BADARGUMENT; | 201 return PP_ERROR_BADARGUMENT; |
| 208 | 202 |
| 209 if (!state_.IsConnected()) | 203 if (!state_.IsConnected()) |
| 210 return PP_ERROR_FAILED; | 204 return PP_ERROR_FAILED; |
| 211 if (TrackedCallback::IsPending(read_callback_) || | 205 if (TrackedCallback::IsPending(read_callback_) || |
| 212 state_.IsPending(TCPSocketState::SSL_CONNECT)) | 206 state_.IsPending(TCPSocketState::SSL_CONNECT)) |
| 213 return PP_ERROR_INPROGRESS; | 207 return PP_ERROR_INPROGRESS; |
| 214 read_buffer_ = buffer; | 208 read_buffer_ = buffer; |
| 215 bytes_to_read_ = std::min(bytes_to_read, kMaxReadSize); | 209 bytes_to_read_ = |
| 210 std::min(bytes_to_read, TCPSocketResourceConstants::kMaxReadSize); |
| 216 read_callback_ = callback; | 211 read_callback_ = callback; |
| 217 | 212 |
| 218 Call<PpapiPluginMsg_TCPSocket_ReadReply>( | 213 Call<PpapiPluginMsg_TCPSocket_ReadReply>( |
| 219 BROWSER, | 214 BROWSER, |
| 220 PpapiHostMsg_TCPSocket_Read(bytes_to_read_), | 215 PpapiHostMsg_TCPSocket_Read(bytes_to_read_), |
| 221 base::Bind(&TCPSocketResourceBase::OnPluginMsgReadReply, | 216 base::Bind(&TCPSocketResourceBase::OnPluginMsgReadReply, |
| 222 base::Unretained(this)), | 217 base::Unretained(this)), |
| 223 callback); | 218 callback); |
| 224 return PP_OK_COMPLETIONPENDING; | 219 return PP_OK_COMPLETIONPENDING; |
| 225 } | 220 } |
| 226 | 221 |
| 227 int32_t TCPSocketResourceBase::WriteImpl( | 222 int32_t TCPSocketResourceBase::WriteImpl( |
| 228 const char* buffer, | 223 const char* buffer, |
| 229 int32_t bytes_to_write, | 224 int32_t bytes_to_write, |
| 230 scoped_refptr<TrackedCallback> callback) { | 225 scoped_refptr<TrackedCallback> callback) { |
| 231 if (!buffer || bytes_to_write <= 0) | 226 if (!buffer || bytes_to_write <= 0) |
| 232 return PP_ERROR_BADARGUMENT; | 227 return PP_ERROR_BADARGUMENT; |
| 233 | 228 |
| 234 if (!state_.IsConnected()) | 229 if (!state_.IsConnected()) |
| 235 return PP_ERROR_FAILED; | 230 return PP_ERROR_FAILED; |
| 236 if (TrackedCallback::IsPending(write_callback_) || | 231 if (TrackedCallback::IsPending(write_callback_) || |
| 237 state_.IsPending(TCPSocketState::SSL_CONNECT)) | 232 state_.IsPending(TCPSocketState::SSL_CONNECT)) |
| 238 return PP_ERROR_INPROGRESS; | 233 return PP_ERROR_INPROGRESS; |
| 239 | 234 |
| 240 if (bytes_to_write > kMaxWriteSize) | 235 if (bytes_to_write > TCPSocketResourceConstants::kMaxWriteSize) |
| 241 bytes_to_write = kMaxWriteSize; | 236 bytes_to_write = TCPSocketResourceConstants::kMaxWriteSize; |
| 242 | 237 |
| 243 write_callback_ = callback; | 238 write_callback_ = callback; |
| 244 | 239 |
| 245 Call<PpapiPluginMsg_TCPSocket_WriteReply>( | 240 Call<PpapiPluginMsg_TCPSocket_WriteReply>( |
| 246 BROWSER, | 241 BROWSER, |
| 247 PpapiHostMsg_TCPSocket_Write(std::string(buffer, bytes_to_write)), | 242 PpapiHostMsg_TCPSocket_Write(std::string(buffer, bytes_to_write)), |
| 248 base::Bind(&TCPSocketResourceBase::OnPluginMsgWriteReply, | 243 base::Bind(&TCPSocketResourceBase::OnPluginMsgWriteReply, |
| 249 base::Unretained(this)), | 244 base::Unretained(this)), |
| 250 callback); | 245 callback); |
| 251 return PP_OK_COMPLETIONPENDING; | 246 return PP_OK_COMPLETIONPENDING; |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 } | 499 } |
| 505 | 500 |
| 506 void TCPSocketResourceBase::RunCallback(scoped_refptr<TrackedCallback> callback, | 501 void TCPSocketResourceBase::RunCallback(scoped_refptr<TrackedCallback> callback, |
| 507 int32_t pp_result) { | 502 int32_t pp_result) { |
| 508 callback->Run(ConvertNetworkAPIErrorForCompatibility( | 503 callback->Run(ConvertNetworkAPIErrorForCompatibility( |
| 509 pp_result, version_ == TCP_SOCKET_VERSION_PRIVATE)); | 504 pp_result, version_ == TCP_SOCKET_VERSION_PRIVATE)); |
| 510 } | 505 } |
| 511 | 506 |
| 512 } // namespace ppapi | 507 } // namespace ppapi |
| 513 } // namespace proxy | 508 } // namespace proxy |
| OLD | NEW |