Skip to content

Commit

Permalink
Minor cleanup of Mac/Linux network change notifier code:
Browse files Browse the repository at this point in the history
Add OVERRIDE, replace NewRunnableMethod with Bind,
fix a couple includes.

BUG=none
TEST=compiles


Review URL: http://codereview.chromium.org/8073027

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@103402 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
mmenke@chromium.org committed Sep 30, 2011
1 parent c7b7610 commit 9be87ba
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 15 deletions.
3 changes: 2 additions & 1 deletion net/base/network_change_notifier_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#pragma once

#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "net/base/network_change_notifier.h"

Expand All @@ -22,7 +23,7 @@ class NetworkChangeNotifierLinux : public NetworkChangeNotifier {
virtual ~NetworkChangeNotifierLinux();

// NetworkChangeNotifier:
virtual bool IsCurrentlyOffline() const;
virtual bool IsCurrentlyOffline() const OVERRIDE;

// The thread used to listen for notifications. This relays the notification
// to the registered observers without posting back to the thread the object
Expand Down
10 changes: 6 additions & 4 deletions net/base/network_change_notifier_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <SystemConfiguration/SystemConfiguration.h>

#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/mac/scoped_cftyperef.h"
#include "base/memory/scoped_ptr.h"
#include "base/synchronization/condition_variable.h"
Expand All @@ -24,7 +25,7 @@ class NetworkChangeNotifierMac: public NetworkChangeNotifier {
virtual ~NetworkChangeNotifierMac();

// NetworkChangeNotifier implementation:
virtual bool IsCurrentlyOffline() const;
virtual bool IsCurrentlyOffline() const OVERRIDE;

private:
enum OnlineState {
Expand All @@ -41,13 +42,14 @@ class NetworkChangeNotifierMac: public NetworkChangeNotifier {
: net_config_watcher_(net_config_watcher) {}

// NetworkConfigWatcherMac::Delegate implementation:
virtual void Init() {
virtual void Init() OVERRIDE {
net_config_watcher_->SetInitialState();
}
virtual void SetDynamicStoreNotificationKeys(SCDynamicStoreRef store) {
virtual void SetDynamicStoreNotificationKeys(
SCDynamicStoreRef store) OVERRIDE {
net_config_watcher_->SetDynamicStoreNotificationKeys(store);
}
virtual void OnNetworkConfigChange(CFArrayRef changed_keys) {
virtual void OnNetworkConfigChange(CFArrayRef changed_keys) OVERRIDE {
net_config_watcher_->OnNetworkConfigChange(changed_keys);
}

Expand Down
16 changes: 9 additions & 7 deletions net/base/network_config_watcher_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

#include <algorithm>

#include "base/bind.h"
#include "base/compiler_specific.h"
#include "base/memory/weak_ptr.h"
#include "base/message_loop.h"
#include "base/threading/thread.h"
#include "base/threading/thread_restrictions.h"
#include "base/mac/scoped_cftyperef.h"

namespace net {

Expand All @@ -31,8 +33,8 @@ class NetworkConfigWatcherMacThread : public base::Thread {

protected:
// base::Thread
virtual void Init();
virtual void CleanUp();
virtual void Init() OVERRIDE;
virtual void CleanUp() OVERRIDE;

private:
// The SystemConfiguration calls in this function can lead to contention early
Expand All @@ -41,7 +43,7 @@ class NetworkConfigWatcherMacThread : public base::Thread {

base::mac::ScopedCFTypeRef<CFRunLoopSourceRef> run_loop_source_;
NetworkConfigWatcherMac::Delegate* const delegate_;
ScopedRunnableMethodFactory<NetworkConfigWatcherMacThread> method_factory_;
base::WeakPtrFactory<NetworkConfigWatcherMacThread> weak_factory_;

DISALLOW_COPY_AND_ASSIGN(NetworkConfigWatcherMacThread);
};
Expand All @@ -50,7 +52,7 @@ NetworkConfigWatcherMacThread::NetworkConfigWatcherMacThread(
NetworkConfigWatcherMac::Delegate* delegate)
: base::Thread("NetworkConfigWatcher"),
delegate_(delegate),
ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {}
ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {}

NetworkConfigWatcherMacThread::~NetworkConfigWatcherMacThread() {
// Allow IO because Stop() calls PlatformThread::Join(), which is a blocking
Expand All @@ -72,8 +74,8 @@ void NetworkConfigWatcherMacThread::Init() {
const int kInitializationDelayMS = 1000;
message_loop()->PostDelayedTask(
FROM_HERE,
method_factory_.NewRunnableMethod(
&NetworkConfigWatcherMacThread::InitNotifications),
base::Bind(&NetworkConfigWatcherMacThread::InitNotifications,
weak_factory_.GetWeakPtr()),
kInitializationDelayMS);
}

Expand Down
5 changes: 2 additions & 3 deletions net/base/network_config_watcher_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <SystemConfiguration/SCDynamicStore.h>

#include "base/basictypes.h"
#include "base/message_loop.h"
#include "base/mac/scoped_cftyperef.h"
#include "base/memory/scoped_ptr.h"

Expand All @@ -18,7 +17,7 @@ class Thread;

namespace net {

// Base class for watching the Mac OS system network settings.
// Helper class for watching the Mac OS system network settings.
class NetworkConfigWatcherMac {
public:
// NOTE: The lifetime of Delegate is expected to exceed the lifetime of
Expand All @@ -42,7 +41,7 @@ class NetworkConfigWatcherMac {
};

explicit NetworkConfigWatcherMac(Delegate* delegate);
virtual ~NetworkConfigWatcherMac();
~NetworkConfigWatcherMac();

private:
// The thread used to listen for notifications. This relays the notification
Expand Down
1 change: 1 addition & 0 deletions net/proxy/proxy_config_service_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "base/logging.h"
#include "base/mac/mac_util.h"
#include "base/mac/scoped_cftyperef.h"
#include "base/message_loop.h"
#include "base/sys_string_conversions.h"
#include "net/base/net_errors.h"
#include "net/proxy/proxy_config.h"
Expand Down
2 changes: 2 additions & 0 deletions net/proxy/proxy_config_service_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "net/proxy/proxy_config.h"
#include "net/proxy/proxy_config_service.h"

class MessageLoop;

namespace net {

class ProxyConfigServiceMac : public ProxyConfigService {
Expand Down

0 comments on commit 9be87ba

Please sign in to comment.