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

Side by Side Diff: net/proxy/proxy_service.h

Issue 21328: Add support to ProxyService for downloading a PAC script on behalf of the Pro... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Add missing files (for constructor boolean flag fall-out) Created 11 years, 10 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
« no previous file with comments | « net/proxy/proxy_resolver_winhttp.cc ('k') | net/proxy/proxy_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <deque>
8 #include <map> 9 #include <map>
9 #include <string> 10 #include <string>
10 #include <vector> 11 #include <vector>
11 12
12 #include "base/ref_counted.h" 13 #include "base/ref_counted.h"
13 #include "base/scoped_ptr.h" 14 #include "base/scoped_ptr.h"
14 #include "base/string_util.h" 15 #include "base/string_util.h"
15 #include "base/thread.h" 16 #include "base/thread.h"
16 #include "base/time.h" 17 #include "base/time.h"
17 #include "base/waitable_event.h" 18 #include "base/waitable_event.h"
18 #include "googleurl/src/gurl.h" 19 #include "googleurl/src/gurl.h"
19 #include "net/base/completion_callback.h" 20 #include "net/base/completion_callback.h"
21 #include "net/proxy/proxy_script_fetcher.h"
20 #include "net/proxy/proxy_server.h" 22 #include "net/proxy/proxy_server.h"
21 23
22 class GURL; 24 class GURL;
23 25
24 namespace net { 26 namespace net {
25 27
26 class ProxyConfigService; 28 class ProxyConfigService;
27 class ProxyInfo; 29 class ProxyInfo;
28 class ProxyResolver; 30 class ProxyResolver;
29 31
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 97
96 // This class can be used to resolve the proxy server to use when loading a 98 // This class can be used to resolve the proxy server to use when loading a
97 // HTTP(S) URL. It uses the given ProxyResolver to handle the actual proxy 99 // HTTP(S) URL. It uses the given ProxyResolver to handle the actual proxy
98 // resolution. See ProxyResolverWinHttp for example. 100 // resolution. See ProxyResolverWinHttp for example.
99 class ProxyService { 101 class ProxyService {
100 public: 102 public:
101 // The instance takes ownership of |config_service| and |resolver|. 103 // The instance takes ownership of |config_service| and |resolver|.
102 ProxyService(ProxyConfigService* config_service, 104 ProxyService(ProxyConfigService* config_service,
103 ProxyResolver* resolver); 105 ProxyResolver* resolver);
104 106
107 ~ProxyService();
108
105 // Used internally to handle PAC queries. 109 // Used internally to handle PAC queries.
106 class PacRequest; 110 class PacRequest;
107 111
108 // Returns ERR_IO_PENDING if the proxy information could not be provided 112 // Returns ERR_IO_PENDING if the proxy information could not be provided
109 // synchronously, to indicate that the result will be available when the 113 // synchronously, to indicate that the result will be available when the
110 // callback is run. The callback is run on the thread that calls 114 // callback is run. The callback is run on the thread that calls
111 // ResolveProxy. 115 // ResolveProxy.
112 // 116 //
113 // The caller is responsible for ensuring that |results| and |callback| 117 // The caller is responsible for ensuring that |results| and |callback|
114 // remain valid until the callback is run or until |pac_request| is cancelled 118 // remain valid until the callback is run or until |pac_request| is cancelled
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 153
150 // Create a proxy service using the specified settings. If |pi| is NULL then 154 // Create a proxy service using the specified settings. If |pi| is NULL then
151 // the system's default proxy settings will be used (on Windows this will 155 // the system's default proxy settings will be used (on Windows this will
152 // use IE's settings). 156 // use IE's settings).
153 static ProxyService* Create(const ProxyInfo* pi); 157 static ProxyService* Create(const ProxyInfo* pi);
154 158
155 // Create a proxy service that always fails to fetch the proxy configuration, 159 // Create a proxy service that always fails to fetch the proxy configuration,
156 // so it falls back to direct connect. 160 // so it falls back to direct connect.
157 static ProxyService* CreateNull(); 161 static ProxyService* CreateNull();
158 162
163 // Set the ProxyScriptFetcher dependency. This is needed if the ProxyResolver
164 // is of type ProxyResolverWithoutFetch. ProxyService takes ownership of
165 // |proxy_script_fetcher|.
166 void SetProxyScriptFetcher(ProxyScriptFetcher* proxy_script_fetcher) {
167 proxy_script_fetcher_.reset(proxy_script_fetcher);
168 }
169
159 private: 170 private:
160 friend class PacRequest; 171 friend class PacRequest;
161 172
162 ProxyResolver* resolver() { return resolver_.get(); } 173 ProxyResolver* resolver() { return resolver_.get(); }
163 base::Thread* pac_thread() { return pac_thread_.get(); } 174 base::Thread* pac_thread() { return pac_thread_.get(); }
164 175
165 // Identifies the proxy configuration. 176 // Identifies the proxy configuration.
166 ProxyConfig::ID config_id() const { return config_.id(); } 177 ProxyConfig::ID config_id() const { return config_.id(); }
167 178
168 // Checks to see if the proxy configuration changed, and then updates config_ 179 // Checks to see if the proxy configuration changed, and then updates config_
169 // to reference the new configuration. 180 // to reference the new configuration.
170 void UpdateConfig(); 181 void UpdateConfig();
171 182
183 // Tries to update the configuration if it hasn't been checked in a while.
184 void UpdateConfigIfOld();
185
186 // Returns true if this ProxyService is downloading a PAC script on behalf
187 // of ProxyResolverWithoutFetch. Resolve requests will be frozen until
188 // the fetch has completed.
189 bool IsFetchingPacScript() const {
190 return in_progress_fetch_config_id_ != ProxyConfig::INVALID_ID;
191 }
192
193 // Callback for when the PAC script has finished downloading.
194 void OnScriptFetchCompletion(int result);
195
196 // Returns ERR_IO_PENDING if the request cannot be completed synchronously.
197 // Otherwise it fills |result| with the proxy information for |url|.
198 // Completing synchronously means we don't need to query ProxyResolver.
199 // (ProxyResolver runs on PAC thread.)
200 int TryToCompleteSynchronously(const GURL& url, ProxyInfo* result);
201
202 // Starts the PAC thread if it isn't already running.
203 void InitPacThread();
204
205 // Starts the next request from |pending_requests_| is possible.
206 // |recent_req| is the request that just got added, or NULL.
207 void ProcessPendingRequests(PacRequest* recent_req);
208
209 // Removes the front entry of the requests queue. |expected_req| is our
210 // expectation of what the front of the request queue is; it is only used by
211 // DCHECK for verification purposes.
212 void RemoveFrontOfRequestQueue(PacRequest* expected_req);
213
172 // Called to indicate that a PacRequest completed. The |config_id| parameter 214 // Called to indicate that a PacRequest completed. The |config_id| parameter
173 // indicates the proxy configuration that was queried. |result_code| is OK 215 // indicates the proxy configuration that was queried. |result_code| is OK
174 // if the PAC file could be downloaded and executed. Otherwise, it is an 216 // if the PAC file could be downloaded and executed. Otherwise, it is an
175 // error code, indicating a bad proxy configuration. 217 // error code, indicating a bad proxy configuration.
176 void DidCompletePacRequest(int config_id, int result_code); 218 void DidCompletePacRequest(int config_id, int result_code);
177 219
178 // Returns true if the URL passed in should not go through the proxy server. 220 // Returns true if the URL passed in should not go through the proxy server.
179 // 1. If the bypass proxy list contains the string <local> and the URL 221 // 1. If the bypass proxy list contains the string <local> and the URL
180 // passed in is a local URL, i.e. a URL without a DOT (.) 222 // passed in is a local URL, i.e. a URL without a DOT (.)
181 // 2. The URL matches one of the entities in the proxy bypass list. 223 // 2. The URL matches one of the entities in the proxy bypass list.
(...skipping 12 matching lines...) Expand all
194 236
195 // false if the ProxyService has not been initialized yet. 237 // false if the ProxyService has not been initialized yet.
196 bool config_has_been_updated_; 238 bool config_has_been_updated_;
197 239
198 // The time when the proxy configuration was last read from the system. 240 // The time when the proxy configuration was last read from the system.
199 base::TimeTicks config_last_update_time_; 241 base::TimeTicks config_last_update_time_;
200 242
201 // Map of the known bad proxies and the information about the retry time. 243 // Map of the known bad proxies and the information about the retry time.
202 ProxyRetryInfoMap proxy_retry_info_; 244 ProxyRetryInfoMap proxy_retry_info_;
203 245
246 // FIFO queue of pending/inprogress requests.
247 typedef std::deque<scoped_refptr<PacRequest> > PendingRequestsQueue;
248 PendingRequestsQueue pending_requests_;
249
250 // The fetcher to use when downloading PAC scripts for the ProxyResolver.
251 // This dependency can be NULL if our ProxyResolver has no need for
252 // external PAC script fetching.
253 scoped_ptr<ProxyScriptFetcher> proxy_script_fetcher_;
254
255 // Callback for when |proxy_script_fetcher_| is done.
256 CompletionCallbackImpl<ProxyService> proxy_script_fetcher_callback_;
257
258 // The ID of the configuration for which we last downloaded a PAC script.
259 // If no PAC script has been fetched yet, will be ProxyConfig::INVALID_ID.
260 ProxyConfig::ID fetched_pac_config_id_;
261
262 // The error corresponding with |fetched_pac_config_id_|, or OK.
263 int fetched_pac_error_;
264
265 // The ID of the configuration for which we are currently downloading the
266 // PAC script. If no fetch is in progress, will be ProxyConfig::INVALID_ID.
267 ProxyConfig::ID in_progress_fetch_config_id_;
268
269 // The results of the current in progress fetch, or empty string.
270 std::string in_progress_fetch_bytes_;
271
204 DISALLOW_COPY_AND_ASSIGN(ProxyService); 272 DISALLOW_COPY_AND_ASSIGN(ProxyService);
205 }; 273 };
206 274
207 // This class is used to hold a list of proxies returned by GetProxyForUrl or 275 // This class is used to hold a list of proxies returned by GetProxyForUrl or
208 // manually configured. It handles proxy fallback if multiple servers are 276 // manually configured. It handles proxy fallback if multiple servers are
209 // specified. 277 // specified.
210 class ProxyList { 278 class ProxyList {
211 public: 279 public:
212 // Initializes the proxy list to a string containing one or more proxy servers 280 // Initializes the proxy list to a string containing one or more proxy servers
213 // delimited by a semicolon. 281 // delimited by a semicolon.
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 // Get the proxy configuration. Returns OK if successful or an error code if 385 // Get the proxy configuration. Returns OK if successful or an error code if
318 // otherwise. |config| should be in its initial state when this method is 386 // otherwise. |config| should be in its initial state when this method is
319 // called. 387 // called.
320 virtual int GetProxyConfig(ProxyConfig* config) = 0; 388 virtual int GetProxyConfig(ProxyConfig* config) = 0;
321 }; 389 };
322 390
323 // Synchronously resolve the proxy for a URL, using a PAC script. Called on the 391 // Synchronously resolve the proxy for a URL, using a PAC script. Called on the
324 // PAC Thread. 392 // PAC Thread.
325 class ProxyResolver { 393 class ProxyResolver {
326 public: 394 public:
395
396 // If a subclass sets |does_fetch| to false, then the owning ProxyResolver
397 // will download PAC scripts on our behalf, and notify changes with
398 // SetPacScript(). Otherwise the subclass is expected to fetch the
399 // PAC script internally, and SetPacScript() will go unused.
400 ProxyResolver(bool does_fetch) : does_fetch_(does_fetch) {}
401
327 virtual ~ProxyResolver() {} 402 virtual ~ProxyResolver() {}
328 403
329 // Query the proxy auto-config file (specified by |pac_url|) for the proxy to 404 // Query the proxy auto-config file (specified by |pac_url|) for the proxy to
330 // use to load the given |query_url|. Returns OK if successful or an error 405 // use to load the given |query_url|. Returns OK if successful or an error
331 // code otherwise. 406 // code otherwise.
332 virtual int GetProxyForURL(const GURL& query_url, 407 virtual int GetProxyForURL(const GURL& query_url,
333 const GURL& pac_url, 408 const GURL& pac_url,
334 ProxyInfo* results) = 0; 409 ProxyInfo* results) = 0;
410
411 // Called whenever the PAC script has changed, with the contents of the
412 // PAC script. |bytes| may be empty string if there was a fetch error.
413 virtual void SetPacScript(const std::string& bytes) {
414 // Must override SetPacScript() if |does_fetch_ = true|.
415 NOTREACHED();
416 }
417
418 bool does_fetch() const { return does_fetch_; }
419
420 protected:
421 bool does_fetch_;
335 }; 422 };
336 423
337 // Wrapper for invoking methods on a ProxyService synchronously. 424 // Wrapper for invoking methods on a ProxyService synchronously.
338 class SyncProxyServiceHelper 425 class SyncProxyServiceHelper
339 : public base::RefCountedThreadSafe<SyncProxyServiceHelper> { 426 : public base::RefCountedThreadSafe<SyncProxyServiceHelper> {
340 public: 427 public:
341 SyncProxyServiceHelper(MessageLoop* io_message_loop, 428 SyncProxyServiceHelper(MessageLoop* io_message_loop,
342 ProxyService* proxy_service); 429 ProxyService* proxy_service);
343 430
344 int ResolveProxy(const GURL& url, ProxyInfo* proxy_info); 431 int ResolveProxy(const GURL& url, ProxyInfo* proxy_info);
(...skipping 11 matching lines...) Expand all
356 base::WaitableEvent event_; 443 base::WaitableEvent event_;
357 CompletionCallbackImpl<SyncProxyServiceHelper> callback_; 444 CompletionCallbackImpl<SyncProxyServiceHelper> callback_;
358 ProxyInfo proxy_info_; 445 ProxyInfo proxy_info_;
359 int result_; 446 int result_;
360 }; 447 };
361 448
362 } // namespace net 449 } // namespace net
363 450
364 #endif // NET_PROXY_PROXY_SERVICE_H_ 451 #endif // NET_PROXY_PROXY_SERVICE_H_
365 452
OLDNEW
« no previous file with comments | « net/proxy/proxy_resolver_winhttp.cc ('k') | net/proxy/proxy_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698