Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(537)

Side by Side Diff: net/proxy/proxy_script_decider.cc

Issue 8896019: Refactor: Extract "InitProxyResolver" to "ProxyScriptDecider". (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: do another sync since commitbot failed... Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/proxy/proxy_script_decider.h ('k') | net/proxy/proxy_script_decider_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "net/proxy/init_proxy_resolver.h" 5 #include "net/proxy/proxy_script_decider.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/format_macros.h" 8 #include "base/format_macros.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/utf_string_conversions.h"
11 #include "net/base/net_log.h" 12 #include "net/base/net_log.h"
12 #include "net/base/net_errors.h" 13 #include "net/base/net_errors.h"
13 #include "net/proxy/dhcp_proxy_script_fetcher.h" 14 #include "net/proxy/dhcp_proxy_script_fetcher.h"
14 #include "net/proxy/dhcp_proxy_script_fetcher_factory.h" 15 #include "net/proxy/dhcp_proxy_script_fetcher_factory.h"
15 #include "net/proxy/proxy_config.h"
16 #include "net/proxy/proxy_resolver.h"
17 #include "net/proxy/proxy_script_fetcher.h" 16 #include "net/proxy/proxy_script_fetcher.h"
18 17
19 namespace net { 18 namespace net {
20 19
20 namespace {
21 bool LooksLikePacScript(const string16& script) {
22 // Note: this is only an approximation! It may not always work correctly,
23 // however it is very likely that legitimate scripts have this exact string,
24 // since they must minimally define a function of this name. Conversely, a
25 // file not containing the string is not likely to be a PAC script.
26 //
27 // An exact test would have to load the script in a javascript evaluator.
28 return script.find(ASCIIToUTF16("FindProxyForURL")) != string16::npos;
29 }
30 }
31
21 // This is the hard-coded location used by the DNS portion of web proxy 32 // This is the hard-coded location used by the DNS portion of web proxy
22 // auto-discovery. 33 // auto-discovery.
23 // 34 //
24 // Note that we not use DNS devolution to find the WPAD host, since that could 35 // Note that we not use DNS devolution to find the WPAD host, since that could
25 // be dangerous should our top level domain registry become out of date. 36 // be dangerous should our top level domain registry become out of date.
26 // 37 //
27 // Instead we directly resolve "wpad", and let the operating system apply the 38 // Instead we directly resolve "wpad", and let the operating system apply the
28 // DNS suffix search paths. This is the same approach taken by Firefox, and 39 // DNS suffix search paths. This is the same approach taken by Firefox, and
29 // compatibility hasn't been an issue. 40 // compatibility hasn't been an issue.
30 // 41 //
31 // For more details, also check out this comment: 42 // For more details, also check out this comment:
32 // http://code.google.com/p/chromium/issues/detail?id=18575#c20 43 // http://code.google.com/p/chromium/issues/detail?id=18575#c20
33 static const char kWpadUrl[] = "http://wpad/wpad.dat"; 44 static const char kWpadUrl[] = "http://wpad/wpad.dat";
34 45
35 InitProxyResolver::InitProxyResolver( 46 ProxyScriptDecider::ProxyScriptDecider(
36 ProxyResolver* resolver,
37 ProxyScriptFetcher* proxy_script_fetcher, 47 ProxyScriptFetcher* proxy_script_fetcher,
38 DhcpProxyScriptFetcher* dhcp_proxy_script_fetcher, 48 DhcpProxyScriptFetcher* dhcp_proxy_script_fetcher,
39 NetLog* net_log) 49 NetLog* net_log)
40 : resolver_(resolver), 50 : proxy_script_fetcher_(proxy_script_fetcher),
41 proxy_script_fetcher_(proxy_script_fetcher),
42 dhcp_proxy_script_fetcher_(dhcp_proxy_script_fetcher), 51 dhcp_proxy_script_fetcher_(dhcp_proxy_script_fetcher),
43 ALLOW_THIS_IN_INITIALIZER_LIST(io_callback_( 52 ALLOW_THIS_IN_INITIALIZER_LIST(io_callback_(
44 this, &InitProxyResolver::OnIOCompletion)), 53 this, &ProxyScriptDecider::OnIOCompletion)),
45 user_callback_(NULL), 54 user_callback_(NULL),
46 current_pac_source_index_(0u), 55 current_pac_source_index_(0u),
47 pac_mandatory_(false), 56 pac_mandatory_(false),
48 next_state_(STATE_NONE), 57 next_state_(STATE_NONE),
49 net_log_(BoundNetLog::Make( 58 net_log_(BoundNetLog::Make(
50 net_log, NetLog::SOURCE_INIT_PROXY_RESOLVER)), 59 net_log, NetLog::SOURCE_PROXY_SCRIPT_DECIDER)),
51 effective_config_(NULL) { 60 fetch_pac_bytes_(false) {
52 } 61 }
53 62
54 InitProxyResolver::~InitProxyResolver() { 63 ProxyScriptDecider::~ProxyScriptDecider() {
55 if (next_state_ != STATE_NONE) 64 if (next_state_ != STATE_NONE)
56 Cancel(); 65 Cancel();
57 } 66 }
58 67
59 int InitProxyResolver::Init(const ProxyConfig& config, 68 int ProxyScriptDecider::Start(const ProxyConfig& config,
60 const base::TimeDelta wait_delay, 69 const base::TimeDelta wait_delay,
61 ProxyConfig* effective_config, 70 bool fetch_pac_bytes,
62 OldCompletionCallback* callback) { 71 OldCompletionCallback* callback) {
63 DCHECK_EQ(STATE_NONE, next_state_); 72 DCHECK_EQ(STATE_NONE, next_state_);
64 DCHECK(callback); 73 DCHECK(callback);
65 DCHECK(config.HasAutomaticSettings()); 74 DCHECK(config.HasAutomaticSettings());
66 75
67 net_log_.BeginEvent(NetLog::TYPE_INIT_PROXY_RESOLVER, NULL); 76 net_log_.BeginEvent(NetLog::TYPE_PROXY_SCRIPT_DECIDER, NULL);
77
78 fetch_pac_bytes_ = fetch_pac_bytes;
68 79
69 // Save the |wait_delay| as a non-negative value. 80 // Save the |wait_delay| as a non-negative value.
70 wait_delay_ = wait_delay; 81 wait_delay_ = wait_delay;
71 if (wait_delay_ < base::TimeDelta()) 82 if (wait_delay_ < base::TimeDelta())
72 wait_delay_ = base::TimeDelta(); 83 wait_delay_ = base::TimeDelta();
73 84
74 effective_config_ = effective_config;
75
76 pac_mandatory_ = config.pac_mandatory(); 85 pac_mandatory_ = config.pac_mandatory();
77 86
78 pac_sources_ = BuildPacSourcesFallbackList(config); 87 pac_sources_ = BuildPacSourcesFallbackList(config);
79 DCHECK(!pac_sources_.empty()); 88 DCHECK(!pac_sources_.empty());
80 89
81 next_state_ = STATE_WAIT; 90 next_state_ = STATE_WAIT;
82 91
83 int rv = DoLoop(OK); 92 int rv = DoLoop(OK);
84 if (rv == ERR_IO_PENDING) 93 if (rv == ERR_IO_PENDING)
85 user_callback_ = callback; 94 user_callback_ = callback;
86 else 95 else
87 DidCompleteInit(); 96 DidComplete();
88 97
89 return rv; 98 return rv;
90 } 99 }
91 100
101 const ProxyConfig& ProxyScriptDecider::effective_config() const {
102 DCHECK_EQ(STATE_NONE, next_state_);
103 return effective_config_;
104 }
105
106 // TODO(eroman): Return a const-pointer.
107 ProxyResolverScriptData* ProxyScriptDecider::script_data() const {
108 DCHECK_EQ(STATE_NONE, next_state_);
109 return script_data_.get();
110 }
111
92 // Initialize the fallback rules. 112 // Initialize the fallback rules.
93 // (1) WPAD (DHCP). 113 // (1) WPAD (DHCP).
94 // (2) WPAD (DNS). 114 // (2) WPAD (DNS).
95 // (3) Custom PAC URL. 115 // (3) Custom PAC URL.
96 InitProxyResolver::PacSourceList InitProxyResolver::BuildPacSourcesFallbackList( 116 ProxyScriptDecider::PacSourceList ProxyScriptDecider::
117 BuildPacSourcesFallbackList(
97 const ProxyConfig& config) const { 118 const ProxyConfig& config) const {
98 PacSourceList pac_sources; 119 PacSourceList pac_sources;
99 if (config.auto_detect()) { 120 if (config.auto_detect()) {
100 pac_sources.push_back(PacSource(PacSource::WPAD_DHCP, GURL())); 121 pac_sources.push_back(PacSource(PacSource::WPAD_DHCP, GURL()));
101 pac_sources.push_back(PacSource(PacSource::WPAD_DNS, GURL())); 122 pac_sources.push_back(PacSource(PacSource::WPAD_DNS, GURL()));
102 } 123 }
103 if (config.has_pac_url()) 124 if (config.has_pac_url())
104 pac_sources.push_back(PacSource(PacSource::CUSTOM, config.pac_url())); 125 pac_sources.push_back(PacSource(PacSource::CUSTOM, config.pac_url()));
105 return pac_sources; 126 return pac_sources;
106 } 127 }
107 128
108 void InitProxyResolver::OnIOCompletion(int result) { 129 void ProxyScriptDecider::OnIOCompletion(int result) {
109 DCHECK_NE(STATE_NONE, next_state_); 130 DCHECK_NE(STATE_NONE, next_state_);
110 int rv = DoLoop(result); 131 int rv = DoLoop(result);
111 if (rv != ERR_IO_PENDING) { 132 if (rv != ERR_IO_PENDING) {
112 DidCompleteInit(); 133 DidComplete();
113 DoCallback(rv); 134 DoCallback(rv);
114 } 135 }
115 } 136 }
116 137
117 int InitProxyResolver::DoLoop(int result) { 138 int ProxyScriptDecider::DoLoop(int result) {
118 DCHECK_NE(next_state_, STATE_NONE); 139 DCHECK_NE(next_state_, STATE_NONE);
119 int rv = result; 140 int rv = result;
120 do { 141 do {
121 State state = next_state_; 142 State state = next_state_;
122 next_state_ = STATE_NONE; 143 next_state_ = STATE_NONE;
123 switch (state) { 144 switch (state) {
124 case STATE_WAIT: 145 case STATE_WAIT:
125 DCHECK_EQ(OK, rv); 146 DCHECK_EQ(OK, rv);
126 rv = DoWait(); 147 rv = DoWait();
127 break; 148 break;
128 case STATE_WAIT_COMPLETE: 149 case STATE_WAIT_COMPLETE:
129 rv = DoWaitComplete(rv); 150 rv = DoWaitComplete(rv);
130 break; 151 break;
131 case STATE_FETCH_PAC_SCRIPT: 152 case STATE_FETCH_PAC_SCRIPT:
132 DCHECK_EQ(OK, rv); 153 DCHECK_EQ(OK, rv);
133 rv = DoFetchPacScript(); 154 rv = DoFetchPacScript();
134 break; 155 break;
135 case STATE_FETCH_PAC_SCRIPT_COMPLETE: 156 case STATE_FETCH_PAC_SCRIPT_COMPLETE:
136 rv = DoFetchPacScriptComplete(rv); 157 rv = DoFetchPacScriptComplete(rv);
137 break; 158 break;
138 case STATE_SET_PAC_SCRIPT: 159 case STATE_VERIFY_PAC_SCRIPT:
139 DCHECK_EQ(OK, rv); 160 DCHECK_EQ(OK, rv);
140 rv = DoSetPacScript(); 161 rv = DoVerifyPacScript();
141 break; 162 break;
142 case STATE_SET_PAC_SCRIPT_COMPLETE: 163 case STATE_VERIFY_PAC_SCRIPT_COMPLETE:
143 rv = DoSetPacScriptComplete(rv); 164 rv = DoVerifyPacScriptComplete(rv);
144 break; 165 break;
145 default: 166 default:
146 NOTREACHED() << "bad state"; 167 NOTREACHED() << "bad state";
147 rv = ERR_UNEXPECTED; 168 rv = ERR_UNEXPECTED;
148 break; 169 break;
149 } 170 }
150 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); 171 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE);
151 return rv; 172 return rv;
152 } 173 }
153 174
154 void InitProxyResolver::DoCallback(int result) { 175 void ProxyScriptDecider::DoCallback(int result) {
155 DCHECK_NE(ERR_IO_PENDING, result); 176 DCHECK_NE(ERR_IO_PENDING, result);
156 DCHECK(user_callback_); 177 DCHECK(user_callback_);
157 user_callback_->Run(result); 178 user_callback_->Run(result);
158 } 179 }
159 180
160 int InitProxyResolver::DoWait() { 181 int ProxyScriptDecider::DoWait() {
161 next_state_ = STATE_WAIT_COMPLETE; 182 next_state_ = STATE_WAIT_COMPLETE;
162 183
163 // If no waiting is required, continue on to the next state. 184 // If no waiting is required, continue on to the next state.
164 if (wait_delay_.ToInternalValue() == 0) 185 if (wait_delay_.ToInternalValue() == 0)
165 return OK; 186 return OK;
166 187
167 // Otherwise wait the specified amount of time. 188 // Otherwise wait the specified amount of time.
168 wait_timer_.Start(FROM_HERE, wait_delay_, this, 189 wait_timer_.Start(FROM_HERE, wait_delay_, this,
169 &InitProxyResolver::OnWaitTimerFired); 190 &ProxyScriptDecider::OnWaitTimerFired);
170 net_log_.BeginEvent(NetLog::TYPE_INIT_PROXY_RESOLVER_WAIT, NULL); 191 net_log_.BeginEvent(NetLog::TYPE_PROXY_SCRIPT_DECIDER_WAIT, NULL);
171 return ERR_IO_PENDING; 192 return ERR_IO_PENDING;
172 } 193 }
173 194
174 int InitProxyResolver::DoWaitComplete(int result) { 195 int ProxyScriptDecider::DoWaitComplete(int result) {
175 DCHECK_EQ(OK, result); 196 DCHECK_EQ(OK, result);
176 if (wait_delay_.ToInternalValue() != 0) { 197 if (wait_delay_.ToInternalValue() != 0) {
177 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_INIT_PROXY_RESOLVER_WAIT, 198 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_PROXY_SCRIPT_DECIDER_WAIT,
178 result); 199 result);
179 } 200 }
180 next_state_ = GetStartState(); 201 next_state_ = GetStartState();
181 return OK; 202 return OK;
182 } 203 }
183 204
184 int InitProxyResolver::DoFetchPacScript() { 205 int ProxyScriptDecider::DoFetchPacScript() {
185 DCHECK(resolver_->expects_pac_bytes()); 206 DCHECK(fetch_pac_bytes_);
186 207
187 next_state_ = STATE_FETCH_PAC_SCRIPT_COMPLETE; 208 next_state_ = STATE_FETCH_PAC_SCRIPT_COMPLETE;
188 209
189 const PacSource& pac_source = current_pac_source(); 210 const PacSource& pac_source = current_pac_source();
190 211
191 GURL effective_pac_url; 212 GURL effective_pac_url;
192 NetLogStringParameter* log_parameter = 213 NetLogStringParameter* log_parameter =
193 CreateNetLogParameterAndDetermineURL(pac_source, &effective_pac_url); 214 CreateNetLogParameterAndDetermineURL(pac_source, &effective_pac_url);
194 215
195 net_log_.BeginEvent( 216 net_log_.BeginEvent(
196 NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT, 217 NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT,
197 make_scoped_refptr(log_parameter)); 218 make_scoped_refptr(log_parameter));
198 219
199 if (pac_source.type == PacSource::WPAD_DHCP) { 220 if (pac_source.type == PacSource::WPAD_DHCP) {
200 if (!dhcp_proxy_script_fetcher_) { 221 if (!dhcp_proxy_script_fetcher_) {
201 net_log_.AddEvent(NetLog::TYPE_INIT_PROXY_RESOLVER_HAS_NO_FETCHER, NULL); 222 net_log_.AddEvent(NetLog::TYPE_PROXY_SCRIPT_DECIDER_HAS_NO_FETCHER, NULL);
202 return ERR_UNEXPECTED; 223 return ERR_UNEXPECTED;
203 } 224 }
204 225
205 return dhcp_proxy_script_fetcher_->Fetch(&pac_script_, &io_callback_); 226 return dhcp_proxy_script_fetcher_->Fetch(&pac_script_, &io_callback_);
206 } 227 }
207 228
208 if (!proxy_script_fetcher_) { 229 if (!proxy_script_fetcher_) {
209 net_log_.AddEvent(NetLog::TYPE_INIT_PROXY_RESOLVER_HAS_NO_FETCHER, NULL); 230 net_log_.AddEvent(NetLog::TYPE_PROXY_SCRIPT_DECIDER_HAS_NO_FETCHER, NULL);
210 return ERR_UNEXPECTED; 231 return ERR_UNEXPECTED;
211 } 232 }
212 233
213 return proxy_script_fetcher_->Fetch( 234 return proxy_script_fetcher_->Fetch(
214 effective_pac_url, &pac_script_, &io_callback_); 235 effective_pac_url, &pac_script_, &io_callback_);
215 } 236 }
216 237
217 int InitProxyResolver::DoFetchPacScriptComplete(int result) { 238 int ProxyScriptDecider::DoFetchPacScriptComplete(int result) {
218 DCHECK(resolver_->expects_pac_bytes()); 239 DCHECK(fetch_pac_bytes_);
219 240
220 net_log_.EndEventWithNetErrorCode( 241 net_log_.EndEventWithNetErrorCode(
221 NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT, result); 242 NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT, result);
222 if (result != OK) 243 if (result != OK)
223 return TryToFallbackPacSource(result); 244 return TryToFallbackPacSource(result);
224 245
225 next_state_ = STATE_SET_PAC_SCRIPT; 246 next_state_ = STATE_VERIFY_PAC_SCRIPT;
226 return result; 247 return result;
227 } 248 }
228 249
229 int InitProxyResolver::DoSetPacScript() { 250 int ProxyScriptDecider::DoVerifyPacScript() {
230 net_log_.BeginEvent(NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT, NULL); 251 next_state_ = STATE_VERIFY_PAC_SCRIPT_COMPLETE;
252
253 // This is just a heuristic. Ideally we would try to parse the script.
254 if (fetch_pac_bytes_ && !LooksLikePacScript(pac_script_))
255 return ERR_PAC_SCRIPT_FAILED;
256
257 return OK;
258 }
259
260 int ProxyScriptDecider::DoVerifyPacScriptComplete(int result) {
261 if (result != OK)
262 return TryToFallbackPacSource(result);
231 263
232 const PacSource& pac_source = current_pac_source(); 264 const PacSource& pac_source = current_pac_source();
233 265
234 next_state_ = STATE_SET_PAC_SCRIPT_COMPLETE; 266 // Extract the current script data.
235 267 if (fetch_pac_bytes_) {
236 scoped_refptr<ProxyResolverScriptData> script_data; 268 script_data_ = ProxyResolverScriptData::FromUTF16(pac_script_);
237
238 if (resolver_->expects_pac_bytes()) {
239 script_data = ProxyResolverScriptData::FromUTF16(pac_script_);
240 } else { 269 } else {
241 script_data = pac_source.type == PacSource::CUSTOM ? 270 script_data_ = pac_source.type == PacSource::CUSTOM ?
242 ProxyResolverScriptData::FromURL(pac_source.url) : 271 ProxyResolverScriptData::FromURL(pac_source.url) :
243 ProxyResolverScriptData::ForAutoDetect(); 272 ProxyResolverScriptData::ForAutoDetect();
244 } 273 }
245 274
246 return resolver_->SetPacScript(script_data, &io_callback_);
247 }
248
249 int InitProxyResolver::DoSetPacScriptComplete(int result) {
250 net_log_.EndEventWithNetErrorCode(
251 NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT, result);
252 if (result != OK)
253 return TryToFallbackPacSource(result);
254
255 // Let the caller know which automatic setting we ended up initializing the 275 // Let the caller know which automatic setting we ended up initializing the
256 // resolver for (there may have been multiple fallbacks to choose from.) 276 // resolver for (there may have been multiple fallbacks to choose from.)
257 if (effective_config_) { 277 if (current_pac_source().type == PacSource::CUSTOM) {
258 if (current_pac_source().type == PacSource::CUSTOM) { 278 effective_config_ =
259 *effective_config_ = 279 ProxyConfig::CreateFromCustomPacURL(current_pac_source().url);
260 ProxyConfig::CreateFromCustomPacURL(current_pac_source().url); 280 effective_config_.set_pac_mandatory(pac_mandatory_);
261 effective_config_->set_pac_mandatory(pac_mandatory_); 281 } else {
282 if (fetch_pac_bytes_) {
283 GURL auto_detected_url;
284
285 switch (current_pac_source().type) {
286 case PacSource::WPAD_DHCP:
287 auto_detected_url = dhcp_proxy_script_fetcher_->GetPacURL();
288 break;
289
290 case PacSource::WPAD_DNS:
291 auto_detected_url = GURL(kWpadUrl);
292 break;
293
294 default:
295 NOTREACHED();
296 }
297
298 effective_config_ =
299 ProxyConfig::CreateFromCustomPacURL(auto_detected_url);
262 } else { 300 } else {
263 if (resolver_->expects_pac_bytes()) { 301 // The resolver does its own resolution so we cannot know the
264 GURL auto_detected_url; 302 // URL. Just do the best we can and state that the configuration
265 303 // is to auto-detect proxy settings.
266 switch (current_pac_source().type) { 304 effective_config_ = ProxyConfig::CreateAutoDetect();
267 case PacSource::WPAD_DHCP:
268 auto_detected_url = dhcp_proxy_script_fetcher_->GetPacURL();
269 break;
270
271 case PacSource::WPAD_DNS:
272 auto_detected_url = GURL(kWpadUrl);
273 break;
274
275 default:
276 NOTREACHED();
277 }
278
279 *effective_config_ =
280 ProxyConfig::CreateFromCustomPacURL(auto_detected_url);
281 } else {
282 // The resolver does its own resolution so we cannot know the
283 // URL. Just do the best we can and state that the configuration
284 // is to auto-detect proxy settings.
285 *effective_config_ = ProxyConfig::CreateAutoDetect();
286 }
287 } 305 }
288 } 306 }
289 307
290 return result; 308 return OK;
291 } 309 }
292 310
293 int InitProxyResolver::TryToFallbackPacSource(int error) { 311 int ProxyScriptDecider::TryToFallbackPacSource(int error) {
294 DCHECK_LT(error, 0); 312 DCHECK_LT(error, 0);
295 313
296 if (current_pac_source_index_ + 1 >= pac_sources_.size()) { 314 if (current_pac_source_index_ + 1 >= pac_sources_.size()) {
297 // Nothing left to fall back to. 315 // Nothing left to fall back to.
298 return error; 316 return error;
299 } 317 }
300 318
301 // Advance to next URL in our list. 319 // Advance to next URL in our list.
302 ++current_pac_source_index_; 320 ++current_pac_source_index_;
303 321
304 net_log_.AddEvent( 322 net_log_.AddEvent(
305 NetLog::TYPE_INIT_PROXY_RESOLVER_FALLING_BACK_TO_NEXT_PAC_SOURCE, NULL); 323 NetLog::TYPE_PROXY_SCRIPT_DECIDER_FALLING_BACK_TO_NEXT_PAC_SOURCE, NULL);
306 324
307 next_state_ = GetStartState(); 325 next_state_ = GetStartState();
308 326
309 return OK; 327 return OK;
310 } 328 }
311 329
312 InitProxyResolver::State InitProxyResolver::GetStartState() const { 330 ProxyScriptDecider::State ProxyScriptDecider::GetStartState() const {
313 return resolver_->expects_pac_bytes() ? 331 return fetch_pac_bytes_ ? STATE_FETCH_PAC_SCRIPT : STATE_VERIFY_PAC_SCRIPT;
314 STATE_FETCH_PAC_SCRIPT : STATE_SET_PAC_SCRIPT;
315 } 332 }
316 333
317 NetLogStringParameter* InitProxyResolver::CreateNetLogParameterAndDetermineURL( 334 NetLogStringParameter* ProxyScriptDecider::CreateNetLogParameterAndDetermineURL(
318 const PacSource& pac_source, 335 const PacSource& pac_source,
319 GURL* effective_pac_url) { 336 GURL* effective_pac_url) {
320 DCHECK(effective_pac_url); 337 DCHECK(effective_pac_url);
321 338
322 std::string source_field; 339 std::string source_field;
323 switch (pac_source.type) { 340 switch (pac_source.type) {
324 case PacSource::WPAD_DHCP: 341 case PacSource::WPAD_DHCP:
325 source_field = "WPAD DHCP"; 342 source_field = "WPAD DHCP";
326 break; 343 break;
327 case PacSource::WPAD_DNS: 344 case PacSource::WPAD_DNS:
328 *effective_pac_url = GURL(kWpadUrl); 345 *effective_pac_url = GURL(kWpadUrl);
329 source_field = "WPAD DNS: "; 346 source_field = "WPAD DNS: ";
330 source_field += effective_pac_url->possibly_invalid_spec(); 347 source_field += effective_pac_url->possibly_invalid_spec();
331 break; 348 break;
332 case PacSource::CUSTOM: 349 case PacSource::CUSTOM:
333 *effective_pac_url = pac_source.url; 350 *effective_pac_url = pac_source.url;
334 source_field = "Custom PAC URL: "; 351 source_field = "Custom PAC URL: ";
335 source_field += effective_pac_url->possibly_invalid_spec(); 352 source_field += effective_pac_url->possibly_invalid_spec();
336 break; 353 break;
337 } 354 }
338 return new NetLogStringParameter("source", source_field); 355 return new NetLogStringParameter("source", source_field);
339 } 356 }
340 357
341 const InitProxyResolver::PacSource& 358 const ProxyScriptDecider::PacSource&
342 InitProxyResolver::current_pac_source() const { 359 ProxyScriptDecider::current_pac_source() const {
343 DCHECK_LT(current_pac_source_index_, pac_sources_.size()); 360 DCHECK_LT(current_pac_source_index_, pac_sources_.size());
344 return pac_sources_[current_pac_source_index_]; 361 return pac_sources_[current_pac_source_index_];
345 } 362 }
346 363
347 void InitProxyResolver::OnWaitTimerFired() { 364 void ProxyScriptDecider::OnWaitTimerFired() {
348 OnIOCompletion(OK); 365 OnIOCompletion(OK);
349 } 366 }
350 367
351 void InitProxyResolver::DidCompleteInit() { 368 void ProxyScriptDecider::DidComplete() {
352 net_log_.EndEvent(NetLog::TYPE_INIT_PROXY_RESOLVER, NULL); 369 net_log_.EndEvent(NetLog::TYPE_PROXY_SCRIPT_DECIDER, NULL);
353 } 370 }
354 371
355 void InitProxyResolver::Cancel() { 372 void ProxyScriptDecider::Cancel() {
356 DCHECK_NE(STATE_NONE, next_state_); 373 DCHECK_NE(STATE_NONE, next_state_);
357 374
358 net_log_.AddEvent(NetLog::TYPE_CANCELLED, NULL); 375 net_log_.AddEvent(NetLog::TYPE_CANCELLED, NULL);
359 376
360 switch (next_state_) { 377 switch (next_state_) {
361 case STATE_WAIT_COMPLETE: 378 case STATE_WAIT_COMPLETE:
362 wait_timer_.Stop(); 379 wait_timer_.Stop();
363 break; 380 break;
364 case STATE_FETCH_PAC_SCRIPT_COMPLETE: 381 case STATE_FETCH_PAC_SCRIPT_COMPLETE:
365 proxy_script_fetcher_->Cancel(); 382 proxy_script_fetcher_->Cancel();
366 break; 383 break;
367 case STATE_SET_PAC_SCRIPT_COMPLETE:
368 resolver_->CancelSetPacScript();
369 break;
370 default: 384 default:
371 NOTREACHED(); 385 NOTREACHED();
372 break; 386 break;
373 } 387 }
374 388
375 // This is safe to call in any state. 389 // This is safe to call in any state.
376 if (dhcp_proxy_script_fetcher_) 390 if (dhcp_proxy_script_fetcher_)
377 dhcp_proxy_script_fetcher_->Cancel(); 391 dhcp_proxy_script_fetcher_->Cancel();
378 392
379 DidCompleteInit(); 393 DidComplete();
380 } 394 }
381 395
382 } // namespace net 396 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_script_decider.h ('k') | net/proxy/proxy_script_decider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698