diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-17 21:24:02 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-17 21:24:02 +0000 |
commit | afed2dc02a3cce27bbe132aa9f97cb5bbb31d45a (patch) | |
tree | dd57bea37e892bf63dbcbd3d759548a3b1b626eb /net | |
parent | e106b901229419b078903bdd7f2bac97f2932bdc (diff) | |
download | chromium_src-afed2dc02a3cce27bbe132aa9f97cb5bbb31d45a.zip chromium_src-afed2dc02a3cce27bbe132aa9f97cb5bbb31d45a.tar.gz chromium_src-afed2dc02a3cce27bbe132aa9f97cb5bbb31d45a.tar.bz2 |
Implement a TODO: Move "NonThreadSafe" inheritance from NetworkChangeNotifier interface to implementations. Also add CalledOnValidThread() DCHECKs in as many places as possible.
Some minor style changes.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/2813019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50139 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-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 |
8 files changed, 82 insertions, 49 deletions
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; |