| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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" |
| 12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
| 13 #include "base/waitable_event.h" | 13 #include "base/waitable_event.h" |
| 14 #include "net/base/completion_callback.h" | 14 #include "net/base/completion_callback.h" |
| 15 #include "net/base/network_change_notifier.h" | 15 #include "net/base/network_change_notifier.h" |
| 16 #include "net/base/net_log.h" |
| 16 #include "net/proxy/proxy_server.h" | 17 #include "net/proxy/proxy_server.h" |
| 17 #include "net/proxy/proxy_info.h" | 18 #include "net/proxy/proxy_info.h" |
| 18 #include "testing/gtest/include/gtest/gtest_prod.h" | 19 #include "testing/gtest/include/gtest/gtest_prod.h" |
| 19 | 20 |
| 20 class GURL; | 21 class GURL; |
| 21 class MessageLoop; | 22 class MessageLoop; |
| 22 class URLRequestContext; | 23 class URLRequestContext; |
| 23 | 24 |
| 24 namespace net { | 25 namespace net { |
| 25 | 26 |
| 26 class InitProxyResolver; | 27 class InitProxyResolver; |
| 27 class LoadLog; | |
| 28 class ProxyConfigService; | 28 class ProxyConfigService; |
| 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: |
| (...skipping 19 matching lines...) Expand all Loading... |
| 57 // callback is still pending. NULL can be passed for |pac_request| if | 57 // callback is still pending. NULL can be passed for |pac_request| if |
| 58 // the caller will not need to cancel the request. | 58 // the caller will not need to cancel the request. |
| 59 // | 59 // |
| 60 // We use the three possible proxy access types in the following order, | 60 // We use the three possible proxy access types in the following order, |
| 61 // doing fallback if one doesn't work. See "init_proxy_resolver.h" | 61 // doing fallback if one doesn't work. See "init_proxy_resolver.h" |
| 62 // for the specifics. | 62 // for the specifics. |
| 63 // 1. WPAD auto-detection | 63 // 1. WPAD auto-detection |
| 64 // 2. PAC URL | 64 // 2. PAC URL |
| 65 // 3. named proxy | 65 // 3. named proxy |
| 66 // | 66 // |
| 67 // Profiling information for the request is saved to |load_log| if non-NULL. | 67 // Profiling information for the request is saved to |net_log| if non-NULL. |
| 68 int ResolveProxy(const GURL& url, | 68 int ResolveProxy(const GURL& url, |
| 69 ProxyInfo* results, | 69 ProxyInfo* results, |
| 70 CompletionCallback* callback, | 70 CompletionCallback* callback, |
| 71 PacRequest** pac_request, | 71 PacRequest** pac_request, |
| 72 LoadLog* load_log); | 72 const BoundNetLog& net_log); |
| 73 | 73 |
| 74 // This method is called after a failure to connect or resolve a host name. | 74 // This method is called after a failure to connect or resolve a host name. |
| 75 // It gives the proxy service an opportunity to reconsider the proxy to use. | 75 // It gives the proxy service an opportunity to reconsider the proxy to use. |
| 76 // The |results| parameter contains the results returned by an earlier call | 76 // The |results| parameter contains the results returned by an earlier call |
| 77 // to ResolveProxy. The semantics of this call are otherwise similar to | 77 // to ResolveProxy. The semantics of this call are otherwise similar to |
| 78 // ResolveProxy. | 78 // ResolveProxy. |
| 79 // | 79 // |
| 80 // NULL can be passed for |pac_request| if the caller will not need to | 80 // NULL can be passed for |pac_request| if the caller will not need to |
| 81 // cancel the request. | 81 // cancel the request. |
| 82 // | 82 // |
| 83 // Returns ERR_FAILED if there is not another proxy config to try. | 83 // Returns ERR_FAILED if there is not another proxy config to try. |
| 84 // | 84 // |
| 85 // Profiling information for the request is saved to |load_log| if non-NULL. | 85 // Profiling information for the request is saved to |net_log| if non-NULL. |
| 86 int ReconsiderProxyAfterError(const GURL& url, | 86 int ReconsiderProxyAfterError(const GURL& url, |
| 87 ProxyInfo* results, | 87 ProxyInfo* results, |
| 88 CompletionCallback* callback, | 88 CompletionCallback* callback, |
| 89 PacRequest** pac_request, | 89 PacRequest** pac_request, |
| 90 LoadLog* load_log); | 90 const BoundNetLog& net_log); |
| 91 | 91 |
| 92 // Call this method with a non-null |pac_request| to cancel the PAC request. | 92 // Call this method with a non-null |pac_request| to cancel the PAC request. |
| 93 void CancelPacRequest(PacRequest* pac_request); | 93 void CancelPacRequest(PacRequest* pac_request); |
| 94 | 94 |
| 95 // Sets the ProxyScriptFetcher dependency. This is needed if the ProxyResolver | 95 // Sets the ProxyScriptFetcher dependency. This is needed if the ProxyResolver |
| 96 // is of type ProxyResolverWithoutFetch. ProxyService takes ownership of | 96 // is of type ProxyResolverWithoutFetch. ProxyService takes ownership of |
| 97 // |proxy_script_fetcher|. | 97 // |proxy_script_fetcher|. |
| 98 void SetProxyScriptFetcher(ProxyScriptFetcher* proxy_script_fetcher); | 98 void SetProxyScriptFetcher(ProxyScriptFetcher* proxy_script_fetcher); |
| 99 ProxyScriptFetcher* GetProxyScriptFetcher() const; | 99 ProxyScriptFetcher* GetProxyScriptFetcher() const; |
| 100 | 100 |
| 101 // Tells this ProxyService to start using a new ProxyConfigService to | 101 // Tells this ProxyService to start using a new ProxyConfigService to |
| 102 // retrieve its ProxyConfig from. The new ProxyConfigService will immediately | 102 // retrieve its ProxyConfig from. The new ProxyConfigService will immediately |
| 103 // be queried for new config info which will be used for all subsequent | 103 // be queried for new config info which will be used for all subsequent |
| 104 // ResolveProxy calls. ProxyService takes ownership of | 104 // ResolveProxy calls. ProxyService takes ownership of |
| 105 // |new_proxy_config_service|. | 105 // |new_proxy_config_service|. |
| 106 void ResetConfigService(ProxyConfigService* new_proxy_config_service); | 106 void ResetConfigService(ProxyConfigService* new_proxy_config_service); |
| 107 | 107 |
| 108 // Tells the resolver to purge any memory it does not need. | 108 // Tells the resolver to purge any memory it does not need. |
| 109 void PurgeMemory(); | 109 void PurgeMemory(); |
| 110 | 110 |
| 111 // Returns the log for the most recent WPAD + PAC initialization. | 111 // Returns the log for the most recent WPAD + PAC initialization. |
| 112 // (This shows how much time was spent downloading and parsing the | 112 // (This shows how much time was spent downloading and parsing the |
| 113 // PAC scripts for the current configuration). | 113 // PAC scripts for the current configuration). |
| 114 LoadLog* init_proxy_resolver_log() const { | 114 const CapturingBoundNetLog& init_proxy_resolver_log() const { |
| 115 return init_proxy_resolver_log_; | 115 return init_proxy_resolver_log_; |
| 116 } | 116 } |
| 117 | 117 |
| 118 // Returns true if we have called UpdateConfig() at least once. | 118 // Returns true if we have called UpdateConfig() at least once. |
| 119 bool config_has_been_initialized() const { | 119 bool config_has_been_initialized() const { |
| 120 return config_.id() != ProxyConfig::INVALID_ID; | 120 return config_.id() != ProxyConfig::INVALID_ID; |
| 121 } | 121 } |
| 122 | 122 |
| 123 // Returns the last configuration fetched from ProxyConfigService. | 123 // Returns the last configuration fetched from ProxyConfigService. |
| 124 const ProxyConfig& config() { | 124 const ProxyConfig& config() { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 | 192 |
| 193 // Creates a proxy resolver appropriate for this platform that doesn't rely | 193 // Creates a proxy resolver appropriate for this platform that doesn't rely |
| 194 // on V8. | 194 // on V8. |
| 195 static ProxyResolver* CreateNonV8ProxyResolver(); | 195 static ProxyResolver* CreateNonV8ProxyResolver(); |
| 196 | 196 |
| 197 // Identifies the proxy configuration. | 197 // Identifies the proxy configuration. |
| 198 ProxyConfig::ID config_id() const { return config_.id(); } | 198 ProxyConfig::ID config_id() const { return config_.id(); } |
| 199 | 199 |
| 200 // Checks to see if the proxy configuration changed, and then updates config_ | 200 // Checks to see if the proxy configuration changed, and then updates config_ |
| 201 // to reference the new configuration. | 201 // to reference the new configuration. |
| 202 void UpdateConfig(LoadLog* load_log); | 202 void UpdateConfig(const BoundNetLog& net_log); |
| 203 | 203 |
| 204 // Assign |config| as the current configuration. | 204 // Assign |config| as the current configuration. |
| 205 void SetConfig(const ProxyConfig& config); | 205 void SetConfig(const ProxyConfig& config); |
| 206 | 206 |
| 207 // Starts downloading and testing the various PAC choices. | 207 // Starts downloading and testing the various PAC choices. |
| 208 // Calls OnInitProxyResolverComplete() when completed. | 208 // Calls OnInitProxyResolverComplete() when completed. |
| 209 void StartInitProxyResolver(); | 209 void StartInitProxyResolver(); |
| 210 | 210 |
| 211 // Tries to update the configuration if it hasn't been checked in a while. | 211 // Tries to update the configuration if it hasn't been checked in a while. |
| 212 void UpdateConfigIfOld(LoadLog* load_log); | 212 void UpdateConfigIfOld(const BoundNetLog& net_log); |
| 213 | 213 |
| 214 // Returns true if the proxy resolver is being initialized for PAC | 214 // Returns true if the proxy resolver is being initialized for PAC |
| 215 // (downloading PAC script(s) + testing). | 215 // (downloading PAC script(s) + testing). |
| 216 // Resolve requests will be frozen until the initialization has completed. | 216 // Resolve requests will be frozen until the initialization has completed. |
| 217 bool IsInitializingProxyResolver() const { | 217 bool IsInitializingProxyResolver() const { |
| 218 return init_proxy_resolver_.get() != NULL; | 218 return init_proxy_resolver_.get() != NULL; |
| 219 } | 219 } |
| 220 | 220 |
| 221 // Callback for when the proxy resolver has been initialized with a | 221 // Callback for when the proxy resolver has been initialized with a |
| 222 // PAC script. | 222 // PAC script. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 238 bool ContainsPendingRequest(PacRequest* req); | 238 bool ContainsPendingRequest(PacRequest* req); |
| 239 | 239 |
| 240 // Removes |req| from the list of pending requests. | 240 // Removes |req| from the list of pending requests. |
| 241 void RemovePendingRequest(PacRequest* req); | 241 void RemovePendingRequest(PacRequest* req); |
| 242 | 242 |
| 243 // Called when proxy resolution has completed (either synchronously or | 243 // Called when proxy resolution has completed (either synchronously or |
| 244 // asynchronously). Handles logging the result, and cleaning out | 244 // asynchronously). Handles logging the result, and cleaning out |
| 245 // bad entries from the results list. | 245 // bad entries from the results list. |
| 246 int DidFinishResolvingProxy(ProxyInfo* result, | 246 int DidFinishResolvingProxy(ProxyInfo* result, |
| 247 int result_code, | 247 int result_code, |
| 248 LoadLog* load_log); | 248 const BoundNetLog& net_log); |
| 249 | 249 |
| 250 // NetworkChangeNotifier::Observer methods: | 250 // NetworkChangeNotifier::Observer methods: |
| 251 virtual void OnIPAddressChanged(); | 251 virtual void OnIPAddressChanged(); |
| 252 | 252 |
| 253 scoped_ptr<ProxyConfigService> config_service_; | 253 scoped_ptr<ProxyConfigService> config_service_; |
| 254 scoped_ptr<ProxyResolver> resolver_; | 254 scoped_ptr<ProxyResolver> resolver_; |
| 255 | 255 |
| 256 // We store the proxy config and a counter (ID) that is incremented each time | 256 // We store the proxy config and a counter (ID) that is incremented each time |
| 257 // the config changes. | 257 // the config changes. |
| 258 ProxyConfig config_; | 258 ProxyConfig config_; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 280 // Callback for when |init_proxy_resolver_| is done. | 280 // Callback for when |init_proxy_resolver_| is done. |
| 281 CompletionCallbackImpl<ProxyService> init_proxy_resolver_callback_; | 281 CompletionCallbackImpl<ProxyService> init_proxy_resolver_callback_; |
| 282 | 282 |
| 283 // Helper to download the PAC script (wpad + custom) and apply fallback rules. | 283 // Helper to download the PAC script (wpad + custom) and apply fallback rules. |
| 284 // | 284 // |
| 285 // Note that the declaration is important here: |proxy_script_fetcher_| and | 285 // Note that the declaration is important here: |proxy_script_fetcher_| and |
| 286 // |proxy_resolver_| must outlive |init_proxy_resolver_|. | 286 // |proxy_resolver_| must outlive |init_proxy_resolver_|. |
| 287 scoped_ptr<InitProxyResolver> init_proxy_resolver_; | 287 scoped_ptr<InitProxyResolver> init_proxy_resolver_; |
| 288 | 288 |
| 289 // Log from the *last* time |init_proxy_resolver_.Init()| was called, or NULL. | 289 // Log from the *last* time |init_proxy_resolver_.Init()| was called, or NULL. |
| 290 scoped_refptr<LoadLog> init_proxy_resolver_log_; | 290 CapturingBoundNetLog init_proxy_resolver_log_; |
| 291 | 291 |
| 292 // The (possibly NULL) network change notifier that we use to decide when | 292 // The (possibly NULL) network change notifier that we use to decide when |
| 293 // to refetch PAC scripts or re-run WPAD. | 293 // to refetch PAC scripts or re-run WPAD. |
| 294 NetworkChangeNotifier* const network_change_notifier_; | 294 NetworkChangeNotifier* const network_change_notifier_; |
| 295 | 295 |
| 296 DISALLOW_COPY_AND_ASSIGN(ProxyService); | 296 DISALLOW_COPY_AND_ASSIGN(ProxyService); |
| 297 }; | 297 }; |
| 298 | 298 |
| 299 // Wrapper for invoking methods on a ProxyService synchronously. | 299 // Wrapper for invoking methods on a ProxyService synchronously. |
| 300 class SyncProxyServiceHelper | 300 class SyncProxyServiceHelper |
| 301 : public base::RefCountedThreadSafe<SyncProxyServiceHelper> { | 301 : public base::RefCountedThreadSafe<SyncProxyServiceHelper> { |
| 302 public: | 302 public: |
| 303 SyncProxyServiceHelper(MessageLoop* io_message_loop, | 303 SyncProxyServiceHelper(MessageLoop* io_message_loop, |
| 304 ProxyService* proxy_service); | 304 ProxyService* proxy_service); |
| 305 | 305 |
| 306 int ResolveProxy(const GURL& url, ProxyInfo* proxy_info, LoadLog* load_log); | 306 int ResolveProxy(const GURL& url, ProxyInfo* proxy_info, const BoundNetLog& ne
t_log); |
| 307 int ReconsiderProxyAfterError(const GURL& url, | 307 int ReconsiderProxyAfterError(const GURL& url, |
| 308 ProxyInfo* proxy_info, LoadLog* load_log); | 308 ProxyInfo* proxy_info, const BoundNetLog& net_lo
g); |
| 309 | 309 |
| 310 private: | 310 private: |
| 311 friend class base::RefCountedThreadSafe<SyncProxyServiceHelper>; | 311 friend class base::RefCountedThreadSafe<SyncProxyServiceHelper>; |
| 312 | 312 |
| 313 ~SyncProxyServiceHelper() {} | 313 ~SyncProxyServiceHelper() {} |
| 314 | 314 |
| 315 void StartAsyncResolve(const GURL& url, LoadLog* load_log); | 315 void StartAsyncResolve(const GURL& url, const BoundNetLog& net_log); |
| 316 void StartAsyncReconsider(const GURL& url, LoadLog* load_log); | 316 void StartAsyncReconsider(const GURL& url, const BoundNetLog& net_log); |
| 317 | 317 |
| 318 void OnCompletion(int result); | 318 void OnCompletion(int result); |
| 319 | 319 |
| 320 MessageLoop* io_message_loop_; | 320 MessageLoop* io_message_loop_; |
| 321 ProxyService* proxy_service_; | 321 ProxyService* proxy_service_; |
| 322 | 322 |
| 323 base::WaitableEvent event_; | 323 base::WaitableEvent event_; |
| 324 CompletionCallbackImpl<SyncProxyServiceHelper> callback_; | 324 CompletionCallbackImpl<SyncProxyServiceHelper> callback_; |
| 325 ProxyInfo proxy_info_; | 325 ProxyInfo proxy_info_; |
| 326 int result_; | 326 int result_; |
| 327 }; | 327 }; |
| 328 | 328 |
| 329 } // namespace net | 329 } // namespace net |
| 330 | 330 |
| 331 #endif // NET_PROXY_PROXY_SERVICE_H_ | 331 #endif // NET_PROXY_PROXY_SERVICE_H_ |
| OLD | NEW |