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

Unified Diff: net/proxy/proxy_script_decider.cc

Issue 23181010: Fast-fail WPAD detection. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Move STATE_QUICK_CHECK after STATE_WAIT Created 7 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 side-by-side diff with in-line comments
Download patch
« net/proxy/proxy_script_decider.h ('K') | « net/proxy/proxy_script_decider.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/proxy/proxy_script_decider.cc
diff --git a/net/proxy/proxy_script_decider.cc b/net/proxy/proxy_script_decider.cc
index 38bf751cd4da3e3c89ccdacbe079854911e1c058..3af695a7369479e80f0801ea6b7f6cf550f0bb5d 100644
--- a/net/proxy/proxy_script_decider.cc
+++ b/net/proxy/proxy_script_decider.cc
@@ -9,6 +9,7 @@
#include "base/compiler_specific.h"
#include "base/format_macros.h"
#include "base/logging.h"
+#include "base/metrics/histogram.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
@@ -16,6 +17,7 @@
#include "net/proxy/dhcp_proxy_script_fetcher.h"
#include "net/proxy/dhcp_proxy_script_fetcher_factory.h"
#include "net/proxy/proxy_script_fetcher.h"
+#include "net/url_request/url_request_context.h"
namespace net {
@@ -47,6 +49,8 @@ bool LooksLikePacScript(const base::string16& script) {
// http://code.google.com/p/chromium/issues/detail?id=18575#c20
static const char kWpadUrl[] = "http://wpad/wpad.dat";
+static const int kQuickCheckDelayMs = 1000;
+
base::Value* ProxyScriptDecider::PacSource::NetLogCallback(
const GURL* effective_pac_url,
NetLog::LogLevel /* log_level */) const {
@@ -81,7 +85,9 @@ ProxyScriptDecider::ProxyScriptDecider(
next_state_(STATE_NONE),
net_log_(BoundNetLog::Make(
net_log, NetLog::SOURCE_PROXY_SCRIPT_DECIDER)),
- fetch_pac_bytes_(false) {
+ fetch_pac_bytes_(false),
+ host_resolver_(
+ proxy_script_fetcher->GetRequestContext()->host_resolver()) {
}
ProxyScriptDecider::~ProxyScriptDecider() {
@@ -172,6 +178,13 @@ int ProxyScriptDecider::DoLoop(int result) {
case STATE_WAIT_COMPLETE:
rv = DoWaitComplete(rv);
break;
+ case STATE_QUICK_CHECK:
+ DCHECK_EQ(OK, rv);
+ rv = DoQuickCheck();
+ break;
+ case STATE_QUICK_CHECK_COMPLETE:
+ rv = DoQuickCheckComplete(rv);
+ break;
case STATE_FETCH_PAC_SCRIPT:
DCHECK_EQ(OK, rv);
rv = DoFetchPacScript();
@@ -201,6 +214,45 @@ void ProxyScriptDecider::DoCallback(int result) {
callback_.Run(result);
}
+int ProxyScriptDecider::DoQuickCheck() {
szym 2013/08/23 20:45:57 nit: Move both after DoWait() (to match my nit reg
Elly Fong-Jones 2013/08/26 15:17:29 Done.
+ quick_check_started_ = base::Time::Now();
+ HostResolver::RequestInfo reqinfo(HostPortPair("wpad", 80));
+ CompletionCallback callback = base::Bind(
+ &ProxyScriptDecider::OnIOCompletion,
+ base::Unretained(this));
+
+ int rv = host_resolver_.Resolve(reqinfo, HIGHEST, // we block startup...
szym 2013/08/23 20:45:57 nit: suggest putting this comment above this line.
Elly Fong-Jones 2013/08/26 15:17:29 Done.
+ &wpad_addrs_, callback, net_log_);
+
+ // we can't get an error response - the name is known to be valid, and we
+ // don't cache negative dns responses.
+ CHECK(rv == OK || rv == ERR_IO_PENDING);
+
+ if (rv == OK) {
+ // already in cache or something and valid, we're golden
+ next_state_ = STATE_FETCH_PAC_SCRIPT;
szym 2013/08/23 20:45:57 Perhaps this should be GetStartState()... ... but
+ return OK;
+ }
+
+ quick_check_timer_.Start(FROM_HERE,
+ base::TimeDelta::FromMilliseconds(
+ kQuickCheckDelayMs),
+ base::Bind(callback, ERR_NAME_NOT_RESOLVED));
+
+ next_state_ = STATE_QUICK_CHECK_COMPLETE;
+ return ERR_IO_PENDING;
+}
+
+int ProxyScriptDecider::DoQuickCheckComplete(int result) {
+ base::TimeDelta delta = base::Time::Now()
+ - quick_check_started_;
+ UMA_HISTOGRAM_TIMES("Net.WpadQuickCheck", delta);
+ host_resolver_.Cancel();
+ quick_check_timer_.Stop();
+ next_state_ = result == OK ? GetStartState() : STATE_NONE;
+ return result;
+}
+
int ProxyScriptDecider::DoWait() {
next_state_ = STATE_WAIT_COMPLETE;
@@ -221,7 +273,7 @@ int ProxyScriptDecider::DoWaitComplete(int result) {
net_log_.EndEventWithNetErrorCode(NetLog::TYPE_PROXY_SCRIPT_DECIDER_WAIT,
result);
}
- next_state_ = GetStartState();
+ next_state_ = STATE_QUICK_CHECK;
return OK;
}
@@ -399,6 +451,8 @@ void ProxyScriptDecider::Cancel() {
case STATE_FETCH_PAC_SCRIPT_COMPLETE:
proxy_script_fetcher_->Cancel();
break;
+ case STATE_FAILED:
+ break;
default:
NOTREACHED();
break;
« net/proxy/proxy_script_decider.h ('K') | « net/proxy/proxy_script_decider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698