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_SOCKET_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "chrome/browser/extensions/api/api_resource.h" | 14 #include "chrome/browser/extensions/api/api_resource.h" |
15 #include "net/base/completion_callback.h" | 15 #include "net/base/completion_callback.h" |
16 #include "net/base/io_buffer.h" | 16 #include "net/base/io_buffer.h" |
17 #include "net/base/ip_endpoint.h" | 17 #include "net/base/ip_endpoint.h" |
| 18 #include "net/socket/tcp_client_socket.h" |
18 | 19 |
19 namespace net { | 20 namespace net { |
20 class AddressList; | 21 class AddressList; |
21 class IPEndPoint; | 22 class IPEndPoint; |
22 class Socket; | 23 class Socket; |
23 } | 24 } |
24 | 25 |
25 namespace extensions { | 26 namespace extensions { |
26 | 27 |
27 typedef base::Callback<void(int)> CompletionCallback; | 28 typedef base::Callback<void(int)> CompletionCallback; |
28 typedef base::Callback<void(int, scoped_refptr<net::IOBuffer> io_buffer)> | 29 typedef base::Callback<void(int, scoped_refptr<net::IOBuffer> io_buffer)> |
29 ReadCompletionCallback; | 30 ReadCompletionCallback; |
30 typedef base::Callback< | 31 typedef base::Callback< |
31 void(int, scoped_refptr<net::IOBuffer> io_buffer, const std::string&, int)> | 32 void(int, scoped_refptr<net::IOBuffer> io_buffer, const std::string&, int)> |
32 RecvFromCompletionCallback; | 33 RecvFromCompletionCallback; |
| 34 typedef base::Callback<void(int, net::TCPClientSocket*)> AcceptCompletionCallbac
k; |
33 | 35 |
34 // A Socket wraps a low-level socket and includes housekeeping information that | 36 // A Socket wraps a low-level socket and includes housekeeping information that |
35 // we need to manage it in the context of an extension. | 37 // we need to manage it in the context of an extension. |
36 class Socket : public ApiResource { | 38 class Socket : public ApiResource { |
37 public: | 39 public: |
38 virtual ~Socket(); | 40 virtual ~Socket(); |
39 virtual void Connect(const std::string& address, | 41 virtual void Connect(const std::string& address, |
40 int port, | 42 int port, |
41 const CompletionCallback& callback) = 0; | 43 const CompletionCallback& callback) = 0; |
42 virtual void Disconnect() = 0; | 44 virtual void Disconnect() = 0; |
(...skipping 13 matching lines...) Expand all Loading... |
56 virtual void RecvFrom(int count, | 58 virtual void RecvFrom(int count, |
57 const RecvFromCompletionCallback& callback) = 0; | 59 const RecvFromCompletionCallback& callback) = 0; |
58 virtual void SendTo(scoped_refptr<net::IOBuffer> io_buffer, | 60 virtual void SendTo(scoped_refptr<net::IOBuffer> io_buffer, |
59 int byte_count, | 61 int byte_count, |
60 const std::string& address, | 62 const std::string& address, |
61 int port, | 63 int port, |
62 const CompletionCallback& callback) = 0; | 64 const CompletionCallback& callback) = 0; |
63 | 65 |
64 virtual bool SetKeepAlive(bool enable, int delay); | 66 virtual bool SetKeepAlive(bool enable, int delay); |
65 virtual bool SetNoDelay(bool no_delay); | 67 virtual bool SetNoDelay(bool no_delay); |
| 68 virtual bool Listen(int backlog); |
| 69 virtual void Accept(const AcceptCompletionCallback &callback); |
66 | 70 |
67 bool IsConnected(); | 71 bool IsConnected(); |
68 virtual bool IsTCPSocket() = 0; | 72 virtual bool IsTCPSocket() = 0; |
69 | 73 |
70 virtual bool GetPeerAddress(net::IPEndPoint* address) = 0; | 74 virtual bool GetPeerAddress(net::IPEndPoint* address) = 0; |
71 virtual bool GetLocalAddress(net::IPEndPoint* address) = 0; | 75 virtual bool GetLocalAddress(net::IPEndPoint* address) = 0; |
72 | 76 |
73 static bool StringAndPortToAddressList(const std::string& ip_address_str, | 77 static bool StringAndPortToAddressList(const std::string& ip_address_str, |
74 int port, | 78 int port, |
75 net::AddressList* address_list); | 79 net::AddressList* address_list); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 CompletionCallback callback; | 112 CompletionCallback callback; |
109 int bytes_written; | 113 int bytes_written; |
110 }; | 114 }; |
111 std::queue<WriteRequest> write_queue_; | 115 std::queue<WriteRequest> write_queue_; |
112 scoped_refptr<net::IOBuffer> io_buffer_write_; | 116 scoped_refptr<net::IOBuffer> io_buffer_write_; |
113 }; | 117 }; |
114 | 118 |
115 } // namespace extensions | 119 } // namespace extensions |
116 | 120 |
117 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ | 121 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ |
OLD | NEW |