| OLD | NEW |
| (Empty) |
| 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_CHANGE_NOTIFIER_MAC_H_ | |
| 6 #define NET_BASE_NETWORK_CHANGE_NOTIFIER_MAC_H_ | |
| 7 | |
| 8 #include <SystemConfiguration/SystemConfiguration.h> | |
| 9 | |
| 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" | |
| 18 | |
| 19 namespace net { | |
| 20 | |
| 21 class NetworkChangeNotifierMac: public NetworkChangeNotifier { | |
| 22 public: | |
| 23 NetworkChangeNotifierMac(); | |
| 24 ~NetworkChangeNotifierMac() override; | |
| 25 | |
| 26 // NetworkChangeNotifier implementation: | |
| 27 ConnectionType GetCurrentConnectionType() const override; | |
| 28 | |
| 29 // Forwarder just exists to keep the NetworkConfigWatcherMac API out of | |
| 30 // NetworkChangeNotifierMac's public API. | |
| 31 class Forwarder : public NetworkConfigWatcherMac::Delegate { | |
| 32 public: | |
| 33 explicit Forwarder(NetworkChangeNotifierMac* net_config_watcher) | |
| 34 : net_config_watcher_(net_config_watcher) {} | |
| 35 | |
| 36 // NetworkConfigWatcherMac::Delegate implementation: | |
| 37 void Init() override; | |
| 38 void StartReachabilityNotifications() override; | |
| 39 void SetDynamicStoreNotificationKeys(SCDynamicStoreRef store) override; | |
| 40 void OnNetworkConfigChange(CFArrayRef changed_keys) override; | |
| 41 | |
| 42 private: | |
| 43 NetworkChangeNotifierMac* const net_config_watcher_; | |
| 44 DISALLOW_COPY_AND_ASSIGN(Forwarder); | |
| 45 }; | |
| 46 | |
| 47 private: | |
| 48 class DnsConfigServiceThread; | |
| 49 | |
| 50 // Methods directly called by the NetworkConfigWatcherMac::Delegate: | |
| 51 void StartReachabilityNotifications(); | |
| 52 void SetDynamicStoreNotificationKeys(SCDynamicStoreRef store); | |
| 53 void OnNetworkConfigChange(CFArrayRef changed_keys); | |
| 54 | |
| 55 void SetInitialConnectionType(); | |
| 56 | |
| 57 static void ReachabilityCallback(SCNetworkReachabilityRef target, | |
| 58 SCNetworkConnectionFlags flags, | |
| 59 void* notifier); | |
| 60 | |
| 61 static NetworkChangeCalculatorParams NetworkChangeCalculatorParamsMac(); | |
| 62 | |
| 63 // These must be constructed before config_watcher_ to ensure | |
| 64 // the lock is in a valid state when Forwarder::Init is called. | |
| 65 ConnectionType connection_type_; | |
| 66 bool connection_type_initialized_; | |
| 67 mutable base::Lock connection_type_lock_; | |
| 68 mutable base::ConditionVariable initial_connection_type_cv_; | |
| 69 base::ScopedCFTypeRef<SCNetworkReachabilityRef> reachability_; | |
| 70 base::ScopedCFTypeRef<CFRunLoopRef> run_loop_; | |
| 71 | |
| 72 Forwarder forwarder_; | |
| 73 scoped_ptr<const NetworkConfigWatcherMac> config_watcher_; | |
| 74 | |
| 75 scoped_ptr<DnsConfigServiceThread> dns_config_service_thread_; | |
| 76 | |
| 77 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierMac); | |
| 78 }; | |
| 79 | |
| 80 } // namespace net | |
| 81 | |
| 82 #endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_MAC_H_ | |
| OLD | NEW |