OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_SHARED_IMPL_PRIVATE_UDP_SOCKET_PRIVATE_IMPL_H_ | 5 #ifndef PPAPI_PROXY_UDP_SOCKET_PRIVATE_RESOURCE_H_ |
6 #define PPAPI_SHARED_IMPL_PRIVATE_UDP_SOCKET_PRIVATE_IMPL_H_ | 6 #define PPAPI_PROXY_UDP_SOCKET_PRIVATE_RESOURCE_H_ |
7 | 7 |
8 #include <string> | 8 #include "base/basictypes.h" |
9 | |
10 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
11 #include "ppapi/shared_impl/resource.h" | 10 #include "ppapi/proxy/plugin_resource.h" |
| 11 #include "ppapi/proxy/ppapi_proxy_export.h" |
12 #include "ppapi/shared_impl/tracked_callback.h" | 12 #include "ppapi/shared_impl/tracked_callback.h" |
13 #include "ppapi/thunk/ppb_udp_socket_private_api.h" | 13 #include "ppapi/thunk/ppb_udp_socket_private_api.h" |
14 | 14 |
15 namespace ppapi { | 15 namespace ppapi { |
| 16 namespace proxy { |
16 | 17 |
17 // This class provides the shared implementation of a | 18 class PPAPI_PROXY_EXPORT UDPSocketPrivateResource |
18 // PPB_UDPSocket_Private. The functions that actually send messages | 19 : public PluginResource, |
19 // to browser are implemented differently for the proxied and | 20 public thunk::PPB_UDPSocket_Private_API { |
20 // non-proxied derived classes. | |
21 class PPAPI_SHARED_EXPORT UDPSocketPrivateImpl | |
22 : public thunk::PPB_UDPSocket_Private_API, | |
23 public Resource { | |
24 public: | 21 public: |
25 // C-tor used in Impl case. | 22 UDPSocketPrivateResource(Connection connection, |
26 UDPSocketPrivateImpl(PP_Instance instance, uint32 socket_id); | 23 PP_Instance instance); |
27 // C-tor used in Proxy case. | 24 virtual ~UDPSocketPrivateResource(); |
28 UDPSocketPrivateImpl(const HostResource& resource, uint32 socket_id); | |
29 | |
30 virtual ~UDPSocketPrivateImpl(); | |
31 | 25 |
32 // The maximum number of bytes that each PpapiHostMsg_PPBUDPSocket_RecvFrom | 26 // The maximum number of bytes that each PpapiHostMsg_PPBUDPSocket_RecvFrom |
33 // message is allowed to request. | 27 // message is allowed to request. |
34 static const int32_t kMaxReadSize; | 28 static const int32_t kMaxReadSize; |
35 // The maximum number of bytes that each PpapiHostMsg_PPBUDPSocket_SendTo | 29 // The maximum number of bytes that each PpapiHostMsg_PPBUDPSocket_SendTo |
36 // message is allowed to carry. | 30 // message is allowed to carry. |
37 static const int32_t kMaxWriteSize; | 31 static const int32_t kMaxWriteSize; |
38 | 32 |
39 // Resource overrides. | 33 // PluginResource implementation. |
40 virtual PPB_UDPSocket_Private_API* AsPPB_UDPSocket_Private_API() OVERRIDE; | 34 virtual thunk::PPB_UDPSocket_Private_API* |
| 35 AsPPB_UDPSocket_Private_API() OVERRIDE; |
41 | 36 |
42 // PPB_UDPSocket_Private_API implementation. | 37 // PPB_UDPSocket_Private_API implementation. |
43 virtual int32_t SetSocketFeature(PP_UDPSocketFeature_Private name, | 38 virtual int32_t SetSocketFeature(PP_UDPSocketFeature_Private name, |
44 PP_Var value) OVERRIDE; | 39 PP_Var value) OVERRIDE; |
45 virtual int32_t Bind(const PP_NetAddress_Private* addr, | 40 virtual int32_t Bind(const PP_NetAddress_Private* addr, |
46 scoped_refptr<TrackedCallback> callback) OVERRIDE; | 41 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
47 virtual PP_Bool GetBoundAddress(PP_NetAddress_Private* addr) OVERRIDE; | 42 virtual PP_Bool GetBoundAddress(PP_NetAddress_Private* addr) OVERRIDE; |
48 virtual int32_t RecvFrom(char* buffer, | 43 virtual int32_t RecvFrom(char* buffer, |
49 int32_t num_bytes, | 44 int32_t num_bytes, |
50 scoped_refptr<TrackedCallback> callback) OVERRIDE; | 45 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
51 virtual PP_Bool GetRecvFromAddress(PP_NetAddress_Private* addr) OVERRIDE; | 46 virtual PP_Bool GetRecvFromAddress(PP_NetAddress_Private* addr) OVERRIDE; |
52 virtual int32_t SendTo(const char* buffer, | 47 virtual int32_t SendTo(const char* buffer, |
53 int32_t num_bytes, | 48 int32_t num_bytes, |
54 const PP_NetAddress_Private* addr, | 49 const PP_NetAddress_Private* addr, |
55 scoped_refptr<TrackedCallback> callback) OVERRIDE; | 50 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
56 virtual void Close() OVERRIDE; | 51 virtual void Close() OVERRIDE; |
57 | 52 |
58 // Notifications from the proxy. | 53 private: |
59 void OnBindCompleted(bool succeeded, | |
60 const PP_NetAddress_Private& bound_addr); | |
61 void OnRecvFromCompleted(bool succeeded, | |
62 const std::string& data, | |
63 const PP_NetAddress_Private& addr); | |
64 void OnSendToCompleted(bool succeeded, int32_t bytes_written); | |
65 | |
66 // Send functions that need to be implemented differently for | |
67 // the proxied and non-proxied derived classes. | |
68 virtual void SendBoolSocketFeature(int32_t name, bool value) = 0; | |
69 virtual void SendBind(const PP_NetAddress_Private& addr) = 0; | |
70 virtual void SendRecvFrom(int32_t num_bytes) = 0; | |
71 virtual void SendSendTo(const std::string& buffer, | |
72 const PP_NetAddress_Private& addr) = 0; | |
73 virtual void SendClose() = 0; | |
74 | |
75 protected: | |
76 void Init(uint32 socket_id); | |
77 void PostAbortIfNecessary(scoped_refptr<TrackedCallback>* callback); | 54 void PostAbortIfNecessary(scoped_refptr<TrackedCallback>* callback); |
78 | 55 |
79 uint32 socket_id_; | 56 void SendBoolSocketFeature(int32_t name, bool value); |
| 57 void SendBind(const PP_NetAddress_Private& addr); |
| 58 void SendRecvFrom(int32_t num_bytes); |
| 59 void SendSendTo(const std::string& buffer, |
| 60 const PP_NetAddress_Private& addr); |
| 61 void SendClose(); |
| 62 |
| 63 // IPC message handlers. |
| 64 void OnPluginMsgBindReply(const ResourceMessageReplyParams& params, |
| 65 bool succeeded, |
| 66 const PP_NetAddress_Private& bound_addr); |
| 67 void OnPluginMsgRecvFromReply(const ResourceMessageReplyParams& params, |
| 68 bool succeeded, |
| 69 const std::string& data, |
| 70 const PP_NetAddress_Private& addr); |
| 71 void OnPluginMsgSendToReply(const ResourceMessageReplyParams& params, |
| 72 bool succeeded, |
| 73 int32_t bytes_written); |
80 | 74 |
81 bool bound_; | 75 bool bound_; |
82 bool closed_; | 76 bool closed_; |
83 | 77 |
84 scoped_refptr<TrackedCallback> bind_callback_; | 78 scoped_refptr<TrackedCallback> bind_callback_; |
85 scoped_refptr<TrackedCallback> recvfrom_callback_; | 79 scoped_refptr<TrackedCallback> recvfrom_callback_; |
86 scoped_refptr<TrackedCallback> sendto_callback_; | 80 scoped_refptr<TrackedCallback> sendto_callback_; |
87 | 81 |
88 char* read_buffer_; | 82 char* read_buffer_; |
89 int32_t bytes_to_read_; | 83 int32_t bytes_to_read_; |
90 | 84 |
91 PP_NetAddress_Private recvfrom_addr_; | 85 PP_NetAddress_Private recvfrom_addr_; |
92 PP_NetAddress_Private bound_addr_; | 86 PP_NetAddress_Private bound_addr_; |
93 | 87 |
94 DISALLOW_COPY_AND_ASSIGN(UDPSocketPrivateImpl); | 88 DISALLOW_COPY_AND_ASSIGN(UDPSocketPrivateResource); |
95 }; | 89 }; |
96 | 90 |
| 91 } // namespace proxy |
97 } // namespace ppapi | 92 } // namespace ppapi |
98 | 93 |
99 #endif // PPAPI_SHARED_IMPL_PRIVATE_UDP_SOCKET_PRIVATE_IMPL_H_ | 94 #endif // PPAPI_PROXY_UDP_SOCKET_PRIVATE_RESOURCE_H_ |
OLD | NEW |