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 3 // found in the LICENSE file. 4 5 #ifndef NET_BASE_NETWORK_CONFIG_WATCHER_MAC_H_ 6 #define NET_BASE_NETWORK_CONFIG_WATCHER_MAC_H_ 7 8 #include <SystemConfiguration/SCDynamicStore.h> 9 10 #include "base/basictypes.h" 11 #include "base/mac/scoped_cftyperef.h" 12 #include "base/memory/scoped_ptr.h" 13 14 namespace base { 15 class Thread; 16 } 17 18 namespace net { 19 20 // Helper class for watching the Mac OS system network settings. 21 class NetworkConfigWatcherMac { 22 public: 23 // NOTE: The lifetime of Delegate is expected to exceed the lifetime of 24 // NetworkConfigWatcherMac. 25 class Delegate { 26 public: 27 virtual ~Delegate() {} 28 29 // Called to let the delegate do any setup work the must be run on the 30 // notifier thread immediately after it starts. 31 virtual void Init() {} 32 33 // Called to start receiving notifications from the SCNetworkReachability 34 // API. 35 // Will be called on the notifier thread. 36 virtual void StartReachabilityNotifications() = 0; 37 38 // Called to register the notification keys on |store|. 39 // Implementors are expected to call SCDynamicStoreSetNotificationKeys(). 40 // Will be called on the notifier thread. 41 virtual void SetDynamicStoreNotificationKeys(SCDynamicStoreRef store) = 0; 42 43 // Called when one of the notification keys has changed. 44 // Will be called on the notifier thread. 45 virtual void OnNetworkConfigChange(CFArrayRef changed_keys) = 0; 46 }; 47 48 explicit NetworkConfigWatcherMac(Delegate* delegate); 49 ~NetworkConfigWatcherMac(); 50 51 private: 52 // The thread used to listen for notifications. This relays the notification 53 // to the registered observers without posting back to the thread the object 54 // was created on. 55 scoped_ptr<base::Thread> notifier_thread_; 56 57 DISALLOW_COPY_AND_ASSIGN(NetworkConfigWatcherMac); 58 }; 59 60 } // namespace net 61 62 #endif // NET_BASE_NETWORK_CONFIG_WATCHER_MAC_H_ 63