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 EXTENSIONS_BROWSER_API_SOCKET_SOCKET_API_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_H_ | 6 #define EXTENSIONS_BROWSER_API_SOCKET_SOCKET_API_H_ |
| 7 |
| 8 #include <string> |
7 | 9 |
8 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
9 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
10 #include "chrome/common/extensions/api/socket.h" | |
11 #include "extensions/browser/api/api_resource_manager.h" | 12 #include "extensions/browser/api/api_resource_manager.h" |
12 #include "extensions/browser/api/async_api_function.h" | 13 #include "extensions/browser/api/async_api_function.h" |
13 #include "extensions/browser/extension_function.h" | 14 #include "extensions/browser/extension_function.h" |
| 15 #include "extensions/common/api/socket.h" |
14 #include "net/base/address_list.h" | 16 #include "net/base/address_list.h" |
15 #include "net/dns/host_resolver.h" | 17 #include "net/dns/host_resolver.h" |
16 #include "net/socket/tcp_client_socket.h" | 18 #include "net/socket/tcp_client_socket.h" |
17 | 19 |
18 #include <string> | |
19 | |
20 namespace content { | 20 namespace content { |
21 class BrowserContext; | 21 class BrowserContext; |
22 class ResourceContext; | 22 class ResourceContext; |
23 } | 23 } |
24 | 24 |
25 namespace net { | 25 namespace net { |
26 class IOBuffer; | 26 class IOBuffer; |
27 } | 27 } |
28 | 28 |
29 namespace extensions { | 29 namespace extensions { |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 virtual ~SocketCreateFunction(); | 143 virtual ~SocketCreateFunction(); |
144 | 144 |
145 // AsyncApiFunction: | 145 // AsyncApiFunction: |
146 virtual bool Prepare() OVERRIDE; | 146 virtual bool Prepare() OVERRIDE; |
147 virtual void Work() OVERRIDE; | 147 virtual void Work() OVERRIDE; |
148 | 148 |
149 private: | 149 private: |
150 FRIEND_TEST_ALL_PREFIXES(SocketUnitTest, Create); | 150 FRIEND_TEST_ALL_PREFIXES(SocketUnitTest, Create); |
151 enum SocketType { kSocketTypeInvalid = -1, kSocketTypeTCP, kSocketTypeUDP }; | 151 enum SocketType { kSocketTypeInvalid = -1, kSocketTypeTCP, kSocketTypeUDP }; |
152 | 152 |
153 scoped_ptr<api::socket::Create::Params> params_; | 153 scoped_ptr<core_api::socket::Create::Params> params_; |
154 SocketType socket_type_; | 154 SocketType socket_type_; |
155 }; | 155 }; |
156 | 156 |
157 class SocketDestroyFunction : public SocketAsyncApiFunction { | 157 class SocketDestroyFunction : public SocketAsyncApiFunction { |
158 public: | 158 public: |
159 DECLARE_EXTENSION_FUNCTION("socket.destroy", SOCKET_DESTROY) | 159 DECLARE_EXTENSION_FUNCTION("socket.destroy", SOCKET_DESTROY) |
160 | 160 |
161 protected: | 161 protected: |
162 virtual ~SocketDestroyFunction() {} | 162 virtual ~SocketDestroyFunction() {} |
163 | 163 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 SocketListenFunction(); | 234 SocketListenFunction(); |
235 | 235 |
236 protected: | 236 protected: |
237 virtual ~SocketListenFunction(); | 237 virtual ~SocketListenFunction(); |
238 | 238 |
239 // AsyncApiFunction: | 239 // AsyncApiFunction: |
240 virtual bool Prepare() OVERRIDE; | 240 virtual bool Prepare() OVERRIDE; |
241 virtual void Work() OVERRIDE; | 241 virtual void Work() OVERRIDE; |
242 | 242 |
243 private: | 243 private: |
244 scoped_ptr<api::socket::Listen::Params> params_; | 244 scoped_ptr<core_api::socket::Listen::Params> params_; |
245 }; | 245 }; |
246 | 246 |
247 class SocketAcceptFunction : public SocketAsyncApiFunction { | 247 class SocketAcceptFunction : public SocketAsyncApiFunction { |
248 public: | 248 public: |
249 DECLARE_EXTENSION_FUNCTION("socket.accept", SOCKET_ACCEPT) | 249 DECLARE_EXTENSION_FUNCTION("socket.accept", SOCKET_ACCEPT) |
250 | 250 |
251 SocketAcceptFunction(); | 251 SocketAcceptFunction(); |
252 | 252 |
253 protected: | 253 protected: |
254 virtual ~SocketAcceptFunction(); | 254 virtual ~SocketAcceptFunction(); |
255 | 255 |
256 // AsyncApiFunction: | 256 // AsyncApiFunction: |
257 virtual bool Prepare() OVERRIDE; | 257 virtual bool Prepare() OVERRIDE; |
258 virtual void AsyncWorkStart() OVERRIDE; | 258 virtual void AsyncWorkStart() OVERRIDE; |
259 | 259 |
260 private: | 260 private: |
261 void OnAccept(int result_code, net::TCPClientSocket* socket); | 261 void OnAccept(int result_code, net::TCPClientSocket* socket); |
262 scoped_ptr<api::socket::Accept::Params> params_; | 262 |
| 263 scoped_ptr<core_api::socket::Accept::Params> params_; |
263 }; | 264 }; |
264 | 265 |
265 class SocketReadFunction : public SocketAsyncApiFunction { | 266 class SocketReadFunction : public SocketAsyncApiFunction { |
266 public: | 267 public: |
267 DECLARE_EXTENSION_FUNCTION("socket.read", SOCKET_READ) | 268 DECLARE_EXTENSION_FUNCTION("socket.read", SOCKET_READ) |
268 | 269 |
269 SocketReadFunction(); | 270 SocketReadFunction(); |
270 | 271 |
271 protected: | 272 protected: |
272 virtual ~SocketReadFunction(); | 273 virtual ~SocketReadFunction(); |
273 | 274 |
274 // AsyncApiFunction: | 275 // AsyncApiFunction: |
275 virtual bool Prepare() OVERRIDE; | 276 virtual bool Prepare() OVERRIDE; |
276 virtual void AsyncWorkStart() OVERRIDE; | 277 virtual void AsyncWorkStart() OVERRIDE; |
277 void OnCompleted(int result, scoped_refptr<net::IOBuffer> io_buffer); | 278 void OnCompleted(int result, scoped_refptr<net::IOBuffer> io_buffer); |
278 | 279 |
279 private: | 280 private: |
280 scoped_ptr<api::socket::Read::Params> params_; | 281 scoped_ptr<core_api::socket::Read::Params> params_; |
281 }; | 282 }; |
282 | 283 |
283 class SocketWriteFunction : public SocketAsyncApiFunction { | 284 class SocketWriteFunction : public SocketAsyncApiFunction { |
284 public: | 285 public: |
285 DECLARE_EXTENSION_FUNCTION("socket.write", SOCKET_WRITE) | 286 DECLARE_EXTENSION_FUNCTION("socket.write", SOCKET_WRITE) |
286 | 287 |
287 SocketWriteFunction(); | 288 SocketWriteFunction(); |
288 | 289 |
289 protected: | 290 protected: |
290 virtual ~SocketWriteFunction(); | 291 virtual ~SocketWriteFunction(); |
(...skipping 20 matching lines...) Expand all Loading... |
311 | 312 |
312 // AsyncApiFunction | 313 // AsyncApiFunction |
313 virtual bool Prepare() OVERRIDE; | 314 virtual bool Prepare() OVERRIDE; |
314 virtual void AsyncWorkStart() OVERRIDE; | 315 virtual void AsyncWorkStart() OVERRIDE; |
315 void OnCompleted(int result, | 316 void OnCompleted(int result, |
316 scoped_refptr<net::IOBuffer> io_buffer, | 317 scoped_refptr<net::IOBuffer> io_buffer, |
317 const std::string& address, | 318 const std::string& address, |
318 int port); | 319 int port); |
319 | 320 |
320 private: | 321 private: |
321 scoped_ptr<api::socket::RecvFrom::Params> params_; | 322 scoped_ptr<core_api::socket::RecvFrom::Params> params_; |
322 }; | 323 }; |
323 | 324 |
324 class SocketSendToFunction : public SocketExtensionWithDnsLookupFunction { | 325 class SocketSendToFunction : public SocketExtensionWithDnsLookupFunction { |
325 public: | 326 public: |
326 DECLARE_EXTENSION_FUNCTION("socket.sendTo", SOCKET_SENDTO) | 327 DECLARE_EXTENSION_FUNCTION("socket.sendTo", SOCKET_SENDTO) |
327 | 328 |
328 SocketSendToFunction(); | 329 SocketSendToFunction(); |
329 | 330 |
330 protected: | 331 protected: |
331 virtual ~SocketSendToFunction(); | 332 virtual ~SocketSendToFunction(); |
(...skipping 24 matching lines...) Expand all Loading... |
356 SocketSetKeepAliveFunction(); | 357 SocketSetKeepAliveFunction(); |
357 | 358 |
358 protected: | 359 protected: |
359 virtual ~SocketSetKeepAliveFunction(); | 360 virtual ~SocketSetKeepAliveFunction(); |
360 | 361 |
361 // AsyncApiFunction: | 362 // AsyncApiFunction: |
362 virtual bool Prepare() OVERRIDE; | 363 virtual bool Prepare() OVERRIDE; |
363 virtual void Work() OVERRIDE; | 364 virtual void Work() OVERRIDE; |
364 | 365 |
365 private: | 366 private: |
366 scoped_ptr<api::socket::SetKeepAlive::Params> params_; | 367 scoped_ptr<core_api::socket::SetKeepAlive::Params> params_; |
367 }; | 368 }; |
368 | 369 |
369 class SocketSetNoDelayFunction : public SocketAsyncApiFunction { | 370 class SocketSetNoDelayFunction : public SocketAsyncApiFunction { |
370 public: | 371 public: |
371 DECLARE_EXTENSION_FUNCTION("socket.setNoDelay", SOCKET_SETNODELAY) | 372 DECLARE_EXTENSION_FUNCTION("socket.setNoDelay", SOCKET_SETNODELAY) |
372 | 373 |
373 SocketSetNoDelayFunction(); | 374 SocketSetNoDelayFunction(); |
374 | 375 |
375 protected: | 376 protected: |
376 virtual ~SocketSetNoDelayFunction(); | 377 virtual ~SocketSetNoDelayFunction(); |
377 | 378 |
378 // AsyncApiFunction: | 379 // AsyncApiFunction: |
379 virtual bool Prepare() OVERRIDE; | 380 virtual bool Prepare() OVERRIDE; |
380 virtual void Work() OVERRIDE; | 381 virtual void Work() OVERRIDE; |
381 | 382 |
382 private: | 383 private: |
383 scoped_ptr<api::socket::SetNoDelay::Params> params_; | 384 scoped_ptr<core_api::socket::SetNoDelay::Params> params_; |
384 }; | 385 }; |
385 | 386 |
386 class SocketGetInfoFunction : public SocketAsyncApiFunction { | 387 class SocketGetInfoFunction : public SocketAsyncApiFunction { |
387 public: | 388 public: |
388 DECLARE_EXTENSION_FUNCTION("socket.getInfo", SOCKET_GETINFO) | 389 DECLARE_EXTENSION_FUNCTION("socket.getInfo", SOCKET_GETINFO) |
389 | 390 |
390 SocketGetInfoFunction(); | 391 SocketGetInfoFunction(); |
391 | 392 |
392 protected: | 393 protected: |
393 virtual ~SocketGetInfoFunction(); | 394 virtual ~SocketGetInfoFunction(); |
394 | 395 |
395 // AsyncApiFunction: | 396 // AsyncApiFunction: |
396 virtual bool Prepare() OVERRIDE; | 397 virtual bool Prepare() OVERRIDE; |
397 virtual void Work() OVERRIDE; | 398 virtual void Work() OVERRIDE; |
398 | 399 |
399 private: | 400 private: |
400 scoped_ptr<api::socket::GetInfo::Params> params_; | 401 scoped_ptr<core_api::socket::GetInfo::Params> params_; |
401 }; | 402 }; |
402 | 403 |
403 class SocketGetNetworkListFunction : public AsyncExtensionFunction { | 404 class SocketGetNetworkListFunction : public AsyncExtensionFunction { |
404 public: | 405 public: |
405 DECLARE_EXTENSION_FUNCTION("socket.getNetworkList", SOCKET_GETNETWORKLIST) | 406 DECLARE_EXTENSION_FUNCTION("socket.getNetworkList", SOCKET_GETNETWORKLIST) |
406 | 407 |
407 protected: | 408 protected: |
408 virtual ~SocketGetNetworkListFunction() {} | 409 virtual ~SocketGetNetworkListFunction() {} |
409 virtual bool RunImpl() OVERRIDE; | 410 virtual bool RunImpl() OVERRIDE; |
410 | 411 |
(...skipping 10 matching lines...) Expand all Loading... |
421 SocketJoinGroupFunction(); | 422 SocketJoinGroupFunction(); |
422 | 423 |
423 protected: | 424 protected: |
424 virtual ~SocketJoinGroupFunction(); | 425 virtual ~SocketJoinGroupFunction(); |
425 | 426 |
426 // AsyncApiFunction | 427 // AsyncApiFunction |
427 virtual bool Prepare() OVERRIDE; | 428 virtual bool Prepare() OVERRIDE; |
428 virtual void Work() OVERRIDE; | 429 virtual void Work() OVERRIDE; |
429 | 430 |
430 private: | 431 private: |
431 scoped_ptr<api::socket::JoinGroup::Params> params_; | 432 scoped_ptr<core_api::socket::JoinGroup::Params> params_; |
432 }; | 433 }; |
433 | 434 |
434 class SocketLeaveGroupFunction : public SocketAsyncApiFunction { | 435 class SocketLeaveGroupFunction : public SocketAsyncApiFunction { |
435 public: | 436 public: |
436 DECLARE_EXTENSION_FUNCTION("socket.leaveGroup", SOCKET_MULTICAST_LEAVE_GROUP) | 437 DECLARE_EXTENSION_FUNCTION("socket.leaveGroup", SOCKET_MULTICAST_LEAVE_GROUP) |
437 | 438 |
438 SocketLeaveGroupFunction(); | 439 SocketLeaveGroupFunction(); |
439 | 440 |
440 protected: | 441 protected: |
441 virtual ~SocketLeaveGroupFunction(); | 442 virtual ~SocketLeaveGroupFunction(); |
442 | 443 |
443 // AsyncApiFunction | 444 // AsyncApiFunction |
444 virtual bool Prepare() OVERRIDE; | 445 virtual bool Prepare() OVERRIDE; |
445 virtual void Work() OVERRIDE; | 446 virtual void Work() OVERRIDE; |
446 | 447 |
447 private: | 448 private: |
448 scoped_ptr<api::socket::LeaveGroup::Params> params_; | 449 scoped_ptr<core_api::socket::LeaveGroup::Params> params_; |
449 }; | 450 }; |
450 | 451 |
451 class SocketSetMulticastTimeToLiveFunction : public SocketAsyncApiFunction { | 452 class SocketSetMulticastTimeToLiveFunction : public SocketAsyncApiFunction { |
452 public: | 453 public: |
453 DECLARE_EXTENSION_FUNCTION("socket.setMulticastTimeToLive", | 454 DECLARE_EXTENSION_FUNCTION("socket.setMulticastTimeToLive", |
454 SOCKET_MULTICAST_SET_TIME_TO_LIVE) | 455 SOCKET_MULTICAST_SET_TIME_TO_LIVE) |
455 | 456 |
456 SocketSetMulticastTimeToLiveFunction(); | 457 SocketSetMulticastTimeToLiveFunction(); |
457 | 458 |
458 protected: | 459 protected: |
459 virtual ~SocketSetMulticastTimeToLiveFunction(); | 460 virtual ~SocketSetMulticastTimeToLiveFunction(); |
460 | 461 |
461 // AsyncApiFunction | 462 // AsyncApiFunction |
462 virtual bool Prepare() OVERRIDE; | 463 virtual bool Prepare() OVERRIDE; |
463 virtual void Work() OVERRIDE; | 464 virtual void Work() OVERRIDE; |
464 | 465 |
465 private: | 466 private: |
466 scoped_ptr<api::socket::SetMulticastTimeToLive::Params> params_; | 467 scoped_ptr<core_api::socket::SetMulticastTimeToLive::Params> params_; |
467 }; | 468 }; |
468 | 469 |
469 class SocketSetMulticastLoopbackModeFunction : public SocketAsyncApiFunction { | 470 class SocketSetMulticastLoopbackModeFunction : public SocketAsyncApiFunction { |
470 public: | 471 public: |
471 DECLARE_EXTENSION_FUNCTION("socket.setMulticastLoopbackMode", | 472 DECLARE_EXTENSION_FUNCTION("socket.setMulticastLoopbackMode", |
472 SOCKET_MULTICAST_SET_LOOPBACK_MODE) | 473 SOCKET_MULTICAST_SET_LOOPBACK_MODE) |
473 | 474 |
474 SocketSetMulticastLoopbackModeFunction(); | 475 SocketSetMulticastLoopbackModeFunction(); |
475 | 476 |
476 protected: | 477 protected: |
477 virtual ~SocketSetMulticastLoopbackModeFunction(); | 478 virtual ~SocketSetMulticastLoopbackModeFunction(); |
478 | 479 |
479 // AsyncApiFunction | 480 // AsyncApiFunction |
480 virtual bool Prepare() OVERRIDE; | 481 virtual bool Prepare() OVERRIDE; |
481 virtual void Work() OVERRIDE; | 482 virtual void Work() OVERRIDE; |
482 | 483 |
483 private: | 484 private: |
484 scoped_ptr<api::socket::SetMulticastLoopbackMode::Params> params_; | 485 scoped_ptr<core_api::socket::SetMulticastLoopbackMode::Params> params_; |
485 }; | 486 }; |
486 | 487 |
487 class SocketGetJoinedGroupsFunction : public SocketAsyncApiFunction { | 488 class SocketGetJoinedGroupsFunction : public SocketAsyncApiFunction { |
488 public: | 489 public: |
489 DECLARE_EXTENSION_FUNCTION("socket.getJoinedGroups", | 490 DECLARE_EXTENSION_FUNCTION("socket.getJoinedGroups", |
490 SOCKET_MULTICAST_GET_JOINED_GROUPS) | 491 SOCKET_MULTICAST_GET_JOINED_GROUPS) |
491 | 492 |
492 SocketGetJoinedGroupsFunction(); | 493 SocketGetJoinedGroupsFunction(); |
493 | 494 |
494 protected: | 495 protected: |
495 virtual ~SocketGetJoinedGroupsFunction(); | 496 virtual ~SocketGetJoinedGroupsFunction(); |
496 | 497 |
497 // AsyncApiFunction | 498 // AsyncApiFunction |
498 virtual bool Prepare() OVERRIDE; | 499 virtual bool Prepare() OVERRIDE; |
499 virtual void Work() OVERRIDE; | 500 virtual void Work() OVERRIDE; |
500 | 501 |
501 private: | 502 private: |
502 scoped_ptr<api::socket::GetJoinedGroups::Params> params_; | 503 scoped_ptr<core_api::socket::GetJoinedGroups::Params> params_; |
503 }; | 504 }; |
504 } // namespace extensions | 505 } // namespace extensions |
505 | 506 |
506 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_H_ | 507 #endif // EXTENSIONS_BROWSER_API_SOCKET_SOCKET_API_H_ |
OLD | NEW |