[email protected] | a301055d | 2012-01-11 10:58:17 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 100d5fb9 | 2009-12-21 21:08:35 | [diff] [blame] | 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_CHANGE_NOTIFIER_MAC_H_ | ||||
6 | #define NET_BASE_NETWORK_CHANGE_NOTIFIER_MAC_H_ | ||||
7 | |||||
[email protected] | 88a59c8 | 2011-09-12 21:28:15 | [diff] [blame] | 8 | #include <SystemConfiguration/SystemConfiguration.h> |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 9 | |
danakj | 7f767e6 | 2016-04-16 23:20:23 | [diff] [blame] | 10 | #include <memory> |
11 | |||||
[email protected] | 9be87ba | 2011-09-30 01:49:25 | [diff] [blame] | 12 | #include "base/compiler_specific.h" |
[email protected] | 12bd2c0 | 2011-06-02 21:56:44 | [diff] [blame] | 13 | #include "base/mac/scoped_cftyperef.h" |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 14 | #include "base/macros.h" |
[email protected] | f671d79 | 2011-09-02 18:11:47 | [diff] [blame] | 15 | #include "base/synchronization/condition_variable.h" |
[email protected] | d72b8a8 | 2011-06-08 20:43:25 | [diff] [blame] | 16 | #include "base/synchronization/lock.h" |
[email protected] | 100d5fb9 | 2009-12-21 21:08:35 | [diff] [blame] | 17 | #include "net/base/network_change_notifier.h" |
[email protected] | 9328443b | 2010-07-30 06:09:40 | [diff] [blame] | 18 | #include "net/base/network_config_watcher_mac.h" |
[email protected] | 100d5fb9 | 2009-12-21 21:08:35 | [diff] [blame] | 19 | |
20 | namespace net { | ||||
21 | |||||
[email protected] | 6688a496 | 2010-09-07 19:41:36 | [diff] [blame] | 22 | class NetworkChangeNotifierMac: public NetworkChangeNotifier { |
[email protected] | 100d5fb9 | 2009-12-21 21:08:35 | [diff] [blame] | 23 | public: |
[email protected] | aa92ba2 | 2010-06-21 23:17:24 | [diff] [blame] | 24 | NetworkChangeNotifierMac(); |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 25 | ~NetworkChangeNotifierMac() override; |
[email protected] | 9328443b | 2010-07-30 06:09:40 | [diff] [blame] | 26 | |
[email protected] | 8bbc7a79 | 2012-05-24 11:30:05 | [diff] [blame] | 27 | // NetworkChangeNotifier implementation: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 28 | ConnectionType GetCurrentConnectionType() const override; |
[email protected] | f671d79 | 2011-09-02 18:11:47 | [diff] [blame] | 29 | |
[email protected] | 6688a496 | 2010-09-07 19:41:36 | [diff] [blame] | 30 | // Forwarder just exists to keep the NetworkConfigWatcherMac API out of |
31 | // NetworkChangeNotifierMac's public API. | ||||
32 | class Forwarder : public NetworkConfigWatcherMac::Delegate { | ||||
33 | public: | ||||
34 | explicit Forwarder(NetworkChangeNotifierMac* net_config_watcher) | ||||
35 | : net_config_watcher_(net_config_watcher) {} | ||||
36 | |||||
37 | // NetworkConfigWatcherMac::Delegate implementation: | ||||
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 38 | void Init() override; |
39 | void StartReachabilityNotifications() override; | ||||
40 | void SetDynamicStoreNotificationKeys(SCDynamicStoreRef store) override; | ||||
41 | void OnNetworkConfigChange(CFArrayRef changed_keys) override; | ||||
[email protected] | 6688a496 | 2010-09-07 19:41:36 | [diff] [blame] | 42 | |
43 | private: | ||||
44 | NetworkChangeNotifierMac* const net_config_watcher_; | ||||
45 | DISALLOW_COPY_AND_ASSIGN(Forwarder); | ||||
46 | }; | ||||
47 | |||||
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 48 | private: |
49 | class DnsConfigServiceThread; | ||||
50 | |||||
jkarlin | 5780bb0 | 2017-05-31 16:39:49 | [diff] [blame] | 51 | // Called on the main thread on startup, afterwards on the notifier thread. |
52 | static ConnectionType CalculateConnectionType(SCNetworkConnectionFlags flags); | ||||
53 | |||||
[email protected] | a301055d | 2012-01-11 10:58:17 | [diff] [blame] | 54 | // Methods directly called by the NetworkConfigWatcherMac::Delegate: |
55 | void StartReachabilityNotifications(); | ||||
[email protected] | 6688a496 | 2010-09-07 19:41:36 | [diff] [blame] | 56 | void SetDynamicStoreNotificationKeys(SCDynamicStoreRef store); |
57 | void OnNetworkConfigChange(CFArrayRef changed_keys); | ||||
58 | |||||
[email protected] | 8bbc7a79 | 2012-05-24 11:30:05 | [diff] [blame] | 59 | void SetInitialConnectionType(); |
[email protected] | f671d79 | 2011-09-02 18:11:47 | [diff] [blame] | 60 | |
[email protected] | 12bd2c0 | 2011-06-02 21:56:44 | [diff] [blame] | 61 | static void ReachabilityCallback(SCNetworkReachabilityRef target, |
62 | SCNetworkConnectionFlags flags, | ||||
63 | void* notifier); | ||||
64 | |||||
[email protected] | 0384887 | 2012-12-08 02:46:41 | [diff] [blame] | 65 | static NetworkChangeCalculatorParams NetworkChangeCalculatorParamsMac(); |
66 | |||||
[email protected] | f671d79 | 2011-09-02 18:11:47 | [diff] [blame] | 67 | // These must be constructed before config_watcher_ to ensure |
68 | // the lock is in a valid state when Forwarder::Init is called. | ||||
[email protected] | 8bbc7a79 | 2012-05-24 11:30:05 | [diff] [blame] | 69 | ConnectionType connection_type_; |
70 | bool connection_type_initialized_; | ||||
71 | mutable base::Lock connection_type_lock_; | ||||
72 | mutable base::ConditionVariable initial_connection_type_cv_; | ||||
[email protected] | 3df79f4 | 2013-06-24 18:49:05 | [diff] [blame] | 73 | base::ScopedCFTypeRef<SCNetworkReachabilityRef> reachability_; |
74 | base::ScopedCFTypeRef<CFRunLoopRef> run_loop_; | ||||
[email protected] | f671d79 | 2011-09-02 18:11:47 | [diff] [blame] | 75 | |
76 | Forwarder forwarder_; | ||||
danakj | 7f767e6 | 2016-04-16 23:20:23 | [diff] [blame] | 77 | std::unique_ptr<const NetworkConfigWatcherMac> config_watcher_; |
[email protected] | 6688a496 | 2010-09-07 19:41:36 | [diff] [blame] | 78 | |
danakj | 7f767e6 | 2016-04-16 23:20:23 | [diff] [blame] | 79 | std::unique_ptr<DnsConfigServiceThread> dns_config_service_thread_; |
[email protected] | 05aad32d | 2012-05-16 18:10:53 | [diff] [blame] | 80 | |
[email protected] | 100d5fb9 | 2009-12-21 21:08:35 | [diff] [blame] | 81 | DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierMac); |
82 | }; | ||||
83 | |||||
84 | } // namespace net | ||||
85 | |||||
86 | #endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_MAC_H_ |