diff options
author | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-26 21:12:20 +0000 |
---|---|---|
committer | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-26 21:12:20 +0000 |
commit | 775fd9e3215360868781cb7bc615b0b4d782f0a9 (patch) | |
tree | 1436421924de756654737312b2dad652315981d1 /net/proxy/proxy_resolver.h | |
parent | 44d178bbf8cf937dc1180da5ccfd27ce9abe3f51 (diff) | |
download | chromium_src-775fd9e3215360868781cb7bc615b0b4d782f0a9.zip chromium_src-775fd9e3215360868781cb7bc615b0b4d782f0a9.tar.gz chromium_src-775fd9e3215360868781cb7bc615b0b4d782f0a9.tar.bz2 |
Remove the concept of threading from ProxyService, and move it into the ProxyResolver dependency.
ProxyResolver may now complete requests asynchronously, and is defined to handle multiple requests.
The code from ProxyService that queued requests onto the single PAC thread has moved into SingleThreadedProxyResolver.
This refactor lays the groundwork for:
(1) http://crbug.com/11746 -- Run PAC proxy resolving out of process.
(Can inject an IPC bridge implementation of ProxyResolver)
(2) http://crbug.com/11079 -- Run PAC proxy resolving on multiple threads.
(Can implement a MultithreadedProxyResolver type class; still complications around v8 threadsafety though).
BUG=http://crbug.com/11746, http://crbug.com/11079
TEST=existing unit-tests.
Review URL: http://codereview.chromium.org/149525
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21631 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/proxy/proxy_resolver.h')
-rw-r--r-- | net/proxy/proxy_resolver.h | 75 |
1 files changed, 54 insertions, 21 deletions
diff --git a/net/proxy/proxy_resolver.h b/net/proxy/proxy_resolver.h index fac8fa0..ce0e81d 100644 --- a/net/proxy/proxy_resolver.h +++ b/net/proxy/proxy_resolver.h @@ -8,6 +8,7 @@ #include <string> #include "base/logging.h" +#include "net/base/completion_callback.h" class GURL; @@ -15,37 +16,69 @@ namespace net { class ProxyInfo; -// Synchronously resolve the proxy for a URL, using a PAC script. Called on the -// PAC Thread. +// Interface for "proxy resolvers". A ProxyResolver fills in a list of proxies +// to use for a particular URL. Generally the backend for a ProxyResolver is +// a PAC script, but it doesn't need to be. ProxyResolver can service multiple +// requests at a time. class ProxyResolver { public: + // Opaque pointer type, to return a handle to cancel outstanding requests. + typedef void* RequestHandle; - // If a subclass sets |does_fetch| to false, then the owning ProxyResolver - // will download PAC scripts on our behalf, and notify changes with - // SetPacScript(). Otherwise the subclass is expected to fetch the - // PAC script internally, and SetPacScript() will go unused. - ProxyResolver(bool does_fetch) : does_fetch_(does_fetch) {} + // See |expects_pac_bytes()| for the meaning of |expects_pac_bytes|. + explicit ProxyResolver(bool expects_pac_bytes) + : expects_pac_bytes_(expects_pac_bytes) {} virtual ~ProxyResolver() {} - // Query the proxy auto-config file (specified by |pac_url|) for the proxy to - // use to load the given |query_url|. Returns OK if successful or an error - // code otherwise. - virtual int GetProxyForURL(const GURL& query_url, - const GURL& pac_url, - ProxyInfo* results) = 0; - - // Called whenever the PAC script has changed, with the contents of the - // PAC script. |bytes| may be empty string if there was a fetch error. - virtual void SetPacScript(const std::string& bytes) { - // Must override SetPacScript() if |does_fetch_ = true|. + // Gets a list of proxy servers to use for |url|. If the request will + // complete asynchronously returns ERR_IO_PENDING and notifies the result + // by running |callback|. If the result code is OK then + // the request was successful and |results| contains the proxy + // resolution information. In the case of asynchronous completion + // |*request| is written to, and can be passed to CancelRequest(). + virtual int GetProxyForURL(const GURL& url, + ProxyInfo* results, + CompletionCallback* callback, + RequestHandle* request) = 0; + + // Cancels |request|. + virtual void CancelRequest(RequestHandle request) = 0; + + // The PAC script backend can be specified to the ProxyResolver either via + // URL, or via the javascript text itself. If |expects_pac_bytes| is true, + // then PAC scripts should be specified using SetPacScriptByData(). Otherwise + // they should be specified using SetPacScriptByUrl(). + bool expects_pac_bytes() const { return expects_pac_bytes_; } + + // Sets the PAC script backend to use for this proxy resolver (by URL). + void SetPacScriptByUrl(const GURL& pac_url) { + DCHECK(!expects_pac_bytes()); + SetPacScriptByUrlInternal(pac_url); + } + + // Sets the PAC script backend to use for this proxy resolver (by contents). + void SetPacScriptByData(const std::string& bytes) { + DCHECK(expects_pac_bytes()); + SetPacScriptByDataInternal(bytes); + } + + private: + // Called to set the PAC script backend to use. If |pac_url| is invalid, + // this is a request to use WPAD (auto detect). + virtual void SetPacScriptByUrlInternal(const GURL& pac_url) { + NOTREACHED(); + } + + // Called to set the PAC script backend to use. |bytes| may be empty if the + // fetch failed, or if the fetch returned no content. + virtual void SetPacScriptByDataInternal(const std::string& bytes) { NOTREACHED(); } - bool does_fetch() const { return does_fetch_; } + const bool expects_pac_bytes_; - protected: - bool does_fetch_; + DISALLOW_COPY_AND_ASSIGN(ProxyResolver); }; } // namespace net |