| 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 <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 // TODO(eroman): remove this unused header; other callers are depending on it! | 13 // TODO(eroman): remove this unused header; other callers are depending on it! |
| 14 #include "base/thread.h" | 14 #include "base/thread.h" |
| 15 #include "base/waitable_event.h" | 15 #include "base/waitable_event.h" |
| 16 #include "net/base/completion_callback.h" | 16 #include "net/base/completion_callback.h" |
| 17 #include "net/proxy/proxy_server.h" | 17 #include "net/proxy/proxy_server.h" |
| 18 #include "net/proxy/proxy_info.h" | 18 #include "net/proxy/proxy_info.h" |
| 19 #include "testing/gtest/include/gtest/gtest_prod.h" | 19 #include "testing/gtest/include/gtest/gtest_prod.h" |
| 20 | 20 |
| 21 class GURL; | 21 class GURL; |
| 22 class MessageLoop; | 22 class MessageLoop; |
| 23 class URLRequestContext; | 23 class URLRequestContext; |
| 24 | 24 |
| 25 namespace net { | 25 namespace net { |
| 26 | 26 |
| 27 class ProxyScriptFetcher; | 27 class InitProxyResolver; |
| 28 class ProxyConfigService; | 28 class ProxyConfigService; |
| 29 class ProxyResolver; | 29 class ProxyResolver; |
| 30 class ProxyScriptFetcher; |
| 30 | 31 |
| 31 // 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 |
| 32 // 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 |
| 33 // resolution. See ProxyResolverV8 for example. | 34 // resolution. See ProxyResolverV8 for example. |
| 34 class ProxyService { | 35 class ProxyService { |
| 35 public: | 36 public: |
| 36 // The instance takes ownership of |config_service| and |resolver|. | 37 // The instance takes ownership of |config_service| and |resolver|. |
| 37 ProxyService(ProxyConfigService* config_service, | 38 ProxyService(ProxyConfigService* config_service, |
| 38 ProxyResolver* resolver); | 39 ProxyResolver* resolver); |
| 39 | 40 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 // Checks to see if the proxy configuration changed, and then updates config_ | 159 // Checks to see if the proxy configuration changed, and then updates config_ |
| 159 // to reference the new configuration. | 160 // to reference the new configuration. |
| 160 void UpdateConfig(); | 161 void UpdateConfig(); |
| 161 | 162 |
| 162 // Assign |config| as the current configuration. | 163 // Assign |config| as the current configuration. |
| 163 void SetConfig(const ProxyConfig& config); | 164 void SetConfig(const ProxyConfig& config); |
| 164 | 165 |
| 165 // Tries to update the configuration if it hasn't been checked in a while. | 166 // Tries to update the configuration if it hasn't been checked in a while. |
| 166 void UpdateConfigIfOld(); | 167 void UpdateConfigIfOld(); |
| 167 | 168 |
| 168 // Returns true if this ProxyService is downloading a PAC script on behalf | 169 // Returns true if the proxy resolver is being initialized for PAC |
| 169 // of ProxyResolverWithoutFetch. Resolve requests will be frozen until | 170 // (downloading PAC script(s) + testing). |
| 170 // the fetch has completed. | 171 // Resolve requests will be frozen until the initialization has completed. |
| 171 bool IsFetchingPacScript() const { | 172 bool IsInitializingProxyResolver() const { |
| 172 return in_progress_fetch_config_id_ != ProxyConfig::INVALID_ID; | 173 return init_proxy_resolver_.get() != NULL; |
| 173 } | 174 } |
| 174 | 175 |
| 175 // Callback for when the PAC script has finished downloading. | 176 // Callback for when the proxy resolver has been initialized with a |
| 176 void OnScriptFetchCompletion(int result); | 177 // PAC script. |
| 178 void OnInitProxyResolverComplete(int result); |
| 177 | 179 |
| 178 // Returns ERR_IO_PENDING if the request cannot be completed synchronously. | 180 // Returns ERR_IO_PENDING if the request cannot be completed synchronously. |
| 179 // Otherwise it fills |result| with the proxy information for |url|. | 181 // Otherwise it fills |result| with the proxy information for |url|. |
| 180 // Completing synchronously means we don't need to query ProxyResolver. | 182 // Completing synchronously means we don't need to query ProxyResolver. |
| 181 int TryToCompleteSynchronously(const GURL& url, ProxyInfo* result); | 183 int TryToCompleteSynchronously(const GURL& url, ProxyInfo* result); |
| 182 | 184 |
| 183 // Set |result| with the proxy to use for |url|, based on |rules|. | 185 // Set |result| with the proxy to use for |url|, based on |rules|. |
| 184 void ApplyProxyRules(const GURL& url, | 186 void ApplyProxyRules(const GURL& url, |
| 185 const ProxyConfig::ProxyRules& rules, | 187 const ProxyConfig::ProxyRules& rules, |
| 186 ProxyInfo* result); | 188 ProxyInfo* result); |
| 187 | 189 |
| 190 // Cancel all of the requests sent to the ProxyResolver. These will be |
| 191 // restarted when calling ResumeAllPendingRequests(). |
| 192 void SuspendAllPendingRequests(); |
| 193 |
| 188 // Sends all the unstarted pending requests off to the resolver. | 194 // Sends all the unstarted pending requests off to the resolver. |
| 189 void ResumeAllPendingRequests(); | 195 void ResumeAllPendingRequests(); |
| 190 | 196 |
| 191 // Returns true if |pending_requests_| contains |req|. | 197 // Returns true if |pending_requests_| contains |req|. |
| 192 bool ContainsPendingRequest(PacRequest* req); | 198 bool ContainsPendingRequest(PacRequest* req); |
| 193 | 199 |
| 194 // Removes |req| from the list of pending requests. | 200 // Removes |req| from the list of pending requests. |
| 195 void RemovePendingRequest(PacRequest* req); | 201 void RemovePendingRequest(PacRequest* req); |
| 196 | 202 |
| 197 // Returns true if the resolver is all set-up and ready to accept requests. | |
| 198 // Returns false if requests are blocked (because the PAC script is being | |
| 199 // downloaded). May have the side-effect of starting the PAC script | |
| 200 // download. | |
| 201 bool PrepareResolverForRequests(); | |
| 202 | |
| 203 // Called to indicate that a PacRequest completed. The |config_id| parameter | 203 // Called to indicate that a PacRequest completed. The |config_id| parameter |
| 204 // indicates the proxy configuration that was queried. |result_code| is OK | 204 // indicates the proxy configuration that was queried. |result_code| is OK |
| 205 // if the PAC file could be downloaded and executed. Otherwise, it is an | 205 // if the PAC file could be downloaded and executed. Otherwise, it is an |
| 206 // error code, indicating a bad proxy configuration. | 206 // error code, indicating a bad proxy configuration. |
| 207 void DidCompletePacRequest(int config_id, int result_code); | 207 void DidCompletePacRequest(int config_id, int result_code); |
| 208 | 208 |
| 209 // Returns true if the URL passed in should not go through the proxy server. | 209 // Returns true if the URL passed in should not go through the proxy server. |
| 210 // 1. If the proxy settings say to bypass local names, and |IsLocalName(url)|. | 210 // 1. If the proxy settings say to bypass local names, and |IsLocalName(url)|. |
| 211 // 2. The URL matches one of the entities in the proxy bypass list. | 211 // 2. The URL matches one of the entities in the proxy bypass list. |
| 212 bool ShouldBypassProxyForURL(const GURL& url); | 212 bool ShouldBypassProxyForURL(const GURL& url); |
| 213 | 213 |
| 214 // Returns true if |url| is to an intranet site (using non-FQDN as the | 214 // Returns true if |url| is to an intranet site (using non-FQDN as the |
| 215 // heuristic). | 215 // heuristic). |
| 216 static bool IsLocalName(const GURL& url); | 216 static bool IsLocalName(const GURL& url); |
| 217 | 217 |
| 218 // Helper to download the PAC script (wpad + custom) and apply fallback rules. |
| 219 scoped_ptr<InitProxyResolver> init_proxy_resolver_; |
| 220 |
| 218 scoped_ptr<ProxyConfigService> config_service_; | 221 scoped_ptr<ProxyConfigService> config_service_; |
| 219 scoped_ptr<ProxyResolver> resolver_; | 222 scoped_ptr<ProxyResolver> resolver_; |
| 220 | 223 |
| 221 // We store the proxy config and a counter (ID) that is incremented each time | 224 // We store the proxy config and a counter (ID) that is incremented each time |
| 222 // the config changes. | 225 // the config changes. |
| 223 ProxyConfig config_; | 226 ProxyConfig config_; |
| 224 | 227 |
| 225 // Increasing ID to give to the next ProxyConfig that we set. | 228 // Increasing ID to give to the next ProxyConfig that we set. |
| 226 int next_config_id_; | 229 int next_config_id_; |
| 227 | 230 |
| 228 // Indicates that the configuration is bad and should be ignored. | 231 // Indicates that the configuration is bad and should be ignored. |
| 229 bool config_is_bad_; | 232 bool config_is_bad_; |
| 230 | 233 |
| 231 // The time when the proxy configuration was last read from the system. | 234 // The time when the proxy configuration was last read from the system. |
| 232 base::TimeTicks config_last_update_time_; | 235 base::TimeTicks config_last_update_time_; |
| 233 | 236 |
| 234 // Map of the known bad proxies and the information about the retry time. | 237 // Map of the known bad proxies and the information about the retry time. |
| 235 ProxyRetryInfoMap proxy_retry_info_; | 238 ProxyRetryInfoMap proxy_retry_info_; |
| 236 | 239 |
| 237 // Set of pending/inprogress requests. | 240 // Set of pending/inprogress requests. |
| 238 PendingRequests pending_requests_; | 241 PendingRequests pending_requests_; |
| 239 | 242 |
| 240 // The fetcher to use when downloading PAC scripts for the ProxyResolver. | 243 // The fetcher to use when downloading PAC scripts for the ProxyResolver. |
| 241 // This dependency can be NULL if our ProxyResolver has no need for | 244 // This dependency can be NULL if our ProxyResolver has no need for |
| 242 // external PAC script fetching. | 245 // external PAC script fetching. |
| 243 scoped_ptr<ProxyScriptFetcher> proxy_script_fetcher_; | 246 scoped_ptr<ProxyScriptFetcher> proxy_script_fetcher_; |
| 244 | 247 |
| 245 // Callback for when |proxy_script_fetcher_| is done. | 248 // Callback for when |init_proxy_resolver_| is done. |
| 246 CompletionCallbackImpl<ProxyService> proxy_script_fetcher_callback_; | 249 CompletionCallbackImpl<ProxyService> init_proxy_resolver_callback_; |
| 247 | |
| 248 // The ID of the configuration for which we last downloaded a PAC script. | |
| 249 // If no PAC script has been fetched yet, will be ProxyConfig::INVALID_ID. | |
| 250 ProxyConfig::ID fetched_pac_config_id_; | |
| 251 | |
| 252 // The error corresponding with |fetched_pac_config_id_|, or OK. | |
| 253 int fetched_pac_error_; | |
| 254 | |
| 255 // The ID of the configuration for which we are currently downloading the | |
| 256 // PAC script. If no fetch is in progress, will be ProxyConfig::INVALID_ID. | |
| 257 ProxyConfig::ID in_progress_fetch_config_id_; | |
| 258 | |
| 259 // The results of the current in progress fetch, or empty string. | |
| 260 std::string in_progress_fetch_bytes_; | |
| 261 | |
| 262 DISALLOW_COPY_AND_ASSIGN(ProxyService); | 250 DISALLOW_COPY_AND_ASSIGN(ProxyService); |
| 263 }; | 251 }; |
| 264 | 252 |
| 265 // Wrapper for invoking methods on a ProxyService synchronously. | 253 // Wrapper for invoking methods on a ProxyService synchronously. |
| 266 class SyncProxyServiceHelper | 254 class SyncProxyServiceHelper |
| 267 : public base::RefCountedThreadSafe<SyncProxyServiceHelper> { | 255 : public base::RefCountedThreadSafe<SyncProxyServiceHelper> { |
| 268 public: | 256 public: |
| 269 SyncProxyServiceHelper(MessageLoop* io_message_loop, | 257 SyncProxyServiceHelper(MessageLoop* io_message_loop, |
| 270 ProxyService* proxy_service); | 258 ProxyService* proxy_service); |
| 271 | 259 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 283 | 271 |
| 284 base::WaitableEvent event_; | 272 base::WaitableEvent event_; |
| 285 CompletionCallbackImpl<SyncProxyServiceHelper> callback_; | 273 CompletionCallbackImpl<SyncProxyServiceHelper> callback_; |
| 286 ProxyInfo proxy_info_; | 274 ProxyInfo proxy_info_; |
| 287 int result_; | 275 int result_; |
| 288 }; | 276 }; |
| 289 | 277 |
| 290 } // namespace net | 278 } // namespace net |
| 291 | 279 |
| 292 #endif // NET_PROXY_PROXY_SERVICE_H_ | 280 #endif // NET_PROXY_PROXY_SERVICE_H_ |
| OLD | NEW |