Index: net/dns/dns_config_service_posix.cc |
diff --git a/net/dns/dns_config_service_posix.cc b/net/dns/dns_config_service_posix.cc |
index a53739e1ba873b3a29c9d04c42b64821dca7772b..11a48a534386e9dd7c623615b92ee4ea6aa49858 100644 |
--- a/net/dns/dns_config_service_posix.cc |
+++ b/net/dns/dns_config_service_posix.cc |
@@ -16,18 +16,14 @@ |
#include "net/dns/file_path_watcher_wrapper.h" |
#include "net/dns/serial_worker.h" |
-#if defined(OS_MACOSX) |
-#include "net/dns/notify_watcher_mac.h" |
-#endif |
+namespace net { |
+ |
+namespace { |
#ifndef _PATH_RESCONF // Normally defined in <resolv.h> |
#define _PATH_RESCONF "/etc/resolv.conf" |
#endif |
-namespace net { |
- |
-namespace { |
- |
const FilePath::CharType* kFilePathHosts = FILE_PATH_LITERAL("/etc/hosts"); |
// A SerialWorker that uses libresolv to initialize res_state and converts |
@@ -85,32 +81,7 @@ class ConfigReader : public SerialWorker { |
namespace internal { |
-#if defined(OS_MACOSX) |
-// From 10.7.3 configd-395.10/dnsinfo/dnsinfo.h |
-static const char* kDnsNotifyKey = |
- "com.apple.system.SystemConfiguration.dns_configuration"; |
- |
-class DnsConfigServicePosix::ConfigWatcher : public NotifyWatcherMac { |
- public: |
- bool Watch(const base::Callback<void(bool succeeded)>& callback) { |
- return NotifyWatcherMac::Watch(kDnsNotifyKey, callback); |
- } |
-}; |
-#else |
-static const FilePath::CharType* kFilePathConfig = |
- FILE_PATH_LITERAL(_PATH_RESCONF); |
- |
-class DnsConfigServicePosix::ConfigWatcher : public FilePathWatcherWrapper { |
- public: |
- bool Watch(const base::Callback<void(bool succeeded)>& callback) { |
- return FilePathWatcherWrapper::Watch(FilePath(kFilePathConfig), callback); |
- } |
-}; |
-#endif |
- |
-DnsConfigServicePosix::DnsConfigServicePosix() |
- : config_watcher_(new ConfigWatcher()), |
- hosts_watcher_(new FilePathWatcherWrapper()) { |
+DnsConfigServicePosix::DnsConfigServicePosix() { |
config_reader_ = new ConfigReader( |
base::Bind(&DnsConfigServicePosix::OnConfigRead, |
base::Unretained(this))); |
@@ -125,46 +96,25 @@ DnsConfigServicePosix::~DnsConfigServicePosix() { |
hosts_reader_->Cancel(); |
} |
-void DnsConfigServicePosix::Watch(const CallbackType& callback) { |
- DCHECK(CalledOnValidThread()); |
- DCHECK(!callback.is_null()); |
- set_callback(callback); |
- |
- // Even if watchers fail, we keep the other one as it provides useful signals. |
- if (config_watcher_->Watch( |
- base::Bind(&DnsConfigServicePosix::OnConfigChanged, |
- base::Unretained(this)))) { |
- OnConfigChanged(true); |
- } else { |
- OnConfigChanged(false); |
- } |
- |
- if (hosts_watcher_->Watch( |
- FilePath(kFilePathHosts), |
- base::Bind(&DnsConfigServicePosix::OnHostsChanged, |
- base::Unretained(this)))) { |
- OnHostsChanged(true); |
- } else { |
- OnHostsChanged(false); |
+void DnsConfigServicePosix::OnDNSChanged(unsigned detail) { |
mmenke
2012/05/16 16:18:03
This function is identical on Windows and posix.
|
+ if (detail & NetworkChangeNotifier::CHANGE_DNS_WATCH_FAILED) { |
+ InvalidateConfig(); |
+ InvalidateHosts(); |
+ // We don't trust a config that we cannot watch in the future. |
+ config_reader_->Cancel(); |
+ hosts_reader_->Cancel(); |
+ return; |
} |
-} |
- |
-void DnsConfigServicePosix::OnConfigChanged(bool watch_succeeded) { |
- InvalidateConfig(); |
- // We don't trust a config that we cannot watch in the future. |
- // TODO(szym): re-start watcher if that makes sense. http://crbug.com/116139 |
- if (watch_succeeded) |
+ if (detail & NetworkChangeNotifier::CHANGE_DNS_WATCH_STARTED) |
+ detail = ~0; // Assume everything changed. |
+ if (detail & NetworkChangeNotifier::CHANGE_DNS_SETTINGS) { |
+ InvalidateConfig(); |
config_reader_->WorkNow(); |
- else |
- LOG(ERROR) << "Failed to watch DNS config"; |
-} |
- |
-void DnsConfigServicePosix::OnHostsChanged(bool watch_succeeded) { |
- InvalidateHosts(); |
- if (watch_succeeded) |
+ } |
+ if (detail & NetworkChangeNotifier::CHANGE_DNS_HOSTS) { |
+ InvalidateHosts(); |
hosts_reader_->WorkNow(); |
- else |
- LOG(ERROR) << "Failed to watch DNS hosts"; |
+ } |
} |
#if !defined(OS_ANDROID) |