| 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 <stdint.h> |
| 8 |
| 7 #include <utility> | 9 #include <utility> |
| 8 | 10 |
| 9 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
| 10 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 11 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "net/base/ip_address.h" |
| 12 #include "net/base/ip_endpoint.h" | 15 #include "net/base/ip_endpoint.h" |
| 13 #include "net/dns/dns_client.h" | 16 #include "net/dns/dns_client.h" |
| 14 #include "net/dns/dns_config_service.h" | 17 #include "net/dns/dns_config_service.h" |
| 15 #include "net/dns/dns_protocol.h" | 18 #include "net/dns/dns_protocol.h" |
| 16 | 19 |
| 17 using base::FieldTrialList; | 20 using base::FieldTrialList; |
| 18 using base::StringToInt; | 21 using base::StringToInt; |
| 19 using error_page::DnsProbeStatus; | 22 using error_page::DnsProbeStatus; |
| 20 using net::DnsClient; | 23 using net::DnsClient; |
| 21 using net::DnsConfig; | 24 using net::DnsConfig; |
| 22 using net::IPAddressNumber; | |
| 23 using net::ParseIPLiteralToNumber; | 25 using net::ParseIPLiteralToNumber; |
| 24 using net::NetworkChangeNotifier; | 26 using net::NetworkChangeNotifier; |
| 25 | 27 |
| 26 namespace chrome_browser_net { | 28 namespace chrome_browser_net { |
| 27 | 29 |
| 28 namespace { | 30 namespace { |
| 29 | 31 |
| 30 // How long the DnsProbeService will cache the probe result for. | 32 // 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 | 33 // If it's older than this and we get a probe request, the service expires it |
| 32 // and starts a new probe. | 34 // and starts a new probe. |
| 33 const int kMaxResultAgeMs = 5000; | 35 const int kMaxResultAgeMs = 5000; |
| 34 | 36 |
| 35 // The public DNS servers used by the DnsProbeService to verify internet | 37 // The public DNS servers used by the DnsProbeService to verify internet |
| 36 // connectivity. | 38 // connectivity. |
| 37 const char kGooglePublicDns1[] = "8.8.8.8"; | 39 const uint8_t kGooglePublicDns1[] = {8, 8, 8, 8}; |
| 38 const char kGooglePublicDns2[] = "8.8.4.4"; | 40 const uint8_t kGooglePublicDns2[] = {8, 8, 4, 4}; |
| 39 | |
| 40 net::IPEndPoint MakeDnsEndPoint(const std::string& dns_ip_literal) { | |
| 41 IPAddressNumber dns_ip_number; | |
| 42 bool rv = ParseIPLiteralToNumber(dns_ip_literal, &dns_ip_number); | |
| 43 DCHECK(rv); | |
| 44 return net::IPEndPoint(dns_ip_number, net::dns_protocol::kDefaultPort); | |
| 45 } | |
| 46 | 41 |
| 47 DnsProbeStatus EvaluateResults(DnsProbeRunner::Result system_result, | 42 DnsProbeStatus EvaluateResults(DnsProbeRunner::Result system_result, |
| 48 DnsProbeRunner::Result public_result) { | 43 DnsProbeRunner::Result public_result) { |
| 49 // If the system DNS is working, assume the domain doesn't exist. | 44 // If the system DNS is working, assume the domain doesn't exist. |
| 50 if (system_result == DnsProbeRunner::CORRECT) | 45 if (system_result == DnsProbeRunner::CORRECT) |
| 51 return error_page::DNS_PROBE_FINISHED_NXDOMAIN; | 46 return error_page::DNS_PROBE_FINISHED_NXDOMAIN; |
| 52 | 47 |
| 53 // If the system DNS is unknown (e.g. on Android), but the public server is | 48 // If the system DNS is unknown (e.g. on Android), but the public server is |
| 54 // reachable, assume the domain doesn't exist. | 49 // reachable, assume the domain doesn't exist. |
| 55 if (system_result == DnsProbeRunner::UNKNOWN && | 50 if (system_result == DnsProbeRunner::UNKNOWN && |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 system_config.randomize_ports = false; | 142 system_config.randomize_ports = false; |
| 148 | 143 |
| 149 scoped_ptr<DnsClient> system_client(DnsClient::CreateClient(NULL)); | 144 scoped_ptr<DnsClient> system_client(DnsClient::CreateClient(NULL)); |
| 150 system_client->SetConfig(system_config); | 145 system_client->SetConfig(system_config); |
| 151 | 146 |
| 152 system_runner_.SetClient(std::move(system_client)); | 147 system_runner_.SetClient(std::move(system_client)); |
| 153 } | 148 } |
| 154 | 149 |
| 155 void DnsProbeService::SetPublicClientToGooglePublicDns() { | 150 void DnsProbeService::SetPublicClientToGooglePublicDns() { |
| 156 DnsConfig public_config; | 151 DnsConfig public_config; |
| 157 public_config.nameservers.push_back(MakeDnsEndPoint(kGooglePublicDns1)); | 152 public_config.nameservers.push_back(net::IPEndPoint( |
| 158 public_config.nameservers.push_back(MakeDnsEndPoint(kGooglePublicDns2)); | 153 net::IPAddress(kGooglePublicDns1), net::dns_protocol::kDefaultPort)); |
| 154 public_config.nameservers.push_back(net::IPEndPoint( |
| 155 net::IPAddress(kGooglePublicDns2), net::dns_protocol::kDefaultPort)); |
| 159 public_config.attempts = 1; | 156 public_config.attempts = 1; |
| 160 public_config.randomize_ports = false; | 157 public_config.randomize_ports = false; |
| 161 | 158 |
| 162 scoped_ptr<DnsClient> public_client(DnsClient::CreateClient(NULL)); | 159 scoped_ptr<DnsClient> public_client(DnsClient::CreateClient(NULL)); |
| 163 public_client->SetConfig(public_config); | 160 public_client->SetConfig(public_config); |
| 164 | 161 |
| 165 public_runner_.SetClient(std::move(public_client)); | 162 public_runner_.SetClient(std::move(public_client)); |
| 166 } | 163 } |
| 167 | 164 |
| 168 void DnsProbeService::StartProbes() { | 165 void DnsProbeService::StartProbes() { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 bool DnsProbeService::CachedResultIsExpired() const { | 218 bool DnsProbeService::CachedResultIsExpired() const { |
| 222 if (state_ != STATE_RESULT_CACHED) | 219 if (state_ != STATE_RESULT_CACHED) |
| 223 return false; | 220 return false; |
| 224 | 221 |
| 225 const base::TimeDelta kMaxResultAge = | 222 const base::TimeDelta kMaxResultAge = |
| 226 base::TimeDelta::FromMilliseconds(kMaxResultAgeMs); | 223 base::TimeDelta::FromMilliseconds(kMaxResultAgeMs); |
| 227 return base::Time::Now() - probe_start_time_ > kMaxResultAge; | 224 return base::Time::Now() - probe_start_time_ > kMaxResultAge; |
| 228 } | 225 } |
| 229 | 226 |
| 230 } // namespace chrome_browser_net | 227 } // namespace chrome_browser_net |
| OLD | NEW |