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 "base/android/java_system.h" | 33 #include <sys/system_properties.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. The DNS system properties are implementation | 157 // Theoretically, this is bad. __system_property_get is not a supported API |
158 // details that may disappear in future Android releases. Practically, the DNS | 158 // (but it's currently visible to anyone using Bionic), and the properties |
159 // code (and its clients) are already robust against failing to get the DNS | 159 // are implementation details that may disappear in future Android releases. |
| 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 |
160 // config for whatever reason, so the properties can disappear and the world | 162 // config for whatever reason, so the properties can disappear and the world |
161 // won't end. | 163 // won't end. |
| 164 // TODO(ttuttle): Depend on libcutils, then switch this (and other uses of |
| 165 // __system_property_get) to property_get. |
162 ConfigParsePosixResult ReadDnsConfig(DnsConfig* dns_config) { | 166 ConfigParsePosixResult ReadDnsConfig(DnsConfig* dns_config) { |
163 std::string dns1_string = base::android::JavaSystem::GetProperty("net.dns1"); | 167 std::string dns1_string, dns2_string; |
164 std::string dns2_string = base::android::JavaSystem::GetProperty("net.dns2"); | 168 char property_value[PROP_VALUE_MAX]; |
| 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; |
165 if (dns1_string.length() == 0 && dns2_string.length() == 0) | 173 if (dns1_string.length() == 0 && dns2_string.length() == 0) |
166 return CONFIG_PARSE_POSIX_NO_NAMESERVERS; | 174 return CONFIG_PARSE_POSIX_NO_NAMESERVERS; |
167 | 175 |
168 IPAddressNumber dns1_number, dns2_number; | 176 IPAddressNumber dns1_number, dns2_number; |
169 bool parsed1 = ParseIPLiteralToNumber(dns1_string, &dns1_number); | 177 bool parsed1 = ParseIPLiteralToNumber(dns1_string, &dns1_number); |
170 bool parsed2 = ParseIPLiteralToNumber(dns2_string, &dns2_number); | 178 bool parsed2 = ParseIPLiteralToNumber(dns2_string, &dns2_number); |
171 if (!parsed1 && !parsed2) | 179 if (!parsed1 && !parsed2) |
172 return CONFIG_PARSE_POSIX_BAD_ADDRESS; | 180 return CONFIG_PARSE_POSIX_BAD_ADDRESS; |
173 | 181 |
174 if (parsed1) { | 182 if (parsed1) { |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 #endif // defined(OS_ANDROID) | 548 #endif // defined(OS_ANDROID) |
541 | 549 |
542 } // namespace internal | 550 } // namespace internal |
543 | 551 |
544 // static | 552 // static |
545 scoped_ptr<DnsConfigService> DnsConfigService::CreateSystemService() { | 553 scoped_ptr<DnsConfigService> DnsConfigService::CreateSystemService() { |
546 return scoped_ptr<DnsConfigService>(new internal::DnsConfigServicePosix()); | 554 return scoped_ptr<DnsConfigService>(new internal::DnsConfigServicePosix()); |
547 } | 555 } |
548 | 556 |
549 } // namespace net | 557 } // namespace net |
OLD | NEW |