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_CHANGE_NOTIFIER_MAC_H_
6 #define NET_BASE_NETWORK_CHANGE_NOTIFIER_MAC_H_
8 #include <SystemConfiguration/SystemConfiguration.h>
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/mac/scoped_cftyperef.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/synchronization/condition_variable.h"
15 #include "base/synchronization/lock.h"
16 #include "net/base/network_change_notifier.h"
17 #include "net/base/network_config_watcher_mac.h"
21 class NetworkChangeNotifierMac
: public NetworkChangeNotifier
{
23 NetworkChangeNotifierMac();
24 virtual ~NetworkChangeNotifierMac();
26 // NetworkChangeNotifier implementation:
27 virtual ConnectionType
GetCurrentConnectionType() const OVERRIDE
;
29 // Forwarder just exists to keep the NetworkConfigWatcherMac API out of
30 // NetworkChangeNotifierMac's public API.
31 class Forwarder
: public NetworkConfigWatcherMac::Delegate
{
33 explicit Forwarder(NetworkChangeNotifierMac
* net_config_watcher
)
34 : net_config_watcher_(net_config_watcher
) {}
36 // NetworkConfigWatcherMac::Delegate implementation:
37 virtual void Init() OVERRIDE
;
38 virtual void StartReachabilityNotifications() OVERRIDE
;
39 virtual void SetDynamicStoreNotificationKeys(
40 SCDynamicStoreRef store
) OVERRIDE
;
41 virtual void OnNetworkConfigChange(CFArrayRef changed_keys
) OVERRIDE
;
44 NetworkChangeNotifierMac
* const net_config_watcher_
;
45 DISALLOW_COPY_AND_ASSIGN(Forwarder
);
49 class DnsConfigServiceThread
;
51 // Methods directly called by the NetworkConfigWatcherMac::Delegate:
52 void StartReachabilityNotifications();
53 void SetDynamicStoreNotificationKeys(SCDynamicStoreRef store
);
54 void OnNetworkConfigChange(CFArrayRef changed_keys
);
56 void SetInitialConnectionType();
58 static void ReachabilityCallback(SCNetworkReachabilityRef target
,
59 SCNetworkConnectionFlags flags
,
62 static NetworkChangeCalculatorParams
NetworkChangeCalculatorParamsMac();
64 // These must be constructed before config_watcher_ to ensure
65 // the lock is in a valid state when Forwarder::Init is called.
66 ConnectionType connection_type_
;
67 bool connection_type_initialized_
;
68 mutable base::Lock connection_type_lock_
;
69 mutable base::ConditionVariable initial_connection_type_cv_
;
70 base::ScopedCFTypeRef
<SCNetworkReachabilityRef
> reachability_
;
71 base::ScopedCFTypeRef
<CFRunLoopRef
> run_loop_
;
74 scoped_ptr
<const NetworkConfigWatcherMac
> config_watcher_
;
76 scoped_ptr
<DnsConfigServiceThread
> dns_config_service_thread_
;
78 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierMac
);
83 #endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_MAC_H_