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

Side by Side Diff: ppapi/proxy/tcp_socket_resource_base.h

Issue 22923014: TCPSockets are switched to the new Pepper proxy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync. Created 7 years, 4 months 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef PPAPI_SHARED_IMPL_TCP_SOCKET_SHARED_H_ 5 #ifndef PPAPI_PROXY_PPB_TCP_SOCKET_RESOURCE_BASE_H_
6 #define PPAPI_SHARED_IMPL_TCP_SOCKET_SHARED_H_ 6 #define PPAPI_PROXY_PPB_TCP_SOCKET_RESOURCE_BASE_H_
7 7
8 #include <queue>
yzshen1 2013/08/16 20:40:42 it is still needed, right?
ygorshenin1 2013/08/19 14:33:35 Done.
9 #include <string> 8 #include <string>
10 #include <vector> 9 #include <vector>
11 10
12 #include "base/compiler_specific.h" 11 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h"
13 #include "ppapi/c/ppb_tcp_socket.h" 13 #include "ppapi/c/ppb_tcp_socket.h"
14 #include "ppapi/c/private/ppb_net_address_private.h" 14 #include "ppapi/c/private/ppb_net_address_private.h"
15 #include "ppapi/shared_impl/resource.h" 15 #include "ppapi/proxy/plugin_resource.h"
16 #include "ppapi/proxy/ppapi_proxy_export.h"
16 #include "ppapi/shared_impl/tracked_callback.h" 17 #include "ppapi/shared_impl/tracked_callback.h"
17 18
18 namespace ppapi { 19 namespace ppapi {
19 20
20 class PPB_X509Certificate_Fields; 21 class PPB_X509Certificate_Fields;
21 class PPB_X509Certificate_Private_Shared; 22 class PPB_X509Certificate_Private_Shared;
22 class SocketOptionData; 23 class SocketOptionData;
23 24
24 // This class provides the shared implementation for both PPB_TCPSocket and 25 namespace proxy {
25 // PPB_TCPSocket_Private. 26
26 class PPAPI_SHARED_EXPORT TCPSocketShared { 27 class PPAPI_PROXY_EXPORT TCPSocketResourceBase : public PluginResource {
27 public: 28 public:
28 // The maximum number of bytes that each PpapiHostMsg_PPBTCPSocket_Read 29 // The maximum number of bytes that each PpapiHostMsg_PPBTCPSocket_Read
29 // message is allowed to request. 30 // message is allowed to request.
30 static const int32_t kMaxReadSize; 31 static const int32_t kMaxReadSize;
31 // The maximum number of bytes that each PpapiHostMsg_PPBTCPSocket_Write 32 // The maximum number of bytes that each PpapiHostMsg_PPBTCPSocket_Write
32 // message is allowed to carry. 33 // message is allowed to carry.
33 static const int32_t kMaxWriteSize; 34 static const int32_t kMaxWriteSize;
34 35
35 // The maximum number that we allow for setting 36 // The maximum number that we allow for setting
36 // PP_TCPSOCKET_OPTION_SEND_BUFFER_SIZE. This number is only for input 37 // PP_TCPSOCKET_OPTION_SEND_BUFFER_SIZE. This number is only for input
37 // argument sanity check, it doesn't mean the browser guarantees to support 38 // argument sanity check, it doesn't mean the browser guarantees to support
38 // such a buffer size. 39 // such a buffer size.
39 static const int32_t kMaxSendBufferSize; 40 static const int32_t kMaxSendBufferSize;
40 // The maximum number that we allow for setting 41 // The maximum number that we allow for setting
41 // PP_TCPSOCKET_OPTION_RECV_BUFFER_SIZE. This number is only for input 42 // PP_TCPSOCKET_OPTION_RECV_BUFFER_SIZE. This number is only for input
42 // argument sanity check, it doesn't mean the browser guarantees to support 43 // argument sanity check, it doesn't mean the browser guarantees to support
43 // such a buffer size. 44 // such a buffer size.
44 static const int32_t kMaxReceiveBufferSize; 45 static const int32_t kMaxReceiveBufferSize;
45 46
46 // Notifications on operations completion.
47 void OnConnectCompleted(int32_t result,
48 const PP_NetAddress_Private& local_addr,
49 const PP_NetAddress_Private& remote_addr);
50 void OnSSLHandshakeCompleted(
51 bool succeeded,
52 const PPB_X509Certificate_Fields& certificate_fields);
53 void OnReadCompleted(int32_t result, const std::string& data);
54 void OnWriteCompleted(int32_t result);
55 void OnSetOptionCompleted(int32_t result);
56
57 // Send functions that need to be implemented differently for the
58 // proxied and non-proxied derived classes.
59 virtual void SendConnect(const std::string& host, uint16_t port) = 0;
60 virtual void SendConnectWithNetAddress(const PP_NetAddress_Private& addr) = 0;
61 virtual void SendSSLHandshake(
62 const std::string& server_name,
63 uint16_t server_port,
64 const std::vector<std::vector<char> >& trusted_certs,
65 const std::vector<std::vector<char> >& untrusted_certs) = 0;
66 virtual void SendRead(int32_t bytes_to_read) = 0;
67 virtual void SendWrite(const std::string& buffer) = 0;
68 virtual void SendDisconnect() = 0;
69 virtual void SendSetOption(PP_TCPSocket_Option name,
70 const SocketOptionData& value) = 0;
71
72 virtual Resource* GetOwnerResource() = 0;
73
74 // Used to override PP_Error codes received from the browser side.
75 virtual int32_t OverridePPError(int32_t pp_error);
76
77 protected: 47 protected:
78 enum ConnectionState { 48 enum ConnectionState {
79 // Before a connection is successfully established (including a connect 49 // Before a connection is successfully established (including a connect
80 // request is pending or a previous connect request failed). 50 // request is pending or a previous connect request failed).
81 BEFORE_CONNECT, 51 BEFORE_CONNECT,
82 // A connection has been successfully established (including a request of 52 // A connection has been successfully established (including a request of
83 // initiating SSL is pending). 53 // initiating SSL is pending).
84 CONNECTED, 54 CONNECTED,
85 // An SSL connection has been successfully established. 55 // An SSL connection has been successfully established.
86 SSL_CONNECTED, 56 SSL_CONNECTED,
87 // The connection has been ended. 57 // The connection has been ended.
88 DISCONNECTED 58 DISCONNECTED
89 }; 59 };
90 60
91 TCPSocketShared(ResourceObjectType resource_type, uint32 socket_id); 61 // C-tor used for new sockets.
92 virtual ~TCPSocketShared(); 62 TCPSocketResourceBase(Connection connection,
63 PP_Instance instance,
64 bool private_api);
65
66 // C-tor used for already accepted sockets.
67 TCPSocketResourceBase(Connection connection,
68 PP_Instance instance,
69 bool private_api,
70 const PP_NetAddress_Private& local_addr,
71 const PP_NetAddress_Private& remote_addr);
72
73 virtual ~TCPSocketResourceBase();
93 74
94 int32_t ConnectImpl(const char* host, 75 int32_t ConnectImpl(const char* host,
95 uint16_t port, 76 uint16_t port,
96 scoped_refptr<TrackedCallback> callback); 77 scoped_refptr<TrackedCallback> callback);
97 int32_t ConnectWithNetAddressImpl(const PP_NetAddress_Private* addr, 78 int32_t ConnectWithNetAddressImpl(const PP_NetAddress_Private* addr,
98 scoped_refptr<TrackedCallback> callback); 79 scoped_refptr<TrackedCallback> callback);
99 PP_Bool GetLocalAddressImpl(PP_NetAddress_Private* local_addr); 80 PP_Bool GetLocalAddressImpl(PP_NetAddress_Private* local_addr);
100 PP_Bool GetRemoteAddressImpl(PP_NetAddress_Private* remote_addr); 81 PP_Bool GetRemoteAddressImpl(PP_NetAddress_Private* remote_addr);
101 int32_t SSLHandshakeImpl(const char* server_name, 82 int32_t SSLHandshakeImpl(const char* server_name,
102 uint16_t server_port, 83 uint16_t server_port,
103 scoped_refptr<TrackedCallback> callback); 84 scoped_refptr<TrackedCallback> callback);
104 PP_Resource GetServerCertificateImpl(); 85 PP_Resource GetServerCertificateImpl();
105 PP_Bool AddChainBuildingCertificateImpl(PP_Resource certificate, 86 PP_Bool AddChainBuildingCertificateImpl(PP_Resource certificate,
106 PP_Bool trusted); 87 PP_Bool trusted);
107 int32_t ReadImpl(char* buffer, 88 int32_t ReadImpl(char* buffer,
108 int32_t bytes_to_read, 89 int32_t bytes_to_read,
109 scoped_refptr<TrackedCallback> callback); 90 scoped_refptr<TrackedCallback> callback);
110 int32_t WriteImpl(const char* buffer, 91 int32_t WriteImpl(const char* buffer,
111 int32_t bytes_to_write, 92 int32_t bytes_to_write,
112 scoped_refptr<TrackedCallback> callback); 93 scoped_refptr<TrackedCallback> callback);
113 void DisconnectImpl(); 94 void DisconnectImpl();
114 int32_t SetOptionImpl(PP_TCPSocket_Option name, 95 int32_t SetOptionImpl(PP_TCPSocket_Option name,
115 const PP_Var& value, 96 const PP_Var& value,
116 scoped_refptr<TrackedCallback> callback); 97 scoped_refptr<TrackedCallback> callback);
117 98
118 void Init(uint32 socket_id);
119 bool IsConnected() const; 99 bool IsConnected() const;
120 void PostAbortIfNecessary(scoped_refptr<TrackedCallback>* callback); 100 void PostAbortIfNecessary(scoped_refptr<TrackedCallback>* callback);
121 101
122 ResourceObjectType resource_type_; 102 // IPC message handlers.
123 103 void OnPluginMsgConnectReply(const ResourceMessageReplyParams& params,
124 uint32 socket_id_; 104 const PP_NetAddress_Private& local_addr,
125 ConnectionState connection_state_; 105 const PP_NetAddress_Private& remote_addr);
106 void OnPluginMsgSSLHandshakeReply(
107 const ResourceMessageReplyParams& params,
108 const PPB_X509Certificate_Fields& certificate_fields);
109 void OnPluginMsgReadReply(const ResourceMessageReplyParams& params,
110 const std::string& data);
111 void OnPluginMsgWriteReply(const ResourceMessageReplyParams& params);
112 void OnPluginMsgSetOptionReply(const ResourceMessageReplyParams& params);
126 113
127 scoped_refptr<TrackedCallback> connect_callback_; 114 scoped_refptr<TrackedCallback> connect_callback_;
128 scoped_refptr<TrackedCallback> ssl_handshake_callback_; 115 scoped_refptr<TrackedCallback> ssl_handshake_callback_;
129 scoped_refptr<TrackedCallback> read_callback_; 116 scoped_refptr<TrackedCallback> read_callback_;
130 scoped_refptr<TrackedCallback> write_callback_; 117 scoped_refptr<TrackedCallback> write_callback_;
131 std::queue<scoped_refptr<TrackedCallback> > set_option_callbacks_; 118 std::queue<scoped_refptr<TrackedCallback> > set_option_callbacks_;
132 119
120 ConnectionState connection_state_;
133 char* read_buffer_; 121 char* read_buffer_;
134 int32_t bytes_to_read_; 122 int32_t bytes_to_read_;
135 123
136 PP_NetAddress_Private local_addr_; 124 PP_NetAddress_Private local_addr_;
137 PP_NetAddress_Private remote_addr_; 125 PP_NetAddress_Private remote_addr_;
138 126
139 scoped_refptr<PPB_X509Certificate_Private_Shared> server_certificate_; 127 scoped_refptr<PPB_X509Certificate_Private_Shared> server_certificate_;
140 128
141 std::vector<std::vector<char> > trusted_certificates_; 129 std::vector<std::vector<char> > trusted_certificates_;
142 std::vector<std::vector<char> > untrusted_certificates_; 130 std::vector<std::vector<char> > untrusted_certificates_;
143 131
144 private: 132 private:
145 DISALLOW_COPY_AND_ASSIGN(TCPSocketShared); 133 void RunCallback(scoped_refptr<TrackedCallback> callback, int32_t pp_result);
134
135 bool private_api_;
136
137 DISALLOW_COPY_AND_ASSIGN(TCPSocketResourceBase);
146 }; 138 };
147 139
140 } // namespace proxy
148 } // namespace ppapi 141 } // namespace ppapi
149 142
150 #endif // PPAPI_SHARED_IMPL_TCP_SOCKET_SHARED_H_ 143 #endif // PPAPI_PROXY_PPB_TCP_SOCKET_RESOURCE_BASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698