| OLD | NEW | 
|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/base/network_change_notifier_win.h" | 5 #include "net/base/network_change_notifier_win.h" | 
| 6 | 6 | 
| 7 #include <iphlpapi.h> | 7 #include <iphlpapi.h> | 
| 8 #include <winsock2.h> | 8 #include <winsock2.h> | 
| 9 | 9 | 
| 10 #include "base/logging.h" | 10 #include "base/logging.h" | 
|  | 11 #include "base/time.h" | 
| 11 #include "net/base/winsock_init.h" | 12 #include "net/base/winsock_init.h" | 
| 12 | 13 | 
| 13 #pragma comment(lib, "iphlpapi.lib") | 14 #pragma comment(lib, "iphlpapi.lib") | 
| 14 | 15 | 
| 15 namespace net { | 16 namespace net { | 
| 16 | 17 | 
| 17 NetworkChangeNotifierWin::NetworkChangeNotifierWin() { | 18 NetworkChangeNotifierWin::NetworkChangeNotifierWin() { | 
| 18   memset(&addr_overlapped_, 0, sizeof addr_overlapped_); | 19   memset(&addr_overlapped_, 0, sizeof addr_overlapped_); | 
| 19   addr_overlapped_.hEvent = WSACreateEvent(); | 20   addr_overlapped_.hEvent = WSACreateEvent(); | 
| 20   WatchForAddressChange(); | 21   WatchForAddressChange(); | 
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 139   result = WSALookupServiceEnd(ws_handle); | 140   result = WSALookupServiceEnd(ws_handle); | 
| 140   LOG_IF(ERROR, result != 0) | 141   LOG_IF(ERROR, result != 0) | 
| 141       << "WSALookupServiceEnd() failed with: " << result; | 142       << "WSALookupServiceEnd() failed with: " << result; | 
| 142 | 143 | 
| 143   return !found_connection; | 144   return !found_connection; | 
| 144 } | 145 } | 
| 145 | 146 | 
| 146 void NetworkChangeNotifierWin::OnObjectSignaled(HANDLE object) { | 147 void NetworkChangeNotifierWin::OnObjectSignaled(HANDLE object) { | 
| 147   NotifyObserversOfIPAddressChange(); | 148   NotifyObserversOfIPAddressChange(); | 
| 148 | 149 | 
|  | 150   // Calling IsOffline() at this very moment is likely to give | 
|  | 151   // the wrong result, so we delay that until a little bit later. | 
|  | 152   // | 
|  | 153   // The one second delay chosen here was determined experimentally | 
|  | 154   // by adamk on Windows 7. | 
|  | 155   timer_.Stop();  // cancel any already waiting notification | 
|  | 156   timer_.Start(base::TimeDelta::FromSeconds(1), this, | 
|  | 157                &NetworkChangeNotifierWin::NotifyParentOfOnlineStateChange); | 
|  | 158 | 
| 149   // Start watching for the next address change. | 159   // Start watching for the next address change. | 
| 150   WatchForAddressChange(); | 160   WatchForAddressChange(); | 
| 151 } | 161 } | 
| 152 | 162 | 
| 153 void NetworkChangeNotifierWin::WatchForAddressChange() { | 163 void NetworkChangeNotifierWin::WatchForAddressChange() { | 
| 154   HANDLE handle = NULL; | 164   HANDLE handle = NULL; | 
| 155   DWORD ret = NotifyAddrChange(&handle, &addr_overlapped_); | 165   DWORD ret = NotifyAddrChange(&handle, &addr_overlapped_); | 
| 156   CHECK(ret == ERROR_IO_PENDING); | 166   CHECK(ret == ERROR_IO_PENDING); | 
| 157   addr_watcher_.StartWatching(addr_overlapped_.hEvent, this); | 167   addr_watcher_.StartWatching(addr_overlapped_.hEvent, this); | 
| 158 } | 168 } | 
| 159 | 169 | 
|  | 170 void NetworkChangeNotifierWin::NotifyParentOfOnlineStateChange() { | 
|  | 171   NotifyObserversOfOnlineStateChange(); | 
|  | 172 } | 
|  | 173 | 
| 160 }  // namespace net | 174 }  // namespace net | 
| OLD | NEW | 
|---|