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

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

Issue 2214693002: First step to remove SingleRequestHostResolver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: single Created 4 years, 4 months 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
« no previous file with comments | « net/proxy/proxy_script_decider.h ('k') | net/quic/chromium/quic_stream_factory.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) 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"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 ProxyScriptFetcher* proxy_script_fetcher, 81 ProxyScriptFetcher* proxy_script_fetcher,
82 DhcpProxyScriptFetcher* dhcp_proxy_script_fetcher, 82 DhcpProxyScriptFetcher* dhcp_proxy_script_fetcher,
83 NetLog* net_log) 83 NetLog* net_log)
84 : proxy_script_fetcher_(proxy_script_fetcher), 84 : proxy_script_fetcher_(proxy_script_fetcher),
85 dhcp_proxy_script_fetcher_(dhcp_proxy_script_fetcher), 85 dhcp_proxy_script_fetcher_(dhcp_proxy_script_fetcher),
86 current_pac_source_index_(0u), 86 current_pac_source_index_(0u),
87 pac_mandatory_(false), 87 pac_mandatory_(false),
88 next_state_(STATE_NONE), 88 next_state_(STATE_NONE),
89 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_PROXY_SCRIPT_DECIDER)), 89 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_PROXY_SCRIPT_DECIDER)),
90 fetch_pac_bytes_(false), 90 fetch_pac_bytes_(false),
91 quick_check_enabled_(true) { 91 quick_check_enabled_(true),
92 host_resolver_(nullptr) {
92 if (proxy_script_fetcher && 93 if (proxy_script_fetcher &&
93 proxy_script_fetcher->GetRequestContext() && 94 proxy_script_fetcher->GetRequestContext() &&
94 proxy_script_fetcher->GetRequestContext()->host_resolver()) { 95 proxy_script_fetcher->GetRequestContext()->host_resolver()) {
95 host_resolver_.reset(new SingleRequestHostResolver( 96 host_resolver_ = proxy_script_fetcher->GetRequestContext()->host_resolver();
96 proxy_script_fetcher->GetRequestContext()->host_resolver()));
97 } 97 }
98 } 98 }
99 99
100 ProxyScriptDecider::~ProxyScriptDecider() { 100 ProxyScriptDecider::~ProxyScriptDecider() {
101 if (next_state_ != STATE_NONE) 101 if (next_state_ != STATE_NONE)
102 Cancel(); 102 Cancel();
103 } 103 }
104 104
105 int ProxyScriptDecider::Start( 105 int ProxyScriptDecider::Start(
106 const ProxyConfig& config, const base::TimeDelta wait_delay, 106 const ProxyConfig& config, const base::TimeDelta wait_delay,
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 } 244 }
245 if (quick_check_enabled_ && current_pac_source().type == PacSource::WPAD_DNS) 245 if (quick_check_enabled_ && current_pac_source().type == PacSource::WPAD_DNS)
246 next_state_ = STATE_QUICK_CHECK; 246 next_state_ = STATE_QUICK_CHECK;
247 else 247 else
248 next_state_ = GetStartState(); 248 next_state_ = GetStartState();
249 return OK; 249 return OK;
250 } 250 }
251 251
252 int ProxyScriptDecider::DoQuickCheck() { 252 int ProxyScriptDecider::DoQuickCheck() {
253 DCHECK(quick_check_enabled_); 253 DCHECK(quick_check_enabled_);
254 if (host_resolver_.get() == NULL) { 254 if (host_resolver_ == nullptr) {
255 // If we have no resolver, skip QuickCheck altogether. 255 // If we have no resolver, skip QuickCheck altogether.
256 next_state_ = GetStartState(); 256 next_state_ = GetStartState();
257 return OK; 257 return OK;
258 } 258 }
259 259
260 quick_check_start_time_ = base::Time::Now(); 260 quick_check_start_time_ = base::Time::Now();
261 std::string host = current_pac_source().url.host(); 261 std::string host = current_pac_source().url.host();
262 HostResolver::RequestInfo reqinfo(HostPortPair(host, 80)); 262 HostResolver::RequestInfo reqinfo(HostPortPair(host, 80));
263 reqinfo.set_host_resolver_flags(HOST_RESOLVER_SYSTEM_ONLY); 263 reqinfo.set_host_resolver_flags(HOST_RESOLVER_SYSTEM_ONLY);
264 CompletionCallback callback = base::Bind( 264 CompletionCallback callback = base::Bind(
265 &ProxyScriptDecider::OnIOCompletion, 265 &ProxyScriptDecider::OnIOCompletion,
266 base::Unretained(this)); 266 base::Unretained(this));
267 267
268 next_state_ = STATE_QUICK_CHECK_COMPLETE; 268 next_state_ = STATE_QUICK_CHECK_COMPLETE;
269 quick_check_timer_.Start(FROM_HERE, 269 quick_check_timer_.Start(FROM_HERE,
270 base::TimeDelta::FromMilliseconds( 270 base::TimeDelta::FromMilliseconds(
271 kQuickCheckDelayMs), 271 kQuickCheckDelayMs),
272 base::Bind(callback, ERR_NAME_NOT_RESOLVED)); 272 base::Bind(callback, ERR_NAME_NOT_RESOLVED));
273 273
274 // We use HIGHEST here because proxy decision blocks doing any other requests. 274 // We use HIGHEST here because proxy decision blocks doing any other requests.
275 return host_resolver_->Resolve(reqinfo, HIGHEST, &wpad_addresses_, 275 return host_resolver_->Resolve(reqinfo, HIGHEST, &wpad_addresses_, callback,
276 callback, net_log_); 276 &request_, net_log_);
277 } 277 }
278 278
279 int ProxyScriptDecider::DoQuickCheckComplete(int result) { 279 int ProxyScriptDecider::DoQuickCheckComplete(int result) {
280 DCHECK(quick_check_enabled_); 280 DCHECK(quick_check_enabled_);
281 base::TimeDelta delta = base::Time::Now() - quick_check_start_time_; 281 base::TimeDelta delta = base::Time::Now() - quick_check_start_time_;
282 if (result == OK) 282 if (result == OK)
283 UMA_HISTOGRAM_TIMES("Net.WpadQuickCheckSuccess", delta); 283 UMA_HISTOGRAM_TIMES("Net.WpadQuickCheckSuccess", delta);
284 else 284 else
285 UMA_HISTOGRAM_TIMES("Net.WpadQuickCheckFailure", delta); 285 UMA_HISTOGRAM_TIMES("Net.WpadQuickCheckFailure", delta);
286 host_resolver_->Cancel(); 286 request_.reset();
287 quick_check_timer_.Stop(); 287 quick_check_timer_.Stop();
288 if (result != OK) 288 if (result != OK)
289 return TryToFallbackPacSource(result); 289 return TryToFallbackPacSource(result);
290 next_state_ = GetStartState(); 290 next_state_ = GetStartState();
291 return result; 291 return result;
292 } 292 }
293 293
294 int ProxyScriptDecider::DoFetchPacScript() { 294 int ProxyScriptDecider::DoFetchPacScript() {
295 DCHECK(fetch_pac_bytes_); 295 DCHECK(fetch_pac_bytes_);
296 296
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 } 472 }
473 473
474 // This is safe to call in any state. 474 // This is safe to call in any state.
475 if (dhcp_proxy_script_fetcher_) 475 if (dhcp_proxy_script_fetcher_)
476 dhcp_proxy_script_fetcher_->Cancel(); 476 dhcp_proxy_script_fetcher_->Cancel();
477 477
478 DidComplete(); 478 DidComplete();
479 } 479 }
480 480
481 } // namespace net 481 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_script_decider.h ('k') | net/quic/chromium/quic_stream_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698