| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_BASE_NETWORK_CHANGE_NOTIFIER_MAC_H_ | 5 #ifndef NET_BASE_NETWORK_CHANGE_NOTIFIER_MAC_H_ |
| 6 #define NET_BASE_NETWORK_CHANGE_NOTIFIER_MAC_H_ | 6 #define NET_BASE_NETWORK_CHANGE_NOTIFIER_MAC_H_ |
| 7 | 7 |
| 8 #include <SystemConfiguration/SystemConfiguration.h> | 8 #include <SystemConfiguration/SystemConfiguration.h> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/mac/scoped_cftyperef.h" | 12 #include "base/mac/scoped_cftyperef.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/synchronization/condition_variable.h" | 14 #include "base/synchronization/condition_variable.h" |
| 15 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
| 16 #include "net/base/network_change_notifier.h" | 16 #include "net/base/network_change_notifier.h" |
| 17 #include "net/base/network_config_watcher_mac.h" | 17 #include "net/base/network_config_watcher_mac.h" |
| 18 | 18 |
| 19 namespace net { | 19 namespace net { |
| 20 | 20 |
| 21 class NetworkChangeNotifierMac: public NetworkChangeNotifier { | 21 class NetworkChangeNotifierMac: public NetworkChangeNotifier { |
| 22 public: | 22 public: |
| 23 NetworkChangeNotifierMac(); | 23 NetworkChangeNotifierMac(); |
| 24 virtual ~NetworkChangeNotifierMac(); | 24 virtual ~NetworkChangeNotifierMac(); |
| 25 | 25 |
| 26 // NetworkChangeNotifier implementation: | 26 // NetworkChangeNotifier implementation: |
| 27 virtual ConnectionType GetCurrentConnectionType() const OVERRIDE; | 27 virtual ConnectionType GetCurrentConnectionType() const OVERRIDE; |
| 28 | 28 |
| 29 class DnsWatcherThread; | |
| 30 | |
| 31 // Forwarder just exists to keep the NetworkConfigWatcherMac API out of | 29 // Forwarder just exists to keep the NetworkConfigWatcherMac API out of |
| 32 // NetworkChangeNotifierMac's public API. | 30 // NetworkChangeNotifierMac's public API. |
| 33 class Forwarder : public NetworkConfigWatcherMac::Delegate { | 31 class Forwarder : public NetworkConfigWatcherMac::Delegate { |
| 34 public: | 32 public: |
| 35 explicit Forwarder(NetworkChangeNotifierMac* net_config_watcher) | 33 explicit Forwarder(NetworkChangeNotifierMac* net_config_watcher) |
| 36 : net_config_watcher_(net_config_watcher) {} | 34 : net_config_watcher_(net_config_watcher) {} |
| 37 | 35 |
| 38 // NetworkConfigWatcherMac::Delegate implementation: | 36 // NetworkConfigWatcherMac::Delegate implementation: |
| 39 virtual void Init() OVERRIDE; | 37 virtual void Init() OVERRIDE; |
| 40 virtual void StartReachabilityNotifications() OVERRIDE; | 38 virtual void StartReachabilityNotifications() OVERRIDE; |
| 41 virtual void SetDynamicStoreNotificationKeys( | 39 virtual void SetDynamicStoreNotificationKeys( |
| 42 SCDynamicStoreRef store) OVERRIDE; | 40 SCDynamicStoreRef store) OVERRIDE; |
| 43 virtual void OnNetworkConfigChange(CFArrayRef changed_keys) OVERRIDE; | 41 virtual void OnNetworkConfigChange(CFArrayRef changed_keys) OVERRIDE; |
| 44 | 42 |
| 45 private: | 43 private: |
| 46 NetworkChangeNotifierMac* const net_config_watcher_; | 44 NetworkChangeNotifierMac* const net_config_watcher_; |
| 47 DISALLOW_COPY_AND_ASSIGN(Forwarder); | 45 DISALLOW_COPY_AND_ASSIGN(Forwarder); |
| 48 }; | 46 }; |
| 49 | 47 |
| 48 private: |
| 49 class DnsConfigServiceThread; |
| 50 |
| 50 // Methods directly called by the NetworkConfigWatcherMac::Delegate: | 51 // Methods directly called by the NetworkConfigWatcherMac::Delegate: |
| 51 void StartReachabilityNotifications(); | 52 void StartReachabilityNotifications(); |
| 52 void SetDynamicStoreNotificationKeys(SCDynamicStoreRef store); | 53 void SetDynamicStoreNotificationKeys(SCDynamicStoreRef store); |
| 53 void OnNetworkConfigChange(CFArrayRef changed_keys); | 54 void OnNetworkConfigChange(CFArrayRef changed_keys); |
| 54 | 55 |
| 55 void SetInitialConnectionType(); | 56 void SetInitialConnectionType(); |
| 56 | 57 |
| 57 static void ReachabilityCallback(SCNetworkReachabilityRef target, | 58 static void ReachabilityCallback(SCNetworkReachabilityRef target, |
| 58 SCNetworkConnectionFlags flags, | 59 SCNetworkConnectionFlags flags, |
| 59 void* notifier); | 60 void* notifier); |
| 60 | 61 |
| 61 // These must be constructed before config_watcher_ to ensure | 62 // These must be constructed before config_watcher_ to ensure |
| 62 // the lock is in a valid state when Forwarder::Init is called. | 63 // the lock is in a valid state when Forwarder::Init is called. |
| 63 ConnectionType connection_type_; | 64 ConnectionType connection_type_; |
| 64 bool connection_type_initialized_; | 65 bool connection_type_initialized_; |
| 65 mutable base::Lock connection_type_lock_; | 66 mutable base::Lock connection_type_lock_; |
| 66 mutable base::ConditionVariable initial_connection_type_cv_; | 67 mutable base::ConditionVariable initial_connection_type_cv_; |
| 67 base::mac::ScopedCFTypeRef<SCNetworkReachabilityRef> reachability_; | 68 base::mac::ScopedCFTypeRef<SCNetworkReachabilityRef> reachability_; |
| 68 base::mac::ScopedCFTypeRef<CFRunLoopRef> run_loop_; | 69 base::mac::ScopedCFTypeRef<CFRunLoopRef> run_loop_; |
| 69 | 70 |
| 70 Forwarder forwarder_; | 71 Forwarder forwarder_; |
| 71 scoped_ptr<const NetworkConfigWatcherMac> config_watcher_; | 72 scoped_ptr<const NetworkConfigWatcherMac> config_watcher_; |
| 72 | 73 |
| 73 // Thread on which we can run DnsConfigWatcher, which requires TYPE_IO. | 74 scoped_ptr<DnsConfigServiceThread> dns_config_service_thread_; |
| 74 scoped_ptr<DnsWatcherThread> dns_watcher_thread_; | |
| 75 | 75 |
| 76 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierMac); | 76 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierMac); |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 } // namespace net | 79 } // namespace net |
| 80 | 80 |
| 81 #endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_MAC_H_ | 81 #endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_MAC_H_ |
| OLD | NEW |