OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_SCRIPT_DECIDER_H_ | 5 #ifndef NET_PROXY_PROXY_SCRIPT_DECIDER_H_ |
6 #define NET_PROXY_PROXY_SCRIPT_DECIDER_H_ | 6 #define NET_PROXY_PROXY_SCRIPT_DECIDER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "base/timer/timer.h" | 14 #include "base/timer/timer.h" |
15 #include "net/base/address_list.h" | |
15 #include "net/base/completion_callback.h" | 16 #include "net/base/completion_callback.h" |
16 #include "net/base/net_export.h" | 17 #include "net/base/net_export.h" |
17 #include "net/base/net_log.h" | 18 #include "net/base/net_log.h" |
19 #include "net/dns/host_resolver.h" | |
20 #include "net/dns/single_request_host_resolver.h" | |
18 #include "net/proxy/proxy_config.h" | 21 #include "net/proxy/proxy_config.h" |
19 #include "net/proxy/proxy_resolver.h" | 22 #include "net/proxy/proxy_resolver.h" |
20 #include "url/gurl.h" | 23 #include "url/gurl.h" |
21 | 24 |
22 namespace net { | 25 namespace net { |
23 | 26 |
24 class DhcpProxyScriptFetcher; | 27 class DhcpProxyScriptFetcher; |
25 class NetLogParameter; | 28 class NetLogParameter; |
26 class ProxyResolver; | 29 class ProxyResolver; |
27 class ProxyScriptFetcher; | 30 class ProxyScriptFetcher; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 int Start(const ProxyConfig& config, | 72 int Start(const ProxyConfig& config, |
70 const base::TimeDelta wait_delay, | 73 const base::TimeDelta wait_delay, |
71 bool fetch_pac_bytes, | 74 bool fetch_pac_bytes, |
72 const net::CompletionCallback& callback); | 75 const net::CompletionCallback& callback); |
73 | 76 |
74 const ProxyConfig& effective_config() const; | 77 const ProxyConfig& effective_config() const; |
75 | 78 |
76 // TODO(eroman): Return a const-pointer. | 79 // TODO(eroman): Return a const-pointer. |
77 ProxyResolverScriptData* script_data() const; | 80 ProxyResolverScriptData* script_data() const; |
78 | 81 |
82 void SetHostResolverForTesting(HostResolver* resolver); | |
szym
2013/09/16 21:50:32
Needs comment. Is this going to be used for quickc
Elly Fong-Jones
2013/09/16 22:10:11
Deleted.
| |
83 | |
79 private: | 84 private: |
80 // Represents the sources from which we can get PAC files; two types of | 85 // Represents the sources from which we can get PAC files; two types of |
81 // auto-detect or a custom URL. | 86 // auto-detect or a custom URL. |
82 struct PacSource { | 87 struct PacSource { |
83 enum Type { | 88 enum Type { |
84 WPAD_DHCP, | 89 WPAD_DHCP, |
85 WPAD_DNS, | 90 WPAD_DNS, |
86 CUSTOM | 91 CUSTOM |
87 }; | 92 }; |
88 | 93 |
89 PacSource(Type type, const GURL& url) | 94 PacSource(Type type, const GURL& url) |
90 : type(type), url(url) {} | 95 : type(type), url(url) {} |
91 | 96 |
92 // Returns a Value representing the PacSource. |effective_pac_url| must | 97 // Returns a Value representing the PacSource. |effective_pac_url| must |
93 // be non-NULL and point to the URL derived from information contained in | 98 // be non-NULL and point to the URL derived from information contained in |
94 // |this|, if Type is not WPAD_DHCP. | 99 // |this|, if Type is not WPAD_DHCP. |
95 base::Value* NetLogCallback(const GURL* effective_pac_url, | 100 base::Value* NetLogCallback(const GURL* effective_pac_url, |
96 NetLog::LogLevel log_level) const; | 101 NetLog::LogLevel log_level) const; |
97 | 102 |
98 Type type; | 103 Type type; |
99 GURL url; // Empty unless |type == PAC_SOURCE_CUSTOM|. | 104 GURL url; // Empty unless |type == PAC_SOURCE_CUSTOM|. |
100 }; | 105 }; |
101 | 106 |
102 typedef std::vector<PacSource> PacSourceList; | 107 typedef std::vector<PacSource> PacSourceList; |
103 | 108 |
104 enum State { | 109 enum State { |
105 STATE_NONE, | 110 STATE_NONE, |
106 STATE_WAIT, | 111 STATE_WAIT, |
107 STATE_WAIT_COMPLETE, | 112 STATE_WAIT_COMPLETE, |
113 STATE_QUICK_CHECK, | |
114 STATE_QUICK_CHECK_COMPLETE, | |
108 STATE_FETCH_PAC_SCRIPT, | 115 STATE_FETCH_PAC_SCRIPT, |
109 STATE_FETCH_PAC_SCRIPT_COMPLETE, | 116 STATE_FETCH_PAC_SCRIPT_COMPLETE, |
110 STATE_VERIFY_PAC_SCRIPT, | 117 STATE_VERIFY_PAC_SCRIPT, |
111 STATE_VERIFY_PAC_SCRIPT_COMPLETE, | 118 STATE_VERIFY_PAC_SCRIPT_COMPLETE, |
112 }; | 119 }; |
113 | 120 |
114 // Returns ordered list of PAC urls to try for |config|. | 121 // Returns ordered list of PAC urls to try for |config|. |
115 PacSourceList BuildPacSourcesFallbackList(const ProxyConfig& config) const; | 122 PacSourceList BuildPacSourcesFallbackList(const ProxyConfig& config) const; |
116 | 123 |
117 void OnIOCompletion(int result); | 124 void OnIOCompletion(int result); |
118 int DoLoop(int result); | 125 int DoLoop(int result); |
119 void DoCallback(int result); | 126 void DoCallback(int result); |
120 | 127 |
121 int DoWait(); | 128 int DoWait(); |
122 int DoWaitComplete(int result); | 129 int DoWaitComplete(int result); |
123 | 130 |
131 int DoQuickCheck(); | |
132 int DoQuickCheckComplete(int result); | |
133 | |
124 int DoFetchPacScript(); | 134 int DoFetchPacScript(); |
125 int DoFetchPacScriptComplete(int result); | 135 int DoFetchPacScriptComplete(int result); |
126 | 136 |
127 int DoVerifyPacScript(); | 137 int DoVerifyPacScript(); |
128 int DoVerifyPacScriptComplete(int result); | 138 int DoVerifyPacScriptComplete(int result); |
129 | 139 |
130 // Tries restarting using the next fallback PAC URL: | 140 // Tries restarting using the next fallback PAC URL: |
131 // |pac_sources_[++current_pac_source_index]|. | 141 // |pac_sources_[++current_pac_source_index]|. |
132 // Returns OK and rewinds the state machine when there | 142 // Returns OK and rewinds the state machine when there |
133 // is something to try, otherwise returns |error|. | 143 // is something to try, otherwise returns |error|. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
168 | 178 |
169 bool fetch_pac_bytes_; | 179 bool fetch_pac_bytes_; |
170 | 180 |
171 base::TimeDelta wait_delay_; | 181 base::TimeDelta wait_delay_; |
172 base::OneShotTimer<ProxyScriptDecider> wait_timer_; | 182 base::OneShotTimer<ProxyScriptDecider> wait_timer_; |
173 | 183 |
174 // Results. | 184 // Results. |
175 ProxyConfig effective_config_; | 185 ProxyConfig effective_config_; |
176 scoped_refptr<ProxyResolverScriptData> script_data_; | 186 scoped_refptr<ProxyResolverScriptData> script_data_; |
177 | 187 |
188 AddressList wpad_addresses_; | |
189 base::OneShotTimer<ProxyScriptDecider> quick_check_timer_; | |
190 scoped_ptr<SingleRequestHostResolver> host_resolver_; | |
191 base::Time quick_check_start_time_; | |
178 | 192 |
179 DISALLOW_COPY_AND_ASSIGN(ProxyScriptDecider); | 193 DISALLOW_COPY_AND_ASSIGN(ProxyScriptDecider); |
180 }; | 194 }; |
181 | 195 |
182 } // namespace net | 196 } // namespace net |
183 | 197 |
184 #endif // NET_PROXY_PROXY_SCRIPT_DECIDER_H_ | 198 #endif // NET_PROXY_PROXY_SCRIPT_DECIDER_H_ |
OLD | NEW |