From 9715b85f74e95db5345fd33ef43ff48eb0ce983f Mon Sep 17 00:00:00 2001
From: "willchan@chromium.org"
 <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>
Date: Fri, 3 Sep 2010 19:06:01 +0000
Subject: 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
---
 net/base/network_config_watcher_mac.cc | 34 ++++++++++++++--------------------
 1 file changed, 14 insertions(+), 20 deletions(-)

(limited to 'net/base/network_config_watcher_mac.cc')

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);
 }
-- 
cgit v1.1