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_posix.h" | 5 #include "net/dns/dns_config_service_posix.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 12 matching lines...) Expand all Loading... | |
23 #include "net/dns/dns_hosts.h" | 23 #include "net/dns/dns_hosts.h" |
24 #include "net/dns/dns_protocol.h" | 24 #include "net/dns/dns_protocol.h" |
25 #include "net/dns/notify_watcher_mac.h" | 25 #include "net/dns/notify_watcher_mac.h" |
26 #include "net/dns/serial_worker.h" | 26 #include "net/dns/serial_worker.h" |
27 | 27 |
28 #if defined(OS_MACOSX) && !defined(OS_IOS) | 28 #if defined(OS_MACOSX) && !defined(OS_IOS) |
29 #include "net/dns/dns_config_watcher_mac.h" | 29 #include "net/dns/dns_config_watcher_mac.h" |
30 #endif | 30 #endif |
31 | 31 |
32 #if defined(OS_ANDROID) | 32 #if defined(OS_ANDROID) |
33 #include <sys/system_properties.h> | 33 #include "base/android/java_system.h" |
34 #include "net/base/network_change_notifier.h" | 34 #include "net/base/network_change_notifier.h" |
35 #endif | 35 #endif |
36 | 36 |
37 namespace net { | 37 namespace net { |
38 | 38 |
39 namespace internal { | 39 namespace internal { |
40 | 40 |
41 namespace { | 41 namespace { |
42 | 42 |
43 #if !defined(OS_ANDROID) | 43 #if !defined(OS_ANDROID) |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
147 config->unhandled_options = true; | 147 config->unhandled_options = true; |
148 default: | 148 default: |
149 return error; | 149 return error; |
150 } | 150 } |
151 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 151 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
152 // Override timeout value to match default setting on Windows. | 152 // Override timeout value to match default setting on Windows. |
153 config->timeout = base::TimeDelta::FromSeconds(kDnsTimeoutSeconds); | 153 config->timeout = base::TimeDelta::FromSeconds(kDnsTimeoutSeconds); |
154 return result; | 154 return result; |
155 } | 155 } |
156 #else // defined(OS_ANDROID) | 156 #else // defined(OS_ANDROID) |
157 // Theoretically, this is bad. __system_property_get is not a supported API | |
158 // (but it's currently visible to anyone using Bionic), and the properties | |
159 // are implementation details that may disappear in future Android releases. | |
davidben
2015/08/13 15:53:42
It seems part of this comment is still relevant. _
jdduke (slow)
2015/08/13 17:19:13
You're absolutely right, I completely glossed over
| |
160 // Practically, libcutils provides property_get, which is a public API, and the | |
161 // DNS code (and its clients) are already robust against failing to get the DNS | |
162 // config for whatever reason, so the properties can disappear and the world | |
163 // won't end. | |
164 // TODO(ttuttle): Depend on libcutils, then switch this (and other uses of | |
165 // __system_property_get) to property_get. | |
166 ConfigParsePosixResult ReadDnsConfig(DnsConfig* dns_config) { | 157 ConfigParsePosixResult ReadDnsConfig(DnsConfig* dns_config) { |
167 std::string dns1_string, dns2_string; | 158 std::string dns1_string = base::android::JavaSystem::GetProperty("net.dns1"); |
168 char property_value[PROP_VALUE_MAX]; | 159 std::string dns2_string = base::android::JavaSystem::GetProperty("net.dns2"); |
169 __system_property_get("net.dns1", property_value); | |
170 dns1_string = property_value; | |
171 __system_property_get("net.dns2", property_value); | |
172 dns2_string = property_value; | |
173 if (dns1_string.length() == 0 && dns2_string.length() == 0) | 160 if (dns1_string.length() == 0 && dns2_string.length() == 0) |
174 return CONFIG_PARSE_POSIX_NO_NAMESERVERS; | 161 return CONFIG_PARSE_POSIX_NO_NAMESERVERS; |
175 | 162 |
176 IPAddressNumber dns1_number, dns2_number; | 163 IPAddressNumber dns1_number, dns2_number; |
177 bool parsed1 = ParseIPLiteralToNumber(dns1_string, &dns1_number); | 164 bool parsed1 = ParseIPLiteralToNumber(dns1_string, &dns1_number); |
178 bool parsed2 = ParseIPLiteralToNumber(dns2_string, &dns2_number); | 165 bool parsed2 = ParseIPLiteralToNumber(dns2_string, &dns2_number); |
179 if (!parsed1 && !parsed2) | 166 if (!parsed1 && !parsed2) |
180 return CONFIG_PARSE_POSIX_BAD_ADDRESS; | 167 return CONFIG_PARSE_POSIX_BAD_ADDRESS; |
181 | 168 |
182 if (parsed1) { | 169 if (parsed1) { |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
548 #endif // defined(OS_ANDROID) | 535 #endif // defined(OS_ANDROID) |
549 | 536 |
550 } // namespace internal | 537 } // namespace internal |
551 | 538 |
552 // static | 539 // static |
553 scoped_ptr<DnsConfigService> DnsConfigService::CreateSystemService() { | 540 scoped_ptr<DnsConfigService> DnsConfigService::CreateSystemService() { |
554 return scoped_ptr<DnsConfigService>(new internal::DnsConfigServicePosix()); | 541 return scoped_ptr<DnsConfigService>(new internal::DnsConfigServicePosix()); |
555 } | 542 } |
556 | 543 |
557 } // namespace net | 544 } // namespace net |
OLD | NEW |