Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: chrome/browser/extensions/api/socket/socket_api.h

Issue 10777003: Refactor APIResourceController to ProfileKeyedService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/common/extensions/api/experimental_socket.h" 11 #include "chrome/common/extensions/api/experimental_socket.h"
11 #include "net/base/address_list.h" 12 #include "net/base/address_list.h"
12 #include "net/base/host_resolver.h" 13 #include "net/base/host_resolver.h"
13 14
14 #include <string> 15 #include <string>
15 16
17 class IOThread;
18
16 namespace net { 19 namespace net {
17 class IOBuffer; 20 class IOBuffer;
18 } 21 }
19 22
20 class IOThread;
21
22 namespace extensions { 23 namespace extensions {
23 24
24 class APIResourceController; 25 class ApiResourceEventNotifier;
25 class APIResourceEventNotifier; 26 class Socket;
26 27
27 class SocketExtensionFunction : public AsyncAPIFunction { 28 class SocketExtensionFunction : public AsyncApiFunction {
asargent_no_longer_on_chrome 2012/07/16 18:08:25 would it make sense to name this "SocketAsyncApiFu
miket_OOO 2012/07/16 19:46:02 Done, and confirmed that usb devices are following
29 public:
30 SocketExtensionFunction();
31
28 protected: 32 protected:
29 virtual ~SocketExtensionFunction() {} 33 virtual ~SocketExtensionFunction();
30 34
31 // AsyncAPIFunction: 35 // AsyncApiFunction:
36 virtual bool PrePrepare() OVERRIDE;
32 virtual void Work() OVERRIDE; 37 virtual void Work() OVERRIDE;
33 virtual bool Respond() OVERRIDE; 38 virtual bool Respond() OVERRIDE;
39
40 ApiResourceManager<Socket>* manager_;
34 }; 41 };
35 42
36 class SocketExtensionWithDnsLookupFunction : public SocketExtensionFunction { 43 class SocketExtensionWithDnsLookupFunction : public SocketExtensionFunction {
37 protected: 44 protected:
38 SocketExtensionWithDnsLookupFunction(); 45 SocketExtensionWithDnsLookupFunction();
39 virtual ~SocketExtensionWithDnsLookupFunction(); 46 virtual ~SocketExtensionWithDnsLookupFunction();
40 47
41 void StartDnsLookup(const std::string& hostname); 48 void StartDnsLookup(const std::string& hostname);
42 virtual void AfterDnsLookup(int lookup_result) = 0; 49 virtual void AfterDnsLookup(int lookup_result) = 0;
43 50
(...skipping 13 matching lines...) Expand all
57 64
58 class SocketCreateFunction : public SocketExtensionFunction { 65 class SocketCreateFunction : public SocketExtensionFunction {
59 public: 66 public:
60 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.create") 67 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.create")
61 68
62 SocketCreateFunction(); 69 SocketCreateFunction();
63 70
64 protected: 71 protected:
65 virtual ~SocketCreateFunction(); 72 virtual ~SocketCreateFunction();
66 73
67 // AsyncAPIFunction: 74 // AsyncApiFunction:
68 virtual bool Prepare() OVERRIDE; 75 virtual bool Prepare() OVERRIDE;
69 virtual void Work() OVERRIDE; 76 virtual void Work() OVERRIDE;
70 77
71 private: 78 private:
72 enum SocketType { 79 enum SocketType {
73 kSocketTypeInvalid = -1, 80 kSocketTypeInvalid = -1,
74 kSocketTypeTCP, 81 kSocketTypeTCP,
75 kSocketTypeUDP 82 kSocketTypeUDP
76 }; 83 };
77 84
78 scoped_ptr<api::experimental_socket::Create::Params> params_; 85 scoped_ptr<api::experimental_socket::Create::Params> params_;
79 SocketType socket_type_; 86 SocketType socket_type_;
80 int src_id_; 87 int src_id_;
81 APIResourceEventNotifier* event_notifier_; 88 ApiResourceEventNotifier* event_notifier_;
82 }; 89 };
83 90
84 class SocketDestroyFunction : public SocketExtensionFunction { 91 class SocketDestroyFunction : public SocketExtensionFunction {
85 public: 92 public:
86 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.destroy") 93 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.destroy")
87 94
88 protected: 95 protected:
89 virtual ~SocketDestroyFunction() {} 96 virtual ~SocketDestroyFunction() {}
90 97
91 // AsyncAPIFunction: 98 // AsyncApiFunction:
92 virtual bool Prepare() OVERRIDE; 99 virtual bool Prepare() OVERRIDE;
93 virtual void Work() OVERRIDE; 100 virtual void Work() OVERRIDE;
94 101
95 private: 102 private:
96 int socket_id_; 103 int socket_id_;
97 }; 104 };
98 105
99 class SocketConnectFunction : public SocketExtensionWithDnsLookupFunction { 106 class SocketConnectFunction : public SocketExtensionWithDnsLookupFunction {
100 public: 107 public:
101 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.connect") 108 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.connect")
102 109
103 SocketConnectFunction(); 110 SocketConnectFunction();
104 111
105 protected: 112 protected:
106 virtual ~SocketConnectFunction(); 113 virtual ~SocketConnectFunction();
107 114
108 // AsyncAPIFunction: 115 // AsyncApiFunction:
109 virtual bool Prepare() OVERRIDE; 116 virtual bool Prepare() OVERRIDE;
110 virtual void AsyncWorkStart() OVERRIDE; 117 virtual void AsyncWorkStart() OVERRIDE;
111 118
112 // SocketExtensionWithDnsLookupFunction: 119 // SocketExtensionWithDnsLookupFunction:
113 virtual void AfterDnsLookup(int lookup_result) OVERRIDE; 120 virtual void AfterDnsLookup(int lookup_result) OVERRIDE;
114 121
115 private: 122 private:
116 void StartConnect(); 123 void StartConnect();
117 void OnConnect(int result); 124 void OnConnect(int result);
118 125
119 int socket_id_; 126 int socket_id_;
120 std::string hostname_; 127 std::string hostname_;
121 int port_; 128 int port_;
122 }; 129 };
123 130
124 class SocketDisconnectFunction : public SocketExtensionFunction { 131 class SocketDisconnectFunction : public SocketExtensionFunction {
125 public: 132 public:
126 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.disconnect") 133 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.disconnect")
127 134
128 protected: 135 protected:
129 virtual ~SocketDisconnectFunction() {} 136 virtual ~SocketDisconnectFunction() {}
130 137
131 // AsyncAPIFunction: 138 // AsyncApiFunction:
132 virtual bool Prepare() OVERRIDE; 139 virtual bool Prepare() OVERRIDE;
133 virtual void Work() OVERRIDE; 140 virtual void Work() OVERRIDE;
134 141
135 private: 142 private:
136 int socket_id_; 143 int socket_id_;
137 }; 144 };
138 145
139 class SocketBindFunction : public SocketExtensionFunction { 146 class SocketBindFunction : public SocketExtensionFunction {
140 public: 147 public:
141 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.bind") 148 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.bind")
142 149
143 protected: 150 protected:
144 virtual ~SocketBindFunction() {} 151 virtual ~SocketBindFunction() {}
145 152
146 // AsyncAPIFunction: 153 // AsyncApiFunction:
147 virtual bool Prepare() OVERRIDE; 154 virtual bool Prepare() OVERRIDE;
148 virtual void Work() OVERRIDE; 155 virtual void Work() OVERRIDE;
149 156
150 private: 157 private:
151 int socket_id_; 158 int socket_id_;
152 std::string address_; 159 std::string address_;
153 int port_; 160 int port_;
154 }; 161 };
155 162
156 class SocketReadFunction : public SocketExtensionFunction { 163 class SocketReadFunction : public SocketExtensionFunction {
157 public: 164 public:
158 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.read") 165 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.read")
159 166
160 SocketReadFunction(); 167 SocketReadFunction();
161 168
162 protected: 169 protected:
163 virtual ~SocketReadFunction(); 170 virtual ~SocketReadFunction();
164 171
165 // AsyncAPIFunction: 172 // AsyncApiFunction:
166 virtual bool Prepare() OVERRIDE; 173 virtual bool Prepare() OVERRIDE;
167 virtual void AsyncWorkStart() OVERRIDE; 174 virtual void AsyncWorkStart() OVERRIDE;
168 void OnCompleted(int result, scoped_refptr<net::IOBuffer> io_buffer); 175 void OnCompleted(int result, scoped_refptr<net::IOBuffer> io_buffer);
169 176
170 private: 177 private:
171 scoped_ptr<api::experimental_socket::Read::Params> params_; 178 scoped_ptr<api::experimental_socket::Read::Params> params_;
172 }; 179 };
173 180
174 class SocketWriteFunction : public SocketExtensionFunction { 181 class SocketWriteFunction : public SocketExtensionFunction {
175 public: 182 public:
176 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.write") 183 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.write")
177 184
178 SocketWriteFunction(); 185 SocketWriteFunction();
179 186
180 protected: 187 protected:
181 virtual ~SocketWriteFunction(); 188 virtual ~SocketWriteFunction();
182 189
183 // AsyncAPIFunction: 190 // AsyncApiFunction:
184 virtual bool Prepare() OVERRIDE; 191 virtual bool Prepare() OVERRIDE;
185 virtual void AsyncWorkStart() OVERRIDE; 192 virtual void AsyncWorkStart() OVERRIDE;
186 void OnCompleted(int result); 193 void OnCompleted(int result);
187 194
188 private: 195 private:
189 int socket_id_; 196 int socket_id_;
190 scoped_refptr<net::IOBuffer> io_buffer_; 197 scoped_refptr<net::IOBuffer> io_buffer_;
191 size_t io_buffer_size_; 198 size_t io_buffer_size_;
192 }; 199 };
193 200
194 class SocketRecvFromFunction : public SocketExtensionFunction { 201 class SocketRecvFromFunction : public SocketExtensionFunction {
195 public: 202 public:
196 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.recvFrom") 203 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.recvFrom")
197 204
198 SocketRecvFromFunction(); 205 SocketRecvFromFunction();
199 206
200 protected: 207 protected:
201 virtual ~SocketRecvFromFunction(); 208 virtual ~SocketRecvFromFunction();
202 209
203 // AsyncAPIFunction 210 // AsyncApiFunction
204 virtual bool Prepare() OVERRIDE; 211 virtual bool Prepare() OVERRIDE;
205 virtual void AsyncWorkStart() OVERRIDE; 212 virtual void AsyncWorkStart() OVERRIDE;
206 void OnCompleted(int result, 213 void OnCompleted(int result,
207 scoped_refptr<net::IOBuffer> io_buffer, 214 scoped_refptr<net::IOBuffer> io_buffer,
208 const std::string& address, 215 const std::string& address,
209 int port); 216 int port);
210 217
211 private: 218 private:
212 scoped_ptr<api::experimental_socket::RecvFrom::Params> params_; 219 scoped_ptr<api::experimental_socket::RecvFrom::Params> params_;
213 }; 220 };
214 221
215 class SocketSendToFunction : public SocketExtensionWithDnsLookupFunction { 222 class SocketSendToFunction : public SocketExtensionWithDnsLookupFunction {
216 public: 223 public:
217 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.sendTo") 224 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.sendTo")
218 225
219 SocketSendToFunction(); 226 SocketSendToFunction();
220 227
221 protected: 228 protected:
222 virtual ~SocketSendToFunction(); 229 virtual ~SocketSendToFunction();
223 230
224 // AsyncAPIFunction: 231 // AsyncApiFunction:
225 virtual bool Prepare() OVERRIDE; 232 virtual bool Prepare() OVERRIDE;
226 virtual void AsyncWorkStart() OVERRIDE; 233 virtual void AsyncWorkStart() OVERRIDE;
227 void OnCompleted(int result); 234 void OnCompleted(int result);
228 235
229 // SocketExtensionWithDnsLookupFunction: 236 // SocketExtensionWithDnsLookupFunction:
230 virtual void AfterDnsLookup(int lookup_result) OVERRIDE; 237 virtual void AfterDnsLookup(int lookup_result) OVERRIDE;
231 238
232 private: 239 private:
233 void StartSendTo(); 240 void StartSendTo();
234 241
235 int socket_id_; 242 int socket_id_;
236 scoped_refptr<net::IOBuffer> io_buffer_; 243 scoped_refptr<net::IOBuffer> io_buffer_;
237 size_t io_buffer_size_; 244 size_t io_buffer_size_;
238 std::string hostname_; 245 std::string hostname_;
239 int port_; 246 int port_;
240 }; 247 };
241 248
242 class SocketSetKeepAliveFunction : public SocketExtensionFunction { 249 class SocketSetKeepAliveFunction : public SocketExtensionFunction {
243 public: 250 public:
244 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.setKeepAlive") 251 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.setKeepAlive")
245 252
246 SocketSetKeepAliveFunction(); 253 SocketSetKeepAliveFunction();
247 254
248 protected: 255 protected:
249 virtual ~SocketSetKeepAliveFunction(); 256 virtual ~SocketSetKeepAliveFunction();
250 257
251 // AsyncAPIFunction: 258 // AsyncApiFunction:
252 virtual bool Prepare() OVERRIDE; 259 virtual bool Prepare() OVERRIDE;
253 virtual void Work() OVERRIDE; 260 virtual void Work() OVERRIDE;
254 261
255 private: 262 private:
256 scoped_ptr<api::experimental_socket::SetKeepAlive::Params> params_; 263 scoped_ptr<api::experimental_socket::SetKeepAlive::Params> params_;
257 }; 264 };
258 265
259 class SocketSetNoDelayFunction : public SocketExtensionFunction { 266 class SocketSetNoDelayFunction : public SocketExtensionFunction {
260 public: 267 public:
261 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.setNoDelay") 268 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.setNoDelay")
262 269
263 SocketSetNoDelayFunction(); 270 SocketSetNoDelayFunction();
264 271
265 protected: 272 protected:
266 virtual ~SocketSetNoDelayFunction(); 273 virtual ~SocketSetNoDelayFunction();
267 274
268 // AsyncAPIFunction: 275 // AsyncApiFunction:
269 virtual bool Prepare() OVERRIDE; 276 virtual bool Prepare() OVERRIDE;
270 virtual void Work() OVERRIDE; 277 virtual void Work() OVERRIDE;
271 278
272 private: 279 private:
273 scoped_ptr<api::experimental_socket::SetNoDelay::Params> params_; 280 scoped_ptr<api::experimental_socket::SetNoDelay::Params> params_;
274 }; 281 };
275 282
276 } // namespace extensions 283 } // namespace extensions
277 284
278 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_H_ 285 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698