Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(625)

Side by Side Diff: ppapi/shared_impl/private/tcp_socket_private_impl.h

Issue 8804006: Reland 8688002: PPB_TCPSocket_Private/PPB_UDPSocket_Private are exposed to Browser (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix destruction issue Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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_TCP_SOCKET_PRIVATE_IMPL_H_
6 #define PPAPI_SHARED_IMPL_PRIVATE_TCP_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_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 messages
18 // to browser are implemented differently for the proxied and
19 // non-proxied derived classes.
20 class PPAPI_SHARED_EXPORT TCPSocketPrivateImpl
21 : public thunk::PPB_TCPSocket_Private_API,
22 public Resource {
23 public:
24 // C-tor used in Impl case.
25 TCPSocketPrivateImpl(PP_Instance instance, uint32 socket_id);
26 // C-tor used in Proxy case.
27 TCPSocketPrivateImpl(const HostResource& resource, uint32 socket_id);
28
29 virtual ~TCPSocketPrivateImpl();
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
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(TCPSocketPrivateImpl);
112 };
113
114 } // namespace ppapi
115
116 #endif // PPAPI_SHARED_IMPL_PRIVATE_TCP_SOCKET_PRIVATE_IMPL_H_
OLDNEW
« no previous file with comments | « ppapi/proxy/ppb_udp_socket_private_proxy.cc ('k') | ppapi/shared_impl/private/tcp_socket_private_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698