Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "chrome/browser/net/dns_probe_job.h" | 5 #include "chrome/browser/net/dns_probe_job.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 using net::BoundNetLog; | 22 using net::BoundNetLog; |
| 23 using net::DnsClient; | 23 using net::DnsClient; |
| 24 using net::DnsResponse; | 24 using net::DnsResponse; |
| 25 using net::DnsTransaction; | 25 using net::DnsTransaction; |
| 26 using net::NetLog; | 26 using net::NetLog; |
| 27 | 27 |
| 28 namespace chrome_browser_net { | 28 namespace chrome_browser_net { |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 // Returns true if the given net_error indicates that we received a response | |
| 33 // from the DNS server containing an error, or false if the given net_error | |
| 34 // indicates that we never received a response. | |
| 35 static bool IsDnsServerError(int net_error) { | |
|
szym
2012/12/11 21:05:31
no need for static
szym
2012/12/11 21:05:31
The name is a bit misleading. Some of those errors
Deprecated (see juliatuttle)
2012/12/11 23:54:03
Done.
Deprecated (see juliatuttle)
2012/12/11 23:54:03
What's a better name? DoesErrorMeanServerResponde
szym
2012/12/12 01:13:14
DidReceiveDnsResponse()
This is a local name so d
mmenke
2012/12/12 17:01:19
Alternatively, you could name this DnsErrorToQuery
| |
| 36 switch (net_error) { | |
| 37 case net::ERR_NAME_NOT_RESOLVED: // NXDOMAIN maps to this. | |
| 38 case net::ERR_DNS_MALFORMED_RESPONSE: | |
|
szym
2012/12/11 21:05:31
This one is tricky. If DnsTransaction receives a r
Deprecated (see juliatuttle)
2012/12/11 23:54:03
This is mostly fine. Our primary goal is to diffe
| |
| 39 case net::ERR_DNS_SERVER_REQUIRES_TCP: | |
| 40 case net::ERR_DNS_SERVER_FAILED: | |
| 41 case net::ERR_DNS_SORT_ERROR: // Can only happen if the server responds. | |
| 42 return true; | |
| 43 default: | |
| 44 return false; | |
|
szym
2012/12/11 21:05:31
One of the issues with retransmissions within DnsT
Deprecated (see juliatuttle)
2012/12/11 23:54:03
Why do we retry on NXDOMAIN?
szym
2012/12/12 01:13:14
Misspoke. We don't retry NXDOMAIN, but we suffix s
| |
| 45 } | |
| 46 } | |
| 47 | |
| 32 class DnsProbeJobImpl : public DnsProbeJob { | 48 class DnsProbeJobImpl : public DnsProbeJob { |
| 33 public: | 49 public: |
| 34 DnsProbeJobImpl(scoped_ptr<DnsClient> dns_client, | 50 DnsProbeJobImpl(scoped_ptr<DnsClient> dns_client, |
| 35 const DnsProbeJob::CallbackType& callback, | 51 const DnsProbeJob::CallbackType& callback, |
| 36 NetLog* net_log); | 52 NetLog* net_log); |
| 37 virtual ~DnsProbeJobImpl(); | 53 virtual ~DnsProbeJobImpl(); |
| 38 | 54 |
| 39 private: | 55 private: |
| 40 enum QueryResult { | 56 enum QueryResult { |
| 41 QUERY_UNKNOWN, | 57 QUERY_UNKNOWN, |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 OnTransactionComplete(transaction, rv, NULL); | 148 OnTransactionComplete(transaction, rv, NULL); |
| 133 } | 149 } |
| 134 | 150 |
| 135 // TODO(ttuttle): Log transaction started. | 151 // TODO(ttuttle): Log transaction started. |
| 136 } | 152 } |
| 137 | 153 |
| 138 DnsProbeJobImpl::QueryResult DnsProbeJobImpl::EvaluateGoodResponse( | 154 DnsProbeJobImpl::QueryResult DnsProbeJobImpl::EvaluateGoodResponse( |
| 139 int net_error, | 155 int net_error, |
| 140 const DnsResponse* response) { | 156 const DnsResponse* response) { |
| 141 if (net_error != net::OK) | 157 if (net_error != net::OK) |
| 142 return QUERY_NET_ERROR; | 158 return IsDnsServerError(net_error) ? QUERY_DNS_ERROR : QUERY_NET_ERROR; |
| 143 | 159 |
| 144 AddressList addr_list; | 160 AddressList addr_list; |
| 145 TimeDelta ttl; | 161 TimeDelta ttl; |
| 146 DnsResponse::Result result = response->ParseToAddressList(&addr_list, &ttl); | 162 DnsResponse::Result result = response->ParseToAddressList(&addr_list, &ttl); |
| 147 | 163 |
| 148 if (result != DnsResponse::DNS_PARSE_OK) | 164 if (result != DnsResponse::DNS_PARSE_OK) |
| 149 return QUERY_DNS_ERROR; | 165 return QUERY_DNS_ERROR; |
| 150 | 166 |
| 151 if (addr_list.empty()) | 167 if (addr_list.empty()) |
| 152 return QUERY_INCORRECT; | 168 return QUERY_INCORRECT; |
| 153 | 169 |
| 154 return QUERY_CORRECT; | 170 return QUERY_CORRECT; |
| 155 } | 171 } |
| 156 | 172 |
| 157 DnsProbeJobImpl::QueryResult DnsProbeJobImpl::EvaluateBadResponse( | 173 DnsProbeJobImpl::QueryResult DnsProbeJobImpl::EvaluateBadResponse( |
| 158 int net_error, | 174 int net_error, |
| 159 const DnsResponse* response) { | 175 const DnsResponse* response) { |
| 160 if (net_error == net::ERR_NAME_NOT_RESOLVED) // NXDOMAIN maps to this | 176 if (net_error == net::ERR_NAME_NOT_RESOLVED) // NXDOMAIN maps to this |
| 161 return QUERY_CORRECT; | 177 return QUERY_CORRECT; |
| 162 | 178 |
| 163 // TODO(ttuttle): Examine net_error a little more closely to see whether | |
| 164 // it's a DNS error or a network error. | |
| 165 if (net_error != net::OK) | 179 if (net_error != net::OK) |
| 166 return QUERY_NET_ERROR; | 180 return IsDnsServerError(net_error) ? QUERY_DNS_ERROR : QUERY_NET_ERROR; |
| 167 | 181 |
| 168 return QUERY_INCORRECT; | 182 return QUERY_INCORRECT; |
| 169 } | 183 } |
| 170 | 184 |
| 171 DnsProbeJob::Result DnsProbeJobImpl::EvaluateQueryResults() { | 185 DnsProbeJob::Result DnsProbeJobImpl::EvaluateQueryResults() { |
| 172 if (good_result_ == QUERY_NET_ERROR || bad_result_ == QUERY_NET_ERROR) | 186 if (good_result_ == QUERY_NET_ERROR || bad_result_ == QUERY_NET_ERROR) |
| 173 return SERVERS_UNREACHABLE; | 187 return SERVERS_UNREACHABLE; |
| 174 | 188 |
| 175 if (good_result_ == QUERY_DNS_ERROR || bad_result_ == QUERY_DNS_ERROR) | 189 if (good_result_ == QUERY_DNS_ERROR || bad_result_ == QUERY_DNS_ERROR) |
| 176 return SERVERS_FAILING; | 190 return SERVERS_FAILING; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 | 227 |
| 214 scoped_ptr<DnsProbeJob> DnsProbeJob::CreateJob( | 228 scoped_ptr<DnsProbeJob> DnsProbeJob::CreateJob( |
| 215 scoped_ptr<DnsClient> dns_client, | 229 scoped_ptr<DnsClient> dns_client, |
| 216 const CallbackType& callback, | 230 const CallbackType& callback, |
| 217 NetLog* net_log) { | 231 NetLog* net_log) { |
| 218 return scoped_ptr<DnsProbeJob>( | 232 return scoped_ptr<DnsProbeJob>( |
| 219 new DnsProbeJobImpl(dns_client.Pass(), callback, net_log)); | 233 new DnsProbeJobImpl(dns_client.Pass(), callback, net_log)); |
| 220 } | 234 } |
| 221 | 235 |
| 222 } // namespace chrome_browser_net | 236 } // namespace chrome_browser_net |
| OLD | NEW |