| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/base/network_config_watcher_mac.h" | 5 #include "net/base/network_config_watcher_mac.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 protected: | 36 protected: |
| 37 // base::Thread | 37 // base::Thread |
| 38 virtual void Init() OVERRIDE; | 38 virtual void Init() OVERRIDE; |
| 39 virtual void CleanUp() OVERRIDE; | 39 virtual void CleanUp() OVERRIDE; |
| 40 | 40 |
| 41 private: | 41 private: |
| 42 // The SystemConfiguration calls in this function can lead to contention early | 42 // The SystemConfiguration calls in this function can lead to contention early |
| 43 // on, so we invoke this function later on in startup to keep it fast. | 43 // on, so we invoke this function later on in startup to keep it fast. |
| 44 void InitNotifications(); | 44 void InitNotifications(); |
| 45 | 45 |
| 46 base::mac::ScopedCFTypeRef<CFRunLoopSourceRef> run_loop_source_; | 46 base::ScopedCFTypeRef<CFRunLoopSourceRef> run_loop_source_; |
| 47 NetworkConfigWatcherMac::Delegate* const delegate_; | 47 NetworkConfigWatcherMac::Delegate* const delegate_; |
| 48 base::WeakPtrFactory<NetworkConfigWatcherMacThread> weak_factory_; | 48 base::WeakPtrFactory<NetworkConfigWatcherMacThread> weak_factory_; |
| 49 | 49 |
| 50 DISALLOW_COPY_AND_ASSIGN(NetworkConfigWatcherMacThread); | 50 DISALLOW_COPY_AND_ASSIGN(NetworkConfigWatcherMacThread); |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 NetworkConfigWatcherMacThread::NetworkConfigWatcherMacThread( | 53 NetworkConfigWatcherMacThread::NetworkConfigWatcherMacThread( |
| 54 NetworkConfigWatcherMac::Delegate* delegate) | 54 NetworkConfigWatcherMac::Delegate* delegate) |
| 55 : base::Thread("NetworkConfigWatcher"), | 55 : base::Thread("NetworkConfigWatcher"), |
| 56 delegate_(delegate), | 56 delegate_(delegate), |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 #if !defined(OS_IOS) | 94 #if !defined(OS_IOS) |
| 95 // SCDynamicStore API does not exist on iOS. | 95 // SCDynamicStore API does not exist on iOS. |
| 96 // Add a run loop source for a dynamic store to the current run loop. | 96 // Add a run loop source for a dynamic store to the current run loop. |
| 97 SCDynamicStoreContext context = { | 97 SCDynamicStoreContext context = { |
| 98 0, // Version 0. | 98 0, // Version 0. |
| 99 delegate_, // User data. | 99 delegate_, // User data. |
| 100 NULL, // This is not reference counted. No retain function. | 100 NULL, // This is not reference counted. No retain function. |
| 101 NULL, // This is not reference counted. No release function. | 101 NULL, // This is not reference counted. No release function. |
| 102 NULL, // No description for this. | 102 NULL, // No description for this. |
| 103 }; | 103 }; |
| 104 base::mac::ScopedCFTypeRef<SCDynamicStoreRef> store(SCDynamicStoreCreate( | 104 base::ScopedCFTypeRef<SCDynamicStoreRef> store(SCDynamicStoreCreate( |
| 105 NULL, CFSTR("org.chromium"), DynamicStoreCallback, &context)); | 105 NULL, CFSTR("org.chromium"), DynamicStoreCallback, &context)); |
| 106 run_loop_source_.reset(SCDynamicStoreCreateRunLoopSource( | 106 run_loop_source_.reset(SCDynamicStoreCreateRunLoopSource( |
| 107 NULL, store.get(), 0)); | 107 NULL, store.get(), 0)); |
| 108 CFRunLoopAddSource(CFRunLoopGetCurrent(), run_loop_source_.get(), | 108 CFRunLoopAddSource(CFRunLoopGetCurrent(), run_loop_source_.get(), |
| 109 kCFRunLoopCommonModes); | 109 kCFRunLoopCommonModes); |
| 110 #endif // !defined(OS_IOS) | 110 #endif // !defined(OS_IOS) |
| 111 | 111 |
| 112 // Set up notifications for interface and IP address changes. | 112 // Set up notifications for interface and IP address changes. |
| 113 delegate_->StartReachabilityNotifications(); | 113 delegate_->StartReachabilityNotifications(); |
| 114 #if !defined(OS_IOS) | 114 #if !defined(OS_IOS) |
| 115 delegate_->SetDynamicStoreNotificationKeys(store.get()); | 115 delegate_->SetDynamicStoreNotificationKeys(store.get()); |
| 116 #endif // !defined(OS_IOS) | 116 #endif // !defined(OS_IOS) |
| 117 } | 117 } |
| 118 | 118 |
| 119 } // namespace | 119 } // namespace |
| 120 | 120 |
| 121 NetworkConfigWatcherMac::NetworkConfigWatcherMac(Delegate* delegate) | 121 NetworkConfigWatcherMac::NetworkConfigWatcherMac(Delegate* delegate) |
| 122 : notifier_thread_(new NetworkConfigWatcherMacThread(delegate)) { | 122 : notifier_thread_(new NetworkConfigWatcherMacThread(delegate)) { |
| 123 // We create this notifier thread because the notification implementation | 123 // We create this notifier thread because the notification implementation |
| 124 // needs a thread with a CFRunLoop, and there's no guarantee that | 124 // needs a thread with a CFRunLoop, and there's no guarantee that |
| 125 // MessageLoop::current() meets that criterion. | 125 // MessageLoop::current() meets that criterion. |
| 126 base::Thread::Options thread_options(base::MessageLoop::TYPE_UI, 0); | 126 base::Thread::Options thread_options(base::MessageLoop::TYPE_UI, 0); |
| 127 notifier_thread_->StartWithOptions(thread_options); | 127 notifier_thread_->StartWithOptions(thread_options); |
| 128 } | 128 } |
| 129 | 129 |
| 130 NetworkConfigWatcherMac::~NetworkConfigWatcherMac() {} | 130 NetworkConfigWatcherMac::~NetworkConfigWatcherMac() {} |
| 131 | 131 |
| 132 } // namespace net | 132 } // namespace net |
| OLD | NEW |