| 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/metrics/histogram.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "net/base/ip_endpoint.h" | 10 #include "net/base/ip_endpoint.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 DCHECK(callback_.is_null()); | 145 DCHECK(callback_.is_null()); |
| 146 NetworkChangeNotifier::AddDNSObserver(this); | 146 NetworkChangeNotifier::AddDNSObserver(this); |
| 147 callback_ = callback; | 147 callback_ = callback; |
| 148 if (NetworkChangeNotifier::IsWatchingDNS()) | 148 if (NetworkChangeNotifier::IsWatchingDNS()) |
| 149 OnDNSChanged(NetworkChangeNotifier::CHANGE_DNS_WATCH_STARTED); | 149 OnDNSChanged(NetworkChangeNotifier::CHANGE_DNS_WATCH_STARTED); |
| 150 // else: Wait until signal before reading. | 150 // else: Wait until signal before reading. |
| 151 } | 151 } |
| 152 | 152 |
| 153 void DnsConfigService::InvalidateConfig() { | 153 void DnsConfigService::InvalidateConfig() { |
| 154 DCHECK(CalledOnValidThread()); | 154 DCHECK(CalledOnValidThread()); |
| 155 base::TimeTicks now = base::TimeTicks::Now(); |
| 156 if (!last_invalidate_config_time_.is_null()) { |
| 157 UMA_HISTOGRAM_LONG_TIMES("AsyncDNS.ConfigNotifyInterval", |
| 158 now - last_invalidate_config_time_); |
| 159 } |
| 160 last_invalidate_config_time_ = now; |
| 155 if (!have_config_) | 161 if (!have_config_) |
| 156 return; | 162 return; |
| 157 have_config_ = false; | 163 have_config_ = false; |
| 158 StartTimer(); | 164 StartTimer(); |
| 159 } | 165 } |
| 160 | 166 |
| 161 void DnsConfigService::InvalidateHosts() { | 167 void DnsConfigService::InvalidateHosts() { |
| 162 DCHECK(CalledOnValidThread()); | 168 DCHECK(CalledOnValidThread()); |
| 169 base::TimeTicks now = base::TimeTicks::Now(); |
| 170 if (!last_invalidate_hosts_time_.is_null()) { |
| 171 UMA_HISTOGRAM_LONG_TIMES("AsyncDNS.HostsNotifyInterval", |
| 172 now - last_invalidate_hosts_time_); |
| 173 } |
| 174 last_invalidate_hosts_time_ = now; |
| 163 if (!have_hosts_) | 175 if (!have_hosts_) |
| 164 return; | 176 return; |
| 165 have_hosts_ = false; | 177 have_hosts_ = false; |
| 166 StartTimer(); | 178 StartTimer(); |
| 167 } | 179 } |
| 168 | 180 |
| 169 void DnsConfigService::OnConfigRead(const DnsConfig& config) { | 181 void DnsConfigService::OnConfigRead(const DnsConfig& config) { |
| 170 DCHECK(CalledOnValidThread()); | 182 DCHECK(CalledOnValidThread()); |
| 171 DCHECK(config.IsValid()); | 183 DCHECK(config.IsValid()); |
| 172 | 184 |
| 185 bool changed = false; |
| 173 if (!config.EqualsIgnoreHosts(dns_config_)) { | 186 if (!config.EqualsIgnoreHosts(dns_config_)) { |
| 174 dns_config_.CopyIgnoreHosts(config); | 187 dns_config_.CopyIgnoreHosts(config); |
| 175 need_update_ = true; | 188 need_update_ = true; |
| 189 changed = true; |
| 176 } | 190 } |
| 191 if (!changed && !last_sent_empty_time_.is_null()) { |
| 192 UMA_HISTOGRAM_LONG_TIMES("AsyncDNS.UnchangedConfigInterval", |
| 193 base::TimeTicks::Now() - last_sent_empty_time_); |
| 194 } |
| 195 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.ConfigChange", changed); |
| 177 | 196 |
| 178 have_config_ = true; | 197 have_config_ = true; |
| 179 if (have_hosts_) | 198 if (have_hosts_) |
| 180 OnCompleteConfig(); | 199 OnCompleteConfig(); |
| 181 } | 200 } |
| 182 | 201 |
| 183 void DnsConfigService::OnHostsRead(const DnsHosts& hosts) { | 202 void DnsConfigService::OnHostsRead(const DnsHosts& hosts) { |
| 184 DCHECK(CalledOnValidThread()); | 203 DCHECK(CalledOnValidThread()); |
| 185 | 204 |
| 205 bool changed = false; |
| 186 if (hosts != dns_config_.hosts) { | 206 if (hosts != dns_config_.hosts) { |
| 187 dns_config_.hosts = hosts; | 207 dns_config_.hosts = hosts; |
| 188 need_update_ = true; | 208 need_update_ = true; |
| 209 changed = true; |
| 189 } | 210 } |
| 211 if (!changed && !last_sent_empty_time_.is_null()) { |
| 212 UMA_HISTOGRAM_LONG_TIMES("AsyncDNS.UnchangedHostsInterval", |
| 213 base::TimeTicks::Now() - last_sent_empty_time_); |
| 214 } |
| 215 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.HostsChange", changed); |
| 190 | 216 |
| 191 have_hosts_ = true; | 217 have_hosts_ = true; |
| 192 if (have_config_) | 218 if (have_config_) |
| 193 OnCompleteConfig(); | 219 OnCompleteConfig(); |
| 194 } | 220 } |
| 195 | 221 |
| 196 void DnsConfigService::StartTimer() { | 222 void DnsConfigService::StartTimer() { |
| 197 DCHECK(CalledOnValidThread()); | 223 DCHECK(CalledOnValidThread()); |
| 198 if (last_sent_empty_) { | 224 if (last_sent_empty_) { |
| 199 DCHECK(!timer_.IsRunning()); | 225 DCHECK(!timer_.IsRunning()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 219 } | 245 } |
| 220 | 246 |
| 221 void DnsConfigService::OnTimeout() { | 247 void DnsConfigService::OnTimeout() { |
| 222 DCHECK(CalledOnValidThread()); | 248 DCHECK(CalledOnValidThread()); |
| 223 DCHECK(!last_sent_empty_); | 249 DCHECK(!last_sent_empty_); |
| 224 // Indicate that even if there is no change in On*Read, we will need to | 250 // Indicate that even if there is no change in On*Read, we will need to |
| 225 // update the receiver when the config becomes complete. | 251 // update the receiver when the config becomes complete. |
| 226 need_update_ = true; | 252 need_update_ = true; |
| 227 // Empty config is considered invalid. | 253 // Empty config is considered invalid. |
| 228 last_sent_empty_ = true; | 254 last_sent_empty_ = true; |
| 255 last_sent_empty_time_ = base::TimeTicks::Now(); |
| 229 callback_.Run(DnsConfig()); | 256 callback_.Run(DnsConfig()); |
| 230 } | 257 } |
| 231 | 258 |
| 232 void DnsConfigService::OnCompleteConfig() { | 259 void DnsConfigService::OnCompleteConfig() { |
| 233 timer_.Stop(); | 260 timer_.Stop(); |
| 234 if (!need_update_) | 261 if (!need_update_) |
| 235 return; | 262 return; |
| 236 if (!checked_rogue_dns_ && dns_config_.IsValid()) { | 263 if (!checked_rogue_dns_ && dns_config_.IsValid()) { |
| 237 CheckRogueDnsConfig(dns_config_); | 264 CheckRogueDnsConfig(dns_config_); |
| 238 checked_rogue_dns_ = true; | 265 checked_rogue_dns_ = true; |
| 239 } | 266 } |
| 240 need_update_ = false; | 267 need_update_ = false; |
| 241 last_sent_empty_ = false; | 268 last_sent_empty_ = false; |
| 242 callback_.Run(dns_config_); | 269 callback_.Run(dns_config_); |
| 243 } | 270 } |
| 244 | 271 |
| 245 } // namespace net | 272 } // namespace net |
| 246 | 273 |
| OLD | NEW |