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_TCP_SOCKET_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SOCKET_TCP_SOCKET_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_TCP_SOCKET_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_TCP_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 | 12 |
13 // This looks like it should be forward-declarable, but it does some tricky | 13 // This looks like it should be forward-declarable, but it does some tricky |
14 // moves that make it easier to just include it. | 14 // moves that make it easier to just include it. |
15 #include "net/socket/tcp_client_socket.h" | 15 #include "net/socket/tcp_client_socket.h" |
16 | 16 |
17 namespace net { | 17 namespace net { |
18 class Socket; | 18 class Socket; |
19 } | 19 } |
20 | 20 |
21 namespace extensions { | 21 namespace extensions { |
22 | 22 |
23 class APIResourceEventNotifier; | 23 class APIResourceEventNotifier; |
24 | 24 |
25 class TCPSocket : public Socket { | 25 class TCPSocket : public Socket { |
26 public: | 26 public: |
27 TCPSocket(const std::string& address, int port, | 27 explicit TCPSocket(APIResourceEventNotifier* event_notifier); |
28 APIResourceEventNotifier* event_notifier); | |
29 virtual ~TCPSocket(); | 28 virtual ~TCPSocket(); |
30 | 29 |
31 virtual bool IsValid() OVERRIDE; | 30 virtual bool IsValid() OVERRIDE; |
32 | 31 |
33 virtual int Connect() OVERRIDE; | 32 virtual int Connect(const std::string& address, int port) OVERRIDE; |
34 virtual void Disconnect() OVERRIDE; | 33 virtual void Disconnect() OVERRIDE; |
| 34 virtual int Bind(const std::string& address, int port) OVERRIDE; |
| 35 virtual int Read(scoped_refptr<net::IOBuffer> io_buffer, |
| 36 int io_buffer_size) OVERRIDE; |
| 37 virtual int Write(scoped_refptr<net::IOBuffer> io_buffer, |
| 38 int bytes) OVERRIDE; |
| 39 virtual int RecvFrom(scoped_refptr<net::IOBuffer> io_buffer, |
| 40 int io_buffer_size, |
| 41 net::IPEndPoint *address) OVERRIDE; |
| 42 virtual int SendTo(scoped_refptr<net::IOBuffer> io_buffer, |
| 43 int byte_count, |
| 44 const std::string& address, |
| 45 int port) OVERRIDE; |
35 | 46 |
36 virtual void OnConnect(int result); | 47 virtual void OnConnect(int result); |
37 | 48 |
38 static TCPSocket* CreateSocketForTesting( | 49 static TCPSocket* CreateSocketForTesting( |
39 net::TCPClientSocket* tcp_client_socket, | 50 net::TCPClientSocket* tcp_client_socket, |
40 const std::string& address, int port, | |
41 APIResourceEventNotifier* event_notifier); | 51 APIResourceEventNotifier* event_notifier); |
42 | 52 |
43 protected: | |
44 virtual net::Socket* socket() OVERRIDE; | |
45 | |
46 private: | 53 private: |
47 TCPSocket(net::TCPClientSocket* tcp_client_socket, | 54 TCPSocket(net::TCPClientSocket* tcp_client_socket, |
48 const std::string& address, int port, | |
49 APIResourceEventNotifier* event_notifier); | 55 APIResourceEventNotifier* event_notifier); |
50 | 56 |
51 scoped_ptr<net::TCPClientSocket> socket_; | 57 scoped_ptr<net::TCPClientSocket> socket_; |
52 }; | 58 }; |
53 | 59 |
54 } // namespace extensions | 60 } // namespace extensions |
55 | 61 |
56 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_TCP_SOCKET_H_ | 62 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_TCP_SOCKET_H_ |
OLD | NEW |