Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: net/dns/dns_config_service.cc

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "net/base/ip_pattern.h" 11 #include "net/base/ip_pattern.h"
12 12
13 namespace net { 13 namespace net {
14 14
15 NameServerClassifier::NameServerClassifier() { 15 NameServerClassifier::NameServerClassifier() {
16 // Google Public DNS addresses from: 16 // Google Public DNS addresses from:
17 // https://developers.google.com/speed/public-dns/docs/using 17 // https://developers.google.com/speed/public-dns/docs/using
18 AddRule("8.8.8.8", NAME_SERVERS_TYPE_GOOGLE_PUBLIC_DNS); 18 AddRule("8.8.8.8", NAME_SERVERS_TYPE_GOOGLE_PUBLIC_DNS);
19 AddRule("8.8.4.4", NAME_SERVERS_TYPE_GOOGLE_PUBLIC_DNS); 19 AddRule("8.8.4.4", NAME_SERVERS_TYPE_GOOGLE_PUBLIC_DNS);
20 AddRule("2001:4860:4860:0:0:0:0:8888", NAME_SERVERS_TYPE_GOOGLE_PUBLIC_DNS), 20 AddRule("2001:4860:4860:0:0:0:0:8888", NAME_SERVERS_TYPE_GOOGLE_PUBLIC_DNS),
21 AddRule("2001:4860:4860:0:0:0:0:8844", NAME_SERVERS_TYPE_GOOGLE_PUBLIC_DNS), 21 AddRule("2001:4860:4860:0:0:0:0:8844",
22 NAME_SERVERS_TYPE_GOOGLE_PUBLIC_DNS),
22 23
23 // Count localhost as private, since we don't know what upstream it uses: 24 // Count localhost as private, since we don't know what upstream it uses:
24 AddRule("127.*.*.*", NAME_SERVERS_TYPE_PRIVATE); 25 AddRule("127.*.*.*", NAME_SERVERS_TYPE_PRIVATE);
25 AddRule("0:0:0:0:0:0:0:1", NAME_SERVERS_TYPE_PRIVATE); 26 AddRule("0:0:0:0:0:0:0:1", NAME_SERVERS_TYPE_PRIVATE);
26 27
27 // RFC 1918 private addresses: 28 // RFC 1918 private addresses:
28 AddRule("10.*.*.*", NAME_SERVERS_TYPE_PRIVATE); 29 AddRule("10.*.*.*", NAME_SERVERS_TYPE_PRIVATE);
29 AddRule("172.[16-31].*.*", NAME_SERVERS_TYPE_PRIVATE); 30 AddRule("172.[16-31].*.*", NAME_SERVERS_TYPE_PRIVATE);
30 AddRule("192.168.*.*", NAME_SERVERS_TYPE_PRIVATE); 31 AddRule("192.168.*.*", NAME_SERVERS_TYPE_PRIVATE);
31 32
32 // IPv4 link-local addresses: 33 // IPv4 link-local addresses:
33 AddRule("169.254.*.*", NAME_SERVERS_TYPE_PRIVATE); 34 AddRule("169.254.*.*", NAME_SERVERS_TYPE_PRIVATE);
34 35
35 // IPv6 link-local addresses: 36 // IPv6 link-local addresses:
36 AddRule("fe80:*:*:*:*:*:*:*", NAME_SERVERS_TYPE_PRIVATE); 37 AddRule("fe80:*:*:*:*:*:*:*", NAME_SERVERS_TYPE_PRIVATE);
37 38
38 // Anything else counts as public: 39 // Anything else counts as public:
39 AddRule("*.*.*.*", NAME_SERVERS_TYPE_PUBLIC); 40 AddRule("*.*.*.*", NAME_SERVERS_TYPE_PUBLIC);
40 AddRule("*:*:*:*:*:*:*:*", NAME_SERVERS_TYPE_PUBLIC); 41 AddRule("*:*:*:*:*:*:*:*", NAME_SERVERS_TYPE_PUBLIC);
41 } 42 }
42 43
43 NameServerClassifier::~NameServerClassifier() {} 44 NameServerClassifier::~NameServerClassifier() {
45 }
44 46
45 NameServerClassifier::NameServersType NameServerClassifier::GetNameServersType( 47 NameServerClassifier::NameServersType NameServerClassifier::GetNameServersType(
46 const std::vector<IPEndPoint>& nameservers) const { 48 const std::vector<IPEndPoint>& nameservers) const {
47 NameServersType type = NAME_SERVERS_TYPE_NONE; 49 NameServersType type = NAME_SERVERS_TYPE_NONE;
48 for (std::vector<IPEndPoint>::const_iterator it = nameservers.begin(); 50 for (std::vector<IPEndPoint>::const_iterator it = nameservers.begin();
49 it != nameservers.end(); 51 it != nameservers.end();
50 ++it) { 52 ++it) {
51 type = MergeNameServersTypes(type, GetNameServerType(it->address())); 53 type = MergeNameServersTypes(type, GetNameServerType(it->address()));
52 } 54 }
53 return type; 55 return type;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 // |kDnsTimeoutSeconds|. 99 // |kDnsTimeoutSeconds|.
98 DnsConfig::DnsConfig() 100 DnsConfig::DnsConfig()
99 : unhandled_options(false), 101 : unhandled_options(false),
100 append_to_multi_label_name(true), 102 append_to_multi_label_name(true),
101 randomize_ports(false), 103 randomize_ports(false),
102 ndots(1), 104 ndots(1),
103 timeout(base::TimeDelta::FromSeconds(kDnsTimeoutSeconds)), 105 timeout(base::TimeDelta::FromSeconds(kDnsTimeoutSeconds)),
104 attempts(2), 106 attempts(2),
105 rotate(false), 107 rotate(false),
106 edns0(false), 108 edns0(false),
107 use_local_ipv6(false) {} 109 use_local_ipv6(false) {
110 }
108 111
109 DnsConfig::~DnsConfig() {} 112 DnsConfig::~DnsConfig() {
113 }
110 114
111 bool DnsConfig::Equals(const DnsConfig& d) const { 115 bool DnsConfig::Equals(const DnsConfig& d) const {
112 return EqualsIgnoreHosts(d) && (hosts == d.hosts); 116 return EqualsIgnoreHosts(d) && (hosts == d.hosts);
113 } 117 }
114 118
115 bool DnsConfig::EqualsIgnoreHosts(const DnsConfig& d) const { 119 bool DnsConfig::EqualsIgnoreHosts(const DnsConfig& d) const {
116 return (nameservers == d.nameservers) && 120 return (nameservers == d.nameservers) && (search == d.search) &&
117 (search == d.search) &&
118 (unhandled_options == d.unhandled_options) && 121 (unhandled_options == d.unhandled_options) &&
119 (append_to_multi_label_name == d.append_to_multi_label_name) && 122 (append_to_multi_label_name == d.append_to_multi_label_name) &&
120 (ndots == d.ndots) && 123 (ndots == d.ndots) && (timeout == d.timeout) &&
121 (timeout == d.timeout) && 124 (attempts == d.attempts) && (rotate == d.rotate) &&
122 (attempts == d.attempts) && 125 (edns0 == d.edns0) && (use_local_ipv6 == d.use_local_ipv6);
123 (rotate == d.rotate) &&
124 (edns0 == d.edns0) &&
125 (use_local_ipv6 == d.use_local_ipv6);
126 } 126 }
127 127
128 void DnsConfig::CopyIgnoreHosts(const DnsConfig& d) { 128 void DnsConfig::CopyIgnoreHosts(const DnsConfig& d) {
129 nameservers = d.nameservers; 129 nameservers = d.nameservers;
130 search = d.search; 130 search = d.search;
131 unhandled_options = d.unhandled_options; 131 unhandled_options = d.unhandled_options;
132 append_to_multi_label_name = d.append_to_multi_label_name; 132 append_to_multi_label_name = d.append_to_multi_label_name;
133 ndots = d.ndots; 133 ndots = d.ndots;
134 timeout = d.timeout; 134 timeout = d.timeout;
135 attempts = d.attempts; 135 attempts = d.attempts;
(...skipping 21 matching lines...) Expand all
157 dict->SetDouble("timeout", timeout.InSecondsF()); 157 dict->SetDouble("timeout", timeout.InSecondsF());
158 dict->SetInteger("attempts", attempts); 158 dict->SetInteger("attempts", attempts);
159 dict->SetBoolean("rotate", rotate); 159 dict->SetBoolean("rotate", rotate);
160 dict->SetBoolean("edns0", edns0); 160 dict->SetBoolean("edns0", edns0);
161 dict->SetBoolean("use_local_ipv6", use_local_ipv6); 161 dict->SetBoolean("use_local_ipv6", use_local_ipv6);
162 dict->SetInteger("num_hosts", hosts.size()); 162 dict->SetInteger("num_hosts", hosts.size());
163 163
164 return dict; 164 return dict;
165 } 165 }
166 166
167
168 DnsConfigService::DnsConfigService() 167 DnsConfigService::DnsConfigService()
169 : watch_failed_(false), 168 : watch_failed_(false),
170 have_config_(false), 169 have_config_(false),
171 have_hosts_(false), 170 have_hosts_(false),
172 need_update_(false), 171 need_update_(false),
173 last_sent_empty_(true) {} 172 last_sent_empty_(true) {
173 }
174 174
175 DnsConfigService::~DnsConfigService() { 175 DnsConfigService::~DnsConfigService() {
176 } 176 }
177 177
178 void DnsConfigService::ReadConfig(const CallbackType& callback) { 178 void DnsConfigService::ReadConfig(const CallbackType& callback) {
179 DCHECK(CalledOnValidThread()); 179 DCHECK(CalledOnValidThread());
180 DCHECK(!callback.is_null()); 180 DCHECK(!callback.is_null());
181 DCHECK(callback_.is_null()); 181 DCHECK(callback_.is_null());
182 callback_ = callback; 182 callback_ = callback;
183 ReadNow(); 183 ReadNow();
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 // the config from the receiver. The goal is to avoid perceivable network 277 // the config from the receiver. The goal is to avoid perceivable network
278 // outage (when using the wrong config) but at the same time avoid 278 // outage (when using the wrong config) but at the same time avoid
279 // unnecessary Job aborts in HostResolverImpl. The signals come from multiple 279 // unnecessary Job aborts in HostResolverImpl. The signals come from multiple
280 // sources so it might receive multiple events during a config change. 280 // sources so it might receive multiple events during a config change.
281 281
282 // DHCP and user-induced changes are on the order of seconds, so 150ms should 282 // DHCP and user-induced changes are on the order of seconds, so 150ms should
283 // not add perceivable delay. On the other hand, config readers should finish 283 // not add perceivable delay. On the other hand, config readers should finish
284 // within 150ms with the rare exception of I/O block or extra large HOSTS. 284 // within 150ms with the rare exception of I/O block or extra large HOSTS.
285 const base::TimeDelta kTimeout = base::TimeDelta::FromMilliseconds(150); 285 const base::TimeDelta kTimeout = base::TimeDelta::FromMilliseconds(150);
286 286
287 timer_.Start(FROM_HERE, 287 timer_.Start(FROM_HERE, kTimeout, this, &DnsConfigService::OnTimeout);
288 kTimeout,
289 this,
290 &DnsConfigService::OnTimeout);
291 } 288 }
292 289
293 void DnsConfigService::OnTimeout() { 290 void DnsConfigService::OnTimeout() {
294 DCHECK(CalledOnValidThread()); 291 DCHECK(CalledOnValidThread());
295 DCHECK(!last_sent_empty_); 292 DCHECK(!last_sent_empty_);
296 // Indicate that even if there is no change in On*Read, we will need to 293 // Indicate that even if there is no change in On*Read, we will need to
297 // update the receiver when the config becomes complete. 294 // update the receiver when the config becomes complete.
298 need_update_ = true; 295 need_update_ = true;
299 // Empty config is considered invalid. 296 // Empty config is considered invalid.
300 last_sent_empty_ = true; 297 last_sent_empty_ = true;
301 last_sent_empty_time_ = base::TimeTicks::Now(); 298 last_sent_empty_time_ = base::TimeTicks::Now();
302 callback_.Run(DnsConfig()); 299 callback_.Run(DnsConfig());
303 } 300 }
304 301
305 void DnsConfigService::OnCompleteConfig() { 302 void DnsConfigService::OnCompleteConfig() {
306 timer_.Stop(); 303 timer_.Stop();
307 if (!need_update_) 304 if (!need_update_)
308 return; 305 return;
309 need_update_ = false; 306 need_update_ = false;
310 last_sent_empty_ = false; 307 last_sent_empty_ = false;
311 if (watch_failed_) { 308 if (watch_failed_) {
312 // If a watch failed, the config may not be accurate, so report empty. 309 // If a watch failed, the config may not be accurate, so report empty.
313 callback_.Run(DnsConfig()); 310 callback_.Run(DnsConfig());
314 } else { 311 } else {
315 callback_.Run(dns_config_); 312 callback_.Run(dns_config_);
316 } 313 }
317 } 314 }
318 315
319 } // namespace net 316 } // namespace net
320
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698