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 "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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 } | 74 } |
| 75 | 75 |
| 76 | 76 |
| 77 DnsConfigService::DnsConfigService() | 77 DnsConfigService::DnsConfigService() |
| 78 : have_config_(false), | 78 : have_config_(false), |
| 79 have_hosts_(false), | 79 have_hosts_(false), |
| 80 need_update_(false), | 80 need_update_(false), |
| 81 last_sent_empty_(true) {} | 81 last_sent_empty_(true) {} |
| 82 | 82 |
| 83 DnsConfigService::~DnsConfigService() { | 83 DnsConfigService::~DnsConfigService() { |
| 84 // Must always clean up. | |
| 85 NetworkChangeNotifier::RemoveDNSObserver(this); | |
| 86 } | 84 } |
| 87 | 85 |
| 88 void DnsConfigService::Read(const CallbackType& callback) { | 86 void DnsConfigService::ReadConfig(const CallbackType& callback) { |
| 89 DCHECK(CalledOnValidThread()); | 87 DCHECK(CalledOnValidThread()); |
| 90 DCHECK(!callback.is_null()); | 88 DCHECK(!callback.is_null()); |
| 91 DCHECK(callback_.is_null()); | 89 DCHECK(callback_.is_null()); |
| 92 callback_ = callback; | 90 callback_ = callback; |
| 93 OnDNSChanged(NetworkChangeNotifier::CHANGE_DNS_WATCH_STARTED); | 91 this->ReadNow(); |
| 94 } | 92 } |
| 95 | 93 |
| 96 void DnsConfigService::Watch(const CallbackType& callback) { | 94 void DnsConfigService::WatchConfig(const CallbackType& callback) { |
| 97 DCHECK(CalledOnValidThread()); | 95 DCHECK(CalledOnValidThread()); |
| 98 DCHECK(!callback.is_null()); | 96 DCHECK(!callback.is_null()); |
| 99 DCHECK(callback_.is_null()); | 97 DCHECK(callback_.is_null()); |
| 100 NetworkChangeNotifier::AddDNSObserver(this); | |
| 101 callback_ = callback; | 98 callback_ = callback; |
| 102 if (NetworkChangeNotifier::IsWatchingDNS()) | 99 this->StartWatching(); |
|
pauljensen
2012/08/27 21:44:10
|StartWatching|'s return value is never used...doe
szym
2012/08/27 21:49:20
Right. http://crbug.com/116139. I guess I should f
| |
| 103 OnDNSChanged(NetworkChangeNotifier::CHANGE_DNS_WATCH_STARTED); | 100 this->ReadNow(); |
| 104 // else: Wait until signal before reading. | |
| 105 } | 101 } |
| 106 | 102 |
| 107 void DnsConfigService::InvalidateConfig() { | 103 void DnsConfigService::InvalidateConfig() { |
| 108 DCHECK(CalledOnValidThread()); | 104 DCHECK(CalledOnValidThread()); |
| 109 base::TimeTicks now = base::TimeTicks::Now(); | 105 base::TimeTicks now = base::TimeTicks::Now(); |
| 110 if (!last_invalidate_config_time_.is_null()) { | 106 if (!last_invalidate_config_time_.is_null()) { |
| 111 UMA_HISTOGRAM_LONG_TIMES("AsyncDNS.ConfigNotifyInterval", | 107 UMA_HISTOGRAM_LONG_TIMES("AsyncDNS.ConfigNotifyInterval", |
| 112 now - last_invalidate_config_time_); | 108 now - last_invalidate_config_time_); |
| 113 } | 109 } |
| 114 last_invalidate_config_time_ = now; | 110 last_invalidate_config_time_ = now; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 timer_.Stop(); | 210 timer_.Stop(); |
| 215 if (!need_update_) | 211 if (!need_update_) |
| 216 return; | 212 return; |
| 217 need_update_ = false; | 213 need_update_ = false; |
| 218 last_sent_empty_ = false; | 214 last_sent_empty_ = false; |
| 219 callback_.Run(dns_config_); | 215 callback_.Run(dns_config_); |
| 220 } | 216 } |
| 221 | 217 |
| 222 } // namespace net | 218 } // namespace net |
| 223 | 219 |
| OLD | NEW |