1 // Copyright (c) 2011 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/message_loop.h" 12 #include "base/mac/scoped_cftyperef.h" 13 #include "base/memory/scoped_ptr.h" 14 15 namespace base { 16 class Thread; 17 } 18 19 namespace net { 20 21 // Base class for watching the Mac OS system network settings. 22 class NetworkConfigWatcherMac { 23 public: 24 // NOTE: The lifetime of Delegate is expected to exceed the lifetime of 25 // NetworkConfigWatcherMac. 26 class Delegate { 27 public: 28 virtual ~Delegate() {} 29 30 // Called to register the notification keys on |store|. 31 // Implementors are expected to call SCDynamicStoreSetNotificationKeys(). 32 // Will be called on the notifier thread. 33 virtual void SetDynamicStoreNotificationKeys(SCDynamicStoreRef store) = 0; 34 35 // Called when one of the notification keys has changed. 36 // Will be called on the notifier thread. 37 virtual void OnNetworkConfigChange(CFArrayRef changed_keys) = 0; 38 }; 39 40 explicit NetworkConfigWatcherMac(Delegate* delegate); 41 virtual ~NetworkConfigWatcherMac(); 42 43 private: 44 // The thread used to listen for notifications. This relays the notification 45 // to the registered observers without posting back to the thread the object 46 // was created on. 47 scoped_ptr<base::Thread> notifier_thread_; 48 49 DISALLOW_COPY_AND_ASSIGN(NetworkConfigWatcherMac); 50 }; 51 52 } // namespace net 53 54 #endif // NET_BASE_NETWORK_CONFIG_WATCHER_MAC_H_ 55