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< |
| 35 void(int, net::TCPClientSocket*)> AcceptCompletionCallback; |
33 | 36 |
34 // A Socket wraps a low-level socket and includes housekeeping information that | 37 // A Socket wraps a low-level socket and includes housekeeping information that |
35 // we need to manage it in the context of an extension. | 38 // we need to manage it in the context of an extension. |
36 class Socket : public ApiResource { | 39 class Socket : public ApiResource { |
37 public: | 40 public: |
38 enum SocketType { | 41 enum SocketType { |
39 TYPE_TCP, | 42 TYPE_TCP, |
40 TYPE_UDP, | 43 TYPE_UDP, |
41 }; | 44 }; |
42 | 45 |
(...skipping 18 matching lines...) Expand all Loading... |
61 virtual void RecvFrom(int count, | 64 virtual void RecvFrom(int count, |
62 const RecvFromCompletionCallback& callback) = 0; | 65 const RecvFromCompletionCallback& callback) = 0; |
63 virtual void SendTo(scoped_refptr<net::IOBuffer> io_buffer, | 66 virtual void SendTo(scoped_refptr<net::IOBuffer> io_buffer, |
64 int byte_count, | 67 int byte_count, |
65 const std::string& address, | 68 const std::string& address, |
66 int port, | 69 int port, |
67 const CompletionCallback& callback) = 0; | 70 const CompletionCallback& callback) = 0; |
68 | 71 |
69 virtual bool SetKeepAlive(bool enable, int delay); | 72 virtual bool SetKeepAlive(bool enable, int delay); |
70 virtual bool SetNoDelay(bool no_delay); | 73 virtual bool SetNoDelay(bool no_delay); |
| 74 virtual int Listen(const std::string& address, int port, int backlog, |
| 75 std::string* error_msg); |
| 76 virtual void Accept(const AcceptCompletionCallback &callback); |
71 | 77 |
72 bool IsConnected(); | 78 bool IsConnected(); |
73 | 79 |
74 virtual bool GetPeerAddress(net::IPEndPoint* address) = 0; | 80 virtual bool GetPeerAddress(net::IPEndPoint* address) = 0; |
75 virtual bool GetLocalAddress(net::IPEndPoint* address) = 0; | 81 virtual bool GetLocalAddress(net::IPEndPoint* address) = 0; |
76 | 82 |
77 virtual SocketType GetSocketType() const = 0; | 83 virtual SocketType GetSocketType() const = 0; |
78 | 84 |
79 static bool StringAndPortToAddressList(const std::string& ip_address_str, | 85 static bool StringAndPortToAddressList(const std::string& ip_address_str, |
80 int port, | 86 int port, |
(...skipping 30 matching lines...) Expand all Loading... |
111 CompletionCallback callback; | 117 CompletionCallback callback; |
112 int bytes_written; | 118 int bytes_written; |
113 }; | 119 }; |
114 std::queue<WriteRequest> write_queue_; | 120 std::queue<WriteRequest> write_queue_; |
115 scoped_refptr<net::IOBuffer> io_buffer_write_; | 121 scoped_refptr<net::IOBuffer> io_buffer_write_; |
116 }; | 122 }; |
117 | 123 |
118 } // namespace extensions | 124 } // namespace extensions |
119 | 125 |
120 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ | 126 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ |
OLD | NEW |