OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_EXTENSIONS_API_SOCKET_UDP_SOCKET_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SOCKET_UDP_SOCKET_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_UDP_SOCKET_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_UDP_SOCKET_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "chrome/browser/extensions/api/socket/socket.h" | 11 #include "chrome/browser/extensions/api/socket/socket.h" |
12 #include "net/udp/datagram_client_socket.h" | 12 #include "net/udp/udp_socket.h" |
13 | 13 |
14 namespace net { | 14 namespace net { |
15 class Socket; | 15 class Socket; |
16 } | 16 } |
17 | 17 |
18 namespace extensions { | 18 namespace extensions { |
19 | 19 |
20 class APIResourceEventNotifier; | 20 class APIResourceEventNotifier; |
21 | 21 |
22 class UDPSocket : public Socket { | 22 class UDPSocket : public Socket { |
23 public: | 23 public: |
24 UDPSocket(const std::string& address, int port, | 24 explicit UDPSocket(APIResourceEventNotifier* event_notifier); |
25 APIResourceEventNotifier* event_notifier); | |
26 virtual ~UDPSocket(); | 25 virtual ~UDPSocket(); |
27 | 26 |
28 virtual bool IsValid() OVERRIDE; | 27 virtual int Connect(const std::string& address, int port) OVERRIDE; |
29 | |
30 virtual int Connect() OVERRIDE; | |
31 virtual void Disconnect() OVERRIDE; | 28 virtual void Disconnect() OVERRIDE; |
32 | 29 virtual int Bind(const std::string& address, int port) OVERRIDE; |
33 static UDPSocket* CreateSocketForTesting( | 30 virtual int Read(scoped_refptr<net::IOBuffer> io_buffer, |
34 net::DatagramClientSocket* datagram_client_socket, | 31 int io_buffer_size) OVERRIDE; |
35 const std::string& address, int port, | 32 virtual int Write(scoped_refptr<net::IOBuffer> io_buffer, |
36 APIResourceEventNotifier* event_notifier); | 33 int bytes) OVERRIDE; |
37 | 34 virtual int RecvFrom(scoped_refptr<net::IOBuffer> io_buffer, |
38 protected: | 35 int io_buffer_size, |
39 virtual net::Socket* socket() OVERRIDE; | 36 net::IPEndPoint* address) OVERRIDE; |
| 37 virtual int SendTo(scoped_refptr<net::IOBuffer> io_buffer, |
| 38 int byte_count, |
| 39 const std::string& address, |
| 40 int port) OVERRIDE; |
40 | 41 |
41 private: | 42 private: |
42 // Special constructor for testing. | 43 scoped_ptr<net::UDPSocket> socket_; |
43 UDPSocket(net::DatagramClientSocket* datagram_client_socket, | |
44 const std::string& address, int port, | |
45 APIResourceEventNotifier* event_notifier); | |
46 | |
47 scoped_ptr<net::DatagramClientSocket> socket_; | |
48 }; | 44 }; |
49 | 45 |
50 } // namespace extensions | 46 } // namespace extensions |
51 | 47 |
52 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_UDP_SOCKET_H_ | 48 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_UDP_SOCKET_H_ |
OLD | NEW |