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_UDP_SOCKETS_UDP_API_H_
6 #define EXTENSIONS_BROWSER_API_SOCKETS_UDP_SOCKETS_UDP_API_H_
8 #include "extensions/browser/api/socket/socket_api.h"
9 #include "extensions/common/api/sockets_udp.h"
11 namespace extensions
{
12 class ResumableUDPSocket
;
15 namespace extensions
{
18 class UDPSocketEventDispatcher
;
20 class UDPSocketAsyncApiFunction
: public SocketAsyncApiFunction
{
22 virtual ~UDPSocketAsyncApiFunction();
24 virtual scoped_ptr
<SocketResourceManagerInterface
>
25 CreateSocketResourceManager() OVERRIDE
;
27 ResumableUDPSocket
* GetUdpSocket(int socket_id
);
30 class UDPSocketExtensionWithDnsLookupFunction
31 : public SocketExtensionWithDnsLookupFunction
{
33 virtual ~UDPSocketExtensionWithDnsLookupFunction();
35 virtual scoped_ptr
<SocketResourceManagerInterface
>
36 CreateSocketResourceManager() OVERRIDE
;
38 ResumableUDPSocket
* GetUdpSocket(int socket_id
);
41 class SocketsUdpCreateFunction
: public UDPSocketAsyncApiFunction
{
43 DECLARE_EXTENSION_FUNCTION("sockets.udp.create", SOCKETS_UDP_CREATE
)
45 SocketsUdpCreateFunction();
48 virtual ~SocketsUdpCreateFunction();
51 virtual bool Prepare() OVERRIDE
;
52 virtual void Work() OVERRIDE
;
55 FRIEND_TEST_ALL_PREFIXES(SocketsUdpUnitTest
, Create
);
56 scoped_ptr
<sockets_udp::Create::Params
> params_
;
59 class SocketsUdpUpdateFunction
: public UDPSocketAsyncApiFunction
{
61 DECLARE_EXTENSION_FUNCTION("sockets.udp.update", SOCKETS_UDP_UPDATE
)
63 SocketsUdpUpdateFunction();
66 virtual ~SocketsUdpUpdateFunction();
69 virtual bool Prepare() OVERRIDE
;
70 virtual void Work() OVERRIDE
;
73 scoped_ptr
<sockets_udp::Update::Params
> params_
;
76 class SocketsUdpSetPausedFunction
: public UDPSocketAsyncApiFunction
{
78 DECLARE_EXTENSION_FUNCTION("sockets.udp.setPaused", SOCKETS_UDP_SETPAUSED
)
80 SocketsUdpSetPausedFunction();
83 virtual ~SocketsUdpSetPausedFunction();
86 virtual bool Prepare() OVERRIDE
;
87 virtual void Work() OVERRIDE
;
90 scoped_ptr
<sockets_udp::SetPaused::Params
> params_
;
91 UDPSocketEventDispatcher
* socket_event_dispatcher_
;
94 class SocketsUdpBindFunction
: public UDPSocketAsyncApiFunction
{
96 DECLARE_EXTENSION_FUNCTION("sockets.udp.bind", SOCKETS_UDP_BIND
)
98 SocketsUdpBindFunction();
101 virtual ~SocketsUdpBindFunction();
104 virtual bool Prepare() OVERRIDE
;
105 virtual void Work() OVERRIDE
;
108 scoped_ptr
<sockets_udp::Bind::Params
> params_
;
109 UDPSocketEventDispatcher
* socket_event_dispatcher_
;
112 class SocketsUdpSendFunction
: public UDPSocketExtensionWithDnsLookupFunction
{
114 DECLARE_EXTENSION_FUNCTION("sockets.udp.send", SOCKETS_UDP_SEND
)
116 SocketsUdpSendFunction();
119 virtual ~SocketsUdpSendFunction();
122 virtual bool Prepare() OVERRIDE
;
123 virtual void AsyncWorkStart() OVERRIDE
;
124 void OnCompleted(int net_result
);
125 void SetSendResult(int net_result
, int bytes_sent
);
127 // SocketExtensionWithDnsLookupFunction:
128 virtual void AfterDnsLookup(int lookup_result
) OVERRIDE
;
133 scoped_ptr
<sockets_udp::Send::Params
> params_
;
134 scoped_refptr
<net::IOBuffer
> io_buffer_
;
135 size_t io_buffer_size_
;
138 class SocketsUdpCloseFunction
: public UDPSocketAsyncApiFunction
{
140 DECLARE_EXTENSION_FUNCTION("sockets.udp.close", SOCKETS_UDP_CLOSE
)
142 SocketsUdpCloseFunction();
145 virtual ~SocketsUdpCloseFunction();
148 virtual bool Prepare() OVERRIDE
;
149 virtual void Work() OVERRIDE
;
152 scoped_ptr
<sockets_udp::Close::Params
> params_
;
155 class SocketsUdpGetInfoFunction
: public UDPSocketAsyncApiFunction
{
157 DECLARE_EXTENSION_FUNCTION("sockets.udp.getInfo", SOCKETS_UDP_GETINFO
)
159 SocketsUdpGetInfoFunction();
162 virtual ~SocketsUdpGetInfoFunction();
165 virtual bool Prepare() OVERRIDE
;
166 virtual void Work() OVERRIDE
;
169 scoped_ptr
<sockets_udp::GetInfo::Params
> params_
;
172 class SocketsUdpGetSocketsFunction
: public UDPSocketAsyncApiFunction
{
174 DECLARE_EXTENSION_FUNCTION("sockets.udp.getSockets", SOCKETS_UDP_GETSOCKETS
)
176 SocketsUdpGetSocketsFunction();
179 virtual ~SocketsUdpGetSocketsFunction();
182 virtual bool Prepare() OVERRIDE
;
183 virtual void Work() OVERRIDE
;
186 class SocketsUdpJoinGroupFunction
: public UDPSocketAsyncApiFunction
{
188 DECLARE_EXTENSION_FUNCTION("sockets.udp.joinGroup", SOCKETS_UDP_JOINGROUP
)
190 SocketsUdpJoinGroupFunction();
193 virtual ~SocketsUdpJoinGroupFunction();
196 virtual bool Prepare() OVERRIDE
;
197 virtual void Work() OVERRIDE
;
200 scoped_ptr
<sockets_udp::JoinGroup::Params
> params_
;
203 class SocketsUdpLeaveGroupFunction
: public UDPSocketAsyncApiFunction
{
205 DECLARE_EXTENSION_FUNCTION("sockets.udp.leaveGroup", SOCKETS_UDP_LEAVEGROUP
)
207 SocketsUdpLeaveGroupFunction();
210 virtual ~SocketsUdpLeaveGroupFunction();
213 virtual bool Prepare() OVERRIDE
;
214 virtual void Work() OVERRIDE
;
217 scoped_ptr
<sockets_udp::LeaveGroup::Params
> params_
;
220 class SocketsUdpSetMulticastTimeToLiveFunction
221 : public UDPSocketAsyncApiFunction
{
223 DECLARE_EXTENSION_FUNCTION("sockets.udp.setMulticastTimeToLive",
224 SOCKETS_UDP_SETMULTICASTTIMETOLIVE
)
226 SocketsUdpSetMulticastTimeToLiveFunction();
229 virtual ~SocketsUdpSetMulticastTimeToLiveFunction();
232 virtual bool Prepare() OVERRIDE
;
233 virtual void Work() OVERRIDE
;
236 scoped_ptr
<sockets_udp::SetMulticastTimeToLive::Params
> params_
;
239 class SocketsUdpSetMulticastLoopbackModeFunction
240 : public UDPSocketAsyncApiFunction
{
242 DECLARE_EXTENSION_FUNCTION("sockets.udp.setMulticastLoopbackMode",
243 SOCKETS_UDP_SETMULTICASTLOOPBACKMODE
)
245 SocketsUdpSetMulticastLoopbackModeFunction();
248 virtual ~SocketsUdpSetMulticastLoopbackModeFunction();
251 virtual bool Prepare() OVERRIDE
;
252 virtual void Work() OVERRIDE
;
255 scoped_ptr
<sockets_udp::SetMulticastLoopbackMode::Params
> params_
;
258 class SocketsUdpGetJoinedGroupsFunction
: public UDPSocketAsyncApiFunction
{
260 DECLARE_EXTENSION_FUNCTION("sockets.udp.getJoinedGroups",
261 SOCKETS_UDP_GETJOINEDGROUPS
)
263 SocketsUdpGetJoinedGroupsFunction();
266 virtual ~SocketsUdpGetJoinedGroupsFunction();
269 virtual bool Prepare() OVERRIDE
;
270 virtual void Work() OVERRIDE
;
273 scoped_ptr
<sockets_udp::GetJoinedGroups::Params
> params_
;
276 } // namespace core_api
277 } // namespace extensions
279 #endif // EXTENSIONS_BROWSER_API_SOCKETS_UDP_SOCKETS_UDP_API_H_