Finish refactoring of DomCodeToUsLayoutKeyboardCode().
[chromium-blink-merge.git] / extensions / browser / api / sockets_tcp / sockets_tcp_api.h
blobe745932d6a266254847588081939eafc6dfb1ea9
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;
13 class TLSSocket;
16 namespace extensions {
17 namespace core_api {
19 class TCPSocketEventDispatcher;
21 class TCPSocketAsyncApiFunction : public SocketAsyncApiFunction {
22 protected:
23 ~TCPSocketAsyncApiFunction() override;
25 scoped_ptr<SocketResourceManagerInterface> CreateSocketResourceManager()
26 override;
28 ResumableTCPSocket* GetTcpSocket(int socket_id);
31 class TCPSocketExtensionWithDnsLookupFunction
32 : public SocketExtensionWithDnsLookupFunction {
33 protected:
34 ~TCPSocketExtensionWithDnsLookupFunction() override;
36 scoped_ptr<SocketResourceManagerInterface> CreateSocketResourceManager()
37 override;
39 ResumableTCPSocket* GetTcpSocket(int socket_id);
42 class SocketsTcpCreateFunction : public TCPSocketAsyncApiFunction {
43 public:
44 DECLARE_EXTENSION_FUNCTION("sockets.tcp.create", SOCKETS_TCP_CREATE)
46 SocketsTcpCreateFunction();
48 protected:
49 ~SocketsTcpCreateFunction() override;
51 // AsyncApiFunction:
52 bool Prepare() override;
53 void Work() override;
55 private:
56 FRIEND_TEST_ALL_PREFIXES(SocketsTcpUnitTest, Create);
57 scoped_ptr<sockets_tcp::Create::Params> params_;
60 class SocketsTcpUpdateFunction : public TCPSocketAsyncApiFunction {
61 public:
62 DECLARE_EXTENSION_FUNCTION("sockets.tcp.update", SOCKETS_TCP_UPDATE)
64 SocketsTcpUpdateFunction();
66 protected:
67 ~SocketsTcpUpdateFunction() override;
69 // AsyncApiFunction:
70 bool Prepare() override;
71 void Work() override;
73 private:
74 scoped_ptr<sockets_tcp::Update::Params> params_;
77 class SocketsTcpSetPausedFunction : public TCPSocketAsyncApiFunction {
78 public:
79 DECLARE_EXTENSION_FUNCTION("sockets.tcp.setPaused", SOCKETS_TCP_SETPAUSED)
81 SocketsTcpSetPausedFunction();
83 protected:
84 ~SocketsTcpSetPausedFunction() override;
86 // AsyncApiFunction
87 bool Prepare() override;
88 void Work() override;
90 private:
91 scoped_ptr<sockets_tcp::SetPaused::Params> params_;
92 TCPSocketEventDispatcher* socket_event_dispatcher_;
95 class SocketsTcpSetKeepAliveFunction : public TCPSocketAsyncApiFunction {
96 public:
97 DECLARE_EXTENSION_FUNCTION("sockets.tcp.setKeepAlive",
98 SOCKETS_TCP_SETKEEPALIVE)
100 SocketsTcpSetKeepAliveFunction();
102 protected:
103 ~SocketsTcpSetKeepAliveFunction() override;
105 // AsyncApiFunction
106 bool Prepare() override;
107 void Work() override;
109 private:
110 scoped_ptr<sockets_tcp::SetKeepAlive::Params> params_;
113 class SocketsTcpSetNoDelayFunction : public TCPSocketAsyncApiFunction {
114 public:
115 DECLARE_EXTENSION_FUNCTION("sockets.tcp.setNoDelay", SOCKETS_TCP_SETNODELAY)
117 SocketsTcpSetNoDelayFunction();
119 protected:
120 ~SocketsTcpSetNoDelayFunction() override;
122 // AsyncApiFunction
123 bool Prepare() override;
124 void Work() override;
126 private:
127 scoped_ptr<sockets_tcp::SetNoDelay::Params> params_;
130 class SocketsTcpConnectFunction
131 : public TCPSocketExtensionWithDnsLookupFunction {
132 public:
133 DECLARE_EXTENSION_FUNCTION("sockets.tcp.connect", SOCKETS_TCP_CONNECT)
135 SocketsTcpConnectFunction();
137 protected:
138 ~SocketsTcpConnectFunction() override;
140 // AsyncApiFunction:
141 bool Prepare() override;
142 void AsyncWorkStart() override;
144 // SocketExtensionWithDnsLookupFunction:
145 void AfterDnsLookup(int lookup_result) override;
147 private:
148 void StartConnect();
149 void OnCompleted(int net_result);
151 scoped_ptr<sockets_tcp::Connect::Params> params_;
152 TCPSocketEventDispatcher* socket_event_dispatcher_;
155 class SocketsTcpDisconnectFunction : public TCPSocketAsyncApiFunction {
156 public:
157 DECLARE_EXTENSION_FUNCTION("sockets.tcp.disconnect", SOCKETS_TCP_DISCONNECT)
159 SocketsTcpDisconnectFunction();
161 protected:
162 ~SocketsTcpDisconnectFunction() override;
164 // AsyncApiFunction:
165 bool Prepare() override;
166 void Work() override;
168 private:
169 scoped_ptr<sockets_tcp::Disconnect::Params> params_;
172 class SocketsTcpSendFunction : public TCPSocketAsyncApiFunction {
173 public:
174 DECLARE_EXTENSION_FUNCTION("sockets.tcp.send", SOCKETS_TCP_SEND)
176 SocketsTcpSendFunction();
178 protected:
179 ~SocketsTcpSendFunction() override;
181 // AsyncApiFunction:
182 bool Prepare() override;
183 void AsyncWorkStart() override;
185 private:
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 {
195 public:
196 DECLARE_EXTENSION_FUNCTION("sockets.tcp.close", SOCKETS_TCP_CLOSE)
198 SocketsTcpCloseFunction();
200 protected:
201 ~SocketsTcpCloseFunction() override;
203 // AsyncApiFunction:
204 bool Prepare() override;
205 void Work() override;
207 private:
208 scoped_ptr<sockets_tcp::Close::Params> params_;
211 class SocketsTcpGetInfoFunction : public TCPSocketAsyncApiFunction {
212 public:
213 DECLARE_EXTENSION_FUNCTION("sockets.tcp.getInfo", SOCKETS_TCP_GETINFO)
215 SocketsTcpGetInfoFunction();
217 protected:
218 ~SocketsTcpGetInfoFunction() override;
220 // AsyncApiFunction:
221 bool Prepare() override;
222 void Work() override;
224 private:
225 scoped_ptr<sockets_tcp::GetInfo::Params> params_;
228 class SocketsTcpGetSocketsFunction : public TCPSocketAsyncApiFunction {
229 public:
230 DECLARE_EXTENSION_FUNCTION("sockets.tcp.getSockets", SOCKETS_TCP_GETSOCKETS)
232 SocketsTcpGetSocketsFunction();
234 protected:
235 ~SocketsTcpGetSocketsFunction() override;
237 // AsyncApiFunction:
238 bool Prepare() override;
239 void Work() override;
242 class SocketsTcpSecureFunction : public TCPSocketAsyncApiFunction {
243 public:
244 DECLARE_EXTENSION_FUNCTION("sockets.tcp.secure", SOCKETS_TCP_SECURE);
246 SocketsTcpSecureFunction();
248 protected:
249 ~SocketsTcpSecureFunction() override;
250 bool Prepare() override;
251 void AsyncWorkStart() override;
253 private:
254 virtual void TlsConnectDone(scoped_ptr<extensions::TLSSocket> sock,
255 int result);
257 bool paused_;
258 bool persistent_;
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_