OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 NET_PROXY_PROXY_SERVICE_H_ | 5 #ifndef NET_PROXY_PROXY_SERVICE_H_ |
6 #define NET_PROXY_PROXY_SERVICE_H_ | 6 #define NET_PROXY_PROXY_SERVICE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/ref_counted.h" | 11 #include "base/ref_counted.h" |
(...skipping 17 matching lines...) Expand all Loading... |
29 class ProxyResolver; | 29 class ProxyResolver; |
30 class ProxyScriptFetcher; | 30 class ProxyScriptFetcher; |
31 | 31 |
32 // This class can be used to resolve the proxy server to use when loading a | 32 // This class can be used to resolve the proxy server to use when loading a |
33 // HTTP(S) URL. It uses the given ProxyResolver to handle the actual proxy | 33 // HTTP(S) URL. It uses the given ProxyResolver to handle the actual proxy |
34 // resolution. See ProxyResolverV8 for example. | 34 // resolution. See ProxyResolverV8 for example. |
35 class ProxyService : public base::RefCountedThreadSafe<ProxyService>, | 35 class ProxyService : public base::RefCountedThreadSafe<ProxyService>, |
36 public NetworkChangeNotifier::Observer { | 36 public NetworkChangeNotifier::Observer { |
37 public: | 37 public: |
38 // The instance takes ownership of |config_service| and |resolver|. | 38 // The instance takes ownership of |config_service| and |resolver|. |
39 // If |network_change_notifier| is non-NULL, the proxy service will register | |
40 // with it to detect when the network setup has changed. This is used to | |
41 // decide when to re-configure the proxy discovery. | |
42 // |net_log| is a possibly NULL destination to send log events to. It must | 39 // |net_log| is a possibly NULL destination to send log events to. It must |
43 // remain alive for the lifetime of this ProxyService. | 40 // remain alive for the lifetime of this ProxyService. |
44 ProxyService(ProxyConfigService* config_service, ProxyResolver* resolver, | 41 ProxyService(ProxyConfigService* config_service, |
45 NetworkChangeNotifier* network_change_notifier, | 42 ProxyResolver* resolver, |
46 NetLog* net_log); | 43 NetLog* net_log); |
47 | 44 |
48 // Used internally to handle PAC queries. | 45 // Used internally to handle PAC queries. |
49 // TODO(eroman): consider naming this simply "Request". | 46 // TODO(eroman): consider naming this simply "Request". |
50 class PacRequest; | 47 class PacRequest; |
51 | 48 |
52 // Returns ERR_IO_PENDING if the proxy information could not be provided | 49 // Returns ERR_IO_PENDING if the proxy information could not be provided |
53 // synchronously, to indicate that the result will be available when the | 50 // synchronously, to indicate that the result will be available when the |
54 // callback is run. The callback is run on the thread that calls | 51 // callback is run. The callback is run on the thread that calls |
55 // ResolveProxy. | 52 // ResolveProxy. |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 // to downloading and testing the PAC files. | 133 // to downloading and testing the PAC files. |
137 void ForceReloadProxyConfig(); | 134 void ForceReloadProxyConfig(); |
138 | 135 |
139 // Creates a proxy service that polls |proxy_config_service| to notice when | 136 // Creates a proxy service that polls |proxy_config_service| to notice when |
140 // the proxy settings change. We take ownership of |proxy_config_service|. | 137 // the proxy settings change. We take ownership of |proxy_config_service|. |
141 // Iff |use_v8_resolver| is true, then the V8 implementation is | 138 // Iff |use_v8_resolver| is true, then the V8 implementation is |
142 // used. | 139 // used. |
143 // |url_request_context| is only used when use_v8_resolver is true: | 140 // |url_request_context| is only used when use_v8_resolver is true: |
144 // it specifies the URL request context that will be used if a PAC | 141 // it specifies the URL request context that will be used if a PAC |
145 // script needs to be fetched. | 142 // script needs to be fetched. |
146 // |network_change_notifier| may be NULL. Otherwise it will be used to | |
147 // signal the ProxyService when the network setup has changed. | |
148 // |io_loop| points to the IO thread's message loop. It is only used | 143 // |io_loop| points to the IO thread's message loop. It is only used |
149 // when pc is NULL. | 144 // when pc is NULL. |
150 // ########################################################################## | 145 // ########################################################################## |
151 // # See the warnings in net/proxy/proxy_resolver_v8.h describing the | 146 // # See the warnings in net/proxy/proxy_resolver_v8.h describing the |
152 // # multi-threading model. In order for this to be safe to use, *ALL* the | 147 // # multi-threading model. In order for this to be safe to use, *ALL* the |
153 // # other V8's running in the process must use v8::Locker. | 148 // # other V8's running in the process must use v8::Locker. |
154 // ########################################################################## | 149 // ########################################################################## |
155 static ProxyService* Create( | 150 static ProxyService* Create( |
156 ProxyConfigService* proxy_config_service, | 151 ProxyConfigService* proxy_config_service, |
157 bool use_v8_resolver, | 152 bool use_v8_resolver, |
158 URLRequestContext* url_request_context, | 153 URLRequestContext* url_request_context, |
159 NetworkChangeNotifier* network_change_notifier, | |
160 NetLog* net_log, | 154 NetLog* net_log, |
161 MessageLoop* io_loop); | 155 MessageLoop* io_loop); |
162 | 156 |
163 // Convenience method that creates a proxy service using the | 157 // Convenience method that creates a proxy service using the |
164 // specified fixed settings. |pc| must not be NULL. | 158 // specified fixed settings. |pc| must not be NULL. |
165 static ProxyService* CreateFixed(const ProxyConfig& pc); | 159 static ProxyService* CreateFixed(const ProxyConfig& pc); |
166 | 160 |
167 // Creates a proxy service that always fails to fetch the proxy configuration, | 161 // Creates a proxy service that always fails to fetch the proxy configuration, |
168 // so it falls back to direct connect. | 162 // so it falls back to direct connect. |
169 static ProxyService* CreateNull(); | 163 static ProxyService* CreateNull(); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 // Removes |req| from the list of pending requests. | 231 // Removes |req| from the list of pending requests. |
238 void RemovePendingRequest(PacRequest* req); | 232 void RemovePendingRequest(PacRequest* req); |
239 | 233 |
240 // Called when proxy resolution has completed (either synchronously or | 234 // Called when proxy resolution has completed (either synchronously or |
241 // asynchronously). Handles logging the result, and cleaning out | 235 // asynchronously). Handles logging the result, and cleaning out |
242 // bad entries from the results list. | 236 // bad entries from the results list. |
243 int DidFinishResolvingProxy(ProxyInfo* result, | 237 int DidFinishResolvingProxy(ProxyInfo* result, |
244 int result_code, | 238 int result_code, |
245 const BoundNetLog& net_log); | 239 const BoundNetLog& net_log); |
246 | 240 |
247 // NetworkChangeNotifier::Observer methods: | 241 // NetworkChangeNotifier::Observer |
| 242 // When this is called, we re-fetch PAC scripts and re-run WPAD. |
248 virtual void OnIPAddressChanged(); | 243 virtual void OnIPAddressChanged(); |
249 | 244 |
250 scoped_ptr<ProxyConfigService> config_service_; | 245 scoped_ptr<ProxyConfigService> config_service_; |
251 scoped_ptr<ProxyResolver> resolver_; | 246 scoped_ptr<ProxyResolver> resolver_; |
252 | 247 |
253 // We store the proxy config and a counter (ID) that is incremented each time | 248 // We store the proxy config and a counter (ID) that is incremented each time |
254 // the config changes. | 249 // the config changes. |
255 ProxyConfig config_; | 250 ProxyConfig config_; |
256 | 251 |
257 // Increasing ID to give to the next ProxyConfig that we set. | 252 // Increasing ID to give to the next ProxyConfig that we set. |
(...skipping 22 matching lines...) Expand all Loading... |
280 // Helper to download the PAC script (wpad + custom) and apply fallback rules. | 275 // Helper to download the PAC script (wpad + custom) and apply fallback rules. |
281 // | 276 // |
282 // Note that the declaration is important here: |proxy_script_fetcher_| and | 277 // Note that the declaration is important here: |proxy_script_fetcher_| and |
283 // |proxy_resolver_| must outlive |init_proxy_resolver_|. | 278 // |proxy_resolver_| must outlive |init_proxy_resolver_|. |
284 scoped_ptr<InitProxyResolver> init_proxy_resolver_; | 279 scoped_ptr<InitProxyResolver> init_proxy_resolver_; |
285 | 280 |
286 // This is the log where any events generated by |init_proxy_resolver_| are | 281 // This is the log where any events generated by |init_proxy_resolver_| are |
287 // sent to. | 282 // sent to. |
288 NetLog* net_log_; | 283 NetLog* net_log_; |
289 | 284 |
290 // The (possibly NULL) network change notifier that we use to decide when | |
291 // to refetch PAC scripts or re-run WPAD. | |
292 NetworkChangeNotifier* const network_change_notifier_; | |
293 | |
294 DISALLOW_COPY_AND_ASSIGN(ProxyService); | 285 DISALLOW_COPY_AND_ASSIGN(ProxyService); |
295 }; | 286 }; |
296 | 287 |
297 // Wrapper for invoking methods on a ProxyService synchronously. | 288 // Wrapper for invoking methods on a ProxyService synchronously. |
298 class SyncProxyServiceHelper | 289 class SyncProxyServiceHelper |
299 : public base::RefCountedThreadSafe<SyncProxyServiceHelper> { | 290 : public base::RefCountedThreadSafe<SyncProxyServiceHelper> { |
300 public: | 291 public: |
301 SyncProxyServiceHelper(MessageLoop* io_message_loop, | 292 SyncProxyServiceHelper(MessageLoop* io_message_loop, |
302 ProxyService* proxy_service); | 293 ProxyService* proxy_service); |
303 | 294 |
304 int ResolveProxy(const GURL& url, ProxyInfo* proxy_info, const BoundNetLog& ne
t_log); | 295 int ResolveProxy(const GURL& url, |
| 296 ProxyInfo* proxy_info, |
| 297 const BoundNetLog& net_log); |
305 int ReconsiderProxyAfterError(const GURL& url, | 298 int ReconsiderProxyAfterError(const GURL& url, |
306 ProxyInfo* proxy_info, const BoundNetLog& net_lo
g); | 299 ProxyInfo* proxy_info, |
| 300 const BoundNetLog& net_log); |
307 | 301 |
308 private: | 302 private: |
309 friend class base::RefCountedThreadSafe<SyncProxyServiceHelper>; | 303 friend class base::RefCountedThreadSafe<SyncProxyServiceHelper>; |
310 | 304 |
311 ~SyncProxyServiceHelper() {} | 305 ~SyncProxyServiceHelper() {} |
312 | 306 |
313 void StartAsyncResolve(const GURL& url, const BoundNetLog& net_log); | 307 void StartAsyncResolve(const GURL& url, const BoundNetLog& net_log); |
314 void StartAsyncReconsider(const GURL& url, const BoundNetLog& net_log); | 308 void StartAsyncReconsider(const GURL& url, const BoundNetLog& net_log); |
315 | 309 |
316 void OnCompletion(int result); | 310 void OnCompletion(int result); |
317 | 311 |
318 MessageLoop* io_message_loop_; | 312 MessageLoop* io_message_loop_; |
319 ProxyService* proxy_service_; | 313 ProxyService* proxy_service_; |
320 | 314 |
321 base::WaitableEvent event_; | 315 base::WaitableEvent event_; |
322 CompletionCallbackImpl<SyncProxyServiceHelper> callback_; | 316 CompletionCallbackImpl<SyncProxyServiceHelper> callback_; |
323 ProxyInfo proxy_info_; | 317 ProxyInfo proxy_info_; |
324 int result_; | 318 int result_; |
325 }; | 319 }; |
326 | 320 |
327 } // namespace net | 321 } // namespace net |
328 | 322 |
329 #endif // NET_PROXY_PROXY_SERVICE_H_ | 323 #endif // NET_PROXY_PROXY_SERVICE_H_ |
OLD | NEW |