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.
5 #ifndef NET_BASE_NETWORK_CONFIG_WATCHER_MAC_H_
6 #define NET_BASE_NETWORK_CONFIG_WATCHER_MAC_H_
8 #include <SystemConfiguration/SCDynamicStore.h>
10 #include "base/basictypes.h"
11 #include "base/mac/scoped_cftyperef.h"
12 #include "base/memory/scoped_ptr.h"
20 // Helper class for watching the Mac OS system network settings.
21 class NetworkConfigWatcherMac
{
23 // NOTE: The lifetime of Delegate is expected to exceed the lifetime of
24 // NetworkConfigWatcherMac.
27 virtual ~Delegate() {}
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() {}
33 // Called to start receiving notifications from the SCNetworkReachability
35 // Will be called on the notifier thread.
36 virtual void StartReachabilityNotifications() = 0;
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;
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;
48 explicit NetworkConfigWatcherMac(Delegate
* delegate
);
49 ~NetworkConfigWatcherMac();
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
55 scoped_ptr
<base::Thread
> notifier_thread_
;
57 DISALLOW_COPY_AND_ASSIGN(NetworkConfigWatcherMac
);
62 #endif // NET_BASE_NETWORK_CONFIG_WATCHER_MAC_H_