Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Unified Diff: net/base/network_change_notifier_win.cc

Issue 2802015: Massively simplify the NetworkChangeNotifier infrastructure:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/base/network_change_notifier_win.cc
===================================================================
--- net/base/network_change_notifier_win.cc (revision 50775)
+++ net/base/network_change_notifier_win.cc (working copy)
@@ -5,84 +5,35 @@
#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"
+#pragma comment(lib, "iphlpapi.lib")
namespace net {
-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_));
+NetworkChangeNotifierWin::NetworkChangeNotifierWin() {
+ memset(&addr_overlapped_, 0, sizeof addr_overlapped_);
addr_overlapped_.hEvent = WSACreateEvent();
}
-NetworkChangeNotifierWin::Impl::~Impl() {
+NetworkChangeNotifierWin::~NetworkChangeNotifierWin() {
CancelIPChangeNotify(&addr_overlapped_);
addr_watcher_.StopWatching();
WSACloseEvent(addr_overlapped_.hEvent);
- memset(&addr_overlapped_, 0, sizeof(addr_overlapped_));
}
-void NetworkChangeNotifierWin::Impl::WatchForAddressChange() {
+void NetworkChangeNotifierWin::OnObjectSignaled(HANDLE object) {
+ NotifyObserversOfIPAddressChange();
+
+ // Start watching for the next address change.
+ WatchForAddressChange();
+}
+
+void NetworkChangeNotifierWin::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();
-}
-void NetworkChangeNotifierWin::OnIPAddressChanged() {
- DCHECK(CalledOnValidThread());
- FOR_EACH_OBSERVER(Observer, observers_, OnIPAddressChanged());
-}
-
-void NetworkChangeNotifierWin::AddObserver(Observer* observer) {
- DCHECK(CalledOnValidThread());
- observers_.AddObserver(observer);
-}
-
-void NetworkChangeNotifierWin::RemoveObserver(Observer* observer) {
- DCHECK(CalledOnValidThread());
- observers_.RemoveObserver(observer);
-}
-
-NetworkChangeNotifierWin::~NetworkChangeNotifierWin() {
- DCHECK(CalledOnValidThread());
-}
-
} // namespace net

Powered by Google App Engine
This is Rietveld 408576698