| Index: net/proxy/init_proxy_resolver.h
|
| diff --git a/net/proxy/init_proxy_resolver.h b/net/proxy/init_proxy_resolver.h
|
| index fd6564278ac83cd15525b18bb9499be873285fe8..34f257c68be674c32c878f4c4f32932d32d300f3 100644
|
| --- a/net/proxy/init_proxy_resolver.h
|
| +++ b/net/proxy/init_proxy_resolver.h
|
| @@ -1,4 +1,4 @@
|
| -// Copyright (c) 2010 The Chromium Authors. All rights reserved.
|
| +// 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.
|
|
|
| @@ -11,15 +11,18 @@
|
| #include "base/string16.h"
|
| #include "base/time.h"
|
| #include "base/timer.h"
|
| +#include "base/scoped_ptr.h"
|
| #include "googleurl/src/gurl.h"
|
| #include "net/base/completion_callback.h"
|
| #include "net/base/net_log.h"
|
|
|
| namespace net {
|
|
|
| +class DhcpProxyScriptFetcher;
|
| class ProxyConfig;
|
| class ProxyResolver;
|
| -class ProxyScriptFetcher;
|
| +class URLProxyScriptFetcher;
|
| +class URLRequestContext;
|
|
|
| // InitProxyResolver is a helper class used by ProxyService to
|
| // initialize a ProxyResolver with the PAC script data specified
|
| @@ -42,11 +45,11 @@ class InitProxyResolver {
|
| // |resolver|, |proxy_script_fetcher| and |net_log| must remain valid for
|
| // the lifespan of InitProxyResolver.
|
| InitProxyResolver(ProxyResolver* resolver,
|
| - ProxyScriptFetcher* proxy_script_fetcher,
|
| + URLProxyScriptFetcher* proxy_script_fetcher,
|
| NetLog* net_log);
|
|
|
| // Aborts any in-progress request.
|
| - ~InitProxyResolver();
|
| + virtual ~InitProxyResolver();
|
|
|
| // Applies the PAC settings of |config| to |resolver_|.
|
| // If |wait_delay| is positive, the initialization will pause for this
|
| @@ -62,15 +65,29 @@ class InitProxyResolver {
|
| ProxyConfig* effective_config,
|
| CompletionCallback* callback);
|
|
|
| + protected:
|
| + // Method introduced to let unit tests stub out dependencies.
|
| + virtual DhcpProxyScriptFetcher* ImplCreateDhcpProxyScriptFetcher(
|
| + URLRequestContext* url_request_context);
|
| +
|
| private:
|
| - struct PacURL {
|
| - PacURL(bool auto_detect, const GURL& url)
|
| - : auto_detect(auto_detect), url(url) {}
|
| - bool auto_detect;
|
| - GURL url;
|
| + // Represents the sources from which we can get PAC files; two types of
|
| + // auto-detect or a custom URL.
|
| + struct PacSource {
|
| + enum Type {
|
| + WPAD_DHCP,
|
| + WPAD_DNS,
|
| + CUSTOM
|
| + };
|
| +
|
| + PacSource(Type type, const GURL& url)
|
| + : type(type), url(url) {}
|
| +
|
| + Type type;
|
| + GURL url; // Empty unless |type == PAC_SOURCE_CUSTOM|.
|
| };
|
|
|
| - typedef std::vector<PacURL> UrlList;
|
| + typedef std::vector<PacSource> PacSourceList;
|
|
|
| enum State {
|
| STATE_NONE,
|
| @@ -83,7 +100,7 @@ class InitProxyResolver {
|
| };
|
|
|
| // Returns ordered list of PAC urls to try for |config|.
|
| - UrlList BuildPacUrlsFallbackList(const ProxyConfig& config) const;
|
| + PacSourceList BuildPacSourcesFallbackList(const ProxyConfig& config) const;
|
|
|
| void OnIOCompletion(int result);
|
| int DoLoop(int result);
|
| @@ -99,34 +116,35 @@ class InitProxyResolver {
|
| int DoSetPacScriptComplete(int result);
|
|
|
| // Tries restarting using the next fallback PAC URL:
|
| - // |pac_urls_[++current_pac_url_index]|.
|
| + // |pac_sources_[++current_pac_source_index]|.
|
| // Returns OK and rewinds the state machine when there
|
| // is something to try, otherwise returns |error|.
|
| - int TryToFallbackPacUrl(int error);
|
| + int TryToFallbackPacSource(int error);
|
|
|
| // Gets the initial state (we skip fetching when the
|
| // ProxyResolver doesn't |expect_pac_bytes()|.
|
| State GetStartState() const;
|
|
|
| // Returns the current PAC URL we are fetching/testing.
|
| - const PacURL& current_pac_url() const;
|
| + const PacSource& current_pac_source() const;
|
|
|
| void OnWaitTimerFired();
|
| void DidCompleteInit();
|
| void Cancel();
|
|
|
| ProxyResolver* resolver_;
|
| - ProxyScriptFetcher* proxy_script_fetcher_;
|
| + URLProxyScriptFetcher* proxy_script_fetcher_;
|
| + scoped_ptr<DhcpProxyScriptFetcher> dhcp_proxy_script_fetcher_;
|
|
|
| CompletionCallbackImpl<InitProxyResolver> io_callback_;
|
| CompletionCallback* user_callback_;
|
|
|
| - size_t current_pac_url_index_;
|
| + size_t current_pac_source_index_;
|
|
|
| // Filled when the PAC script fetch completes.
|
| string16 pac_script_;
|
|
|
| - UrlList pac_urls_;
|
| + PacSourceList pac_sources_;
|
| State next_state_;
|
|
|
| BoundNetLog net_log_;
|
|
|