| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef NET_BASE_NETWORK_CONFIG_WATCHER_MAC_H_ | 5 #ifndef NET_BASE_NETWORK_CONFIG_WATCHER_MAC_H_ |
| 6 #define NET_BASE_NETWORK_CONFIG_WATCHER_MAC_H_ | 6 #define NET_BASE_NETWORK_CONFIG_WATCHER_MAC_H_ |
| 7 | 7 |
| 8 #include <SystemConfiguration/SCDynamicStore.h> | 8 #include <SystemConfiguration/SCDynamicStore.h> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/mac/scoped_cftyperef.h" | 12 #include "base/mac/scoped_cftyperef.h" |
| 13 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
| 14 | 14 |
| 15 namespace base { | 15 namespace base { |
| 16 class Thread; | 16 class Thread; |
| 17 } | 17 } |
| 18 | 18 |
| 19 namespace net { | 19 namespace net { |
| 20 | 20 |
| 21 // Base class for watching the Mac OS system network settings. | 21 // Base class for watching the Mac OS system network settings. |
| 22 class NetworkConfigWatcherMac : public MessageLoop::DestructionObserver { | 22 class NetworkConfigWatcherMac { |
| 23 public: | 23 public: |
| 24 // NOTE: The lifetime of Delegate is expected to exceed the lifetime of | 24 // NOTE: The lifetime of Delegate is expected to exceed the lifetime of |
| 25 // NetworkConfigWatcherMac. | 25 // NetworkConfigWatcherMac. |
| 26 class Delegate { | 26 class Delegate { |
| 27 public: | 27 public: |
| 28 virtual ~Delegate() {} | 28 virtual ~Delegate() {} |
| 29 | 29 |
| 30 // Called to register the notification keys on |store|. | 30 // Called to register the notification keys on |store|. |
| 31 // Implementors are expected to call SCDynamicStoreSetNotificationKeys(). | 31 // Implementors are expected to call SCDynamicStoreSetNotificationKeys(). |
| 32 // Will be called on the notifier thread. | 32 // Will be called on the notifier thread. |
| 33 virtual void SetDynamicStoreNotificationKeys(SCDynamicStoreRef store) = 0; | 33 virtual void SetDynamicStoreNotificationKeys(SCDynamicStoreRef store) = 0; |
| 34 | 34 |
| 35 // Called when one of the notification keys has changed. | 35 // Called when one of the notification keys has changed. |
| 36 // Will be called on the notifier thread. | 36 // Will be called on the notifier thread. |
| 37 virtual void OnNetworkConfigChange(CFArrayRef changed_keys) = 0; | 37 virtual void OnNetworkConfigChange(CFArrayRef changed_keys) = 0; |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 explicit NetworkConfigWatcherMac(Delegate* delegate); | 40 explicit NetworkConfigWatcherMac(Delegate* delegate); |
| 41 virtual ~NetworkConfigWatcherMac(); | 41 virtual ~NetworkConfigWatcherMac(); |
| 42 | 42 |
| 43 private: | 43 private: |
| 44 // MessageLoop::DestructionObserver: | |
| 45 virtual void WillDestroyCurrentMessageLoop(); | |
| 46 | |
| 47 // Called on the notifier thread to initialize the notification | |
| 48 // implementation. The SystemConfiguration calls in this function can lead to | |
| 49 // contention early on, so we invoke this function later on in startup to keep | |
| 50 // it fast. | |
| 51 void Init(); | |
| 52 | |
| 53 // The thread used to listen for notifications. This relays the notification | 44 // The thread used to listen for notifications. This relays the notification |
| 54 // to the registered observers without posting back to the thread the object | 45 // to the registered observers without posting back to the thread the object |
| 55 // was created on. | 46 // was created on. |
| 56 scoped_ptr<base::Thread> notifier_thread_; | 47 scoped_ptr<base::Thread> notifier_thread_; |
| 57 | 48 |
| 58 base::mac::ScopedCFTypeRef<CFRunLoopSourceRef> run_loop_source_; | |
| 59 | |
| 60 Delegate* const delegate_; | |
| 61 | |
| 62 DISALLOW_COPY_AND_ASSIGN(NetworkConfigWatcherMac); | 49 DISALLOW_COPY_AND_ASSIGN(NetworkConfigWatcherMac); |
| 63 }; | 50 }; |
| 64 | 51 |
| 65 } // namespace net | 52 } // namespace net |
| 66 | 53 |
| 67 #endif // NET_BASE_NETWORK_CONFIG_WATCHER_MAC_H_ | 54 #endif // NET_BASE_NETWORK_CONFIG_WATCHER_MAC_H_ |
| OLD | NEW |