| 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 #ifndef PPAPI_PROXY_UDP_SOCKET_RESOURCE_BASE_H_ | 5 #ifndef PPAPI_PROXY_UDP_SOCKET_RESOURCE_BASE_H_ |
| 6 #define PPAPI_PROXY_UDP_SOCKET_RESOURCE_BASE_H_ | 6 #define PPAPI_PROXY_UDP_SOCKET_RESOURCE_BASE_H_ |
| 7 | 7 |
| 8 #include <queue> | 8 #include <queue> |
| 9 #include <string> | |
| 10 | 9 |
| 11 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 12 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 13 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 14 #include "ppapi/c/ppb_udp_socket.h" | 13 #include "ppapi/c/ppb_udp_socket.h" |
| 15 #include "ppapi/c/private/ppb_net_address_private.h" | 14 #include "ppapi/c/private/ppb_net_address_private.h" |
| 16 #include "ppapi/proxy/plugin_resource.h" | 15 #include "ppapi/proxy/plugin_resource.h" |
| 17 #include "ppapi/proxy/ppapi_proxy_export.h" | 16 #include "ppapi/proxy/ppapi_proxy_export.h" |
| 17 #include "ppapi/proxy/udp_socket_filter.h" |
| 18 #include "ppapi/shared_impl/tracked_callback.h" | 18 #include "ppapi/shared_impl/tracked_callback.h" |
| 19 | 19 |
| 20 namespace ppapi { | 20 namespace ppapi { |
| 21 namespace proxy { | 21 namespace proxy { |
| 22 | 22 |
| 23 class ResourceMessageReplyParams; | 23 class ResourceMessageReplyParams; |
| 24 | 24 |
| 25 class PPAPI_PROXY_EXPORT UDPSocketResourceBase: public PluginResource { | 25 class PPAPI_PROXY_EXPORT UDPSocketResourceBase : public PluginResource { |
| 26 public: | 26 public: |
| 27 // The maximum number of bytes that each | 27 // The maximum number of bytes that each |
| 28 // PpapiPluginMsg_PPBUDPSocket_PushRecvResult message is allowed to carry. | 28 // PpapiPluginMsg_PPBUDPSocket_PushRecvResult message is allowed to carry. |
| 29 static const int32_t kMaxReadSize; | 29 static const int32_t kMaxReadSize; |
| 30 // The maximum number of bytes that each PpapiHostMsg_PPBUDPSocket_SendTo | 30 // The maximum number of bytes that each PpapiHostMsg_PPBUDPSocket_SendTo |
| 31 // message is allowed to carry. | 31 // message is allowed to carry. |
| 32 static const int32_t kMaxWriteSize; | 32 static const int32_t kMaxWriteSize; |
| 33 | 33 |
| 34 // The maximum number that we allow for setting | 34 // The maximum number that we allow for setting |
| 35 // PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE. This number is only for input | 35 // PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE. This number is only for input |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 PP_Resource* addr, | 68 PP_Resource* addr, |
| 69 scoped_refptr<TrackedCallback> callback); | 69 scoped_refptr<TrackedCallback> callback); |
| 70 PP_Bool GetRecvFromAddressImpl(PP_NetAddress_Private* addr); | 70 PP_Bool GetRecvFromAddressImpl(PP_NetAddress_Private* addr); |
| 71 int32_t SendToImpl(const char* buffer, | 71 int32_t SendToImpl(const char* buffer, |
| 72 int32_t num_bytes, | 72 int32_t num_bytes, |
| 73 const PP_NetAddress_Private* addr, | 73 const PP_NetAddress_Private* addr, |
| 74 scoped_refptr<TrackedCallback> callback); | 74 scoped_refptr<TrackedCallback> callback); |
| 75 void CloseImpl(); | 75 void CloseImpl(); |
| 76 | 76 |
| 77 private: | 77 private: |
| 78 struct RecvBuffer { | |
| 79 int32_t result; | |
| 80 std::string data; | |
| 81 PP_NetAddress_Private addr; | |
| 82 }; | |
| 83 | |
| 84 // Resource overrides. | |
| 85 virtual void OnReplyReceived(const ResourceMessageReplyParams& params, | |
| 86 const IPC::Message& msg) override; | |
| 87 | |
| 88 void PostAbortIfNecessary(scoped_refptr<TrackedCallback>* callback); | |
| 89 | |
| 90 // IPC message handlers. | 78 // IPC message handlers. |
| 91 void OnPluginMsgSetOptionReply(scoped_refptr<TrackedCallback> callback, | 79 void OnPluginMsgSetOptionReply(scoped_refptr<TrackedCallback> callback, |
| 92 const ResourceMessageReplyParams& params); | 80 const ResourceMessageReplyParams& params); |
| 93 void OnPluginMsgBindReply(const ResourceMessageReplyParams& params, | 81 void OnPluginMsgBindReply(const ResourceMessageReplyParams& params, |
| 94 const PP_NetAddress_Private& bound_addr); | 82 const PP_NetAddress_Private& bound_addr); |
| 95 void OnPluginMsgPushRecvResult(const ResourceMessageReplyParams& params, | |
| 96 int32_t result, | |
| 97 const std::string& data, | |
| 98 const PP_NetAddress_Private& addr); | |
| 99 void OnPluginMsgSendToReply(const ResourceMessageReplyParams& params, | 83 void OnPluginMsgSendToReply(const ResourceMessageReplyParams& params, |
| 100 int32_t bytes_written); | 84 int32_t bytes_written); |
| 101 | 85 |
| 102 void RunCallback(scoped_refptr<TrackedCallback> callback, int32_t pp_result); | 86 void SlotBecameAvailableOnIOThread(); |
| 103 | 87 void SlotBecameAvailable(); |
| 104 // Callers must ensure that |output_buffer| is big enough to store |data|. | |
| 105 int32_t SetRecvFromOutput(int32_t browser_result, | |
| 106 const std::string& data, | |
| 107 const PP_NetAddress_Private& addr, | |
| 108 char* output_buffer, | |
| 109 int32_t num_bytes, | |
| 110 PP_Resource* output_addr); | |
| 111 | 88 |
| 112 bool private_api_; | 89 bool private_api_; |
| 113 | 90 |
| 114 // |bind_called_| is true after Bind() is called, while |bound_| is true, | 91 // |bind_called_| is true after Bind() is called, while |bound_| is true |
| 115 // after Bind() succeeds. Bind() is an asynchronous method, so the timing | 92 // after Bind() succeeds. Bind() is an asynchronous method, so the timing |
| 116 // on which of these is set is slightly different. | 93 // on which of these is set is slightly different. |
| 117 bool bind_called_; | 94 bool bind_called_; |
| 118 bool bound_; | 95 bool bound_; |
| 119 bool closed_; | 96 bool closed_; |
| 120 | 97 |
| 121 scoped_refptr<TrackedCallback> bind_callback_; | 98 scoped_refptr<TrackedCallback> bind_callback_; |
| 122 scoped_refptr<TrackedCallback> recvfrom_callback_; | 99 scoped_refptr<UDPSocketFilter> recv_filter_; |
| 123 | 100 |
| 124 char* read_buffer_; | |
| 125 int32_t bytes_to_read_; | |
| 126 PP_Resource* recvfrom_addr_resource_; | |
| 127 | |
| 128 PP_NetAddress_Private recvfrom_addr_; | |
| 129 PP_NetAddress_Private bound_addr_; | 101 PP_NetAddress_Private bound_addr_; |
| 130 | 102 |
| 131 std::queue<RecvBuffer> recv_buffers_; | |
| 132 | |
| 133 std::queue<scoped_refptr<TrackedCallback>> sendto_callbacks_; | 103 std::queue<scoped_refptr<TrackedCallback>> sendto_callbacks_; |
| 134 | 104 |
| 135 DISALLOW_COPY_AND_ASSIGN(UDPSocketResourceBase); | 105 DISALLOW_COPY_AND_ASSIGN(UDPSocketResourceBase); |
| 136 }; | 106 }; |
| 137 | 107 |
| 138 } // namespace proxy | 108 } // namespace proxy |
| 139 } // namespace ppapi | 109 } // namespace ppapi |
| 140 | 110 |
| 141 #endif // PPAPI_PROXY_UDP_SOCKET_RESOURCE_BASE_H_ | 111 #endif // PPAPI_PROXY_UDP_SOCKET_RESOURCE_BASE_H_ |
| OLD | NEW |