Index: net/base/network_change_notifier_win.cc |
diff --git a/net/base/network_change_notifier_win.cc b/net/base/network_change_notifier_win.cc |
index bc906cb8a61c32e115d9e7e1c665b83882f14680..718e40bb9faa7629998f4a607cb3c569b1754307 100644 |
--- a/net/base/network_change_notifier_win.cc |
+++ b/net/base/network_change_notifier_win.cc |
@@ -8,6 +8,7 @@ |
#include <winsock2.h> |
#include "base/logging.h" |
+#include "base/time.h" |
#include "net/base/winsock_init.h" |
#pragma comment(lib, "iphlpapi.lib") |
@@ -146,6 +147,15 @@ bool NetworkChangeNotifierWin::IsCurrentlyOffline() const { |
void NetworkChangeNotifierWin::OnObjectSignaled(HANDLE object) { |
NotifyObserversOfIPAddressChange(); |
+ // Calling IsOffline() at this very moment is likely to give |
+ // the wrong result, so we delay that until a little bit later. |
+ // |
+ // The one second delay chosen here was determined experimentally |
+ // by adamk on Windows 7. |
+ timer_.Stop(); // cancel any already waiting notification |
+ timer_.Start(base::TimeDelta::FromSeconds(1), this, |
+ &NetworkChangeNotifierWin::NotifyParentOfOnlineStateChange); |
+ |
// Start watching for the next address change. |
WatchForAddressChange(); |
} |
@@ -157,4 +167,8 @@ void NetworkChangeNotifierWin::WatchForAddressChange() { |
addr_watcher_.StartWatching(addr_overlapped_.hEvent, this); |
} |
+void NetworkChangeNotifierWin::NotifyParentOfOnlineStateChange() { |
+ NotifyObserversOfOnlineStateChange(); |
+} |
+ |
} // namespace net |