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_UDP_SOCKET_IMPL_H_ |
| 6 #define PPAPI_SHARED_IMPL_UDP_SOCKET_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 PPB_UDPSocket_Private. |
| 17 // The functions that actually "do stuff" like Bind are implemented |
| 18 // differently for the proxied and non-proxied derived classes. |
| 19 class PPAPI_SHARED_EXPORT UDPSocketImpl |
| 20 : public thunk::PPB_UDPSocket_Private_API, |
| 21 public Resource { |
| 22 public: |
| 23 // C-tor used in Impl case. |
| 24 UDPSocketImpl(PP_Instance instance, uint32 socket_id); |
| 25 // C-tor used in Proxy case. |
| 26 UDPSocketImpl(const HostResource& resource, uint32 socket_id); |
| 27 |
| 28 virtual ~UDPSocketImpl(); |
| 29 |
| 30 // The maximum number of bytes that each PpapiHostMsg_PPBUDPSocket_RecvFrom |
| 31 // message is allowed to request. |
| 32 static const int32_t kMaxReadSize; |
| 33 // The maximum number of bytes that each PpapiHostMsg_PPBUDPSocket_SendTo |
| 34 // message is allowed to carry. |
| 35 static const int32_t kMaxWriteSize; |
| 36 |
| 37 // Resource overrides. |
| 38 virtual PPB_UDPSocket_Private_API* AsPPB_UDPSocket_Private_API() OVERRIDE; |
| 39 |
| 40 // PPB_UDPSocket_Private_API implementation. |
| 41 virtual int32_t Bind(const PP_NetAddress_Private* addr, |
| 42 PP_CompletionCallback callback) OVERRIDE; |
| 43 virtual int32_t RecvFrom(char* buffer, |
| 44 int32_t num_bytes, |
| 45 PP_CompletionCallback callback) OVERRIDE; |
| 46 virtual PP_Bool GetRecvFromAddress(PP_NetAddress_Private* addr) OVERRIDE; |
| 47 virtual int32_t SendTo(const char* buffer, |
| 48 int32_t num_bytes, |
| 49 const PP_NetAddress_Private* addr, |
| 50 PP_CompletionCallback callback) OVERRIDE; |
| 51 virtual void Close() OVERRIDE; |
| 52 |
| 53 // Notifications from the proxy. |
| 54 void OnBindCompleted(bool succeeded); |
| 55 void OnRecvFromCompleted(bool succeeded, |
| 56 const std::string& data, |
| 57 const PP_NetAddress_Private& addr); |
| 58 void OnSendToCompleted(bool succeeded, int32_t bytes_written); |
| 59 |
| 60 // Send functions that need to be implemented differently for |
| 61 // the proxied and non-proxied derived classes. |
| 62 virtual void SendBind(const PP_NetAddress_Private& addr) = 0; |
| 63 virtual void SendRecvFrom(int32_t num_bytes) = 0; |
| 64 virtual void SendSendTo(const std::string& buffer, |
| 65 const PP_NetAddress_Private& addr) = 0; |
| 66 virtual void SendClose() = 0; |
| 67 virtual void PostAbort(PP_CompletionCallback callback) = 0; |
| 68 |
| 69 protected: |
| 70 void Init(uint32 socket_id); |
| 71 void PostAbortAndClearIfNecessary(PP_CompletionCallback* callback); |
| 72 |
| 73 uint32 socket_id_; |
| 74 |
| 75 bool binded_; |
| 76 bool closed_; |
| 77 |
| 78 PP_CompletionCallback bind_callback_; |
| 79 PP_CompletionCallback recvfrom_callback_; |
| 80 PP_CompletionCallback sendto_callback_; |
| 81 |
| 82 char* read_buffer_; |
| 83 int32_t bytes_to_read_; |
| 84 |
| 85 PP_NetAddress_Private recvfrom_addr_; |
| 86 |
| 87 DISALLOW_COPY_AND_ASSIGN(UDPSocketImpl); |
| 88 }; |
| 89 |
| 90 } // namespace ppapi |
| 91 |
| 92 #endif // PPAPI_SHARED_IMPL_UDP_SOCKET_IMPL_H_ |
OLD | NEW |