Chromium Code Reviews| Index: net/proxy/proxy_script_decider.cc |
| diff --git a/net/proxy/proxy_script_decider.cc b/net/proxy/proxy_script_decider.cc |
| index 761d69d96cbd71d3c1802e455464f0cbfad05b89..bc8a96776cedf920eb80c88da0b3d87c5ee46ee1 100644 |
| --- a/net/proxy/proxy_script_decider.cc |
| +++ b/net/proxy/proxy_script_decider.cc |
| @@ -92,14 +92,7 @@ ProxyScriptDecider::ProxyScriptDecider( |
| net_log_(NetLogWithSource::Make(net_log, |
| NetLogSourceType::PROXY_SCRIPT_DECIDER)), |
| fetch_pac_bytes_(false), |
| - quick_check_enabled_(true), |
| - host_resolver_(nullptr) { |
| - if (proxy_script_fetcher && |
| - proxy_script_fetcher->GetRequestContext() && |
| - proxy_script_fetcher->GetRequestContext()->host_resolver()) { |
| - host_resolver_ = proxy_script_fetcher->GetRequestContext()->host_resolver(); |
| - } |
| -} |
| + quick_check_enabled_(true) {} |
| ProxyScriptDecider::~ProxyScriptDecider() { |
| if (next_state_ != STATE_NONE) |
| @@ -139,6 +132,20 @@ int ProxyScriptDecider::Start( |
| return rv; |
| } |
| +void ProxyScriptDecider::OnShutdown() { |
| + // Don't do anything if idle. |
| + if (next_state_ == STATE_NONE) |
| + return; |
| + |
| + CompletionCallback callback = std::move(callback_); |
| + |
| + // Just cancel any pending work. |
| + Cancel(); |
| + |
| + if (callback) |
| + callback.Run(ERR_CONTEXT_SHUT_DOWN); |
| +} |
| + |
| const ProxyConfig& ProxyScriptDecider::effective_config() const { |
| DCHECK_EQ(STATE_NONE, next_state_); |
| return effective_config_; |
| @@ -255,7 +262,8 @@ int ProxyScriptDecider::DoWaitComplete(int result) { |
| int ProxyScriptDecider::DoQuickCheck() { |
| DCHECK(quick_check_enabled_); |
| - if (host_resolver_ == nullptr) { |
| + if (!proxy_script_fetcher_ || !proxy_script_fetcher_->GetRequestContext() || |
| + !proxy_script_fetcher_->GetRequestContext()->host_resolver()) { |
| // If we have no resolver, skip QuickCheck altogether. |
| next_state_ = GetStartState(); |
| return OK; |
| @@ -275,9 +283,12 @@ int ProxyScriptDecider::DoQuickCheck() { |
| kQuickCheckDelayMs), |
| base::Bind(callback, ERR_NAME_NOT_RESOLVED)); |
| + HostResolver* host_resolver = |
| + proxy_script_fetcher_->GetRequestContext()->host_resolver(); |
| + |
| // We use HIGHEST here because proxy decision blocks doing any other requests. |
| - return host_resolver_->Resolve(reqinfo, HIGHEST, &wpad_addresses_, callback, |
| - &request_, net_log_); |
| + return host_resolver->Resolve(reqinfo, HIGHEST, &wpad_addresses_, callback, |
| + &request_, net_log_); |
| } |
| int ProxyScriptDecider::DoQuickCheckComplete(int result) { |
| @@ -465,6 +476,9 @@ void ProxyScriptDecider::Cancel() { |
| net_log_.AddEvent(NetLogEventType::CANCELLED); |
| switch (next_state_) { |
| + case STATE_QUICK_CHECK_COMPLETE: |
| + request_.reset(); |
|
mmenke
2017/05/01 16:52:14
This could just be put in OnShutdown(), but not ha
|
| + break; |
| case STATE_WAIT_COMPLETE: |
| wait_timer_.Stop(); |
| break; |
| @@ -475,10 +489,14 @@ void ProxyScriptDecider::Cancel() { |
| break; |
| } |
| + next_state_ = STATE_NONE; |
| + |
| // This is safe to call in any state. |
| if (dhcp_proxy_script_fetcher_) |
| dhcp_proxy_script_fetcher_->Cancel(); |
| + DCHECK(!request_); |
| + |
| DidComplete(); |
| } |