| Index: net/dns/dns_config_service_win.cc
|
| diff --git a/net/dns/dns_config_service_win.cc b/net/dns/dns_config_service_win.cc
|
| index ddb8a4c18138a12d1d029223e7bf2947a5191eae..dd3ee3d8049e7cdd3258840807281ef1a52c65f3 100644
|
| --- a/net/dns/dns_config_service_win.cc
|
| +++ b/net/dns/dns_config_service_win.cc
|
| @@ -23,8 +23,8 @@
|
| #include "base/threading/non_thread_safe.h"
|
| #include "base/threading/thread_restrictions.h"
|
| #include "base/time/time.h"
|
| +#include "base/win/object_watcher.h"
|
| #include "base/win/registry.h"
|
| -#include "base/win/scoped_handle.h"
|
| #include "base/win/windows_version.h"
|
| #include "net/base/net_util.h"
|
| #include "net/base/network_change_notifier.h"
|
| @@ -292,7 +292,8 @@
|
| }
|
|
|
| // Watches a single registry key for changes.
|
| -class RegistryWatcher : public base::NonThreadSafe {
|
| +class RegistryWatcher : public base::win::ObjectWatcher::Delegate,
|
| + public base::NonThreadSafe {
|
| public:
|
| typedef base::Callback<void(bool succeeded)> CallbackType;
|
| RegistryWatcher() {}
|
| @@ -304,31 +305,35 @@
|
| callback_ = callback;
|
| if (key_.Open(HKEY_LOCAL_MACHINE, key, KEY_NOTIFY) != ERROR_SUCCESS)
|
| return false;
|
| -
|
| - return key_.StartWatching(base::Bind(&RegistryWatcher::OnObjectSignaled,
|
| - base::Unretained(this)));
|
| - }
|
| -
|
| - void OnObjectSignaled() {
|
| + if (key_.StartWatching() != ERROR_SUCCESS)
|
| + return false;
|
| + if (!watcher_.StartWatching(key_.watch_event(), this))
|
| + return false;
|
| + return true;
|
| + }
|
| +
|
| + virtual void OnObjectSignaled(HANDLE object) override {
|
| // TODO(vadimt): Remove ScopedProfile below once crbug.com/418183 is fixed.
|
| tracked_objects::ScopedProfile tracking_profile(
|
| FROM_HERE_WITH_EXPLICIT_FUNCTION(
|
| "RegistryWatcher_OnObjectSignaled"));
|
|
|
| DCHECK(CalledOnValidThread());
|
| - DCHECK(!callback_.is_null());
|
| - if (key_.StartWatching(base::Bind(&RegistryWatcher::OnObjectSignaled,
|
| - base::Unretained(this)))) {
|
| - callback_.Run(true);
|
| - } else {
|
| + bool succeeded = (key_.StartWatching() == ERROR_SUCCESS) &&
|
| + watcher_.StartWatching(key_.watch_event(), this);
|
| + if (!succeeded && key_.Valid()) {
|
| + watcher_.StopWatching();
|
| + key_.StopWatching();
|
| key_.Close();
|
| - callback_.Run(false);
|
| - }
|
| + }
|
| + if (!callback_.is_null())
|
| + callback_.Run(succeeded);
|
| }
|
|
|
| private:
|
| CallbackType callback_;
|
| base::win::RegKey key_;
|
| + base::win::ObjectWatcher watcher_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(RegistryWatcher);
|
| };
|
| @@ -735,8 +740,9 @@
|
|
|
| void DnsConfigServiceWin::OnConfigChanged(bool succeeded) {
|
| InvalidateConfig();
|
| - config_reader_->WorkNow();
|
| - if (!succeeded) {
|
| + if (succeeded) {
|
| + config_reader_->WorkNow();
|
| + } else {
|
| LOG(ERROR) << "DNS config watch failed.";
|
| set_watch_failed(true);
|
| UMA_HISTOGRAM_ENUMERATION("AsyncDNS.WatchStatus",
|
|
|