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" |
11 | 11 |
12 namespace net { | 12 namespace net { |
13 | 13 |
14 // Default values are taken from glibc resolv.h except timeout which is set to | 14 // Default values are taken from glibc resolv.h except timeout which is set to |
15 // |kDnsTimeoutSeconds|. | 15 // |kDnsTimeoutSeconds|. |
16 DnsConfig::DnsConfig() | 16 DnsConfig::DnsConfig() |
17 : unhandled_options(false), | 17 : unhandled_options(false), |
18 append_to_multi_label_name(true), | 18 append_to_multi_label_name(true), |
19 randomize_ports(false), | 19 randomize_ports(false), |
20 ndots(1), | 20 ndots(1), |
21 timeout(base::TimeDelta::FromSeconds(kDnsTimeoutSeconds)), | 21 timeout(base::TimeDelta::FromSeconds(kDnsTimeoutSeconds)), |
22 attempts(2), | 22 attempts(2), |
23 rotate(false), | 23 rotate(false), |
24 edns0(false) {} | 24 edns0(false), |
25 use_local_ipv6(false) {} | |
25 | 26 |
26 DnsConfig::~DnsConfig() {} | 27 DnsConfig::~DnsConfig() {} |
27 | 28 |
28 bool DnsConfig::Equals(const DnsConfig& d) const { | 29 bool DnsConfig::Equals(const DnsConfig& d) const { |
29 return EqualsIgnoreHosts(d) && (hosts == d.hosts); | 30 return EqualsIgnoreHosts(d) && (hosts == d.hosts); |
30 } | 31 } |
31 | 32 |
32 bool DnsConfig::EqualsIgnoreHosts(const DnsConfig& d) const { | 33 bool DnsConfig::EqualsIgnoreHosts(const DnsConfig& d) const { |
33 return (nameservers == d.nameservers) && | 34 return (nameservers == d.nameservers) && |
34 (search == d.search) && | 35 (search == d.search) && |
35 (unhandled_options == d.unhandled_options) && | 36 (unhandled_options == d.unhandled_options) && |
36 (append_to_multi_label_name == d.append_to_multi_label_name) && | 37 (append_to_multi_label_name == d.append_to_multi_label_name) && |
37 (ndots == d.ndots) && | 38 (ndots == d.ndots) && |
38 (timeout == d.timeout) && | 39 (timeout == d.timeout) && |
39 (attempts == d.attempts) && | 40 (attempts == d.attempts) && |
40 (rotate == d.rotate) && | 41 (rotate == d.rotate) && |
41 (edns0 == d.edns0); | 42 (edns0 == d.edns0) && |
43 (use_local_ipv6 == d.use_local_ipv6); | |
42 } | 44 } |
43 | 45 |
44 void DnsConfig::CopyIgnoreHosts(const DnsConfig& d) { | 46 void DnsConfig::CopyIgnoreHosts(const DnsConfig& d) { |
45 nameservers = d.nameservers; | 47 nameservers = d.nameservers; |
46 search = d.search; | 48 search = d.search; |
47 unhandled_options = d.unhandled_options; | 49 unhandled_options = d.unhandled_options; |
48 append_to_multi_label_name = d.append_to_multi_label_name; | 50 append_to_multi_label_name = d.append_to_multi_label_name; |
49 ndots = d.ndots; | 51 ndots = d.ndots; |
50 timeout = d.timeout; | 52 timeout = d.timeout; |
51 attempts = d.attempts; | 53 attempts = d.attempts; |
52 rotate = d.rotate; | 54 rotate = d.rotate; |
53 edns0 = d.edns0; | 55 edns0 = d.edns0; |
56 use_local_ipv6 = d.use_local_ipv6; | |
54 } | 57 } |
55 | 58 |
56 base::Value* DnsConfig::ToValue() const { | 59 base::Value* DnsConfig::ToValue() const { |
57 base::DictionaryValue* dict = new base::DictionaryValue(); | 60 base::DictionaryValue* dict = new base::DictionaryValue(); |
58 | 61 |
59 base::ListValue* list = new base::ListValue(); | 62 base::ListValue* list = new base::ListValue(); |
60 for (size_t i = 0; i < nameservers.size(); ++i) | 63 for (size_t i = 0; i < nameservers.size(); ++i) |
61 list->Append(new base::StringValue(nameservers[i].ToString())); | 64 list->Append(new base::StringValue(nameservers[i].ToString())); |
62 dict->Set("nameservers", list); | 65 dict->Set("nameservers", list); |
63 | 66 |
64 list = new base::ListValue(); | 67 list = new base::ListValue(); |
65 for (size_t i = 0; i < search.size(); ++i) | 68 for (size_t i = 0; i < search.size(); ++i) |
66 list->Append(new base::StringValue(search[i])); | 69 list->Append(new base::StringValue(search[i])); |
67 dict->Set("search", list); | 70 dict->Set("search", list); |
68 | 71 |
69 dict->SetBoolean("unhandled_options", unhandled_options); | 72 dict->SetBoolean("unhandled_options", unhandled_options); |
70 dict->SetBoolean("append_to_multi_label_name", append_to_multi_label_name); | 73 dict->SetBoolean("append_to_multi_label_name", append_to_multi_label_name); |
71 dict->SetInteger("ndots", ndots); | 74 dict->SetInteger("ndots", ndots); |
72 dict->SetDouble("timeout", timeout.InSecondsF()); | 75 dict->SetDouble("timeout", timeout.InSecondsF()); |
73 dict->SetInteger("attempts", attempts); | 76 dict->SetInteger("attempts", attempts); |
74 dict->SetBoolean("rotate", rotate); | 77 dict->SetBoolean("rotate", rotate); |
75 dict->SetBoolean("edns0", edns0); | 78 dict->SetBoolean("edns0", edns0); |
79 dict->SetBoolean("use_local_ipv6", use_local_ipv6); | |
mmenke
2013/09/16 16:34:46
nit: Should update the DNS_CONFIG_CHANGED descript
szym
2013/09/16 19:17:35
I replaced the primitives with
<other>: <See DnsC
| |
76 dict->SetInteger("num_hosts", hosts.size()); | 80 dict->SetInteger("num_hosts", hosts.size()); |
77 | 81 |
78 return dict; | 82 return dict; |
79 } | 83 } |
80 | 84 |
81 | 85 |
82 DnsConfigService::DnsConfigService() | 86 DnsConfigService::DnsConfigService() |
83 : watch_failed_(false), | 87 : watch_failed_(false), |
84 have_config_(false), | 88 have_config_(false), |
85 have_hosts_(false), | 89 have_hosts_(false), |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
221 if (watch_failed_) { | 225 if (watch_failed_) { |
222 // If a watch failed, the config may not be accurate, so report empty. | 226 // If a watch failed, the config may not be accurate, so report empty. |
223 callback_.Run(DnsConfig()); | 227 callback_.Run(DnsConfig()); |
224 } else { | 228 } else { |
225 callback_.Run(dns_config_); | 229 callback_.Run(dns_config_); |
226 } | 230 } |
227 } | 231 } |
228 | 232 |
229 } // namespace net | 233 } // namespace net |
230 | 234 |
OLD | NEW |