diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-04 19:08:29 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-04 19:08:29 +0000 |
commit | 1fabd9a93df25441a704715c05d2e773d9ef4db1 (patch) | |
tree | 4623822f20a901adf12cd4ffb65f257427b34a9e /net | |
parent | 0109730426988f862224c42ad01be37cb6a3c569 (diff) | |
download | chromium_src-1fabd9a93df25441a704715c05d2e773d9ef4db1.zip chromium_src-1fabd9a93df25441a704715c05d2e773d9ef4db1.tar.gz chromium_src-1fabd9a93df25441a704715c05d2e773d9ef4db1.tar.bz2 |
Revert r36842 which reverted r36837.
=====
Implement NetworkChangeNotifierWin.
Uses the NotifyAddrChange() API to detect ip address changes.
BUG=http://crbug.com/26156
=====
It was previously reverted due to a HTTPBridgeTest failing in XP unit_tests. This is because that test would create HttpNetworkSession in the unit test in a thread that didn't have a MessageLoop. The test is still broken, but r38052 moved NetworkChangeNotifier initialization to IOThread, so it's no longer initialized when HttpNetworkSession is. Therefore, it doesn't trigger the same crash now, although the previous test is still broken and is tracked in bug 34352.
Review URL: http://codereview.chromium.org/563029
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38116 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/base/network_change_notifier_win.cc | 60 | ||||
-rw-r--r-- | net/base/network_change_notifier_win.h | 11 | ||||
-rwxr-xr-x | net/net.gyp | 5 |
3 files changed, 73 insertions, 3 deletions
diff --git a/net/base/network_change_notifier_win.cc b/net/base/network_change_notifier_win.cc index 711bd66..e52bd46 100644 --- a/net/base/network_change_notifier_win.cc +++ b/net/base/network_change_notifier_win.cc @@ -3,10 +3,68 @@ // found in the LICENSE file. #include "net/base/network_change_notifier_win.h" +#include <iphlpapi.h> +#include <windows.h> +#include <winsock2.h> +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "base/logging.h" +#include "base/object_watcher.h" namespace net { -NetworkChangeNotifierWin::NetworkChangeNotifierWin() {} +class NetworkChangeNotifierWin::Impl + : public base::ObjectWatcher::Delegate { + public: + explicit Impl(NetworkChangeNotifierWin* notifier); + virtual ~Impl(); + + void WatchForAddressChange(); + + // ObjectWatcher::Delegate methods: + + virtual void OnObjectSignaled(HANDLE object); + + private: + NetworkChangeNotifierWin* const notifier_; + base::ObjectWatcher addr_watcher_; + OVERLAPPED addr_overlapped_; + + DISALLOW_COPY_AND_ASSIGN(Impl); +}; + +NetworkChangeNotifierWin::Impl::Impl(NetworkChangeNotifierWin* notifier) + : notifier_(notifier) { + memset(&addr_overlapped_, 0, sizeof(addr_overlapped_)); + addr_overlapped_.hEvent = WSACreateEvent(); +} + +NetworkChangeNotifierWin::Impl::~Impl() { + CancelIPChangeNotify(&addr_overlapped_); + addr_watcher_.StopWatching(); + WSACloseEvent(addr_overlapped_.hEvent); + memset(&addr_overlapped_, 0, sizeof(addr_overlapped_)); +} + +void NetworkChangeNotifierWin::Impl::WatchForAddressChange() { + HANDLE handle = NULL; + DWORD ret = NotifyAddrChange(&handle, &addr_overlapped_); + CHECK(ret == ERROR_IO_PENDING); + addr_watcher_.StartWatching(addr_overlapped_.hEvent, this); +} + +void NetworkChangeNotifierWin::Impl::OnObjectSignaled(HANDLE object) { + notifier_->OnIPAddressChanged(); + + // Start watching for further address changes. + WatchForAddressChange(); +} + +NetworkChangeNotifierWin::NetworkChangeNotifierWin() + : impl_(new Impl(ALLOW_THIS_IN_INITIALIZER_LIST(this))) { + impl_->WatchForAddressChange(); +} + NetworkChangeNotifierWin::~NetworkChangeNotifierWin() {} } // namespace net diff --git a/net/base/network_change_notifier_win.h b/net/base/network_change_notifier_win.h index b208ad7..b11ec0d 100644 --- a/net/base/network_change_notifier_win.h +++ b/net/base/network_change_notifier_win.h @@ -6,6 +6,7 @@ #define NET_BASE_NETWORK_CHANGE_NOTIFIER_WIN_H_ #include "base/basictypes.h" +#include "base/object_watcher.h" #include "net/base/network_change_notifier_helper.h" namespace net { @@ -14,6 +15,11 @@ class NetworkChangeNotifierWin : public NetworkChangeNotifier { public: NetworkChangeNotifierWin(); + // Called by NetworkChangeNotifierWin::Impl. + void OnIPAddressChanged() { helper_.OnIPAddressChanged(); } + + // NetworkChangeNotifier methods: + virtual void AddObserver(Observer* observer) { helper_.AddObserver(observer); } @@ -23,11 +29,12 @@ class NetworkChangeNotifierWin : public NetworkChangeNotifier { } private: - virtual ~NetworkChangeNotifierWin(); + class Impl; - void OnIPAddressChanged() { helper_.OnIPAddressChanged(); } + virtual ~NetworkChangeNotifierWin(); internal::NetworkChangeNotifierHelper helper_; + scoped_ptr<Impl> impl_; DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierWin); }; diff --git a/net/net.gyp b/net/net.gyp index 37e89a8..b1645d5 100755 --- a/net/net.gyp +++ b/net/net.gyp @@ -525,6 +525,11 @@ 'third_party/nss/nss.gyp:ssl', 'tld_cleanup', ], + 'link_settings': { + 'libraries': [ + '-lIphlpapi.lib', + ], + }, }, { # else: OS != "win" 'sources!': [ |