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

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

Issue 149525: Remove the concept of threading from ProxyService, and move it into the Proxy... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Add missing header for mac Created 11 years, 5 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/net.gyp ('k') | net/proxy/proxy_resolver_mac.h » ('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_RESOLVER_H_ 5 #ifndef NET_PROXY_PROXY_RESOLVER_H_
6 #define NET_PROXY_PROXY_RESOLVER_H_ 6 #define NET_PROXY_PROXY_RESOLVER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "net/base/completion_callback.h"
11 12
12 class GURL; 13 class GURL;
13 14
14 namespace net { 15 namespace net {
15 16
16 class ProxyInfo; 17 class ProxyInfo;
17 18
18 // Synchronously resolve the proxy for a URL, using a PAC script. Called on the 19 // Interface for "proxy resolvers". A ProxyResolver fills in a list of proxies
19 // PAC Thread. 20 // to use for a particular URL. Generally the backend for a ProxyResolver is
21 // a PAC script, but it doesn't need to be. ProxyResolver can service multiple
22 // requests at a time.
20 class ProxyResolver { 23 class ProxyResolver {
21 public: 24 public:
25 // Opaque pointer type, to return a handle to cancel outstanding requests.
26 typedef void* RequestHandle;
22 27
23 // If a subclass sets |does_fetch| to false, then the owning ProxyResolver 28 // See |expects_pac_bytes()| for the meaning of |expects_pac_bytes|.
24 // will download PAC scripts on our behalf, and notify changes with 29 explicit ProxyResolver(bool expects_pac_bytes)
25 // SetPacScript(). Otherwise the subclass is expected to fetch the 30 : expects_pac_bytes_(expects_pac_bytes) {}
26 // PAC script internally, and SetPacScript() will go unused.
27 ProxyResolver(bool does_fetch) : does_fetch_(does_fetch) {}
28 31
29 virtual ~ProxyResolver() {} 32 virtual ~ProxyResolver() {}
30 33
31 // Query the proxy auto-config file (specified by |pac_url|) for the proxy to 34 // Gets a list of proxy servers to use for |url|. If the request will
32 // use to load the given |query_url|. Returns OK if successful or an error 35 // complete asynchronously returns ERR_IO_PENDING and notifies the result
33 // code otherwise. 36 // by running |callback|. If the result code is OK then
34 virtual int GetProxyForURL(const GURL& query_url, 37 // the request was successful and |results| contains the proxy
35 const GURL& pac_url, 38 // resolution information. In the case of asynchronous completion
36 ProxyInfo* results) = 0; 39 // |*request| is written to, and can be passed to CancelRequest().
40 virtual int GetProxyForURL(const GURL& url,
41 ProxyInfo* results,
42 CompletionCallback* callback,
43 RequestHandle* request) = 0;
37 44
38 // Called whenever the PAC script has changed, with the contents of the 45 // Cancels |request|.
39 // PAC script. |bytes| may be empty string if there was a fetch error. 46 virtual void CancelRequest(RequestHandle request) = 0;
40 virtual void SetPacScript(const std::string& bytes) { 47
41 // Must override SetPacScript() if |does_fetch_ = true|. 48 // The PAC script backend can be specified to the ProxyResolver either via
49 // URL, or via the javascript text itself. If |expects_pac_bytes| is true,
50 // then PAC scripts should be specified using SetPacScriptByData(). Otherwise
51 // they should be specified using SetPacScriptByUrl().
52 bool expects_pac_bytes() const { return expects_pac_bytes_; }
53
54 // Sets the PAC script backend to use for this proxy resolver (by URL).
55 void SetPacScriptByUrl(const GURL& pac_url) {
56 DCHECK(!expects_pac_bytes());
57 SetPacScriptByUrlInternal(pac_url);
58 }
59
60 // Sets the PAC script backend to use for this proxy resolver (by contents).
61 void SetPacScriptByData(const std::string& bytes) {
62 DCHECK(expects_pac_bytes());
63 SetPacScriptByDataInternal(bytes);
64 }
65
66 private:
67 // Called to set the PAC script backend to use. If |pac_url| is invalid,
68 // this is a request to use WPAD (auto detect).
69 virtual void SetPacScriptByUrlInternal(const GURL& pac_url) {
42 NOTREACHED(); 70 NOTREACHED();
43 } 71 }
44 72
45 bool does_fetch() const { return does_fetch_; } 73 // Called to set the PAC script backend to use. |bytes| may be empty if the
74 // fetch failed, or if the fetch returned no content.
75 virtual void SetPacScriptByDataInternal(const std::string& bytes) {
76 NOTREACHED();
77 }
46 78
47 protected: 79 const bool expects_pac_bytes_;
48 bool does_fetch_; 80
81 DISALLOW_COPY_AND_ASSIGN(ProxyResolver);
49 }; 82 };
50 83
51 } // namespace net 84 } // namespace net
52 85
53 #endif // NET_PROXY_PROXY_RESOLVER_H_ 86 #endif // NET_PROXY_PROXY_RESOLVER_H_
OLDNEW
« no previous file with comments | « net/net.gyp ('k') | net/proxy/proxy_resolver_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698