| 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 "net/dns/dns_config_service.h" | 5 #include "net/dns/dns_config_service.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/histogram.h" |
| 8 #include "base/values.h" | 9 #include "base/values.h" |
| 9 #include "net/base/ip_endpoint.h" | 10 #include "net/base/ip_endpoint.h" |
| 10 | 11 |
| 11 namespace net { | 12 namespace net { |
| 12 | 13 |
| 13 // Default values are taken from glibc resolv.h. | 14 // Default values are taken from glibc resolv.h. |
| 14 DnsConfig::DnsConfig() | 15 DnsConfig::DnsConfig() |
| 15 : append_to_multi_label_name(true), | 16 : append_to_multi_label_name(true), |
| 16 ndots(1), | 17 ndots(1), |
| 17 timeout(base::TimeDelta::FromSeconds(5)), | 18 timeout(base::TimeDelta::FromSeconds(5)), |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 DCHECK(callback_.is_null()); | 98 DCHECK(callback_.is_null()); |
| 98 NetworkChangeNotifier::AddDNSObserver(this); | 99 NetworkChangeNotifier::AddDNSObserver(this); |
| 99 callback_ = callback; | 100 callback_ = callback; |
| 100 if (NetworkChangeNotifier::IsWatchingDNS()) | 101 if (NetworkChangeNotifier::IsWatchingDNS()) |
| 101 OnDNSChanged(NetworkChangeNotifier::CHANGE_DNS_WATCH_STARTED); | 102 OnDNSChanged(NetworkChangeNotifier::CHANGE_DNS_WATCH_STARTED); |
| 102 // else: Wait until signal before reading. | 103 // else: Wait until signal before reading. |
| 103 } | 104 } |
| 104 | 105 |
| 105 void DnsConfigService::InvalidateConfig() { | 106 void DnsConfigService::InvalidateConfig() { |
| 106 DCHECK(CalledOnValidThread()); | 107 DCHECK(CalledOnValidThread()); |
| 108 base::TimeTicks now = base::TimeTicks::Now(); |
| 109 if (!last_invalidate_config_time_.is_null()) { |
| 110 UMA_HISTOGRAM_LONG_TIMES("AsyncDNS.ConfigNotifyInterval", |
| 111 now - last_invalidate_config_time_); |
| 112 } |
| 113 last_invalidate_config_time_ = now; |
| 107 if (!have_config_) | 114 if (!have_config_) |
| 108 return; | 115 return; |
| 109 have_config_ = false; | 116 have_config_ = false; |
| 110 StartTimer(); | 117 StartTimer(); |
| 111 } | 118 } |
| 112 | 119 |
| 113 void DnsConfigService::InvalidateHosts() { | 120 void DnsConfigService::InvalidateHosts() { |
| 114 DCHECK(CalledOnValidThread()); | 121 DCHECK(CalledOnValidThread()); |
| 122 base::TimeTicks now = base::TimeTicks::Now(); |
| 123 if (!last_invalidate_hosts_time_.is_null()) { |
| 124 UMA_HISTOGRAM_LONG_TIMES("AsyncDNS.HostsNotifyInterval", |
| 125 now - last_invalidate_hosts_time_); |
| 126 } |
| 127 last_invalidate_hosts_time_ = now; |
| 115 if (!have_hosts_) | 128 if (!have_hosts_) |
| 116 return; | 129 return; |
| 117 have_hosts_ = false; | 130 have_hosts_ = false; |
| 118 StartTimer(); | 131 StartTimer(); |
| 119 } | 132 } |
| 120 | 133 |
| 121 void DnsConfigService::OnConfigRead(const DnsConfig& config) { | 134 void DnsConfigService::OnConfigRead(const DnsConfig& config) { |
| 122 DCHECK(CalledOnValidThread()); | 135 DCHECK(CalledOnValidThread()); |
| 123 DCHECK(config.IsValid()); | 136 DCHECK(config.IsValid()); |
| 124 | 137 |
| 138 bool changed = false; |
| 125 if (!config.EqualsIgnoreHosts(dns_config_)) { | 139 if (!config.EqualsIgnoreHosts(dns_config_)) { |
| 126 dns_config_.CopyIgnoreHosts(config); | 140 dns_config_.CopyIgnoreHosts(config); |
| 127 need_update_ = true; | 141 need_update_ = true; |
| 142 changed = true; |
| 128 } | 143 } |
| 144 if (!changed && !last_sent_empty_time_.is_null()) { |
| 145 UMA_HISTOGRAM_LONG_TIMES("AsyncDNS.UnchangedConfigInterval", |
| 146 base::TimeTicks::Now() - last_sent_empty_time_); |
| 147 } |
| 148 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.ConfigChange", changed); |
| 129 | 149 |
| 130 have_config_ = true; | 150 have_config_ = true; |
| 131 if (have_hosts_) | 151 if (have_hosts_) |
| 132 OnCompleteConfig(); | 152 OnCompleteConfig(); |
| 133 } | 153 } |
| 134 | 154 |
| 135 void DnsConfigService::OnHostsRead(const DnsHosts& hosts) { | 155 void DnsConfigService::OnHostsRead(const DnsHosts& hosts) { |
| 136 DCHECK(CalledOnValidThread()); | 156 DCHECK(CalledOnValidThread()); |
| 137 | 157 |
| 158 bool changed = false; |
| 138 if (hosts != dns_config_.hosts) { | 159 if (hosts != dns_config_.hosts) { |
| 139 dns_config_.hosts = hosts; | 160 dns_config_.hosts = hosts; |
| 140 need_update_ = true; | 161 need_update_ = true; |
| 162 changed = true; |
| 141 } | 163 } |
| 164 if (!changed && !last_sent_empty_time_.is_null()) { |
| 165 UMA_HISTOGRAM_LONG_TIMES("AsyncDNS.UnchangedHostsInterval", |
| 166 base::TimeTicks::Now() - last_sent_empty_time_); |
| 167 } |
| 168 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.HostsChange", changed); |
| 142 | 169 |
| 143 have_hosts_ = true; | 170 have_hosts_ = true; |
| 144 if (have_config_) | 171 if (have_config_) |
| 145 OnCompleteConfig(); | 172 OnCompleteConfig(); |
| 146 } | 173 } |
| 147 | 174 |
| 148 void DnsConfigService::StartTimer() { | 175 void DnsConfigService::StartTimer() { |
| 149 DCHECK(CalledOnValidThread()); | 176 DCHECK(CalledOnValidThread()); |
| 150 if (last_sent_empty_) { | 177 if (last_sent_empty_) { |
| 151 DCHECK(!timer_.IsRunning()); | 178 DCHECK(!timer_.IsRunning()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 171 } | 198 } |
| 172 | 199 |
| 173 void DnsConfigService::OnTimeout() { | 200 void DnsConfigService::OnTimeout() { |
| 174 DCHECK(CalledOnValidThread()); | 201 DCHECK(CalledOnValidThread()); |
| 175 DCHECK(!last_sent_empty_); | 202 DCHECK(!last_sent_empty_); |
| 176 // Indicate that even if there is no change in On*Read, we will need to | 203 // Indicate that even if there is no change in On*Read, we will need to |
| 177 // update the receiver when the config becomes complete. | 204 // update the receiver when the config becomes complete. |
| 178 need_update_ = true; | 205 need_update_ = true; |
| 179 // Empty config is considered invalid. | 206 // Empty config is considered invalid. |
| 180 last_sent_empty_ = true; | 207 last_sent_empty_ = true; |
| 208 last_sent_empty_time_ = base::TimeTicks::Now(); |
| 181 callback_.Run(DnsConfig()); | 209 callback_.Run(DnsConfig()); |
| 182 } | 210 } |
| 183 | 211 |
| 184 void DnsConfigService::OnCompleteConfig() { | 212 void DnsConfigService::OnCompleteConfig() { |
| 185 timer_.Stop(); | 213 timer_.Stop(); |
| 186 if (!need_update_) | 214 if (!need_update_) |
| 187 return; | 215 return; |
| 188 need_update_ = false; | 216 need_update_ = false; |
| 189 last_sent_empty_ = false; | 217 last_sent_empty_ = false; |
| 190 callback_.Run(dns_config_); | 218 callback_.Run(dns_config_); |
| 191 } | 219 } |
| 192 | 220 |
| 193 } // namespace net | 221 } // namespace net |
| 194 | 222 |
| OLD | NEW |