| 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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 bool Watch() { | 203 bool Watch() { |
| 204 bool success = true; | 204 bool success = true; |
| 205 if (!config_watcher_.Watch(base::Bind(&Watcher::OnConfigChanged, | 205 if (!config_watcher_.Watch(base::Bind(&Watcher::OnConfigChanged, |
| 206 base::Unretained(this)))) { | 206 base::Unretained(this)))) { |
| 207 LOG(ERROR) << "DNS config watch failed to start."; | 207 LOG(ERROR) << "DNS config watch failed to start."; |
| 208 success = false; | 208 success = false; |
| 209 UMA_HISTOGRAM_ENUMERATION("AsyncDNS.WatchStatus", | 209 UMA_HISTOGRAM_ENUMERATION("AsyncDNS.WatchStatus", |
| 210 DNS_CONFIG_WATCH_FAILED_TO_START_CONFIG, | 210 DNS_CONFIG_WATCH_FAILED_TO_START_CONFIG, |
| 211 DNS_CONFIG_WATCH_MAX); | 211 DNS_CONFIG_WATCH_MAX); |
| 212 } | 212 } |
| 213 #if !defined(OS_IOS) |
| 213 if (!hosts_watcher_.Watch( | 214 if (!hosts_watcher_.Watch( |
| 214 base::FilePath(service_->file_path_hosts_), false, | 215 base::FilePath(service_->file_path_hosts_), false, |
| 215 base::Bind(&Watcher::OnHostsChanged, base::Unretained(this)))) { | 216 base::Bind(&Watcher::OnHostsChanged, base::Unretained(this)))) { |
| 216 LOG(ERROR) << "DNS hosts watch failed to start."; | 217 LOG(ERROR) << "DNS hosts watch failed to start."; |
| 217 success = false; | 218 success = false; |
| 218 UMA_HISTOGRAM_ENUMERATION("AsyncDNS.WatchStatus", | 219 UMA_HISTOGRAM_ENUMERATION("AsyncDNS.WatchStatus", |
| 219 DNS_CONFIG_WATCH_FAILED_TO_START_HOSTS, | 220 DNS_CONFIG_WATCH_FAILED_TO_START_HOSTS, |
| 220 DNS_CONFIG_WATCH_MAX); | 221 DNS_CONFIG_WATCH_MAX); |
| 221 } | 222 } |
| 223 #endif |
| 222 return success; | 224 return success; |
| 223 } | 225 } |
| 224 | 226 |
| 225 #if defined(OS_ANDROID) | 227 #if defined(OS_ANDROID) |
| 226 void OnNetworkChanged(NetworkChangeNotifier::ConnectionType type) { | 228 void OnNetworkChanged(NetworkChangeNotifier::ConnectionType type) { |
| 227 config_watcher_.OnNetworkChanged(type); | 229 config_watcher_.OnNetworkChanged(type); |
| 228 } | 230 } |
| 229 #endif // defined(OS_ANDROID) | 231 #endif // defined(OS_ANDROID) |
| 230 | 232 |
| 231 private: | 233 private: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 242 } | 244 } |
| 243 void OnConfigChangedDelayed(bool succeeded) { | 245 void OnConfigChangedDelayed(bool succeeded) { |
| 244 service_->OnConfigChanged(succeeded); | 246 service_->OnConfigChanged(succeeded); |
| 245 } | 247 } |
| 246 void OnHostsChanged(const base::FilePath& path, bool error) { | 248 void OnHostsChanged(const base::FilePath& path, bool error) { |
| 247 service_->OnHostsChanged(!error); | 249 service_->OnHostsChanged(!error); |
| 248 } | 250 } |
| 249 | 251 |
| 250 DnsConfigServicePosix* service_; | 252 DnsConfigServicePosix* service_; |
| 251 DnsConfigWatcher config_watcher_; | 253 DnsConfigWatcher config_watcher_; |
| 254 #if !defined(OS_IOS) |
| 252 base::FilePathWatcher hosts_watcher_; | 255 base::FilePathWatcher hosts_watcher_; |
| 256 #endif |
| 253 | 257 |
| 254 base::WeakPtrFactory<Watcher> weak_factory_; | 258 base::WeakPtrFactory<Watcher> weak_factory_; |
| 255 | 259 |
| 256 DISALLOW_COPY_AND_ASSIGN(Watcher); | 260 DISALLOW_COPY_AND_ASSIGN(Watcher); |
| 257 }; | 261 }; |
| 258 | 262 |
| 259 // A SerialWorker that uses libresolv to initialize res_state and converts | 263 // A SerialWorker that uses libresolv to initialize res_state and converts |
| 260 // it to DnsConfig (except on Android, where it reads system properties | 264 // it to DnsConfig (except on Android, where it reads system properties |
| 261 // net.dns1 and net.dns2; see #if around ReadDnsConfig above.) | 265 // net.dns1 and net.dns2; see #if around ReadDnsConfig above.) |
| 262 class DnsConfigServicePosix::ConfigReader : public SerialWorker { | 266 class DnsConfigServicePosix::ConfigReader : public SerialWorker { |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 #endif // defined(OS_ANDROID) | 552 #endif // defined(OS_ANDROID) |
| 549 | 553 |
| 550 } // namespace internal | 554 } // namespace internal |
| 551 | 555 |
| 552 // static | 556 // static |
| 553 scoped_ptr<DnsConfigService> DnsConfigService::CreateSystemService() { | 557 scoped_ptr<DnsConfigService> DnsConfigService::CreateSystemService() { |
| 554 return scoped_ptr<DnsConfigService>(new internal::DnsConfigServicePosix()); | 558 return scoped_ptr<DnsConfigService>(new internal::DnsConfigServicePosix()); |
| 555 } | 559 } |
| 556 | 560 |
| 557 } // namespace net | 561 } // namespace net |
| OLD | NEW |