diff options
author | joi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-17 17:29:05 +0000 |
---|---|---|
committer | joi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-17 17:29:05 +0000 |
commit | cfbcab964ac927102ce49c20ea1c4e1bcd667a04 (patch) | |
tree | ff34b602cae9072e4bd5b43f75d73abb91ba142b /net/proxy/dhcp_proxy_script_fetcher.h | |
parent | 0179f39b00af02a9abde26f5003f213e25a4444a (diff) | |
download | chromium_src-cfbcab964ac927102ce49c20ea1c4e1bcd667a04.zip chromium_src-cfbcab964ac927102ce49c20ea1c4e1bcd667a04.tar.gz chromium_src-cfbcab964ac927102ce49c20ea1c4e1bcd667a04.tar.bz2 |
Adds support for the DHCP portion of the WPAD (proxy auto-discovery) protocol.
This is Windows-only for now, and is disabled by default. Start
Chrome with the flag --enable-dhcp-wpad to enable the feature. See
discussion in comment on DhcpProxyScriptFetcherFactory for why this
needs to be done in a per-platform way rather than cross-platform.
The code is factored so that adding other platform implementations
will be straight forward.
Most of the implementation is stand-alone and extends the
ScriptProxyFetcher class hierarchy (and makes its interface slightly
more generic). The integration point into existing code is in
InitProxyResolver, which previously handled fallback from DNS
auto-detect to custom PAC URL and now does fallback from DHCP to DNS
to custom PAC URL.
BUG=18575
TEST=net_unittests has good coverage for the new and changed code, but
manual tests on a network with a PAC URL configured in DHCP are also
needed.
Review URL: http://codereview.chromium.org/6831025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85646 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/proxy/dhcp_proxy_script_fetcher.h')
-rw-r--r-- | net/proxy/dhcp_proxy_script_fetcher.h | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/net/proxy/dhcp_proxy_script_fetcher.h b/net/proxy/dhcp_proxy_script_fetcher.h new file mode 100644 index 0000000..adb011d --- /dev/null +++ b/net/proxy/dhcp_proxy_script_fetcher.h @@ -0,0 +1,98 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NET_PROXY_DHCP_SCRIPT_FETCHER_H_ +#define NET_PROXY_DHCP_SCRIPT_FETCHER_H_ +#pragma once + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "base/string16.h" +#include "net/base/completion_callback.h" +#include "net/proxy/proxy_script_fetcher.h" +#include "net/url_request/url_request_context.h" + +namespace net { + +// Interface for classes that can fetch a proxy script as configured via DHCP. +// +// The Fetch method on this interface tries to retrieve the most appropriate +// PAC script configured via DHCP. +// +// Normally there are zero or one DHCP scripts configured, but in the +// presence of multiple adapters with DHCP enabled, the fetcher resolves +// which PAC script to use if one or more are available. +class DhcpProxyScriptFetcher { + public: + // Destruction should cancel any outstanding requests. + virtual ~DhcpProxyScriptFetcher(); + + // Attempts to retrieve the most appropriate PAC script configured via DHCP, + // and invokes |callback| on completion. + // + // Returns OK on success, otherwise the error code. If the return code is + // ERR_IO_PENDING, then the request completes asynchronously, and |callback| + // will be invoked later with the final error code. + // + // After synchronous or asynchronous completion with a result code of OK, + // |*utf16_text| is filled with the response. On failure, the result text is + // an empty string, and the result code is a network error. Some special + // network errors that may occur are: + // + // ERR_PAC_NOT_IN_DHCP -- no script configured in DHCP. + // + // The following all indicate there was one or more script configured + // in DHCP but all failed to download, and the error for the most + // preferred adapter that had a script configured was what the error + // code says: + // + // ERR_TIMED_OUT -- fetch took too long to complete. + // ERR_FILE_TOO_BIG -- response body was too large. + // ERR_PAC_STATUS_NOT_OK -- script failed to download. + // ERR_NOT_IMPLEMENTED -- script required authentication. + // + // If the request is cancelled (either using the "Cancel()" method or by + // deleting |this|), then no callback is invoked. + // + // Only one fetch is allowed to be outstanding at a time. + virtual int Fetch(string16* utf16_text, + CompletionCallback* callback) = 0; + + // Aborts the in-progress fetch (if any). + virtual void Cancel() = 0; + + // After successful completion of |Fetch()|, this will return the URL + // retrieved from DHCP. It is reset if/when |Fetch()| is called again. + virtual const GURL& GetPacURL() const = 0; + + // Intended for unit tests only, so they can test that factories return + // the right types under given circumstances. + virtual std::string GetFetcherName() const; + + protected: + DhcpProxyScriptFetcher(); + + private: + DISALLOW_COPY_AND_ASSIGN(DhcpProxyScriptFetcher); +}; + +// A do-nothing retriever, always returns synchronously with +// ERR_NOT_IMPLEMENTED result and empty text. +class DoNothingDhcpProxyScriptFetcher : public DhcpProxyScriptFetcher { + public: + DoNothingDhcpProxyScriptFetcher(); + virtual ~DoNothingDhcpProxyScriptFetcher(); + + virtual int Fetch(string16* utf16_text, + CompletionCallback* callback) OVERRIDE; + virtual void Cancel() OVERRIDE; + virtual const GURL& GetPacURL() const OVERRIDE; + private: + GURL gurl_; + DISALLOW_COPY_AND_ASSIGN(DoNothingDhcpProxyScriptFetcher); +}; + +} // namespace net + +#endif // NET_PROXY_DHCP_SCRIPT_FETCHER_H_ |