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