diff options
Diffstat (limited to 'net/base/network_config_watcher_mac.cc')
-rw-r--r-- | net/base/network_config_watcher_mac.cc | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/net/base/network_config_watcher_mac.cc b/net/base/network_config_watcher_mac.cc index 8767dff..8e60223 100644 --- a/net/base/network_config_watcher_mac.cc +++ b/net/base/network_config_watcher_mac.cc @@ -15,8 +15,23 @@ DISABLE_RUNNABLE_METHOD_REFCOUNT(net::NetworkConfigWatcherMac); namespace net { -NetworkConfigWatcherMac::NetworkConfigWatcherMac() - : notifier_thread_(new base::Thread("NetworkConfigWatcher")) { +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) { // 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. @@ -25,7 +40,8 @@ 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); } @@ -37,16 +53,6 @@ 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. @@ -64,11 +70,11 @@ void NetworkConfigWatcherMac::Init() { // Add a run loop source for a dynamic store to the current run loop. SCDynamicStoreContext context = { - 0, // Version 0. - this, // User data. - NULL, // This is not reference counted. No retain function. - NULL, // This is not reference counted. No release function. - NULL, // No description for this. + 0, // Version 0. + delegate_, // User data. + NULL, // This is not reference counted. No retain function. + NULL, // This is not reference counted. No release function. + NULL, // No description for this. }; scoped_cftyperef<SCDynamicStoreRef> store(SCDynamicStoreCreate( NULL, CFSTR("org.chromium"), DynamicStoreCallback, &context)); @@ -78,7 +84,7 @@ void NetworkConfigWatcherMac::Init() { kCFRunLoopCommonModes); // Set up notifications for interface and IP address changes. - SetDynamicStoreNotificationKeys(store.get()); + delegate_->SetDynamicStoreNotificationKeys(store.get()); MessageLoop::current()->AddDestructionObserver(this); } |