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/experimental_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 | 14 |
15 #include <string> | 15 #include <string> |
16 | 16 |
17 class IOThread; | 17 class IOThread; |
18 | 18 |
19 namespace net { | 19 namespace net { |
20 class IOBuffer; | 20 class IOBuffer; |
21 } | 21 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 // acquire it on the UI thread and then use it on the IO thread, so we keep a | 56 // acquire it on the UI thread and then use it on the IO thread, so we keep a |
57 // plain pointer to it here as we move from thread to thread. | 57 // plain pointer to it here as we move from thread to thread. |
58 IOThread* io_thread_; | 58 IOThread* io_thread_; |
59 | 59 |
60 scoped_ptr<net::HostResolver::RequestHandle> request_handle_; | 60 scoped_ptr<net::HostResolver::RequestHandle> request_handle_; |
61 scoped_ptr<net::AddressList> addresses_; | 61 scoped_ptr<net::AddressList> addresses_; |
62 }; | 62 }; |
63 | 63 |
64 class SocketCreateFunction : public SocketAsyncApiFunction { | 64 class SocketCreateFunction : public SocketAsyncApiFunction { |
65 public: | 65 public: |
66 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.create") | 66 DECLARE_EXTENSION_FUNCTION_NAME("socket.create") |
67 | 67 |
68 SocketCreateFunction(); | 68 SocketCreateFunction(); |
69 | 69 |
70 protected: | 70 protected: |
71 virtual ~SocketCreateFunction(); | 71 virtual ~SocketCreateFunction(); |
72 | 72 |
73 // AsyncApiFunction: | 73 // AsyncApiFunction: |
74 virtual bool Prepare() OVERRIDE; | 74 virtual bool Prepare() OVERRIDE; |
75 virtual void Work() OVERRIDE; | 75 virtual void Work() OVERRIDE; |
76 | 76 |
77 private: | 77 private: |
78 enum SocketType { | 78 enum SocketType { |
79 kSocketTypeInvalid = -1, | 79 kSocketTypeInvalid = -1, |
80 kSocketTypeTCP, | 80 kSocketTypeTCP, |
81 kSocketTypeUDP | 81 kSocketTypeUDP |
82 }; | 82 }; |
83 | 83 |
84 scoped_ptr<api::experimental_socket::Create::Params> params_; | 84 scoped_ptr<api::socket::Create::Params> params_; |
85 SocketType socket_type_; | 85 SocketType socket_type_; |
86 int src_id_; | 86 int src_id_; |
87 ApiResourceEventNotifier* event_notifier_; | 87 ApiResourceEventNotifier* event_notifier_; |
88 }; | 88 }; |
89 | 89 |
90 class SocketDestroyFunction : public SocketAsyncApiFunction { | 90 class SocketDestroyFunction : public SocketAsyncApiFunction { |
91 public: | 91 public: |
92 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.destroy") | 92 DECLARE_EXTENSION_FUNCTION_NAME("socket.destroy") |
93 | 93 |
94 protected: | 94 protected: |
95 virtual ~SocketDestroyFunction() {} | 95 virtual ~SocketDestroyFunction() {} |
96 | 96 |
97 // AsyncApiFunction: | 97 // AsyncApiFunction: |
98 virtual bool Prepare() OVERRIDE; | 98 virtual bool Prepare() OVERRIDE; |
99 virtual void Work() OVERRIDE; | 99 virtual void Work() OVERRIDE; |
100 | 100 |
101 private: | 101 private: |
102 int socket_id_; | 102 int socket_id_; |
103 }; | 103 }; |
104 | 104 |
105 class SocketConnectFunction : public SocketExtensionWithDnsLookupFunction { | 105 class SocketConnectFunction : public SocketExtensionWithDnsLookupFunction { |
106 public: | 106 public: |
107 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.connect") | 107 DECLARE_EXTENSION_FUNCTION_NAME("socket.connect") |
108 | 108 |
109 SocketConnectFunction(); | 109 SocketConnectFunction(); |
110 | 110 |
111 protected: | 111 protected: |
112 virtual ~SocketConnectFunction(); | 112 virtual ~SocketConnectFunction(); |
113 | 113 |
114 // AsyncApiFunction: | 114 // AsyncApiFunction: |
115 virtual bool Prepare() OVERRIDE; | 115 virtual bool Prepare() OVERRIDE; |
116 virtual void AsyncWorkStart() OVERRIDE; | 116 virtual void AsyncWorkStart() OVERRIDE; |
117 | 117 |
118 // SocketExtensionWithDnsLookupFunction: | 118 // SocketExtensionWithDnsLookupFunction: |
119 virtual void AfterDnsLookup(int lookup_result) OVERRIDE; | 119 virtual void AfterDnsLookup(int lookup_result) OVERRIDE; |
120 | 120 |
121 private: | 121 private: |
122 void StartConnect(); | 122 void StartConnect(); |
123 void OnConnect(int result); | 123 void OnConnect(int result); |
124 | 124 |
125 int socket_id_; | 125 int socket_id_; |
126 std::string hostname_; | 126 std::string hostname_; |
127 int port_; | 127 int port_; |
128 }; | 128 }; |
129 | 129 |
130 class SocketDisconnectFunction : public SocketAsyncApiFunction { | 130 class SocketDisconnectFunction : public SocketAsyncApiFunction { |
131 public: | 131 public: |
132 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.disconnect") | 132 DECLARE_EXTENSION_FUNCTION_NAME("socket.disconnect") |
133 | 133 |
134 protected: | 134 protected: |
135 virtual ~SocketDisconnectFunction() {} | 135 virtual ~SocketDisconnectFunction() {} |
136 | 136 |
137 // AsyncApiFunction: | 137 // AsyncApiFunction: |
138 virtual bool Prepare() OVERRIDE; | 138 virtual bool Prepare() OVERRIDE; |
139 virtual void Work() OVERRIDE; | 139 virtual void Work() OVERRIDE; |
140 | 140 |
141 private: | 141 private: |
142 int socket_id_; | 142 int socket_id_; |
143 }; | 143 }; |
144 | 144 |
145 class SocketBindFunction : public SocketAsyncApiFunction { | 145 class SocketBindFunction : public SocketAsyncApiFunction { |
146 public: | 146 public: |
147 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.bind") | 147 DECLARE_EXTENSION_FUNCTION_NAME("socket.bind") |
148 | 148 |
149 protected: | 149 protected: |
150 virtual ~SocketBindFunction() {} | 150 virtual ~SocketBindFunction() {} |
151 | 151 |
152 // AsyncApiFunction: | 152 // AsyncApiFunction: |
153 virtual bool Prepare() OVERRIDE; | 153 virtual bool Prepare() OVERRIDE; |
154 virtual void Work() OVERRIDE; | 154 virtual void Work() OVERRIDE; |
155 | 155 |
156 private: | 156 private: |
157 int socket_id_; | 157 int socket_id_; |
158 std::string address_; | 158 std::string address_; |
159 int port_; | 159 int port_; |
160 }; | 160 }; |
161 | 161 |
162 class SocketReadFunction : public SocketAsyncApiFunction { | 162 class SocketReadFunction : public SocketAsyncApiFunction { |
163 public: | 163 public: |
164 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.read") | 164 DECLARE_EXTENSION_FUNCTION_NAME("socket.read") |
165 | 165 |
166 SocketReadFunction(); | 166 SocketReadFunction(); |
167 | 167 |
168 protected: | 168 protected: |
169 virtual ~SocketReadFunction(); | 169 virtual ~SocketReadFunction(); |
170 | 170 |
171 // AsyncApiFunction: | 171 // AsyncApiFunction: |
172 virtual bool Prepare() OVERRIDE; | 172 virtual bool Prepare() OVERRIDE; |
173 virtual void AsyncWorkStart() OVERRIDE; | 173 virtual void AsyncWorkStart() OVERRIDE; |
174 void OnCompleted(int result, scoped_refptr<net::IOBuffer> io_buffer); | 174 void OnCompleted(int result, scoped_refptr<net::IOBuffer> io_buffer); |
175 | 175 |
176 private: | 176 private: |
177 scoped_ptr<api::experimental_socket::Read::Params> params_; | 177 scoped_ptr<api::socket::Read::Params> params_; |
178 }; | 178 }; |
179 | 179 |
180 class SocketWriteFunction : public SocketAsyncApiFunction { | 180 class SocketWriteFunction : public SocketAsyncApiFunction { |
181 public: | 181 public: |
182 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.write") | 182 DECLARE_EXTENSION_FUNCTION_NAME("socket.write") |
183 | 183 |
184 SocketWriteFunction(); | 184 SocketWriteFunction(); |
185 | 185 |
186 protected: | 186 protected: |
187 virtual ~SocketWriteFunction(); | 187 virtual ~SocketWriteFunction(); |
188 | 188 |
189 // AsyncApiFunction: | 189 // AsyncApiFunction: |
190 virtual bool Prepare() OVERRIDE; | 190 virtual bool Prepare() OVERRIDE; |
191 virtual void AsyncWorkStart() OVERRIDE; | 191 virtual void AsyncWorkStart() OVERRIDE; |
192 void OnCompleted(int result); | 192 void OnCompleted(int result); |
193 | 193 |
194 private: | 194 private: |
195 int socket_id_; | 195 int socket_id_; |
196 scoped_refptr<net::IOBuffer> io_buffer_; | 196 scoped_refptr<net::IOBuffer> io_buffer_; |
197 size_t io_buffer_size_; | 197 size_t io_buffer_size_; |
198 }; | 198 }; |
199 | 199 |
200 class SocketRecvFromFunction : public SocketAsyncApiFunction { | 200 class SocketRecvFromFunction : public SocketAsyncApiFunction { |
201 public: | 201 public: |
202 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.recvFrom") | 202 DECLARE_EXTENSION_FUNCTION_NAME("socket.recvFrom") |
203 | 203 |
204 SocketRecvFromFunction(); | 204 SocketRecvFromFunction(); |
205 | 205 |
206 protected: | 206 protected: |
207 virtual ~SocketRecvFromFunction(); | 207 virtual ~SocketRecvFromFunction(); |
208 | 208 |
209 // AsyncApiFunction | 209 // AsyncApiFunction |
210 virtual bool Prepare() OVERRIDE; | 210 virtual bool Prepare() OVERRIDE; |
211 virtual void AsyncWorkStart() OVERRIDE; | 211 virtual void AsyncWorkStart() OVERRIDE; |
212 void OnCompleted(int result, | 212 void OnCompleted(int result, |
213 scoped_refptr<net::IOBuffer> io_buffer, | 213 scoped_refptr<net::IOBuffer> io_buffer, |
214 const std::string& address, | 214 const std::string& address, |
215 int port); | 215 int port); |
216 | 216 |
217 private: | 217 private: |
218 scoped_ptr<api::experimental_socket::RecvFrom::Params> params_; | 218 scoped_ptr<api::socket::RecvFrom::Params> params_; |
219 }; | 219 }; |
220 | 220 |
221 class SocketSendToFunction : public SocketExtensionWithDnsLookupFunction { | 221 class SocketSendToFunction : public SocketExtensionWithDnsLookupFunction { |
222 public: | 222 public: |
223 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.sendTo") | 223 DECLARE_EXTENSION_FUNCTION_NAME("socket.sendTo") |
224 | 224 |
225 SocketSendToFunction(); | 225 SocketSendToFunction(); |
226 | 226 |
227 protected: | 227 protected: |
228 virtual ~SocketSendToFunction(); | 228 virtual ~SocketSendToFunction(); |
229 | 229 |
230 // AsyncApiFunction: | 230 // AsyncApiFunction: |
231 virtual bool Prepare() OVERRIDE; | 231 virtual bool Prepare() OVERRIDE; |
232 virtual void AsyncWorkStart() OVERRIDE; | 232 virtual void AsyncWorkStart() OVERRIDE; |
233 void OnCompleted(int result); | 233 void OnCompleted(int result); |
234 | 234 |
235 // SocketExtensionWithDnsLookupFunction: | 235 // SocketExtensionWithDnsLookupFunction: |
236 virtual void AfterDnsLookup(int lookup_result) OVERRIDE; | 236 virtual void AfterDnsLookup(int lookup_result) OVERRIDE; |
237 | 237 |
238 private: | 238 private: |
239 void StartSendTo(); | 239 void StartSendTo(); |
240 | 240 |
241 int socket_id_; | 241 int socket_id_; |
242 scoped_refptr<net::IOBuffer> io_buffer_; | 242 scoped_refptr<net::IOBuffer> io_buffer_; |
243 size_t io_buffer_size_; | 243 size_t io_buffer_size_; |
244 std::string hostname_; | 244 std::string hostname_; |
245 int port_; | 245 int port_; |
246 }; | 246 }; |
247 | 247 |
248 class SocketSetKeepAliveFunction : public SocketAsyncApiFunction { | 248 class SocketSetKeepAliveFunction : public SocketAsyncApiFunction { |
249 public: | 249 public: |
250 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.setKeepAlive") | 250 DECLARE_EXTENSION_FUNCTION_NAME("socket.setKeepAlive") |
251 | 251 |
252 SocketSetKeepAliveFunction(); | 252 SocketSetKeepAliveFunction(); |
253 | 253 |
254 protected: | 254 protected: |
255 virtual ~SocketSetKeepAliveFunction(); | 255 virtual ~SocketSetKeepAliveFunction(); |
256 | 256 |
257 // AsyncApiFunction: | 257 // AsyncApiFunction: |
258 virtual bool Prepare() OVERRIDE; | 258 virtual bool Prepare() OVERRIDE; |
259 virtual void Work() OVERRIDE; | 259 virtual void Work() OVERRIDE; |
260 | 260 |
261 private: | 261 private: |
262 scoped_ptr<api::experimental_socket::SetKeepAlive::Params> params_; | 262 scoped_ptr<api::socket::SetKeepAlive::Params> params_; |
263 }; | 263 }; |
264 | 264 |
265 class SocketSetNoDelayFunction : public SocketAsyncApiFunction { | 265 class SocketSetNoDelayFunction : public SocketAsyncApiFunction { |
266 public: | 266 public: |
267 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.setNoDelay") | 267 DECLARE_EXTENSION_FUNCTION_NAME("socket.setNoDelay") |
268 | 268 |
269 SocketSetNoDelayFunction(); | 269 SocketSetNoDelayFunction(); |
270 | 270 |
271 protected: | 271 protected: |
272 virtual ~SocketSetNoDelayFunction(); | 272 virtual ~SocketSetNoDelayFunction(); |
273 | 273 |
274 // AsyncApiFunction: | 274 // AsyncApiFunction: |
275 virtual bool Prepare() OVERRIDE; | 275 virtual bool Prepare() OVERRIDE; |
276 virtual void Work() OVERRIDE; | 276 virtual void Work() OVERRIDE; |
277 | 277 |
278 private: | 278 private: |
279 scoped_ptr<api::experimental_socket::SetNoDelay::Params> params_; | 279 scoped_ptr<api::socket::SetNoDelay::Params> params_; |
280 }; | 280 }; |
281 | 281 |
282 } // namespace extensions | 282 } // namespace extensions |
283 | 283 |
284 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_H_ | 284 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_H_ |
OLD | NEW |