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 : append_to_multi_label_name(true), | 17 : unhandled_options(false), |
| 18 append_to_multi_label_name(true), |
18 randomize_ports(false), | 19 randomize_ports(false), |
19 ndots(1), | 20 ndots(1), |
20 timeout(base::TimeDelta::FromSeconds(kDnsTimeoutSeconds)), | 21 timeout(base::TimeDelta::FromSeconds(kDnsTimeoutSeconds)), |
21 attempts(2), | 22 attempts(2), |
22 rotate(false), | 23 rotate(false), |
23 edns0(false) {} | 24 edns0(false) {} |
24 | 25 |
25 DnsConfig::~DnsConfig() {} | 26 DnsConfig::~DnsConfig() {} |
26 | 27 |
27 bool DnsConfig::Equals(const DnsConfig& d) const { | 28 bool DnsConfig::Equals(const DnsConfig& d) const { |
28 return EqualsIgnoreHosts(d) && (hosts == d.hosts); | 29 return EqualsIgnoreHosts(d) && (hosts == d.hosts); |
29 } | 30 } |
30 | 31 |
31 bool DnsConfig::EqualsIgnoreHosts(const DnsConfig& d) const { | 32 bool DnsConfig::EqualsIgnoreHosts(const DnsConfig& d) const { |
32 return (nameservers == d.nameservers) && | 33 return (nameservers == d.nameservers) && |
33 (search == d.search) && | 34 (search == d.search) && |
| 35 (unhandled_options == d.unhandled_options) && |
34 (append_to_multi_label_name == d.append_to_multi_label_name) && | 36 (append_to_multi_label_name == d.append_to_multi_label_name) && |
35 (ndots == d.ndots) && | 37 (ndots == d.ndots) && |
36 (timeout == d.timeout) && | 38 (timeout == d.timeout) && |
37 (attempts == d.attempts) && | 39 (attempts == d.attempts) && |
38 (rotate == d.rotate) && | 40 (rotate == d.rotate) && |
39 (edns0 == d.edns0); | 41 (edns0 == d.edns0); |
40 } | 42 } |
41 | 43 |
42 void DnsConfig::CopyIgnoreHosts(const DnsConfig& d) { | 44 void DnsConfig::CopyIgnoreHosts(const DnsConfig& d) { |
43 nameservers = d.nameservers; | 45 nameservers = d.nameservers; |
44 search = d.search; | 46 search = d.search; |
| 47 unhandled_options = d.unhandled_options; |
45 append_to_multi_label_name = d.append_to_multi_label_name; | 48 append_to_multi_label_name = d.append_to_multi_label_name; |
46 ndots = d.ndots; | 49 ndots = d.ndots; |
47 timeout = d.timeout; | 50 timeout = d.timeout; |
48 attempts = d.attempts; | 51 attempts = d.attempts; |
49 rotate = d.rotate; | 52 rotate = d.rotate; |
50 edns0 = d.edns0; | 53 edns0 = d.edns0; |
51 } | 54 } |
52 | 55 |
53 base::Value* DnsConfig::ToValue() const { | 56 base::Value* DnsConfig::ToValue() const { |
54 base::DictionaryValue* dict = new base::DictionaryValue(); | 57 base::DictionaryValue* dict = new base::DictionaryValue(); |
55 | 58 |
56 base::ListValue* list = new base::ListValue(); | 59 base::ListValue* list = new base::ListValue(); |
57 for (size_t i = 0; i < nameservers.size(); ++i) | 60 for (size_t i = 0; i < nameservers.size(); ++i) |
58 list->Append(new base::StringValue(nameservers[i].ToString())); | 61 list->Append(new base::StringValue(nameservers[i].ToString())); |
59 dict->Set("nameservers", list); | 62 dict->Set("nameservers", list); |
60 | 63 |
61 list = new base::ListValue(); | 64 list = new base::ListValue(); |
62 for (size_t i = 0; i < search.size(); ++i) | 65 for (size_t i = 0; i < search.size(); ++i) |
63 list->Append(new base::StringValue(search[i])); | 66 list->Append(new base::StringValue(search[i])); |
64 dict->Set("search", list); | 67 dict->Set("search", list); |
65 | 68 |
| 69 dict->SetBoolean("unhandled_options", unhandled_options); |
66 dict->SetBoolean("append_to_multi_label_name", append_to_multi_label_name); | 70 dict->SetBoolean("append_to_multi_label_name", append_to_multi_label_name); |
67 dict->SetInteger("ndots", ndots); | 71 dict->SetInteger("ndots", ndots); |
68 dict->SetDouble("timeout", timeout.InSecondsF()); | 72 dict->SetDouble("timeout", timeout.InSecondsF()); |
69 dict->SetInteger("attempts", attempts); | 73 dict->SetInteger("attempts", attempts); |
70 dict->SetBoolean("rotate", rotate); | 74 dict->SetBoolean("rotate", rotate); |
71 dict->SetBoolean("edns0", edns0); | 75 dict->SetBoolean("edns0", edns0); |
72 dict->SetInteger("num_hosts", hosts.size()); | 76 dict->SetInteger("num_hosts", hosts.size()); |
73 | 77 |
74 return dict; | 78 return dict; |
75 } | 79 } |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 if (watch_failed_) { | 221 if (watch_failed_) { |
218 // If a watch failed, the config may not be accurate, so report empty. | 222 // If a watch failed, the config may not be accurate, so report empty. |
219 callback_.Run(DnsConfig()); | 223 callback_.Run(DnsConfig()); |
220 } else { | 224 } else { |
221 callback_.Run(dns_config_); | 225 callback_.Run(dns_config_); |
222 } | 226 } |
223 } | 227 } |
224 | 228 |
225 } // namespace net | 229 } // namespace net |
226 | 230 |
OLD | NEW |