OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_CONTROLLER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_CONTROLLER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_CONTROLLER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <map> | 10 #include <map> |
(...skipping 10 matching lines...) Expand all Loading... |
21 class Value; | 21 class Value; |
22 } | 22 } |
23 | 23 |
24 namespace net { | 24 namespace net { |
25 class UDPClientSocket; | 25 class UDPClientSocket; |
26 class IPEndPoint; | 26 class IPEndPoint; |
27 } | 27 } |
28 | 28 |
29 namespace extensions { | 29 namespace extensions { |
30 | 30 |
| 31 // kSrcIdKey, or "srcId," binds a socket to the onEvent closure that was |
| 32 // optionally passed to the socket.create() method. It's generated by us in |
| 33 // schema_generated_bindings.js; the application code is unaware of it. |
| 34 extern const char kSrcIdKey[]; |
| 35 |
31 class Socket; | 36 class Socket; |
32 | 37 |
33 // SocketController keeps track of a collection of Sockets and provides a | 38 // SocketController keeps track of a collection of Sockets and provides a |
34 // convenient set of methods to manipulate them. | 39 // convenient set of methods to manipulate them. |
35 class SocketController { | 40 class SocketController { |
36 public: | 41 public: |
37 SocketController(); | 42 SocketController(); |
38 virtual ~SocketController(); | 43 virtual ~SocketController(); |
39 | 44 |
40 // Create/Destroy are a pair. They represent the allocation and deallocation | 45 // Create/Destroy are a pair. They represent the allocation and deallocation |
41 // of the Socket object in memory. | 46 // of the Socket object in memory. |
42 // | 47 // |
43 // TODO(miket): aa's suggestion to track lifetime of callbacks associated | 48 // TODO(miket): aa's suggestion to track lifetime of callbacks associated |
44 // with each socket, which will then let us clean up when we go out of scope | 49 // with each socket, which will then let us clean up when we go out of scope |
45 // rather than requiring that the app developer remember to call Destroy. | 50 // rather than requiring that the app developer remember to call Destroy. |
46 int CreateUdp(const Profile* profile, const std::string& extension_id, | 51 int CreateUdp(Profile* profile, const std::string& extension_id, int src_id, |
47 const GURL& src_url); | 52 const GURL& src_url); |
48 bool DestroyUdp(int socket_id); | 53 bool DestroyUdp(int socket_id); |
49 | 54 |
50 // Connect, Close, Read, and Write map to the equivalent methods in | 55 // Connect, Close, Read, and Write map to the equivalent methods in |
51 // UDPClientSocket. | 56 // UDPClientSocket. |
52 // | 57 // |
53 // TODO(miket): Implement Read. | 58 // TODO(miket): Implement Read. |
54 bool ConnectUdp(int socket_id, const std::string address, int port); | 59 bool ConnectUdp(int socket_id, const std::string address, int port); |
55 void CloseUdp(int socket_id); | 60 void CloseUdp(int socket_id); |
56 int WriteUdp(int socket_id, const std::string msg); | 61 int WriteUdp(int socket_id, const std::string msg); |
(...skipping 10 matching lines...) Expand all Loading... |
67 | 72 |
68 // Convenience method for accessing SocketMap. | 73 // Convenience method for accessing SocketMap. |
69 Socket* GetSocket(int socket_id); | 74 Socket* GetSocket(int socket_id); |
70 | 75 |
71 DISALLOW_COPY_AND_ASSIGN(SocketController); | 76 DISALLOW_COPY_AND_ASSIGN(SocketController); |
72 }; | 77 }; |
73 | 78 |
74 } // namespace extensions | 79 } // namespace extensions |
75 | 80 |
76 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_CONTROLLER_H_ | 81 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_CONTROLLER_H_ |
OLD | NEW |