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 #include "net/proxy/proxy_script_decider.h" | 5 #include "net/proxy/proxy_script_decider.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/format_macros.h" | 12 #include "base/format_macros.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "base/values.h" | 17 #include "base/values.h" |
18 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
| 19 #include "net/log/net_log_event_type.h" |
| 20 #include "net/log/net_log_source_type.h" |
19 #include "net/proxy/dhcp_proxy_script_fetcher.h" | 21 #include "net/proxy/dhcp_proxy_script_fetcher.h" |
20 #include "net/proxy/dhcp_proxy_script_fetcher_factory.h" | 22 #include "net/proxy/dhcp_proxy_script_fetcher_factory.h" |
21 #include "net/proxy/proxy_script_fetcher.h" | 23 #include "net/proxy/proxy_script_fetcher.h" |
22 #include "net/url_request/url_request_context.h" | 24 #include "net/url_request/url_request_context.h" |
23 | 25 |
24 namespace net { | 26 namespace net { |
25 | 27 |
26 namespace { | 28 namespace { |
27 | 29 |
28 bool LooksLikePacScript(const base::string16& script) { | 30 bool LooksLikePacScript(const base::string16& script) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 | 81 |
80 ProxyScriptDecider::ProxyScriptDecider( | 82 ProxyScriptDecider::ProxyScriptDecider( |
81 ProxyScriptFetcher* proxy_script_fetcher, | 83 ProxyScriptFetcher* proxy_script_fetcher, |
82 DhcpProxyScriptFetcher* dhcp_proxy_script_fetcher, | 84 DhcpProxyScriptFetcher* dhcp_proxy_script_fetcher, |
83 NetLog* net_log) | 85 NetLog* net_log) |
84 : proxy_script_fetcher_(proxy_script_fetcher), | 86 : proxy_script_fetcher_(proxy_script_fetcher), |
85 dhcp_proxy_script_fetcher_(dhcp_proxy_script_fetcher), | 87 dhcp_proxy_script_fetcher_(dhcp_proxy_script_fetcher), |
86 current_pac_source_index_(0u), | 88 current_pac_source_index_(0u), |
87 pac_mandatory_(false), | 89 pac_mandatory_(false), |
88 next_state_(STATE_NONE), | 90 next_state_(STATE_NONE), |
89 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_PROXY_SCRIPT_DECIDER)), | 91 net_log_(BoundNetLog::Make(net_log, |
| 92 NetLogSourceType::PROXY_SCRIPT_DECIDER)), |
90 fetch_pac_bytes_(false), | 93 fetch_pac_bytes_(false), |
91 quick_check_enabled_(true), | 94 quick_check_enabled_(true), |
92 host_resolver_(nullptr) { | 95 host_resolver_(nullptr) { |
93 if (proxy_script_fetcher && | 96 if (proxy_script_fetcher && |
94 proxy_script_fetcher->GetRequestContext() && | 97 proxy_script_fetcher->GetRequestContext() && |
95 proxy_script_fetcher->GetRequestContext()->host_resolver()) { | 98 proxy_script_fetcher->GetRequestContext()->host_resolver()) { |
96 host_resolver_ = proxy_script_fetcher->GetRequestContext()->host_resolver(); | 99 host_resolver_ = proxy_script_fetcher->GetRequestContext()->host_resolver(); |
97 } | 100 } |
98 } | 101 } |
99 | 102 |
100 ProxyScriptDecider::~ProxyScriptDecider() { | 103 ProxyScriptDecider::~ProxyScriptDecider() { |
101 if (next_state_ != STATE_NONE) | 104 if (next_state_ != STATE_NONE) |
102 Cancel(); | 105 Cancel(); |
103 } | 106 } |
104 | 107 |
105 int ProxyScriptDecider::Start( | 108 int ProxyScriptDecider::Start( |
106 const ProxyConfig& config, const base::TimeDelta wait_delay, | 109 const ProxyConfig& config, const base::TimeDelta wait_delay, |
107 bool fetch_pac_bytes, const CompletionCallback& callback) { | 110 bool fetch_pac_bytes, const CompletionCallback& callback) { |
108 DCHECK_EQ(STATE_NONE, next_state_); | 111 DCHECK_EQ(STATE_NONE, next_state_); |
109 DCHECK(!callback.is_null()); | 112 DCHECK(!callback.is_null()); |
110 DCHECK(config.HasAutomaticSettings()); | 113 DCHECK(config.HasAutomaticSettings()); |
111 | 114 |
112 net_log_.BeginEvent(NetLog::TYPE_PROXY_SCRIPT_DECIDER); | 115 net_log_.BeginEvent(NetLogEventType::PROXY_SCRIPT_DECIDER); |
113 | 116 |
114 fetch_pac_bytes_ = fetch_pac_bytes; | 117 fetch_pac_bytes_ = fetch_pac_bytes; |
115 | 118 |
116 // Save the |wait_delay| as a non-negative value. | 119 // Save the |wait_delay| as a non-negative value. |
117 wait_delay_ = wait_delay; | 120 wait_delay_ = wait_delay; |
118 if (wait_delay_ < base::TimeDelta()) | 121 if (wait_delay_ < base::TimeDelta()) |
119 wait_delay_ = base::TimeDelta(); | 122 wait_delay_ = base::TimeDelta(); |
120 | 123 |
121 pac_mandatory_ = config.pac_mandatory(); | 124 pac_mandatory_ = config.pac_mandatory(); |
122 have_custom_pac_url_ = config.has_pac_url(); | 125 have_custom_pac_url_ = config.has_pac_url(); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 int ProxyScriptDecider::DoWait() { | 228 int ProxyScriptDecider::DoWait() { |
226 next_state_ = STATE_WAIT_COMPLETE; | 229 next_state_ = STATE_WAIT_COMPLETE; |
227 | 230 |
228 // If no waiting is required, continue on to the next state. | 231 // If no waiting is required, continue on to the next state. |
229 if (wait_delay_.ToInternalValue() == 0) | 232 if (wait_delay_.ToInternalValue() == 0) |
230 return OK; | 233 return OK; |
231 | 234 |
232 // Otherwise wait the specified amount of time. | 235 // Otherwise wait the specified amount of time. |
233 wait_timer_.Start(FROM_HERE, wait_delay_, this, | 236 wait_timer_.Start(FROM_HERE, wait_delay_, this, |
234 &ProxyScriptDecider::OnWaitTimerFired); | 237 &ProxyScriptDecider::OnWaitTimerFired); |
235 net_log_.BeginEvent(NetLog::TYPE_PROXY_SCRIPT_DECIDER_WAIT); | 238 net_log_.BeginEvent(NetLogEventType::PROXY_SCRIPT_DECIDER_WAIT); |
236 return ERR_IO_PENDING; | 239 return ERR_IO_PENDING; |
237 } | 240 } |
238 | 241 |
239 int ProxyScriptDecider::DoWaitComplete(int result) { | 242 int ProxyScriptDecider::DoWaitComplete(int result) { |
240 DCHECK_EQ(OK, result); | 243 DCHECK_EQ(OK, result); |
241 if (wait_delay_.ToInternalValue() != 0) { | 244 if (wait_delay_.ToInternalValue() != 0) { |
242 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_PROXY_SCRIPT_DECIDER_WAIT, | 245 net_log_.EndEventWithNetErrorCode( |
243 result); | 246 NetLogEventType::PROXY_SCRIPT_DECIDER_WAIT, |
| 247 result); |
244 } | 248 } |
245 if (quick_check_enabled_ && current_pac_source().type == PacSource::WPAD_DNS) | 249 if (quick_check_enabled_ && current_pac_source().type == PacSource::WPAD_DNS) |
246 next_state_ = STATE_QUICK_CHECK; | 250 next_state_ = STATE_QUICK_CHECK; |
247 else | 251 else |
248 next_state_ = GetStartState(); | 252 next_state_ = GetStartState(); |
249 return OK; | 253 return OK; |
250 } | 254 } |
251 | 255 |
252 int ProxyScriptDecider::DoQuickCheck() { | 256 int ProxyScriptDecider::DoQuickCheck() { |
253 DCHECK(quick_check_enabled_); | 257 DCHECK(quick_check_enabled_); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 int ProxyScriptDecider::DoFetchPacScript() { | 298 int ProxyScriptDecider::DoFetchPacScript() { |
295 DCHECK(fetch_pac_bytes_); | 299 DCHECK(fetch_pac_bytes_); |
296 | 300 |
297 next_state_ = STATE_FETCH_PAC_SCRIPT_COMPLETE; | 301 next_state_ = STATE_FETCH_PAC_SCRIPT_COMPLETE; |
298 | 302 |
299 const PacSource& pac_source = current_pac_source(); | 303 const PacSource& pac_source = current_pac_source(); |
300 | 304 |
301 GURL effective_pac_url; | 305 GURL effective_pac_url; |
302 DetermineURL(pac_source, &effective_pac_url); | 306 DetermineURL(pac_source, &effective_pac_url); |
303 | 307 |
304 net_log_.BeginEvent(NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT, | 308 net_log_.BeginEvent(NetLogEventType::PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT, |
305 base::Bind(&PacSource::NetLogCallback, | 309 base::Bind(&PacSource::NetLogCallback, |
306 base::Unretained(&pac_source), | 310 base::Unretained(&pac_source), |
307 &effective_pac_url)); | 311 &effective_pac_url)); |
308 | 312 |
309 if (pac_source.type == PacSource::WPAD_DHCP) { | 313 if (pac_source.type == PacSource::WPAD_DHCP) { |
310 if (!dhcp_proxy_script_fetcher_) { | 314 if (!dhcp_proxy_script_fetcher_) { |
311 net_log_.AddEvent(NetLog::TYPE_PROXY_SCRIPT_DECIDER_HAS_NO_FETCHER); | 315 net_log_.AddEvent(NetLogEventType::PROXY_SCRIPT_DECIDER_HAS_NO_FETCHER); |
312 return ERR_UNEXPECTED; | 316 return ERR_UNEXPECTED; |
313 } | 317 } |
314 | 318 |
315 return dhcp_proxy_script_fetcher_->Fetch( | 319 return dhcp_proxy_script_fetcher_->Fetch( |
316 &pac_script_, base::Bind(&ProxyScriptDecider::OnIOCompletion, | 320 &pac_script_, base::Bind(&ProxyScriptDecider::OnIOCompletion, |
317 base::Unretained(this))); | 321 base::Unretained(this))); |
318 } | 322 } |
319 | 323 |
320 if (!proxy_script_fetcher_) { | 324 if (!proxy_script_fetcher_) { |
321 net_log_.AddEvent(NetLog::TYPE_PROXY_SCRIPT_DECIDER_HAS_NO_FETCHER); | 325 net_log_.AddEvent(NetLogEventType::PROXY_SCRIPT_DECIDER_HAS_NO_FETCHER); |
322 return ERR_UNEXPECTED; | 326 return ERR_UNEXPECTED; |
323 } | 327 } |
324 | 328 |
325 return proxy_script_fetcher_->Fetch( | 329 return proxy_script_fetcher_->Fetch( |
326 effective_pac_url, &pac_script_, | 330 effective_pac_url, &pac_script_, |
327 base::Bind(&ProxyScriptDecider::OnIOCompletion, base::Unretained(this))); | 331 base::Bind(&ProxyScriptDecider::OnIOCompletion, base::Unretained(this))); |
328 } | 332 } |
329 | 333 |
330 int ProxyScriptDecider::DoFetchPacScriptComplete(int result) { | 334 int ProxyScriptDecider::DoFetchPacScriptComplete(int result) { |
331 DCHECK(fetch_pac_bytes_); | 335 DCHECK(fetch_pac_bytes_); |
332 | 336 |
333 net_log_.EndEventWithNetErrorCode( | 337 net_log_.EndEventWithNetErrorCode( |
334 NetLog::TYPE_PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT, result); | 338 NetLogEventType::PROXY_SCRIPT_DECIDER_FETCH_PAC_SCRIPT, result); |
335 if (result != OK) | 339 if (result != OK) |
336 return TryToFallbackPacSource(result); | 340 return TryToFallbackPacSource(result); |
337 | 341 |
338 next_state_ = STATE_VERIFY_PAC_SCRIPT; | 342 next_state_ = STATE_VERIFY_PAC_SCRIPT; |
339 return result; | 343 return result; |
340 } | 344 } |
341 | 345 |
342 int ProxyScriptDecider::DoVerifyPacScript() { | 346 int ProxyScriptDecider::DoVerifyPacScript() { |
343 next_state_ = STATE_VERIFY_PAC_SCRIPT_COMPLETE; | 347 next_state_ = STATE_VERIFY_PAC_SCRIPT_COMPLETE; |
344 | 348 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 | 409 |
406 if (current_pac_source_index_ + 1 >= pac_sources_.size()) { | 410 if (current_pac_source_index_ + 1 >= pac_sources_.size()) { |
407 // Nothing left to fall back to. | 411 // Nothing left to fall back to. |
408 return error; | 412 return error; |
409 } | 413 } |
410 | 414 |
411 // Advance to next URL in our list. | 415 // Advance to next URL in our list. |
412 ++current_pac_source_index_; | 416 ++current_pac_source_index_; |
413 | 417 |
414 net_log_.AddEvent( | 418 net_log_.AddEvent( |
415 NetLog::TYPE_PROXY_SCRIPT_DECIDER_FALLING_BACK_TO_NEXT_PAC_SOURCE); | 419 NetLogEventType::PROXY_SCRIPT_DECIDER_FALLING_BACK_TO_NEXT_PAC_SOURCE); |
416 if (quick_check_enabled_ && current_pac_source().type == PacSource::WPAD_DNS) | 420 if (quick_check_enabled_ && current_pac_source().type == PacSource::WPAD_DNS) |
417 next_state_ = STATE_QUICK_CHECK; | 421 next_state_ = STATE_QUICK_CHECK; |
418 else | 422 else |
419 next_state_ = GetStartState(); | 423 next_state_ = GetStartState(); |
420 | 424 |
421 return OK; | 425 return OK; |
422 } | 426 } |
423 | 427 |
424 ProxyScriptDecider::State ProxyScriptDecider::GetStartState() const { | 428 ProxyScriptDecider::State ProxyScriptDecider::GetStartState() const { |
425 return fetch_pac_bytes_ ? STATE_FETCH_PAC_SCRIPT : STATE_VERIFY_PAC_SCRIPT; | 429 return fetch_pac_bytes_ ? STATE_FETCH_PAC_SCRIPT : STATE_VERIFY_PAC_SCRIPT; |
(...skipping 19 matching lines...) Expand all Loading... |
445 ProxyScriptDecider::current_pac_source() const { | 449 ProxyScriptDecider::current_pac_source() const { |
446 DCHECK_LT(current_pac_source_index_, pac_sources_.size()); | 450 DCHECK_LT(current_pac_source_index_, pac_sources_.size()); |
447 return pac_sources_[current_pac_source_index_]; | 451 return pac_sources_[current_pac_source_index_]; |
448 } | 452 } |
449 | 453 |
450 void ProxyScriptDecider::OnWaitTimerFired() { | 454 void ProxyScriptDecider::OnWaitTimerFired() { |
451 OnIOCompletion(OK); | 455 OnIOCompletion(OK); |
452 } | 456 } |
453 | 457 |
454 void ProxyScriptDecider::DidComplete() { | 458 void ProxyScriptDecider::DidComplete() { |
455 net_log_.EndEvent(NetLog::TYPE_PROXY_SCRIPT_DECIDER); | 459 net_log_.EndEvent(NetLogEventType::PROXY_SCRIPT_DECIDER); |
456 } | 460 } |
457 | 461 |
458 void ProxyScriptDecider::Cancel() { | 462 void ProxyScriptDecider::Cancel() { |
459 DCHECK_NE(STATE_NONE, next_state_); | 463 DCHECK_NE(STATE_NONE, next_state_); |
460 | 464 |
461 net_log_.AddEvent(NetLog::TYPE_CANCELLED); | 465 net_log_.AddEvent(NetLogEventType::CANCELLED); |
462 | 466 |
463 switch (next_state_) { | 467 switch (next_state_) { |
464 case STATE_WAIT_COMPLETE: | 468 case STATE_WAIT_COMPLETE: |
465 wait_timer_.Stop(); | 469 wait_timer_.Stop(); |
466 break; | 470 break; |
467 case STATE_FETCH_PAC_SCRIPT_COMPLETE: | 471 case STATE_FETCH_PAC_SCRIPT_COMPLETE: |
468 proxy_script_fetcher_->Cancel(); | 472 proxy_script_fetcher_->Cancel(); |
469 break; | 473 break; |
470 default: | 474 default: |
471 break; | 475 break; |
472 } | 476 } |
473 | 477 |
474 // This is safe to call in any state. | 478 // This is safe to call in any state. |
475 if (dhcp_proxy_script_fetcher_) | 479 if (dhcp_proxy_script_fetcher_) |
476 dhcp_proxy_script_fetcher_->Cancel(); | 480 dhcp_proxy_script_fetcher_->Cancel(); |
477 | 481 |
478 DidComplete(); | 482 DidComplete(); |
479 } | 483 } |
480 | 484 |
481 } // namespace net | 485 } // namespace net |
OLD | NEW |