OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef PPAPI_SHARED_IMPL_PRIVATE_UDP_SOCKET_PRIVATE_IMPL_H_ | |
6 #define PPAPI_SHARED_IMPL_PRIVATE_UDP_SOCKET_PRIVATE_IMPL_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/compiler_specific.h" | |
11 #include "ppapi/shared_impl/resource.h" | |
12 #include "ppapi/thunk/ppb_udp_socket_private_api.h" | |
13 | |
14 namespace ppapi { | |
15 | |
16 // This class provides the shared implementation of a | |
17 // PPB_UDPSocket_Private. The functions that actually send messages | |
18 // to browser are implemented differently for the proxied and | |
19 // non-proxied derived classes. | |
20 class PPAPI_SHARED_EXPORT UDPSocketPrivateImpl | |
21 : public thunk::PPB_UDPSocket_Private_API, | |
22 public Resource { | |
23 public: | |
24 // C-tor used in Impl case. | |
25 UDPSocketPrivateImpl(PP_Instance instance, uint32 socket_id); | |
26 // C-tor used in Proxy case. | |
27 UDPSocketPrivateImpl(const HostResource& resource, uint32 socket_id); | |
28 | |
29 virtual ~UDPSocketPrivateImpl(); | |
30 | |
31 // The maximum number of bytes that each PpapiHostMsg_PPBUDPSocket_RecvFrom | |
32 // message is allowed to request. | |
33 static const int32_t kMaxReadSize; | |
34 // The maximum number of bytes that each PpapiHostMsg_PPBUDPSocket_SendTo | |
35 // message is allowed to carry. | |
36 static const int32_t kMaxWriteSize; | |
37 | |
38 // Resource overrides. | |
39 virtual PPB_UDPSocket_Private_API* AsPPB_UDPSocket_Private_API() OVERRIDE; | |
40 | |
41 // PPB_UDPSocket_Private_API implementation. | |
42 virtual int32_t Bind(const PP_NetAddress_Private* addr, | |
43 PP_CompletionCallback callback) OVERRIDE; | |
44 virtual int32_t RecvFrom(char* buffer, | |
45 int32_t num_bytes, | |
46 PP_CompletionCallback callback) OVERRIDE; | |
47 virtual PP_Bool GetRecvFromAddress(PP_NetAddress_Private* addr) OVERRIDE; | |
48 virtual int32_t SendTo(const char* buffer, | |
49 int32_t num_bytes, | |
50 const PP_NetAddress_Private* addr, | |
51 PP_CompletionCallback callback) OVERRIDE; | |
52 virtual void Close() OVERRIDE; | |
53 | |
54 // Notifications from the proxy. | |
55 void OnBindCompleted(bool succeeded); | |
56 void OnRecvFromCompleted(bool succeeded, | |
57 const std::string& data, | |
58 const PP_NetAddress_Private& addr); | |
59 void OnSendToCompleted(bool succeeded, int32_t bytes_written); | |
60 | |
61 // Send functions that need to be implemented differently for | |
62 // the proxied and non-proxied derived classes. | |
63 virtual void SendBind(const PP_NetAddress_Private& addr) = 0; | |
64 virtual void SendRecvFrom(int32_t num_bytes) = 0; | |
65 virtual void SendSendTo(const std::string& buffer, | |
66 const PP_NetAddress_Private& addr) = 0; | |
67 virtual void SendClose() = 0; | |
68 | |
69 void PostAbort(PP_CompletionCallback callback); | |
yzshen1
2011/12/01 18:34:23
This could be removed.
Dmitry Polukhin
2011/12/02 11:37:33
Done.
| |
70 | |
71 protected: | |
72 void Init(uint32 socket_id); | |
73 void PostAbortAndClearIfNecessary(PP_CompletionCallback* callback); | |
74 | |
75 uint32 socket_id_; | |
76 | |
77 bool bound_; | |
78 bool closed_; | |
79 | |
80 PP_CompletionCallback bind_callback_; | |
81 PP_CompletionCallback recvfrom_callback_; | |
82 PP_CompletionCallback sendto_callback_; | |
83 | |
84 char* read_buffer_; | |
85 int32_t bytes_to_read_; | |
86 | |
87 PP_NetAddress_Private recvfrom_addr_; | |
88 | |
89 DISALLOW_COPY_AND_ASSIGN(UDPSocketPrivateImpl); | |
90 }; | |
91 | |
92 } // namespace ppapi | |
93 | |
94 #endif // PPAPI_SHARED_IMPL_PRIVATE_UDP_SOCKET_PRIVATE_IMPL_H_ | |
OLD | NEW |