Chromium Code Reviews| 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_TCP_SOCKET_IMPL_H_ | |
| 6 #define PPAPI_SHARED_IMPL_TCP_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_tcp_socket_private_api.h" | |
| 13 | |
| 14 namespace ppapi { | |
| 15 | |
| 16 // This class provides the shared implementation of a | |
| 17 // PPB_TCPSocket_Private. The functions that actually send methods to | |
|
yzshen1
2011/11/29 20:19:33
methods -> messages.
ygorshenin
2011/11/30 11:50:54
Done.
| |
| 18 // browser are implemented differently for the proxied and non-proxied | |
| 19 // derived classes. | |
| 20 class PPAPI_SHARED_EXPORT TCPSocketImpl | |
| 21 : public thunk::PPB_TCPSocket_Private_API, | |
| 22 public Resource { | |
| 23 public: | |
| 24 // C-tor used in Impl case. | |
| 25 TCPSocketImpl(PP_Instance instance, uint32 socket_id); | |
| 26 // C-tor used in Proxy case. | |
| 27 TCPSocketImpl(const HostResource& resource, uint32 socket_id); | |
| 28 | |
| 29 virtual ~TCPSocketImpl(); | |
| 30 | |
| 31 // The maximum number of bytes that each PpapiHostMsg_PPBTCPSocket_Read | |
| 32 // message is allowed to request. | |
| 33 static const int32_t kMaxReadSize; | |
| 34 // The maximum number of bytes that each PpapiHostMsg_PPBTCPSocket_Write | |
| 35 // message is allowed to carry. | |
| 36 static const int32_t kMaxWriteSize; | |
| 37 | |
| 38 // Resource overrides. | |
| 39 virtual PPB_TCPSocket_Private_API* AsPPB_TCPSocket_Private_API() OVERRIDE; | |
| 40 | |
| 41 // PPB_TCPSocket_Private_API implementation. | |
| 42 virtual int32_t Connect(const char* host, | |
| 43 uint16_t port, | |
| 44 PP_CompletionCallback callback) OVERRIDE; | |
| 45 virtual int32_t ConnectWithNetAddress( | |
| 46 const PP_NetAddress_Private* addr, | |
| 47 PP_CompletionCallback callback) OVERRIDE; | |
| 48 virtual PP_Bool GetLocalAddress(PP_NetAddress_Private* local_addr) OVERRIDE; | |
| 49 virtual PP_Bool GetRemoteAddress(PP_NetAddress_Private* remote_addr) OVERRIDE; | |
| 50 virtual int32_t SSLHandshake(const char* server_name, | |
| 51 uint16_t server_port, | |
| 52 PP_CompletionCallback callback) OVERRIDE; | |
| 53 virtual int32_t Read(char* buffer, | |
| 54 int32_t bytes_to_read, | |
| 55 PP_CompletionCallback callback) OVERRIDE; | |
| 56 virtual int32_t Write(const char* buffer, | |
| 57 int32_t bytes_to_write, | |
| 58 PP_CompletionCallback callback) OVERRIDE; | |
| 59 virtual void Disconnect() OVERRIDE; | |
| 60 | |
| 61 // Notifications on operations completion. | |
| 62 void OnConnectCompleted(bool succeeded, | |
| 63 const PP_NetAddress_Private& local_addr, | |
| 64 const PP_NetAddress_Private& remote_addr); | |
| 65 void OnSSLHandshakeCompleted(bool succeeded); | |
| 66 void OnReadCompleted(bool succeeded, const std::string& data); | |
| 67 void OnWriteCompleted(bool succeeded, int32_t bytes_written); | |
| 68 | |
| 69 // Send functions that need to be implemented differently for the | |
| 70 // proxied and non-proxied derived classes. | |
| 71 virtual void SendConnect(const std::string& host, uint16_t port) = 0; | |
| 72 virtual void SendConnectWithNetAddress(const PP_NetAddress_Private& addr) = 0; | |
| 73 virtual void SendSSLHandshake(const std::string& server_name, | |
| 74 uint16_t server_port) = 0; | |
| 75 virtual void SendRead(int32_t bytes_to_read) = 0; | |
| 76 virtual void SendWrite(const std::string& buffer) = 0; | |
| 77 virtual void SendDisconnect() = 0; | |
| 78 virtual void PostAbort(PP_CompletionCallback callback) = 0; | |
| 79 | |
| 80 protected: | |
| 81 enum ConnectionState { | |
| 82 // Before a connection is successfully established (including a connect | |
| 83 // request is pending or a previous connect request failed). | |
| 84 BEFORE_CONNECT, | |
| 85 // A connection has been successfully established (including a request of | |
| 86 // initiating SSL is pending). | |
| 87 CONNECTED, | |
| 88 // An SSL connection has been successfully established. | |
| 89 SSL_CONNECTED, | |
| 90 // The connection has been ended. | |
| 91 DISCONNECTED | |
| 92 }; | |
| 93 | |
| 94 void Init(uint32 socket_id); | |
| 95 bool IsConnected() const; | |
| 96 void PostAbortAndClearIfNecessary(PP_CompletionCallback* callback); | |
| 97 | |
| 98 uint32 socket_id_; | |
| 99 ConnectionState connection_state_; | |
| 100 | |
| 101 PP_CompletionCallback connect_callback_; | |
| 102 PP_CompletionCallback ssl_handshake_callback_; | |
| 103 PP_CompletionCallback read_callback_; | |
| 104 PP_CompletionCallback write_callback_; | |
| 105 | |
| 106 char* read_buffer_; | |
| 107 int32_t bytes_to_read_; | |
| 108 | |
| 109 PP_NetAddress_Private local_addr_; | |
| 110 PP_NetAddress_Private remote_addr_; | |
| 111 | |
| 112 DISALLOW_COPY_AND_ASSIGN(TCPSocketImpl); | |
| 113 }; | |
| 114 | |
| 115 } // namespace ppapi | |
| 116 | |
| 117 #endif // PPAPI_SHARED_IMPL_TCP_SOCKET_IMPL_H_ | |
| OLD | NEW |