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/values.h" | 8 #include "base/values.h" |
9 #include "net/base/ip_endpoint.h" | 9 #include "net/base/ip_endpoint.h" |
10 | 10 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 70 |
71 return dict; | 71 return dict; |
72 } | 72 } |
73 | 73 |
74 | 74 |
75 DnsConfigService::DnsConfigService() | 75 DnsConfigService::DnsConfigService() |
76 : have_config_(false), | 76 : have_config_(false), |
77 have_hosts_(false), | 77 have_hosts_(false), |
78 need_update_(false) {} | 78 need_update_(false) {} |
79 | 79 |
80 DnsConfigService::~DnsConfigService() {} | 80 DnsConfigService::~DnsConfigService() { |
| 81 // Must always clean up. |
| 82 NetworkChangeNotifier::RemoveDNSObserver(this); |
| 83 } |
| 84 |
| 85 void DnsConfigService::Read(const CallbackType& callback) { |
| 86 DCHECK(CalledOnValidThread()); |
| 87 DCHECK(!callback.is_null()); |
| 88 DCHECK(callback_.is_null()); |
| 89 callback_ = callback; |
| 90 OnDNSChanged(NetworkChangeNotifier::CHANGE_DNS_WATCH_STARTED); |
| 91 } |
| 92 |
| 93 void DnsConfigService::Watch(const CallbackType& callback) { |
| 94 DCHECK(CalledOnValidThread()); |
| 95 DCHECK(!callback.is_null()); |
| 96 DCHECK(callback_.is_null()); |
| 97 NetworkChangeNotifier::AddDNSObserver(this); |
| 98 callback_ = callback; |
| 99 if (NetworkChangeNotifier::IsWatchingDNS()) |
| 100 OnDNSChanged(NetworkChangeNotifier::CHANGE_DNS_WATCH_STARTED); |
| 101 // else: Wait until signal before reading. |
| 102 } |
81 | 103 |
82 void DnsConfigService::InvalidateConfig() { | 104 void DnsConfigService::InvalidateConfig() { |
83 DCHECK(CalledOnValidThread()); | 105 DCHECK(CalledOnValidThread()); |
84 if (!have_config_) | 106 if (!have_config_) |
85 return; | 107 return; |
86 have_config_ = false; | 108 have_config_ = false; |
87 StartTimer(); | 109 StartTimer(); |
88 } | 110 } |
89 | 111 |
90 void DnsConfigService::InvalidateHosts() { | 112 void DnsConfigService::InvalidateHosts() { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 void DnsConfigService::OnCompleteConfig() { | 177 void DnsConfigService::OnCompleteConfig() { |
156 timer_.Stop(); | 178 timer_.Stop(); |
157 if (need_update_) { | 179 if (need_update_) { |
158 need_update_ = false; | 180 need_update_ = false; |
159 callback_.Run(dns_config_); | 181 callback_.Run(dns_config_); |
160 } | 182 } |
161 } | 183 } |
162 | 184 |
163 } // namespace net | 185 } // namespace net |
164 | 186 |
OLD | NEW |