summaryrefslogtreecommitdiffstats
path: root/net/base
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-03 19:06:01 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-03 19:06:01 +0000
commit9715b85f74e95db5345fd33ef43ff48eb0ce983f (patch)
tree4db4724ac54f5e6a37d0cd6f42e2159e69db4d54 /net/base
parent1cfb7420fb7ea2fa5a6360bbee5424918e84a027 (diff)
downloadchromium_src-9715b85f74e95db5345fd33ef43ff48eb0ce983f.zip
chromium_src-9715b85f74e95db5345fd33ef43ff48eb0ce983f.tar.gz
chromium_src-9715b85f74e95db5345fd33ef43ff48eb0ce983f.tar.bz2
Fix NetworkChangeNotifier crashes on Mac.
Revert r58230. BUG=54305,53138 TEST=Make sure ethernet is plugged in. Run Chrome. Unplug ethernet. Does not crash. Review URL: http://codereview.chromium.org/3350009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58520 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base')
-rw-r--r--net/base/network_change_notifier_mac.cc6
-rw-r--r--net/base/network_change_notifier_mac.h36
-rw-r--r--net/base/network_config_watcher_mac.cc34
-rw-r--r--net/base/network_config_watcher_mac.h36
4 files changed, 39 insertions, 73 deletions
diff --git a/net/base/network_change_notifier_mac.cc b/net/base/network_change_notifier_mac.cc
index d07a15c..4c46a99 100644
--- a/net/base/network_change_notifier_mac.cc
+++ b/net/base/network_change_notifier_mac.cc
@@ -9,14 +9,10 @@
namespace net {
-NetworkChangeNotifierMac::NetworkChangeNotifierMac()
- : forwarder_(this),
- config_watcher_(&forwarder_) {}
-NetworkChangeNotifierMac::~NetworkChangeNotifierMac() {}
+NetworkChangeNotifierMac::NetworkChangeNotifierMac() {}
void NetworkChangeNotifierMac::SetDynamicStoreNotificationKeys(
SCDynamicStoreRef store) {
- // Called on notifier thread.
scoped_cftyperef<CFMutableArrayRef> notification_keys(
CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks));
scoped_cftyperef<CFStringRef> key(SCDynamicStoreKeyCreateNetworkGlobalEntity(
diff --git a/net/base/network_change_notifier_mac.h b/net/base/network_change_notifier_mac.h
index 33cf99c..1d23524 100644
--- a/net/base/network_change_notifier_mac.h
+++ b/net/base/network_change_notifier_mac.h
@@ -14,39 +14,17 @@
namespace net {
-class NetworkChangeNotifierMac: public NetworkChangeNotifier {
+class NetworkChangeNotifierMac : public NetworkConfigWatcherMac,
+ public NetworkChangeNotifier {
public:
NetworkChangeNotifierMac();
- virtual ~NetworkChangeNotifierMac();
- private:
- // Forwarder just exists to keep the NetworkConfigWatcherMac API out of
- // NetworkChangeNotifierMac's public API.
- class Forwarder : public NetworkConfigWatcherMac::Delegate {
- public:
- explicit Forwarder(NetworkChangeNotifierMac* net_config_watcher)
- : net_config_watcher_(net_config_watcher_) {}
-
- // NetworkConfigWatcherMac::Delegate implementation:
- virtual void SetDynamicStoreNotificationKeys(SCDynamicStoreRef store) {
- net_config_watcher_->SetDynamicStoreNotificationKeys(store);
- }
- virtual void OnNetworkConfigChange(CFArrayRef changed_keys) {
- net_config_watcher_->OnNetworkConfigChange(changed_keys);
- }
-
- private:
- NetworkChangeNotifierMac* const net_config_watcher_;
- DISALLOW_COPY_AND_ASSIGN(Forwarder);
- };
-
- // NetworkConfigWatcherMac::Delegate implementation:
- void SetDynamicStoreNotificationKeys(SCDynamicStoreRef store);
- void OnNetworkConfigChange(CFArrayRef changed_keys);
-
- Forwarder forwarder_;
- const NetworkConfigWatcherMac config_watcher_;
+ protected:
+ // NetworkConfigWatcherMac implementation:
+ virtual void SetDynamicStoreNotificationKeys(SCDynamicStoreRef store);
+ virtual void OnNetworkConfigChange(CFArrayRef changed_keys);
+ private:
DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierMac);
};
diff --git a/net/base/network_config_watcher_mac.cc b/net/base/network_config_watcher_mac.cc
index 7a77b35..8767dff 100644
--- a/net/base/network_config_watcher_mac.cc
+++ b/net/base/network_config_watcher_mac.cc
@@ -15,23 +15,8 @@ DISABLE_RUNNABLE_METHOD_REFCOUNT(net::NetworkConfigWatcherMac);
namespace net {
-namespace {
-
-// Called back by OS. Calls OnNetworkConfigChange().
-void DynamicStoreCallback(SCDynamicStoreRef /* store */,
- CFArrayRef changed_keys,
- void* config_delegate) {
- NetworkConfigWatcherMac::Delegate* net_config_delegate =
- static_cast<NetworkConfigWatcherMac::Delegate*>(config_delegate);
- net_config_delegate->OnNetworkConfigChange(changed_keys);
-}
-
-} // namespace
-
-NetworkConfigWatcherMac::NetworkConfigWatcherMac(
- Delegate* delegate)
- : notifier_thread_(new base::Thread("NetworkConfigWatcher")),
- delegate_(delegate) {
+NetworkConfigWatcherMac::NetworkConfigWatcherMac()
+ : notifier_thread_(new base::Thread("NetworkConfigWatcher")) {
// We create this notifier thread because the notification implementation
// needs a thread with a CFRunLoop, and there's no guarantee that
// MessageLoop::current() meets that criterion.
@@ -40,8 +25,7 @@ NetworkConfigWatcherMac::NetworkConfigWatcherMac(
// TODO(willchan): Look to see if there's a better signal for when it's ok to
// initialize this, rather than just delaying it by a fixed time.
const int kNotifierThreadInitializationDelayMS = 1000;
- notifier_thread_->message_loop()->PostDelayedTask(
- FROM_HERE,
+ notifier_thread_->message_loop()->PostDelayedTask(FROM_HERE,
NewRunnableMethod(this, &NetworkConfigWatcherMac::Init),
kNotifierThreadInitializationDelayMS);
}
@@ -53,6 +37,16 @@ NetworkConfigWatcherMac::~NetworkConfigWatcherMac() {
DCHECK(run_loop_source_ == NULL);
}
+// static
+void NetworkConfigWatcherMac::DynamicStoreCallback(
+ SCDynamicStoreRef /* store */,
+ CFArrayRef changed_keys,
+ void* config) {
+ NetworkConfigWatcherMac* net_config =
+ static_cast<NetworkConfigWatcherMac*>(config);
+ net_config->OnNetworkConfigChange(changed_keys);
+}
+
void NetworkConfigWatcherMac::WillDestroyCurrentMessageLoop() {
DCHECK(notifier_thread_ != NULL);
// We can't check the notifier_thread_'s message_loop(), as it's now 0.
@@ -84,7 +78,7 @@ void NetworkConfigWatcherMac::Init() {
kCFRunLoopCommonModes);
// Set up notifications for interface and IP address changes.
- delegate_->SetDynamicStoreNotificationKeys(store.get());
+ SetDynamicStoreNotificationKeys(store.get());
MessageLoop::current()->AddDestructionObserver(this);
}
diff --git a/net/base/network_config_watcher_mac.h b/net/base/network_config_watcher_mac.h
index 78f06a5..71fb825 100644
--- a/net/base/network_config_watcher_mac.h
+++ b/net/base/network_config_watcher_mac.h
@@ -21,26 +21,26 @@ namespace net {
// Base class for watching the Mac OS system network settings.
class NetworkConfigWatcherMac : public MessageLoop::DestructionObserver {
public:
- // NOTE: The lifetime of Delegate is expected to exceed the lifetime of
- // NetworkConfigWatcherMac.
- class Delegate {
- public:
- virtual ~Delegate() {}
-
- // Called to register the notification keys on |store|.
- // Implementors are expected to call SCDynamicStoreSetNotificationKeys().
- // Will be called on the notifier thread.
- virtual void SetDynamicStoreNotificationKeys(SCDynamicStoreRef store) = 0;
-
- // Called when one of the notification keys has changed.
- // Will be called on the notifier thread.
- virtual void OnNetworkConfigChange(CFArrayRef changed_keys) = 0;
- };
-
- explicit NetworkConfigWatcherMac(Delegate* delegate);
+ NetworkConfigWatcherMac();
+
+ protected:
virtual ~NetworkConfigWatcherMac();
+ // Called to register the notification keys on |store|.
+ // Implementors are expected to call SCDynamicStoreSetNotificationKeys().
+ // Will be called on the notifier thread.
+ virtual void SetDynamicStoreNotificationKeys(SCDynamicStoreRef store) = 0;
+
+ // Called when one of the notification keys has changed.
+ // Will be called on the notifier thread.
+ virtual void OnNetworkConfigChange(CFArrayRef changed_keys) = 0;
+
private:
+ // Called back by OS. Calls OnNetworkConfigChange().
+ static void DynamicStoreCallback(SCDynamicStoreRef /* store */,
+ CFArrayRef changed_keys,
+ void* config);
+
// MessageLoop::DestructionObserver:
virtual void WillDestroyCurrentMessageLoop();
@@ -57,8 +57,6 @@ class NetworkConfigWatcherMac : public MessageLoop::DestructionObserver {
scoped_cftyperef<CFRunLoopSourceRef> run_loop_source_;
- Delegate* const delegate_;
-
DISALLOW_COPY_AND_ASSIGN(NetworkConfigWatcherMac);
};