OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef NET_PROXY_INIT_PROXY_RESOLVER_H_ |
| 6 #define NET_PROXY_INIT_PROXY_RESOLVER_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "googleurl/src/gurl.h" |
| 12 #include "net/base/completion_callback.h" |
| 13 |
| 14 namespace net { |
| 15 |
| 16 class ProxyConfig; |
| 17 class ProxyResolver; |
| 18 class ProxyScriptFetcher; |
| 19 |
| 20 // InitProxyResolver is a helper class used by ProxyService to |
| 21 // initialize a ProxyResolver with the PAC script data specified |
| 22 // by a particular ProxyConfig. |
| 23 // |
| 24 // This involves trying to use PAC scripts in this order: |
| 25 // |
| 26 // (1) WPAD if auto-detect is on. |
| 27 // (2) Custom PAC script if a URL was given. |
| 28 // |
| 29 // If no PAC script was successfully downloaded + parsed, then it fails with |
| 30 // a network error. Otherwise the proxy resolver is left initialized with |
| 31 // the PAC script. |
| 32 // |
| 33 // Deleting InitProxyResolver while Init() is in progress, will |
| 34 // cancel the request. |
| 35 // |
| 36 class InitProxyResolver { |
| 37 public: |
| 38 // |resolver| and |proxy_script_fetcher| must remain valid for |
| 39 // the lifespan of InitProxyResolver. |
| 40 InitProxyResolver(ProxyResolver* resolver, |
| 41 ProxyScriptFetcher* proxy_script_fetcher); |
| 42 |
| 43 // Aborts any in-progress request. |
| 44 ~InitProxyResolver(); |
| 45 |
| 46 // Apply the PAC settings of |config| to |resolver_|. |
| 47 int Init(const ProxyConfig& config, CompletionCallback* callback); |
| 48 |
| 49 private: |
| 50 enum State { |
| 51 STATE_NONE, |
| 52 STATE_FETCH_PAC_SCRIPT, |
| 53 STATE_FETCH_PAC_SCRIPT_COMPLETE, |
| 54 STATE_SET_PAC_SCRIPT, |
| 55 STATE_SET_PAC_SCRIPT_COMPLETE, |
| 56 }; |
| 57 typedef std::vector<GURL> UrlList; |
| 58 |
| 59 // Returns ordered list of PAC urls to try for |config|. |
| 60 UrlList BuildPacUrlsFallbackList(const ProxyConfig& config) const; |
| 61 |
| 62 void OnIOCompletion(int result); |
| 63 int DoLoop(int result); |
| 64 void DoCallback(int result); |
| 65 |
| 66 int DoFetchPacScript(); |
| 67 int DoFetchPacScriptComplete(int result); |
| 68 |
| 69 int DoSetPacScript(); |
| 70 int DoSetPacScriptComplete(int result); |
| 71 |
| 72 // Tries restarting using the next fallback PAC URL: |
| 73 // |pac_urls_[++current_pac_url_index]|. |
| 74 // Returns OK and rewinds the state machine when there |
| 75 // is something to try, otherwise returns |error|. |
| 76 int TryToFallbackPacUrl(int error); |
| 77 |
| 78 // Gets the initial state (we skip fetching when the |
| 79 // ProxyResolver doesn't |expect_pac_bytes()|. |
| 80 State GetStartState() const; |
| 81 |
| 82 // Returns the current PAC URL we are fetching/testing. |
| 83 const GURL& current_pac_url() const; |
| 84 |
| 85 ProxyResolver* resolver_; |
| 86 ProxyScriptFetcher* proxy_script_fetcher_; |
| 87 |
| 88 CompletionCallbackImpl<InitProxyResolver> io_callback_; |
| 89 CompletionCallback* user_callback_; |
| 90 |
| 91 size_t current_pac_url_index_; |
| 92 |
| 93 // Filled when the PAC script fetch completes. |
| 94 std::string pac_bytes_; |
| 95 |
| 96 UrlList pac_urls_; |
| 97 State next_state_; |
| 98 |
| 99 DISALLOW_COPY_AND_ASSIGN(InitProxyResolver); |
| 100 }; |
| 101 |
| 102 } // namespace net |
| 103 |
| 104 #endif // NET_PROXY_INIT_PROXY_RESOLVER_H_ |
OLD | NEW |