summaryrefslogtreecommitdiffstats
path: root/chrome/browser/net/dns_probe_service.cc
diff options
context:
space:
mode:
authorttuttle@chromium.org <ttuttle@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-20 03:51:30 +0000
committerttuttle@chromium.org <ttuttle@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-20 03:51:30 +0000
commitd99867df5eca85690b93e574d98b297f0dd818ce (patch)
treeb5505c53f2eef63c4c35cb399282040034bf6cf2 /chrome/browser/net/dns_probe_service.cc
parent70ca7775fe7edbe3973e3507c6ca00d26e4df5dc (diff)
downloadchromium_src-d99867df5eca85690b93e574d98b297f0dd818ce.zip
chromium_src-d99867df5eca85690b93e574d98b297f0dd818ce.tar.gz
chromium_src-d99867df5eca85690b93e574d98b297f0dd818ce.tar.bz2
Glue browser-side DNS probing together. We should detect DNS errors on main frame loads, run probes, and get the results, but they won't show error pages yet.
BUG=156415 TEST=extended NetErrorTabHelper test Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=168650 Review URL: https://chromiumcodereview.appspot.com/11363157 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@168716 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/net/dns_probe_service.cc')
-rw-r--r--chrome/browser/net/dns_probe_service.cc48
1 files changed, 42 insertions, 6 deletions
diff --git a/chrome/browser/net/dns_probe_service.cc b/chrome/browser/net/dns_probe_service.cc
index 0d006c3..7b43a4a 100644
--- a/chrome/browser/net/dns_probe_service.cc
+++ b/chrome/browser/net/dns_probe_service.cc
@@ -23,8 +23,8 @@ namespace chrome_browser_net {
namespace {
-const char* kPublicDnsPrimary = "8.8.8.8";
-const char* kPublicDnsSecondary = "8.8.4.4";
+const char kPublicDnsPrimary[] = "8.8.8.8";
+const char kPublicDnsSecondary[] = "8.8.4.4";
IPEndPoint MakeDnsEndPoint(const std::string& dns_ip_literal) {
IPAddressNumber dns_ip_number;
@@ -33,7 +33,9 @@ IPEndPoint MakeDnsEndPoint(const std::string& dns_ip_literal) {
return IPEndPoint(dns_ip_number, net::dns_protocol::kDefaultPort);
}
-}
+const int kMaxResultAgeMs = 5000;
+
+} // namespace
DnsProbeService::DnsProbeService()
: system_result_(DnsProbeJob::SERVERS_UNKNOWN),
@@ -48,7 +50,8 @@ DnsProbeService::~DnsProbeService() {
void DnsProbeService::ProbeDns(const DnsProbeService::CallbackType& callback) {
callbacks_.push_back(callback);
- // TODO(ttuttle): Check for cache expiration.
+ if (state_ == STATE_RESULTS_CACHED && ResultsExpired())
+ ExpireResults();
switch (state_) {
case STATE_NO_RESULTS:
@@ -102,18 +105,45 @@ void DnsProbeService::StartProbes() {
public_job_ = CreatePublicProbeJob(job_callback);
state_ = STATE_PROBE_RUNNING;
+ last_probe_time_ = base::Time::Now();
}
void DnsProbeService::OnProbesComplete() {
DCHECK_EQ(STATE_PROBE_RUNNING, state_);
state_ = STATE_RESULTS_CACHED;
- // TODO(ttuttle): Calculate result.
- result_ = PROBE_NXDOMAIN;
+ result_ = EvaluateResults();
CallCallbacks();
}
+DnsProbeService::Result DnsProbeService::EvaluateResults() {
+ DCHECK_NE(DnsProbeJob::SERVERS_UNKNOWN, system_result_);
+ DCHECK_NE(DnsProbeJob::SERVERS_UNKNOWN, public_result_);
+
+ // If the system DNS is working, assume the domain doesn't exist.
+ if (system_result_ == DnsProbeJob::SERVERS_CORRECT)
+ return PROBE_NXDOMAIN;
+
+ // If the system DNS is not working but another public server is, assume the
+ // DNS config is bad (or perhaps the DNS servers are down or broken).
+ if (public_result_ == DnsProbeJob::SERVERS_CORRECT)
+ return PROBE_BAD_CONFIG;
+
+ // If the system DNS is not working and another public server is unreachable,
+ // assume the internet connection is down (note that system DNS may be a
+ // router on the LAN, so it may be reachable but returning errors.)
+ if (public_result_ == DnsProbeJob::SERVERS_UNREACHABLE)
+ return PROBE_NO_INTERNET;
+
+ // Otherwise: the system DNS is not working and another public server is
+ // responding but with errors or incorrect results. This is an awkward case;
+ // an invasive captive portal or a restrictive firewall may be intercepting
+ // or rewriting DNS traffic, or the public server may itself be failing or
+ // down.
+ return PROBE_UNKNOWN;
+}
+
void DnsProbeService::CallCallbacks() {
DCHECK_EQ(STATE_RESULTS_CACHED, state_);
DCHECK(!callbacks_.empty());
@@ -167,4 +197,10 @@ void DnsProbeService::GetPublicDnsConfig(DnsConfig* config) {
config->nameservers.push_back(MakeDnsEndPoint(kPublicDnsSecondary));
}
+bool DnsProbeService::ResultsExpired() {
+ const base::TimeDelta kMaxResultAge =
+ base::TimeDelta::FromMilliseconds(kMaxResultAgeMs);
+ return base::Time::Now() - last_probe_time_ > kMaxResultAge;
+}
+
} // namespace chrome_browser_net