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_service.h" | 5 #include "chrome/browser/net/dns_probe_service.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "net/base/ip_address.h" | |
| 12 #include "net/base/ip_endpoint.h" | 13 #include "net/base/ip_endpoint.h" |
| 13 #include "net/dns/dns_client.h" | 14 #include "net/dns/dns_client.h" |
| 14 #include "net/dns/dns_config_service.h" | 15 #include "net/dns/dns_config_service.h" |
| 15 #include "net/dns/dns_protocol.h" | 16 #include "net/dns/dns_protocol.h" |
| 16 | 17 |
| 17 using base::FieldTrialList; | 18 using base::FieldTrialList; |
| 18 using base::StringToInt; | 19 using base::StringToInt; |
| 19 using error_page::DnsProbeStatus; | 20 using error_page::DnsProbeStatus; |
| 20 using net::DnsClient; | 21 using net::DnsClient; |
| 21 using net::DnsConfig; | 22 using net::DnsConfig; |
| 22 using net::IPAddressNumber; | 23 using net::IPAddress; |
| 23 using net::ParseIPLiteralToNumber; | 24 using net::ParseIPLiteralToNumber; |
| 24 using net::NetworkChangeNotifier; | 25 using net::NetworkChangeNotifier; |
| 25 | 26 |
| 26 namespace chrome_browser_net { | 27 namespace chrome_browser_net { |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 // How long the DnsProbeService will cache the probe result for. | 31 // How long the DnsProbeService will cache the probe result for. |
| 31 // If it's older than this and we get a probe request, the service expires it | 32 // If it's older than this and we get a probe request, the service expires it |
| 32 // and starts a new probe. | 33 // and starts a new probe. |
| 33 const int kMaxResultAgeMs = 5000; | 34 const int kMaxResultAgeMs = 5000; |
| 34 | 35 |
| 35 // The public DNS servers used by the DnsProbeService to verify internet | 36 // The public DNS servers used by the DnsProbeService to verify internet |
| 36 // connectivity. | 37 // connectivity. |
| 37 const char kGooglePublicDns1[] = "8.8.8.8"; | 38 const char kGooglePublicDns1[] = "8.8.8.8"; |
| 38 const char kGooglePublicDns2[] = "8.8.4.4"; | 39 const char kGooglePublicDns2[] = "8.8.4.4"; |
| 39 | 40 |
| 40 net::IPEndPoint MakeDnsEndPoint(const std::string& dns_ip_literal) { | 41 net::IPEndPoint MakeDnsEndPoint(const std::string& dns_ip_literal) { |
| 41 IPAddressNumber dns_ip_number; | 42 IPAddress dns_ip_address; |
| 42 bool rv = ParseIPLiteralToNumber(dns_ip_literal, &dns_ip_number); | 43 bool rv = dns_ip_address.AssignFromIPLiteral(dns_ip_literal); |
|
eroman
2016/03/15 22:30:17
We can probably replace this whole thing with some
martijnc
2016/03/16 20:01:04
Done. Seems a good idea to avoid the AssignFromIPl
| |
| 43 DCHECK(rv); | 44 DCHECK(rv); |
| 44 return net::IPEndPoint(dns_ip_number, net::dns_protocol::kDefaultPort); | 45 return net::IPEndPoint(dns_ip_address, net::dns_protocol::kDefaultPort); |
| 45 } | 46 } |
| 46 | 47 |
| 47 DnsProbeStatus EvaluateResults(DnsProbeRunner::Result system_result, | 48 DnsProbeStatus EvaluateResults(DnsProbeRunner::Result system_result, |
| 48 DnsProbeRunner::Result public_result) { | 49 DnsProbeRunner::Result public_result) { |
| 49 // If the system DNS is working, assume the domain doesn't exist. | 50 // If the system DNS is working, assume the domain doesn't exist. |
| 50 if (system_result == DnsProbeRunner::CORRECT) | 51 if (system_result == DnsProbeRunner::CORRECT) |
| 51 return error_page::DNS_PROBE_FINISHED_NXDOMAIN; | 52 return error_page::DNS_PROBE_FINISHED_NXDOMAIN; |
| 52 | 53 |
| 53 // If the system DNS is unknown (e.g. on Android), but the public server is | 54 // If the system DNS is unknown (e.g. on Android), but the public server is |
| 54 // reachable, assume the domain doesn't exist. | 55 // reachable, assume the domain doesn't exist. |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 bool DnsProbeService::CachedResultIsExpired() const { | 222 bool DnsProbeService::CachedResultIsExpired() const { |
| 222 if (state_ != STATE_RESULT_CACHED) | 223 if (state_ != STATE_RESULT_CACHED) |
| 223 return false; | 224 return false; |
| 224 | 225 |
| 225 const base::TimeDelta kMaxResultAge = | 226 const base::TimeDelta kMaxResultAge = |
| 226 base::TimeDelta::FromMilliseconds(kMaxResultAgeMs); | 227 base::TimeDelta::FromMilliseconds(kMaxResultAgeMs); |
| 227 return base::Time::Now() - probe_start_time_ > kMaxResultAge; | 228 return base::Time::Now() - probe_start_time_ > kMaxResultAge; |
| 228 } | 229 } |
| 229 | 230 |
| 230 } // namespace chrome_browser_net | 231 } // namespace chrome_browser_net |
| OLD | NEW |