| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <SystemConfiguration/SCDynamicStore.h> | 9 #include <SystemConfiguration/SCDynamicStore.h> |
| 10 #include <SystemConfiguration/SCNetworkReachability.h> |
| 10 | 11 |
| 11 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/mac/scoped_cftyperef.h" |
| 12 #include "net/base/network_change_notifier.h" | 14 #include "net/base/network_change_notifier.h" |
| 13 #include "net/base/network_config_watcher_mac.h" | 15 #include "net/base/network_config_watcher_mac.h" |
| 14 | 16 |
| 15 namespace net { | 17 namespace net { |
| 16 | 18 |
| 17 class NetworkChangeNotifierMac: public NetworkChangeNotifier { | 19 class NetworkChangeNotifierMac: public NetworkChangeNotifier { |
| 18 public: | 20 public: |
| 19 NetworkChangeNotifierMac(); | 21 NetworkChangeNotifierMac(); |
| 20 virtual ~NetworkChangeNotifierMac(); | 22 virtual ~NetworkChangeNotifierMac(); |
| 21 | 23 |
| 22 // NetworkChangeNotifier implementation: | 24 // NetworkChangeNotifier implementation: |
| 23 virtual bool IsCurrentlyOffline() const; | 25 virtual bool IsCurrentlyOffline() const; |
| 24 | 26 |
| 25 private: | 27 private: |
| 26 // Forwarder just exists to keep the NetworkConfigWatcherMac API out of | 28 // Forwarder just exists to keep the NetworkConfigWatcherMac API out of |
| 27 // NetworkChangeNotifierMac's public API. | 29 // NetworkChangeNotifierMac's public API. |
| 28 class Forwarder : public NetworkConfigWatcherMac::Delegate { | 30 class Forwarder : public NetworkConfigWatcherMac::Delegate { |
| 29 public: | 31 public: |
| 30 explicit Forwarder(NetworkChangeNotifierMac* net_config_watcher) | 32 explicit Forwarder(NetworkChangeNotifierMac* net_config_watcher) |
| 31 : net_config_watcher_(net_config_watcher) {} | 33 : net_config_watcher_(net_config_watcher) {} |
| 32 | 34 |
| 33 // NetworkConfigWatcherMac::Delegate implementation: | 35 // NetworkConfigWatcherMac::Delegate implementation: |
| 34 virtual void SetDynamicStoreNotificationKeys(SCDynamicStoreRef store) { | 36 virtual void SetDynamicStoreNotificationKeys(SCDynamicStoreRef store) { |
| 35 net_config_watcher_->SetDynamicStoreNotificationKeys(store); | 37 net_config_watcher_->SetDynamicStoreNotificationKeys(store); |
| 36 } | 38 } |
| 37 virtual void OnNetworkConfigChange(CFArrayRef changed_keys) { | 39 virtual void OnNetworkConfigChange(CFArrayRef changed_keys) { |
| 38 net_config_watcher_->OnNetworkConfigChange(changed_keys); | 40 net_config_watcher_->OnNetworkConfigChange(changed_keys); |
| 39 } | 41 } |
| 42 virtual void CleanUp() { |
| 43 net_config_watcher_->CleanUp(); |
| 44 } |
| 40 | 45 |
| 41 private: | 46 private: |
| 42 NetworkChangeNotifierMac* const net_config_watcher_; | 47 NetworkChangeNotifierMac* const net_config_watcher_; |
| 43 DISALLOW_COPY_AND_ASSIGN(Forwarder); | 48 DISALLOW_COPY_AND_ASSIGN(Forwarder); |
| 44 }; | 49 }; |
| 45 | 50 |
| 46 // NetworkConfigWatcherMac::Delegate implementation: | 51 // NetworkConfigWatcherMac::Delegate implementation: |
| 47 void SetDynamicStoreNotificationKeys(SCDynamicStoreRef store); | 52 void SetDynamicStoreNotificationKeys(SCDynamicStoreRef store); |
| 48 void OnNetworkConfigChange(CFArrayRef changed_keys); | 53 void OnNetworkConfigChange(CFArrayRef changed_keys); |
| 49 | 54 |
| 55 static void ReachabilityCallback(SCNetworkReachabilityRef target, |
| 56 SCNetworkConnectionFlags flags, |
| 57 void* notifier); |
| 58 void CleanUp(); |
| 59 |
| 50 Forwarder forwarder_; | 60 Forwarder forwarder_; |
| 51 const NetworkConfigWatcherMac config_watcher_; | 61 const NetworkConfigWatcherMac config_watcher_; |
| 62 base::mac::ScopedCFTypeRef<SCNetworkReachabilityRef> reachability_; |
| 63 bool network_reachable_; |
| 52 | 64 |
| 53 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierMac); | 65 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierMac); |
| 54 }; | 66 }; |
| 55 | 67 |
| 56 } // namespace net | 68 } // namespace net |
| 57 | 69 |
| 58 #endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_MAC_H_ | 70 #endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_MAC_H_ |
| OLD | NEW |