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