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_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "chrome/browser/extensions/api/api_function.h" | 9 #include "chrome/browser/extensions/api/api_function.h" |
10 #include "chrome/browser/extensions/api/api_resource_manager.h" | 10 #include "chrome/browser/extensions/api/api_resource_manager.h" |
11 #include "chrome/common/extensions/api/socket.h" | 11 #include "chrome/common/extensions/api/socket.h" |
12 #include "net/base/address_list.h" | 12 #include "net/base/address_list.h" |
13 #include "net/base/host_resolver.h" | 13 #include "net/base/host_resolver.h" |
| 14 #include "net/socket/tcp_client_socket.h" |
14 | 15 |
15 #include <string> | 16 #include <string> |
16 | 17 |
17 class IOThread; | 18 class IOThread; |
18 | 19 |
19 namespace net { | 20 namespace net { |
20 class IOBuffer; | 21 class IOBuffer; |
21 } | 22 } |
22 | 23 |
23 namespace extensions { | 24 namespace extensions { |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 // AsyncApiFunction: | 153 // AsyncApiFunction: |
153 virtual bool Prepare() OVERRIDE; | 154 virtual bool Prepare() OVERRIDE; |
154 virtual void Work() OVERRIDE; | 155 virtual void Work() OVERRIDE; |
155 | 156 |
156 private: | 157 private: |
157 int socket_id_; | 158 int socket_id_; |
158 std::string address_; | 159 std::string address_; |
159 int port_; | 160 int port_; |
160 }; | 161 }; |
161 | 162 |
| 163 class SocketListenFunction : public SocketAsyncApiFunction { |
| 164 public: |
| 165 DECLARE_EXTENSION_FUNCTION_NAME("socket.listen"); |
| 166 |
| 167 protected: |
| 168 virtual ~SocketListenFunction() {} |
| 169 |
| 170 // AsyncApiFunction: |
| 171 virtual bool Prepare() OVERRIDE; |
| 172 virtual void Work() OVERRIDE; |
| 173 |
| 174 private: |
| 175 int socket_id_; |
| 176 int backlog_; |
| 177 }; |
| 178 |
| 179 class SocketAcceptFunction : public SocketAsyncApiFunction { |
| 180 public: |
| 181 DECLARE_EXTENSION_FUNCTION_NAME("socket.accept"); |
| 182 |
| 183 SocketAcceptFunction(); |
| 184 |
| 185 protected: |
| 186 virtual ~SocketAcceptFunction(); |
| 187 |
| 188 // AsyncApiFunction: |
| 189 virtual bool Prepare() OVERRIDE; |
| 190 virtual void Work() OVERRIDE; |
| 191 |
| 192 private: |
| 193 void OnAccept(int result_code, net::TCPClientSocket *socket); |
| 194 scoped_ptr<api::socket::Accept::Params> params_; |
| 195 ApiResourceEventNotifier* event_notifier_; |
| 196 int src_id_; |
| 197 }; |
| 198 |
162 class SocketReadFunction : public SocketAsyncApiFunction { | 199 class SocketReadFunction : public SocketAsyncApiFunction { |
163 public: | 200 public: |
164 DECLARE_EXTENSION_FUNCTION_NAME("socket.read") | 201 DECLARE_EXTENSION_FUNCTION_NAME("socket.read") |
165 | 202 |
166 SocketReadFunction(); | 203 SocketReadFunction(); |
167 | 204 |
168 protected: | 205 protected: |
169 virtual ~SocketReadFunction(); | 206 virtual ~SocketReadFunction(); |
170 | 207 |
171 // AsyncApiFunction: | 208 // AsyncApiFunction: |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 virtual bool Prepare() OVERRIDE; | 329 virtual bool Prepare() OVERRIDE; |
293 virtual void Work() OVERRIDE; | 330 virtual void Work() OVERRIDE; |
294 | 331 |
295 private: | 332 private: |
296 scoped_ptr<api::socket::GetInfo::Params> params_; | 333 scoped_ptr<api::socket::GetInfo::Params> params_; |
297 }; | 334 }; |
298 | 335 |
299 } // namespace extensions | 336 } // namespace extensions |
300 | 337 |
301 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_H_ | 338 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_H_ |
OLD | NEW |