Author:
ttu...@chromium.org
Date: Wed Dec 12 18:21:59 2012
New Revision: 172780
Log:
DnsProbeJob: Differentiate network and DNS errors
DnsTransaction uses net_error to return errors returned by the remote DNS
server as well as local errors encountered trying to talk to the server (like
timeouts). Make note of which net errors mean that we received a response
from the DNS server, and mark those as "failing" instead of "unreachable".
Also, add another behavior to mock DNS transactions so we can test cases where
the server is unreachable.
BUG=156415
TEST=updated DnsProbeJobTest with a new case
Review URL:
https://chromiumcodereview.appspot.com/11530018
Modified:
trunk/src/chrome/browser/net/dns_probe_job.cc
trunk/src/chrome/browser/net/dns_probe_job_unittest.cc
trunk/src/net/dns/dns_test_util.cc
trunk/src/net/dns/dns_test_util.h
Modified: trunk/src/chrome/browser/net/dns_probe_job.cc
==============================================================================
--- trunk/src/chrome/browser/net/dns_probe_job.cc (original)
+++ trunk/src/chrome/browser/net/dns_probe_job.cc Wed Dec 12 18:21:59 2012
@@ -29,6 +29,22 @@
namespace {
+// Returns true if the given net_error indicates that we received a response
+// from the DNS server containing an error, or false if the given net_error
+// indicates that we never received a response.
+bool DidReceiveDnsResponse(int net_error) {
+ switch (net_error) {
+ case net::ERR_NAME_NOT_RESOLVED: // NXDOMAIN maps to this.
+ case net::ERR_DNS_MALFORMED_RESPONSE:
+ case net::ERR_DNS_SERVER_REQUIRES_TCP:
+ case net::ERR_DNS_SERVER_FAILED:
+ case net::ERR_DNS_SORT_ERROR: // Can only happen if the server responds.
+ return true;
+ default:
+ return false;
+ }
+}
+
class DnsProbeJobImpl : public DnsProbeJob {
public:
DnsProbeJobImpl(scoped_ptr<DnsClient> dns_client,
@@ -139,7 +155,7 @@
int net_error,
const DnsResponse* response) {
if (net_error != net::OK)
- return QUERY_NET_ERROR;
+ return DidReceiveDnsResponse(net_error) ? QUERY_DNS_ERROR : QUERY_NET_ERROR;
AddressList addr_list;
TimeDelta ttl;
@@ -160,10 +176,8 @@
if (net_error == net::ERR_NAME_NOT_RESOLVED) // NXDOMAIN maps to this
return QUERY_CORRECT;
- // TODO(ttuttle): Examine net_error a little more closely to see whether
- // it's a DNS error or a network error.
if (net_error != net::OK)
- return QUERY_NET_ERROR;
+ return DidReceiveDnsResponse(net_error) ? QUERY_DNS_ERROR : QUERY_NET_ERROR;
return QUERY_INCORRECT;
}
Modified: trunk/src/chrome/browser/net/dns_probe_job_unittest.cc
==============================================================================
--- trunk/src/chrome/browser/net/dns_probe_job_unittest.cc (original)
+++ trunk/src/chrome/browser/net/dns_probe_job_unittest.cc Wed Dec 12 18:21:59 2012
@@ -106,9 +106,12 @@
// (Need to add another mock behavior to MockDnsClient.)
{ MockDnsClientRule::FAIL_ASYNC,
MockDnsClientRule::FAIL_ASYNC,
- DnsProbeJob::SERVERS_UNREACHABLE },
+ DnsProbeJob::SERVERS_FAILING },
{ MockDnsClientRule::FAIL_SYNC,
MockDnsClientRule::FAIL_SYNC,
+ DnsProbeJob::SERVERS_FAILING },
+ { MockDnsClientRule::TIMEOUT,
+ MockDnsClientRule::TIMEOUT,
DnsProbeJob::SERVERS_UNREACHABLE },
};
for (size_t i = 0; i < arraysize(kTestCases); i++) {
Modified: trunk/src/net/dns/dns_test_util.cc
==============================================================================
--- trunk/src/net/dns/dns_test_util.cc (original)
+++ trunk/src/net/dns/dns_test_util.cc Wed Dec 12 18:21:59 2012
@@ -126,6 +126,9 @@
case MockDnsClientRule::FAIL_ASYNC:
callback_.Run(this, ERR_NAME_NOT_RESOLVED, NULL);
break;
+ case MockDnsClientRule::TIMEOUT:
+ callback_.Run(this, ERR_DNS_TIMED_OUT, NULL);
+ break;
default:
NOTREACHED();
break;
Modified: trunk/src/net/dns/dns_test_util.h
==============================================================================
--- trunk/src/net/dns/dns_test_util.h (original)
+++ trunk/src/net/dns/dns_test_util.h Wed Dec 12 18:21:59 2012
@@ -180,6 +180,7 @@
enum Result {
FAIL_SYNC, // Fail synchronously with ERR_NAME_NOT_RESOLVED.
FAIL_ASYNC, // Fail asynchronously with ERR_NAME_NOT_RESOLVED.
+ TIMEOUT, // Fail asynchronously with ERR_DNS_TIMEOUT.
EMPTY, // Return an empty response.
OK, // Return a response with loopback address.
};