Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(584)

Side by Side Diff: net/base/network_change_notifier_mac.h

Issue 9147026: API for connection type (Ethernet/WIFI/WWAN ...) in NetworkChangeNotifier. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed a typo Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #pragma once 7 #pragma once
8 8
9 #include <SystemConfiguration/SystemConfiguration.h> 9 #include <SystemConfiguration/SystemConfiguration.h>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/mac/scoped_cftyperef.h" 13 #include "base/mac/scoped_cftyperef.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/synchronization/condition_variable.h" 15 #include "base/synchronization/condition_variable.h"
16 #include "base/synchronization/lock.h" 16 #include "base/synchronization/lock.h"
17 #include "net/base/network_change_notifier.h" 17 #include "net/base/network_change_notifier.h"
18 #include "net/base/network_config_watcher_mac.h" 18 #include "net/base/network_config_watcher_mac.h"
19 19
20 namespace net { 20 namespace net {
21 21
22 class NetworkChangeNotifierMac: public NetworkChangeNotifier { 22 class NetworkChangeNotifierMac: public NetworkChangeNotifier {
23 public: 23 public:
24 NetworkChangeNotifierMac(); 24 NetworkChangeNotifierMac();
25 virtual ~NetworkChangeNotifierMac(); 25 virtual ~NetworkChangeNotifierMac();
26 26
27 // NetworkChangeNotifier: 27 // NetworkChangeNotifier implementation:
28 virtual bool IsCurrentlyOffline() const OVERRIDE; 28 virtual ConnectionType GetCurrentConnectionType() const OVERRIDE;
29
30 private:
31 enum OnlineState {
32 UNINITIALIZED = -1,
33 OFFLINE = 0,
34 ONLINE = 1
35 };
36 29
37 class DnsWatcherThread; 30 class DnsWatcherThread;
38 31
39 // Forwarder just exists to keep the NetworkConfigWatcherMac API out of 32 // Forwarder just exists to keep the NetworkConfigWatcherMac API out of
40 // NetworkChangeNotifierMac's public API. 33 // NetworkChangeNotifierMac's public API.
41 class Forwarder : public NetworkConfigWatcherMac::Delegate { 34 class Forwarder : public NetworkConfigWatcherMac::Delegate {
42 public: 35 public:
43 explicit Forwarder(NetworkChangeNotifierMac* net_config_watcher) 36 explicit Forwarder(NetworkChangeNotifierMac* net_config_watcher)
44 : net_config_watcher_(net_config_watcher) {} 37 : net_config_watcher_(net_config_watcher) {}
45 38
46 // NetworkConfigWatcherMac::Delegate implementation: 39 // NetworkConfigWatcherMac::Delegate implementation:
47 virtual void Init() OVERRIDE { 40 virtual void Init() OVERRIDE {
48 net_config_watcher_->SetInitialState(); 41 net_config_watcher_->SetInitialConnectionType();
49 } 42 }
50 virtual void StartReachabilityNotifications() OVERRIDE { 43 virtual void StartReachabilityNotifications() OVERRIDE {
51 net_config_watcher_->StartReachabilityNotifications(); 44 net_config_watcher_->StartReachabilityNotifications();
52 } 45 }
53 virtual void SetDynamicStoreNotificationKeys( 46 virtual void SetDynamicStoreNotificationKeys(
54 SCDynamicStoreRef store) OVERRIDE { 47 SCDynamicStoreRef store) OVERRIDE {
55 net_config_watcher_->SetDynamicStoreNotificationKeys(store); 48 net_config_watcher_->SetDynamicStoreNotificationKeys(store);
56 } 49 }
57 virtual void OnNetworkConfigChange(CFArrayRef changed_keys) OVERRIDE { 50 virtual void OnNetworkConfigChange(CFArrayRef changed_keys) OVERRIDE {
58 net_config_watcher_->OnNetworkConfigChange(changed_keys); 51 net_config_watcher_->OnNetworkConfigChange(changed_keys);
59 } 52 }
60 53
61 private: 54 private:
62 NetworkChangeNotifierMac* const net_config_watcher_; 55 NetworkChangeNotifierMac* const net_config_watcher_;
63 DISALLOW_COPY_AND_ASSIGN(Forwarder); 56 DISALLOW_COPY_AND_ASSIGN(Forwarder);
64 }; 57 };
65 58
66 // Methods directly called by the NetworkConfigWatcherMac::Delegate: 59 // Methods directly called by the NetworkConfigWatcherMac::Delegate:
67 void StartReachabilityNotifications(); 60 void StartReachabilityNotifications();
68 void SetDynamicStoreNotificationKeys(SCDynamicStoreRef store); 61 void SetDynamicStoreNotificationKeys(SCDynamicStoreRef store);
69 void OnNetworkConfigChange(CFArrayRef changed_keys); 62 void OnNetworkConfigChange(CFArrayRef changed_keys);
70 63
71 void SetInitialState(); 64 void SetInitialConnectionType();
72 65
73 static void ReachabilityCallback(SCNetworkReachabilityRef target, 66 static void ReachabilityCallback(SCNetworkReachabilityRef target,
74 SCNetworkConnectionFlags flags, 67 SCNetworkConnectionFlags flags,
75 void* notifier); 68 void* notifier);
76 69
77 // These must be constructed before config_watcher_ to ensure 70 // These must be constructed before config_watcher_ to ensure
78 // the lock is in a valid state when Forwarder::Init is called. 71 // the lock is in a valid state when Forwarder::Init is called.
79 OnlineState online_state_; 72 ConnectionType connection_type_;
80 mutable base::Lock online_state_lock_; 73 bool connection_type_initialized_;
81 mutable base::ConditionVariable initial_state_cv_; 74 mutable base::Lock connection_type_lock_;
75 mutable base::ConditionVariable initial_connection_type_cv_;
82 base::mac::ScopedCFTypeRef<SCNetworkReachabilityRef> reachability_; 76 base::mac::ScopedCFTypeRef<SCNetworkReachabilityRef> reachability_;
83 base::mac::ScopedCFTypeRef<CFRunLoopRef> run_loop_; 77 base::mac::ScopedCFTypeRef<CFRunLoopRef> run_loop_;
84 78
85 Forwarder forwarder_; 79 Forwarder forwarder_;
86 scoped_ptr<const NetworkConfigWatcherMac> config_watcher_; 80 scoped_ptr<const NetworkConfigWatcherMac> config_watcher_;
87 81
88 // Thread on which we can run DnsConfigWatcher, which requires TYPE_IO. 82 // Thread on which we can run DnsConfigWatcher, which requires TYPE_IO.
89 scoped_ptr<DnsWatcherThread> dns_watcher_thread_; 83 scoped_ptr<DnsWatcherThread> dns_watcher_thread_;
90 84
91 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierMac); 85 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierMac);
92 }; 86 };
93 87
94 } // namespace net 88 } // namespace net
95 89
96 #endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_MAC_H_ 90 #endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_MAC_H_
OLDNEW
« no previous file with comments | « net/base/network_change_notifier_linux_unittest.cc ('k') | net/base/network_change_notifier_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698