OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 | 146 |
147 void NetworkChangeNotifierWin::OnObjectSignaled(HANDLE object) { | 147 void NetworkChangeNotifierWin::OnObjectSignaled(HANDLE object) { |
148 NotifyObserversOfIPAddressChange(); | 148 NotifyObserversOfIPAddressChange(); |
149 | 149 |
150 // Calling IsOffline() at this very moment is likely to give | 150 // Calling IsOffline() at this very moment is likely to give |
151 // the wrong result, so we delay that until a little bit later. | 151 // the wrong result, so we delay that until a little bit later. |
152 // | 152 // |
153 // The one second delay chosen here was determined experimentally | 153 // The one second delay chosen here was determined experimentally |
154 // by adamk on Windows 7. | 154 // by adamk on Windows 7. |
155 timer_.Stop(); // cancel any already waiting notification | 155 timer_.Stop(); // cancel any already waiting notification |
156 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(1), this, | 156 timer_.Start(base::TimeDelta::FromSeconds(1), this, |
157 &NetworkChangeNotifierWin::NotifyParentOfOnlineStateChange); | 157 &NetworkChangeNotifierWin::NotifyParentOfOnlineStateChange); |
158 | 158 |
159 // Start watching for the next address change. | 159 // Start watching for the next address change. |
160 WatchForAddressChange(); | 160 WatchForAddressChange(); |
161 } | 161 } |
162 | 162 |
163 void NetworkChangeNotifierWin::WatchForAddressChange() { | 163 void NetworkChangeNotifierWin::WatchForAddressChange() { |
164 HANDLE handle = NULL; | 164 HANDLE handle = NULL; |
165 DWORD ret = NotifyAddrChange(&handle, &addr_overlapped_); | 165 DWORD ret = NotifyAddrChange(&handle, &addr_overlapped_); |
166 CHECK_EQ(static_cast<DWORD>(ERROR_IO_PENDING), ret); | 166 CHECK_EQ(static_cast<DWORD>(ERROR_IO_PENDING), ret); |
167 addr_watcher_.StartWatching(addr_overlapped_.hEvent, this); | 167 addr_watcher_.StartWatching(addr_overlapped_.hEvent, this); |
168 } | 168 } |
169 | 169 |
170 void NetworkChangeNotifierWin::NotifyParentOfOnlineStateChange() { | 170 void NetworkChangeNotifierWin::NotifyParentOfOnlineStateChange() { |
171 NotifyObserversOfOnlineStateChange(); | 171 NotifyObserversOfOnlineStateChange(); |
172 } | 172 } |
173 | 173 |
174 } // namespace net | 174 } // namespace net |
OLD | NEW |