diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-24 22:41:47 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-24 22:41:47 +0000 |
commit | 6531594abea873c883782041fea5d126507497e1 (patch) | |
tree | 017227faab41fb16f84a2485ec9b03d3f783d132 /net | |
parent | 60a782e6a5a80fbba8fe690f05502147ae998d8c (diff) | |
download | chromium_src-6531594abea873c883782041fea5d126507497e1.zip chromium_src-6531594abea873c883782041fea5d126507497e1.tar.gz chromium_src-6531594abea873c883782041fea5d126507497e1.tar.bz2 |
Switch NetworkChangeNotifier implementations to use ObserverList.
Fix up observer list so we can use FOR_EACH_OBSERVER when check_empty is set.
Clean up the ObserverList API a bit, replacing GetElementAt() with HasObserver() and Clear().
BUG=36590
Review URL: http://codereview.chromium.org/652205
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39942 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/base/network_change_notifier_helper.cc | 45 | ||||
-rw-r--r-- | net/base/network_change_notifier_helper.h | 44 | ||||
-rw-r--r-- | net/base/network_change_notifier_linux.cc | 2 | ||||
-rw-r--r-- | net/base/network_change_notifier_linux.h | 9 | ||||
-rw-r--r-- | net/base/network_change_notifier_mac.h | 14 | ||||
-rw-r--r-- | net/base/network_change_notifier_win.cc | 2 | ||||
-rw-r--r-- | net/base/network_change_notifier_win.h | 16 | ||||
-rw-r--r-- | net/net.gyp | 2 |
8 files changed, 28 insertions, 106 deletions
diff --git a/net/base/network_change_notifier_helper.cc b/net/base/network_change_notifier_helper.cc deleted file mode 100644 index 052e3ef8..0000000 --- a/net/base/network_change_notifier_helper.cc +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "net/base/network_change_notifier_helper.h" -#include <algorithm> -#include "base/logging.h" - -namespace net { - -namespace internal { - -NetworkChangeNotifierHelper::NetworkChangeNotifierHelper() - : is_notifying_observers_(false) {} - -NetworkChangeNotifierHelper::~NetworkChangeNotifierHelper() { - // TODO(willchan): Re-enable this DCHECK after fixing http://crbug.com/34391 - // since we're leaking URLRequestContextGetters that cause this DCHECK to - // fire. - // DCHECK(observers_.empty()); -} - -void NetworkChangeNotifierHelper::AddObserver(Observer* observer) { - DCHECK(!is_notifying_observers_); - observers_.push_back(observer); -} - -void NetworkChangeNotifierHelper::RemoveObserver(Observer* observer) { - DCHECK(!is_notifying_observers_); - observers_.erase(std::remove(observers_.begin(), observers_.end(), observer)); -} - -void NetworkChangeNotifierHelper::OnIPAddressChanged() { - DCHECK(!is_notifying_observers_); - is_notifying_observers_ = true; - for (std::vector<Observer*>::iterator it = observers_.begin(); - it != observers_.end(); ++it) { - (*it)->OnIPAddressChanged(); - } - is_notifying_observers_ = false; -} - -} // namespace internal - -} // namespace net diff --git a/net/base/network_change_notifier_helper.h b/net/base/network_change_notifier_helper.h deleted file mode 100644 index f860c45..0000000 --- a/net/base/network_change_notifier_helper.h +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// NetworkChangeNotifierHelper is a helper class that assists in implementing -// base functionality for a NetworkChangeNotifier implementation. In -// particular, it manages adding/removing observers and sending them -// notifications of event changes. - -#ifndef NET_BASE_NETWORK_CHANGE_NOTIFIER_HELPER_H_ -#define NET_BASE_NETWORK_CHANGE_NOTIFIER_HELPER_H_ - -#include <vector> -#include "base/basictypes.h" -#include "net/base/network_change_notifier.h" - -namespace net { - -namespace internal { - -class NetworkChangeNotifierHelper { - public: - typedef NetworkChangeNotifier::Observer Observer; - - NetworkChangeNotifierHelper(); - ~NetworkChangeNotifierHelper(); - - void AddObserver(Observer* observer); - void RemoveObserver(Observer* observer); - - void OnIPAddressChanged(); - - private: - bool is_notifying_observers_; - std::vector<Observer*> observers_; - - DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierHelper); -}; - -} // namespace internal - -} // namespace net - -#endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_HELPER_H_ diff --git a/net/base/network_change_notifier_linux.cc b/net/base/network_change_notifier_linux.cc index 2a85c15..e6f5453 100644 --- a/net/base/network_change_notifier_linux.cc +++ b/net/base/network_change_notifier_linux.cc @@ -57,7 +57,7 @@ void NetworkChangeNotifierLinux::ListenForNotifications() { int rv = ReadNotificationMessage(buf, arraysize(buf)); while (rv > 0 ) { if (HandleNetlinkMessage(buf, rv)) - helper_.OnIPAddressChanged(); + FOR_EACH_OBSERVER(Observer, observers_, OnIPAddressChanged()); rv = ReadNotificationMessage(buf, arraysize(buf)); } diff --git a/net/base/network_change_notifier_linux.h b/net/base/network_change_notifier_linux.h index 323ea55..91d73e8 100644 --- a/net/base/network_change_notifier_linux.h +++ b/net/base/network_change_notifier_linux.h @@ -7,7 +7,8 @@ #include "base/basictypes.h" #include "base/message_loop.h" -#include "net/base/network_change_notifier_helper.h" +#include "base/observer_list.h" +#include "net/base/network_change_notifier.h" namespace net { @@ -19,11 +20,11 @@ class NetworkChangeNotifierLinux // NetworkChangeNotifier methods: virtual void AddObserver(Observer* observer) { - helper_.AddObserver(observer); + observers_.AddObserver(observer); } virtual void RemoveObserver(Observer* observer) { - helper_.RemoveObserver(observer); + observers_.RemoveObserver(observer); } // MessageLoopForIO::Watcher methods: @@ -46,7 +47,7 @@ class NetworkChangeNotifierLinux // Handles the netlink message and notifies the observers. void HandleNotifications(const char* buf, size_t len); - internal::NetworkChangeNotifierHelper helper_; + ObserverList<Observer, true> observers_; int netlink_fd_; // This is the netlink socket descriptor. MessageLoopForIO* const loop_; diff --git a/net/base/network_change_notifier_mac.h b/net/base/network_change_notifier_mac.h index 5e777f4..44d4806 100644 --- a/net/base/network_change_notifier_mac.h +++ b/net/base/network_change_notifier_mac.h @@ -6,11 +6,11 @@ #define NET_BASE_NETWORK_CHANGE_NOTIFIER_MAC_H_ #include "base/basictypes.h" +#include "base/observer_list.h" #include "base/ref_counted.h" #include "base/scoped_ptr.h" #include "base/task.h" #include "net/base/network_change_notifier.h" -#include "net/base/network_change_notifier_helper.h" class MessageLoop; namespace base { @@ -23,16 +23,18 @@ class NetworkChangeNotifierMac : public NetworkChangeNotifier { public: NetworkChangeNotifierMac(); - void OnIPAddressChanged() { helper_.OnIPAddressChanged(); } + void OnIPAddressChanged() { + FOR_EACH_OBSERVER(Observer, observers_, OnIPAddressChanged()); + } // NetworkChangeNotifier methods: virtual void AddObserver(Observer* observer) { - helper_.AddObserver(observer); + observers_.AddObserver(observer); } virtual void RemoveObserver(Observer* observer) { - helper_.RemoveObserver(observer); + observers_.RemoveObserver(observer); } private: @@ -49,7 +51,9 @@ class NetworkChangeNotifierMac : public NetworkChangeNotifier { // Receives the OS X network change notifications on this thread. scoped_ptr<base::Thread> notifier_thread_; - internal::NetworkChangeNotifierHelper helper_; + // TODO(willchan): Fix the URLRequestContextGetter leaks and flip the false to + // true so we assert that all observers have been removed. + ObserverList<Observer, false> observers_; // Used to initialize the notifier thread. ScopedRunnableMethodFactory<NetworkChangeNotifierMac> method_factory_; diff --git a/net/base/network_change_notifier_win.cc b/net/base/network_change_notifier_win.cc index e52bd46..d139eb0f 100644 --- a/net/base/network_change_notifier_win.cc +++ b/net/base/network_change_notifier_win.cc @@ -3,9 +3,11 @@ // 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" diff --git a/net/base/network_change_notifier_win.h b/net/base/network_change_notifier_win.h index b11ec0d..0f1f8d4 100644 --- a/net/base/network_change_notifier_win.h +++ b/net/base/network_change_notifier_win.h @@ -7,7 +7,8 @@ #include "base/basictypes.h" #include "base/object_watcher.h" -#include "net/base/network_change_notifier_helper.h" +#include "base/observer_list.h" +#include "net/base/network_change_notifier.h" namespace net { @@ -16,16 +17,19 @@ class NetworkChangeNotifierWin : public NetworkChangeNotifier { NetworkChangeNotifierWin(); // Called by NetworkChangeNotifierWin::Impl. - void OnIPAddressChanged() { helper_.OnIPAddressChanged(); } + void OnIPAddressChanged() { + FOR_EACH_OBSERVER(Observer, observers_, OnIPAddressChanged()); + } + // NetworkChangeNotifier methods: virtual void AddObserver(Observer* observer) { - helper_.AddObserver(observer); + observers_.AddObserver(observer); } virtual void RemoveObserver(Observer* observer) { - helper_.RemoveObserver(observer); + observers_.RemoveObserver(observer); } private: @@ -33,7 +37,9 @@ class NetworkChangeNotifierWin : public NetworkChangeNotifier { virtual ~NetworkChangeNotifierWin(); - internal::NetworkChangeNotifierHelper helper_; + // TODO(willchan): Fix the URLRequestContextGetter leaks and flip the false to + // true so we assert that all observers have been removed. + ObserverList<Observer, false> observers_; scoped_ptr<Impl> impl_; DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierWin); diff --git a/net/net.gyp b/net/net.gyp index 3fc9653..7cabfc7 100644 --- a/net/net.gyp +++ b/net/net.gyp @@ -107,8 +107,6 @@ 'base/net_util_win.cc', 'base/network_change_notifier.cc', 'base/network_change_notifier.h', - 'base/network_change_notifier_helper.cc', - 'base/network_change_notifier_helper.h', 'base/network_change_notifier_linux.cc', 'base/network_change_notifier_linux.h', 'base/network_change_notifier_mac.cc', |