1 // Copyright 2014 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.
5 #ifndef EXTENSIONS_BROWSER_API_SOCKETS_TCP_SOCKETS_TCP_API_H_
6 #define EXTENSIONS_BROWSER_API_SOCKETS_TCP_SOCKETS_TCP_API_H_
8 #include "extensions/browser/api/socket/socket_api.h"
9 #include "extensions/common/api/sockets_tcp.h"
11 namespace extensions {
12 class ResumableTCPSocket;
16 namespace extensions {
19 class TCPSocketEventDispatcher;
21 class TCPSocketAsyncApiFunction : public SocketAsyncApiFunction {
23 ~TCPSocketAsyncApiFunction() override;
25 scoped_ptr<SocketResourceManagerInterface> CreateSocketResourceManager()
28 ResumableTCPSocket* GetTcpSocket(int socket_id);
31 class TCPSocketExtensionWithDnsLookupFunction
32 : public SocketExtensionWithDnsLookupFunction {
34 ~TCPSocketExtensionWithDnsLookupFunction() override;
36 scoped_ptr<SocketResourceManagerInterface> CreateSocketResourceManager()
39 ResumableTCPSocket* GetTcpSocket(int socket_id);
42 class SocketsTcpCreateFunction : public TCPSocketAsyncApiFunction {
44 DECLARE_EXTENSION_FUNCTION("sockets.tcp.create", SOCKETS_TCP_CREATE)
46 SocketsTcpCreateFunction();
49 ~SocketsTcpCreateFunction() override;
52 bool Prepare() override;
56 FRIEND_TEST_ALL_PREFIXES(SocketsTcpUnitTest, Create);
57 scoped_ptr<sockets_tcp::Create::Params> params_;
60 class SocketsTcpUpdateFunction : public TCPSocketAsyncApiFunction {
62 DECLARE_EXTENSION_FUNCTION("sockets.tcp.update", SOCKETS_TCP_UPDATE)
64 SocketsTcpUpdateFunction();
67 ~SocketsTcpUpdateFunction() override;
70 bool Prepare() override;
74 scoped_ptr<sockets_tcp::Update::Params> params_;
77 class SocketsTcpSetPausedFunction : public TCPSocketAsyncApiFunction {
79 DECLARE_EXTENSION_FUNCTION("sockets.tcp.setPaused", SOCKETS_TCP_SETPAUSED)
81 SocketsTcpSetPausedFunction();
84 ~SocketsTcpSetPausedFunction() override;
87 bool Prepare() override;
91 scoped_ptr<sockets_tcp::SetPaused::Params> params_;
92 TCPSocketEventDispatcher* socket_event_dispatcher_;
95 class SocketsTcpSetKeepAliveFunction : public TCPSocketAsyncApiFunction {
97 DECLARE_EXTENSION_FUNCTION("sockets.tcp.setKeepAlive",
98 SOCKETS_TCP_SETKEEPALIVE)
100 SocketsTcpSetKeepAliveFunction();
103 ~SocketsTcpSetKeepAliveFunction() override;
106 bool Prepare() override;
107 void Work() override;
110 scoped_ptr<sockets_tcp::SetKeepAlive::Params> params_;
113 class SocketsTcpSetNoDelayFunction : public TCPSocketAsyncApiFunction {
115 DECLARE_EXTENSION_FUNCTION("sockets.tcp.setNoDelay", SOCKETS_TCP_SETNODELAY)
117 SocketsTcpSetNoDelayFunction();
120 ~SocketsTcpSetNoDelayFunction() override;
123 bool Prepare() override;
124 void Work() override;
127 scoped_ptr<sockets_tcp::SetNoDelay::Params> params_;
130 class SocketsTcpConnectFunction
131 : public TCPSocketExtensionWithDnsLookupFunction {
133 DECLARE_EXTENSION_FUNCTION("sockets.tcp.connect", SOCKETS_TCP_CONNECT)
135 SocketsTcpConnectFunction();
138 ~SocketsTcpConnectFunction() override;
141 bool Prepare() override;
142 void AsyncWorkStart() override;
144 // SocketExtensionWithDnsLookupFunction:
145 void AfterDnsLookup(int lookup_result) override;
149 void OnCompleted(int net_result);
151 scoped_ptr<sockets_tcp::Connect::Params> params_;
152 TCPSocketEventDispatcher* socket_event_dispatcher_;
155 class SocketsTcpDisconnectFunction : public TCPSocketAsyncApiFunction {
157 DECLARE_EXTENSION_FUNCTION("sockets.tcp.disconnect", SOCKETS_TCP_DISCONNECT)
159 SocketsTcpDisconnectFunction();
162 ~SocketsTcpDisconnectFunction() override;
165 bool Prepare() override;
166 void Work() override;
169 scoped_ptr<sockets_tcp::Disconnect::Params> params_;
172 class SocketsTcpSendFunction : public TCPSocketAsyncApiFunction {
174 DECLARE_EXTENSION_FUNCTION("sockets.tcp.send", SOCKETS_TCP_SEND)
176 SocketsTcpSendFunction();
179 ~SocketsTcpSendFunction() override;
182 bool Prepare() override;
183 void AsyncWorkStart() override;
186 void OnCompleted(int net_result);
187 void SetSendResult(int net_result, int bytes_sent);
189 scoped_ptr<sockets_tcp::Send::Params> params_;
190 scoped_refptr<net::IOBuffer> io_buffer_;
191 size_t io_buffer_size_;
194 class SocketsTcpCloseFunction : public TCPSocketAsyncApiFunction {
196 DECLARE_EXTENSION_FUNCTION("sockets.tcp.close", SOCKETS_TCP_CLOSE)
198 SocketsTcpCloseFunction();
201 ~SocketsTcpCloseFunction() override;
204 bool Prepare() override;
205 void Work() override;
208 scoped_ptr<sockets_tcp::Close::Params> params_;
211 class SocketsTcpGetInfoFunction : public TCPSocketAsyncApiFunction {
213 DECLARE_EXTENSION_FUNCTION("sockets.tcp.getInfo", SOCKETS_TCP_GETINFO)
215 SocketsTcpGetInfoFunction();
218 ~SocketsTcpGetInfoFunction() override;
221 bool Prepare() override;
222 void Work() override;
225 scoped_ptr<sockets_tcp::GetInfo::Params> params_;
228 class SocketsTcpGetSocketsFunction : public TCPSocketAsyncApiFunction {
230 DECLARE_EXTENSION_FUNCTION("sockets.tcp.getSockets", SOCKETS_TCP_GETSOCKETS)
232 SocketsTcpGetSocketsFunction();
235 ~SocketsTcpGetSocketsFunction() override;
238 bool Prepare() override;
239 void Work() override;
242 class SocketsTcpSecureFunction : public TCPSocketAsyncApiFunction {
244 DECLARE_EXTENSION_FUNCTION("sockets.tcp.secure", SOCKETS_TCP_SECURE);
246 SocketsTcpSecureFunction();
249 ~SocketsTcpSecureFunction() override;
250 bool Prepare() override;
251 void AsyncWorkStart() override;
254 virtual void TlsConnectDone(scoped_ptr<extensions::TLSSocket> sock,
259 scoped_ptr<sockets_tcp::Secure::Params> params_;
260 scoped_refptr<net::URLRequestContextGetter> url_request_getter_;
262 DISALLOW_COPY_AND_ASSIGN(SocketsTcpSecureFunction);
265 } // namespace core_api
266 } // namespace extensions
268 #endif // EXTENSIONS_BROWSER_API_SOCKETS_TCP_SOCKETS_TCP_API_H_