| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <map> | 8 #include <map> |
| 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/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/thread.h" | 14 #include "base/thread.h" |
| 15 #include "base/time.h" | 15 #include "base/time.h" |
| 16 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
| 17 #include "net/base/completion_callback.h" | 17 #include "net/base/completion_callback.h" |
| 18 | 18 |
| 19 #if defined(OS_WIN) | 19 #if defined(OS_WIN) |
| 20 typedef LPVOID HINTERNET; // From winhttp.h | 20 typedef LPVOID HINTERNET; // From winhttp.h |
| 21 #endif | 21 #endif |
| 22 | 22 |
| 23 class GURL; | 23 class GURL; |
| 24 | 24 |
| 25 namespace net { | 25 namespace net { |
| 26 | 26 |
| 27 class ProxyConfigService; |
| 27 class ProxyInfo; | 28 class ProxyInfo; |
| 28 class ProxyResolver; | 29 class ProxyResolver; |
| 29 | 30 |
| 30 // Proxy configuration used to by the ProxyService. | 31 // Proxy configuration used to by the ProxyService. |
| 31 class ProxyConfig { | 32 class ProxyConfig { |
| 32 public: | 33 public: |
| 33 typedef int ID; | 34 typedef int ID; |
| 34 | 35 |
| 35 // Indicates an invalid proxy config. | 36 // Indicates an invalid proxy config. |
| 36 enum { INVALID_ID = 0 }; | 37 enum { INVALID_ID = 0 }; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 }; | 79 }; |
| 79 | 80 |
| 80 // Map of proxy servers with the associated RetryInfo structures. | 81 // Map of proxy servers with the associated RetryInfo structures. |
| 81 typedef std::map<std::string, ProxyRetryInfo> ProxyRetryInfoMap; | 82 typedef std::map<std::string, ProxyRetryInfo> ProxyRetryInfoMap; |
| 82 | 83 |
| 83 // This class can be used to resolve the proxy server to use when loading a | 84 // This class can be used to resolve the proxy server to use when loading a |
| 84 // HTTP(S) URL. It uses the given ProxyResolver to handle the actual proxy | 85 // HTTP(S) URL. It uses the given ProxyResolver to handle the actual proxy |
| 85 // resolution. See ProxyResolverWinHttp for example. | 86 // resolution. See ProxyResolverWinHttp for example. |
| 86 class ProxyService { | 87 class ProxyService { |
| 87 public: | 88 public: |
| 88 // The instance takes ownership of |resolver|. | 89 // The instance takes ownership of |config_service| and |resolver|. |
| 89 explicit ProxyService(ProxyResolver* resolver); | 90 ProxyService(ProxyConfigService* config_service, |
| 91 ProxyResolver* resolver); |
| 90 | 92 |
| 91 // Used internally to handle PAC queries. | 93 // Used internally to handle PAC queries. |
| 92 class PacRequest; | 94 class PacRequest; |
| 93 | 95 |
| 94 // Returns OK if proxy information could be provided synchronously. Else, | 96 // Returns OK if proxy information could be provided synchronously. Else, |
| 95 // ERR_IO_PENDING is returned to indicate that the result will be available | 97 // ERR_IO_PENDING is returned to indicate that the result will be available |
| 96 // when the callback is run. The callback is run on the thread that calls | 98 // when the callback is run. The callback is run on the thread that calls |
| 97 // ResolveProxy. | 99 // ResolveProxy. |
| 98 // | 100 // |
| 99 // The caller is responsible for ensuring that |results| and |callback| | 101 // The caller is responsible for ensuring that |results| and |callback| |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 PacRequest** pac_request); | 133 PacRequest** pac_request); |
| 132 | 134 |
| 133 // Call this method with a non-null |pac_request| to cancel the PAC request. | 135 // Call this method with a non-null |pac_request| to cancel the PAC request. |
| 134 void CancelPacRequest(PacRequest* pac_request); | 136 void CancelPacRequest(PacRequest* pac_request); |
| 135 | 137 |
| 136 // Create a proxy service using the specified settings. If |pi| is NULL then | 138 // Create a proxy service using the specified settings. If |pi| is NULL then |
| 137 // the system's default proxy settings will be used (on Windows this will | 139 // the system's default proxy settings will be used (on Windows this will |
| 138 // use IE's settings). | 140 // use IE's settings). |
| 139 static ProxyService* Create(const ProxyInfo* pi); | 141 static ProxyService* Create(const ProxyInfo* pi); |
| 140 | 142 |
| 143 // Create a proxy service that always fails to fetch the proxy configuration, |
| 144 // so it falls back to direct connect. |
| 145 static ProxyService* CreateNull(); |
| 146 |
| 141 // TODO(eroman): remove once WinHTTP is gone. | 147 // TODO(eroman): remove once WinHTTP is gone. |
| 142 // Get the ProxyInfo used to create this proxy service (only used by WinHTTP). | 148 // Get the ProxyInfo used to create this proxy service (only used by WinHTTP). |
| 143 const ProxyInfo* proxy_info() const { | 149 const ProxyInfo* proxy_info() const { |
| 144 return proxy_info_.get(); | 150 return proxy_info_.get(); |
| 145 } | 151 } |
| 146 | 152 |
| 147 private: | 153 private: |
| 148 friend class PacRequest; | 154 friend class PacRequest; |
| 149 | 155 |
| 150 ProxyResolver* resolver() { return resolver_.get(); } | 156 ProxyResolver* resolver() { return resolver_.get(); } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 162 // if the PAC file could be downloaded and executed. Otherwise, it is an | 168 // if the PAC file could be downloaded and executed. Otherwise, it is an |
| 163 // error code, indicating a bad proxy configuration. | 169 // error code, indicating a bad proxy configuration. |
| 164 void DidCompletePacRequest(int config_id, int result_code); | 170 void DidCompletePacRequest(int config_id, int result_code); |
| 165 | 171 |
| 166 // Returns true if the URL passed in should not go through the proxy server. | 172 // Returns true if the URL passed in should not go through the proxy server. |
| 167 // 1. If the bypass proxy list contains the string <local> and the URL | 173 // 1. If the bypass proxy list contains the string <local> and the URL |
| 168 // passed in is a local URL, i.e. a URL without a DOT (.) | 174 // passed in is a local URL, i.e. a URL without a DOT (.) |
| 169 // 2. The URL matches one of the entities in the proxy bypass list. | 175 // 2. The URL matches one of the entities in the proxy bypass list. |
| 170 bool ShouldBypassProxyForURL(const GURL& url); | 176 bool ShouldBypassProxyForURL(const GURL& url); |
| 171 | 177 |
| 178 scoped_ptr<ProxyConfigService> config_service_; |
| 172 scoped_ptr<ProxyResolver> resolver_; | 179 scoped_ptr<ProxyResolver> resolver_; |
| 173 scoped_ptr<base::Thread> pac_thread_; | 180 scoped_ptr<base::Thread> pac_thread_; |
| 174 | 181 |
| 175 // We store the proxy config and a counter that is incremented each time | 182 // We store the proxy config and a counter that is incremented each time |
| 176 // the config changes. | 183 // the config changes. |
| 177 ProxyConfig config_; | 184 ProxyConfig config_; |
| 178 | 185 |
| 179 // TODO(eroman): remove this once WinHTTP stack is gone. | 186 // TODO(eroman): remove this once WinHTTP stack is gone. |
| 180 scoped_ptr<ProxyInfo> proxy_info_; | 187 scoped_ptr<ProxyInfo> proxy_info_; |
| 181 | 188 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 // This value identifies the proxy config used to initialize this object. | 288 // This value identifies the proxy config used to initialize this object. |
| 282 ProxyConfig::ID config_id_; | 289 ProxyConfig::ID config_id_; |
| 283 | 290 |
| 284 // This flag is false when the proxy configuration was known to be bad when | 291 // This flag is false when the proxy configuration was known to be bad when |
| 285 // this proxy info was initialized. In such cases, we know that if this | 292 // this proxy info was initialized. In such cases, we know that if this |
| 286 // proxy info does not yield a connection that we might want to reconsider | 293 // proxy info does not yield a connection that we might want to reconsider |
| 287 // the proxy config given by config_id_. | 294 // the proxy config given by config_id_. |
| 288 bool config_was_tried_; | 295 bool config_was_tried_; |
| 289 }; | 296 }; |
| 290 | 297 |
| 291 // This interface provides the low-level functions to access the proxy | 298 // Synchronously fetch the system's proxy configuration settings. Called on |
| 292 // configuration and resolve proxies for given URLs synchronously. | 299 // the IO Thread. |
| 293 class ProxyResolver { | 300 class ProxyConfigService { |
| 294 public: | 301 public: |
| 295 virtual ~ProxyResolver() {} | 302 virtual ~ProxyConfigService() {} |
| 296 | 303 |
| 297 // Get the proxy configuration. Returns OK if successful or an error code if | 304 // Get the proxy configuration. Returns OK if successful or an error code if |
| 298 // otherwise. |config| should be in its initial state when this method is | 305 // otherwise. |config| should be in its initial state when this method is |
| 299 // called. | 306 // called. |
| 300 virtual int GetProxyConfig(ProxyConfig* config) = 0; | 307 virtual int GetProxyConfig(ProxyConfig* config) = 0; |
| 308 }; |
| 309 |
| 310 // Synchronously resolve the proxy for a URL, using a PAC script. Called on the |
| 311 // PAC Thread. |
| 312 class ProxyResolver { |
| 313 public: |
| 314 virtual ~ProxyResolver() {} |
| 301 | 315 |
| 302 // Query the proxy auto-config file (specified by |pac_url|) for the proxy to | 316 // Query the proxy auto-config file (specified by |pac_url|) for the proxy to |
| 303 // use to load the given |query_url|. Returns OK if successful or an error | 317 // use to load the given |query_url|. Returns OK if successful or an error |
| 304 // code if otherwise. | 318 // code otherwise. |
| 305 virtual int GetProxyForURL(const GURL& query_url, | 319 virtual int GetProxyForURL(const GURL& query_url, |
| 306 const GURL& pac_url, | 320 const GURL& pac_url, |
| 307 ProxyInfo* results) = 0; | 321 ProxyInfo* results) = 0; |
| 308 }; | 322 }; |
| 309 | 323 |
| 310 } // namespace net | 324 } // namespace net |
| 311 | 325 |
| 312 #endif // NET_PROXY_PROXY_SERVICE_H_ | 326 #endif // NET_PROXY_PROXY_SERVICE_H_ |
| 313 | 327 |
| OLD | NEW |