diff options
-rw-r--r-- | chrome/common/net/network_change_notifier_proxy.cc | 18 | ||||
-rw-r--r-- | chrome/common/net/network_change_notifier_proxy.h | 11 | ||||
-rw-r--r-- | net/base/mock_network_change_notifier.h | 6 | ||||
-rw-r--r-- | net/base/network_change_notifier.h | 5 | ||||
-rw-r--r-- | net/base/network_change_notifier_linux.cc | 19 | ||||
-rw-r--r-- | net/base/network_change_notifier_linux.h | 16 | ||||
-rw-r--r-- | net/base/network_change_notifier_mac.cc | 24 | ||||
-rw-r--r-- | net/base/network_change_notifier_mac.h | 22 | ||||
-rw-r--r-- | net/base/network_change_notifier_win.cc | 18 | ||||
-rw-r--r-- | net/base/network_change_notifier_win.h | 21 |
10 files changed, 94 insertions, 66 deletions
diff --git a/chrome/common/net/network_change_notifier_proxy.cc b/chrome/common/net/network_change_notifier_proxy.cc index 8a25d22..a0a1961 100644 --- a/chrome/common/net/network_change_notifier_proxy.cc +++ b/chrome/common/net/network_change_notifier_proxy.cc @@ -15,13 +15,6 @@ NetworkChangeNotifierProxy::NetworkChangeNotifierProxy( : observer_proxy_(new NetworkChangeObserverProxy( source_thread, MessageLoop::current())), observer_repeater_(&observers_) { - // TODO(akalin): We get this from NonThreadSafe, which - // net::NetworkChangeNotifier inherits from. Interface classes - // really shouldn't be inheriting from NonThreadSafe; make it so - // that all the implementations of net::NetworkChangeNotifier - // inherit from NonThreadSafe directly and - // net::NetworkChangeNotifier doesn't. - DCHECK(CalledOnValidThread()); DCHECK(observer_proxy_); observer_proxy_->Attach(&observer_repeater_); } @@ -44,16 +37,19 @@ void NetworkChangeNotifierProxy::RemoveObserver( } NetworkChangeNotifierProxy::ObserverRepeater::ObserverRepeater( - NetworkObserverList* observers) : observers_(observers) { + NetworkObserverList* observers) + : observers_(observers) { DCHECK(observers_); } -NetworkChangeNotifierProxy::ObserverRepeater::~ObserverRepeater() {} +NetworkChangeNotifierProxy::ObserverRepeater::~ObserverRepeater() { + DCHECK(CalledOnValidThread()); +} void NetworkChangeNotifierProxy::ObserverRepeater::OnIPAddressChanged() { DCHECK(CalledOnValidThread()); - FOR_EACH_OBSERVER(net::NetworkChangeNotifier::Observer, - *observers_, OnIPAddressChanged()); + FOR_EACH_OBSERVER(net::NetworkChangeNotifier::Observer, *observers_, + OnIPAddressChanged()); } } // namespace chrome_common_net diff --git a/chrome/common/net/network_change_notifier_proxy.h b/chrome/common/net/network_change_notifier_proxy.h index 916d5f8..7ed01a8 100644 --- a/chrome/common/net/network_change_notifier_proxy.h +++ b/chrome/common/net/network_change_notifier_proxy.h @@ -21,19 +21,18 @@ namespace chrome_common_net { class NetworkChangeNotifierThread; class NetworkChangeObserverProxy; -class NetworkChangeNotifierProxy : public net::NetworkChangeNotifier { +class NetworkChangeNotifierProxy : public net::NetworkChangeNotifier, + public NonThreadSafe { public: // |source_thread| must be guaranteed to outlive the current thread. // Does not take ownership of any arguments. - NetworkChangeNotifierProxy( + explicit NetworkChangeNotifierProxy( NetworkChangeNotifierThread* source_thread); virtual ~NetworkChangeNotifierProxy(); // net::NetworkChangeNotifier implementation. - virtual void AddObserver(net::NetworkChangeNotifier::Observer* observer); - virtual void RemoveObserver(net::NetworkChangeNotifier::Observer* observer); private: @@ -42,8 +41,8 @@ class NetworkChangeNotifierProxy : public net::NetworkChangeNotifier { // Utility class that routes received notifications to a list of // observers. - class ObserverRepeater : public NonThreadSafe, - public net::NetworkChangeNotifier::Observer { + class ObserverRepeater : public net::NetworkChangeNotifier::Observer, + public NonThreadSafe { public: // Does not take ownership of the given observer list. explicit ObserverRepeater(NetworkObserverList* observers); diff --git a/net/base/mock_network_change_notifier.h b/net/base/mock_network_change_notifier.h index 840d2e8..7d1b38e 100644 --- a/net/base/mock_network_change_notifier.h +++ b/net/base/mock_network_change_notifier.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -6,11 +6,13 @@ #define NET_BASE_MOCK_NETWORK_CHANGE_NOTIFIER_H_ #include "base/basictypes.h" +#include "base/non_thread_safe.h" #include "net/base/network_change_notifier.h" namespace net { -class MockNetworkChangeNotifier : public NetworkChangeNotifier { +class MockNetworkChangeNotifier : public NetworkChangeNotifier, + public NonThreadSafe { public: MockNetworkChangeNotifier() : observer_(NULL) {} diff --git a/net/base/network_change_notifier.h b/net/base/network_change_notifier.h index 67d57ff..70b195d 100644 --- a/net/base/network_change_notifier.h +++ b/net/base/network_change_notifier.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -6,13 +6,12 @@ #define NET_BASE_NETWORK_CHANGE_NOTIFIER_H_ #include "base/basictypes.h" -#include "base/non_thread_safe.h" namespace net { // NetworkChangeNotifier monitors the system for network changes, and notifies // observers on those events. -class NetworkChangeNotifier : public NonThreadSafe { +class NetworkChangeNotifier { public: class Observer { public: diff --git a/net/base/network_change_notifier_linux.cc b/net/base/network_change_notifier_linux.cc index 03a098b..9821be5 100644 --- a/net/base/network_change_notifier_linux.cc +++ b/net/base/network_change_notifier_linux.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -39,28 +39,43 @@ NetworkChangeNotifierLinux::NetworkChangeNotifierLinux() } NetworkChangeNotifierLinux::~NetworkChangeNotifierLinux() { + DCHECK(CalledOnValidThread()); StopWatching(); if (loop_) loop_->RemoveDestructionObserver(this); } +void NetworkChangeNotifierLinux::AddObserver(Observer* observer) { + DCHECK(CalledOnValidThread()); + observers_.AddObserver(observer); +} + +void NetworkChangeNotifierLinux::RemoveObserver(Observer* observer) { + DCHECK(CalledOnValidThread()); + observers_.RemoveObserver(observer); +} + void NetworkChangeNotifierLinux::OnFileCanReadWithoutBlocking(int fd) { + DCHECK(CalledOnValidThread()); DCHECK_EQ(fd, netlink_fd_); ListenForNotifications(); } void NetworkChangeNotifierLinux::OnFileCanWriteWithoutBlocking(int /* fd */) { + DCHECK(CalledOnValidThread()); NOTREACHED(); } void NetworkChangeNotifierLinux::WillDestroyCurrentMessageLoop() { + DCHECK(CalledOnValidThread()); StopWatching(); loop_ = NULL; } void NetworkChangeNotifierLinux::ListenForNotifications() { + DCHECK(CalledOnValidThread()); char buf[4096]; int rv = ReadNotificationMessage(buf, arraysize(buf)); while (rv > 0 ) { @@ -97,6 +112,7 @@ void NetworkChangeNotifierLinux::NotifyObserversIPAddressChanged() { } int NetworkChangeNotifierLinux::ReadNotificationMessage(char* buf, size_t len) { + DCHECK(CalledOnValidThread()); DCHECK_NE(len, 0u); DCHECK(buf); @@ -116,6 +132,7 @@ int NetworkChangeNotifierLinux::ReadNotificationMessage(char* buf, size_t len) { } void NetworkChangeNotifierLinux::StopWatching() { + DCHECK(CalledOnValidThread()); if (netlink_fd_ != kInvalidSocket) { if (HANDLE_EINTR(close(netlink_fd_)) != 0) PLOG(ERROR) << "Failed to close socket"; diff --git a/net/base/network_change_notifier_linux.h b/net/base/network_change_notifier_linux.h index b2b47a4..dcedbf4 100644 --- a/net/base/network_change_notifier_linux.h +++ b/net/base/network_change_notifier_linux.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -7,6 +7,7 @@ #include "base/basictypes.h" #include "base/message_loop.h" +#include "base/non_thread_safe.h" #include "base/observer_list.h" #include "net/base/network_change_notifier.h" @@ -18,28 +19,21 @@ namespace net { class NetworkChangeNotifierLinux : public NetworkChangeNotifier, + public NonThreadSafe, public MessageLoopForIO::Watcher, public MessageLoop::DestructionObserver { public: NetworkChangeNotifierLinux(); // NetworkChangeNotifier methods: - - virtual void AddObserver(Observer* observer) { - observers_.AddObserver(observer); - } - - virtual void RemoveObserver(Observer* observer) { - observers_.RemoveObserver(observer); - } + virtual void AddObserver(Observer* observer); + virtual void RemoveObserver(Observer* observer); // MessageLoopForIO::Watcher methods: - virtual void OnFileCanReadWithoutBlocking(int fd); virtual void OnFileCanWriteWithoutBlocking(int /* fd */); // MessageLoop::DestructionObserver methods: - virtual void WillDestroyCurrentMessageLoop(); private: diff --git a/net/base/network_change_notifier_mac.cc b/net/base/network_change_notifier_mac.cc index 2dd1b4d..ba38907 100644 --- a/net/base/network_change_notifier_mac.cc +++ b/net/base/network_change_notifier_mac.cc @@ -1,10 +1,10 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. // There are three classes involved here. There's NetworkChangeNotifierMac, // which is the Mac specific implementation of NetworkChangeNotifier. It is the -// class with which clients can register themselves as network change +// class with which clients can register themselves as network change // observers. There's NetworkChangeNotifierThread, which is a base::Thread // subclass of MessageLoop::TYPE_UI (since it needs a CFRunLoop) that contains // the NetworkChangeNotifierImpl. NetworkChangeNotifierImpl is the object @@ -232,9 +232,27 @@ NetworkChangeNotifierMac::NetworkChangeNotifierMac() kNotifierThreadInitializationDelayMS); } -NetworkChangeNotifierMac::~NetworkChangeNotifierMac() {} +void NetworkChangeNotifierMac::OnIPAddressChanged() { + DCHECK(CalledOnValidThread()); + FOR_EACH_OBSERVER(Observer, observers_, OnIPAddressChanged()); +} + +void NetworkChangeNotifierMac::AddObserver(Observer* observer) { + DCHECK(CalledOnValidThread()); + observers_.AddObserver(observer); +} + +void NetworkChangeNotifierMac::RemoveObserver(Observer* observer) { + DCHECK(CalledOnValidThread()); + observers_.RemoveObserver(observer); +} + +NetworkChangeNotifierMac::~NetworkChangeNotifierMac() { + DCHECK(CalledOnValidThread()); +} void NetworkChangeNotifierMac::InitializeNotifierThread(MessageLoop* loop) { + DCHECK(CalledOnValidThread()); notifier_thread_.reset(new NetworkChangeNotifierThread(loop, this)); base::Thread::Options thread_options; thread_options.message_loop_type = MessageLoop::TYPE_UI; diff --git a/net/base/network_change_notifier_mac.h b/net/base/network_change_notifier_mac.h index 44d4806..2ffaaba 100644 --- a/net/base/network_change_notifier_mac.h +++ b/net/base/network_change_notifier_mac.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -6,6 +6,7 @@ #define NET_BASE_NETWORK_CHANGE_NOTIFIER_MAC_H_ #include "base/basictypes.h" +#include "base/non_thread_safe.h" #include "base/observer_list.h" #include "base/ref_counted.h" #include "base/scoped_ptr.h" @@ -19,27 +20,20 @@ class Thread; namespace net { -class NetworkChangeNotifierMac : public NetworkChangeNotifier { +class NetworkChangeNotifierMac : public NetworkChangeNotifier, + public NonThreadSafe { public: NetworkChangeNotifierMac(); - void OnIPAddressChanged() { - FOR_EACH_OBSERVER(Observer, observers_, OnIPAddressChanged()); - } + void OnIPAddressChanged(); // NetworkChangeNotifier methods: - - virtual void AddObserver(Observer* observer) { - observers_.AddObserver(observer); - } - - virtual void RemoveObserver(Observer* observer) { - observers_.RemoveObserver(observer); - } + virtual void AddObserver(Observer* observer); + virtual void RemoveObserver(Observer* observer); private: friend class base::RefCounted<NetworkChangeNotifierMac>; - + virtual ~NetworkChangeNotifierMac(); // Initializes the notifier thread. The SystemConfiguration calls in this diff --git a/net/base/network_change_notifier_win.cc b/net/base/network_change_notifier_win.cc index 02b1834..bed361c 100644 --- a/net/base/network_change_notifier_win.cc +++ b/net/base/network_change_notifier_win.cc @@ -66,7 +66,23 @@ 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); +} -NetworkChangeNotifierWin::~NetworkChangeNotifierWin() {} +void NetworkChangeNotifierWin::RemoveObserver(Observer* observer) { + DCHECK(CalledOnValidThread()); + observers_.RemoveObserver(observer); +} + +NetworkChangeNotifierWin::~NetworkChangeNotifierWin() { + DCHECK(CalledOnValidThread()); +} } // namespace net diff --git a/net/base/network_change_notifier_win.h b/net/base/network_change_notifier_win.h index 0f1f8d4..ba2f53dc 100644 --- a/net/base/network_change_notifier_win.h +++ b/net/base/network_change_notifier_win.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -6,31 +6,24 @@ #define NET_BASE_NETWORK_CHANGE_NOTIFIER_WIN_H_ #include "base/basictypes.h" +#include "base/non_thread_safe.h" #include "base/object_watcher.h" #include "base/observer_list.h" #include "net/base/network_change_notifier.h" namespace net { -class NetworkChangeNotifierWin : public NetworkChangeNotifier { +class NetworkChangeNotifierWin : public NetworkChangeNotifier, + public NonThreadSafe { public: NetworkChangeNotifierWin(); // Called by NetworkChangeNotifierWin::Impl. - void OnIPAddressChanged() { - FOR_EACH_OBSERVER(Observer, observers_, OnIPAddressChanged()); - } - + void OnIPAddressChanged(); // NetworkChangeNotifier methods: - - virtual void AddObserver(Observer* observer) { - observers_.AddObserver(observer); - } - - virtual void RemoveObserver(Observer* observer) { - observers_.RemoveObserver(observer); - } + virtual void AddObserver(Observer* observer); + virtual void RemoveObserver(Observer* observer); private: class Impl; |