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 CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_NETWORK_STATE_INFORMER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_NETWORK_STATE_INFORMER_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_NETWORK_STATE_INFORMER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_NETWORK_STATE_INFORMER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
ygorshenin1
2013/05/06 09:14:39
#include "base/compiler_specific.h"
gauravsh
2013/05/07 23:38:10
Done.
| |
11 #include "base/cancelable_callback.h" | 11 #include "base/cancelable_callback.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
14 #include "chrome/browser/chromeos/cros/network_library.h" | |
15 #include "chrome/browser/chromeos/login/captive_portal_window_proxy.h" | 14 #include "chrome/browser/chromeos/login/captive_portal_window_proxy.h" |
16 #include "chrome/browser/chromeos/net/network_portal_detector.h" | 15 #include "chrome/browser/chromeos/net/network_portal_detector.h" |
16 #include "chromeos/network/network_state_handler_observer.h" | |
17 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
18 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
19 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
20 | 20 |
21 namespace chromeos { | 21 namespace chromeos { |
22 | 22 |
23 class NetworkState; | |
24 | |
23 class NetworkStateInformerDelegate { | 25 class NetworkStateInformerDelegate { |
24 public: | 26 public: |
25 NetworkStateInformerDelegate() {} | 27 NetworkStateInformerDelegate() {} |
26 virtual ~NetworkStateInformerDelegate() {} | 28 virtual ~NetworkStateInformerDelegate() {} |
27 | 29 |
28 // Called when network is connected. | 30 // Called when network is connected. |
29 virtual void OnNetworkReady() = 0; | 31 virtual void OnNetworkReady() = 0; |
30 }; | 32 }; |
31 | 33 |
32 // Class which observes network state changes and calls registered callbacks. | 34 // Class which observes network state changes and calls registered callbacks. |
33 // State is considered changed if connection or the active network has been | 35 // State is considered changed if connection or the active network has been |
34 // changed. Also, it answers to the requests about current network state. | 36 // changed. Also, it answers to the requests about current network state. |
35 class NetworkStateInformer | 37 class NetworkStateInformer |
36 : public chromeos::NetworkLibrary::NetworkManagerObserver, | 38 : public chromeos::NetworkStateHandlerObserver, |
37 public chromeos::NetworkPortalDetector::Observer, | 39 public chromeos::NetworkPortalDetector::Observer, |
38 public content::NotificationObserver, | 40 public content::NotificationObserver, |
39 public CaptivePortalWindowProxyDelegate, | 41 public CaptivePortalWindowProxyDelegate, |
40 public base::RefCounted<NetworkStateInformer> { | 42 public base::RefCounted<NetworkStateInformer> { |
41 public: | 43 public: |
42 enum State { | 44 enum State { |
43 OFFLINE = 0, | 45 OFFLINE = 0, |
44 ONLINE, | 46 ONLINE, |
45 CAPTIVE_PORTAL, | 47 CAPTIVE_PORTAL, |
46 CONNECTING, | 48 CONNECTING, |
47 PROXY_AUTH_REQUIRED, | 49 PROXY_AUTH_REQUIRED, |
48 UNKNOWN | 50 UNKNOWN |
49 }; | 51 }; |
50 | 52 |
51 class NetworkStateInformerObserver { | 53 class NetworkStateInformerObserver { |
52 public: | 54 public: |
53 NetworkStateInformerObserver() {} | 55 NetworkStateInformerObserver() {} |
54 virtual ~NetworkStateInformerObserver() {} | 56 virtual ~NetworkStateInformerObserver() {} |
55 | 57 |
56 virtual void UpdateState(State state, | 58 virtual void UpdateState(State state, |
57 const std::string& service_path, | 59 const std::string& service_path, |
58 ConnectionType connection_type, | 60 const std::string& connection_type, |
59 const std::string& reason) = 0; | 61 const std::string& reason) = 0; |
60 }; | 62 }; |
61 | 63 |
62 NetworkStateInformer(); | 64 NetworkStateInformer(); |
63 | 65 |
64 void Init(); | 66 void Init(); |
65 | 67 |
66 void SetDelegate(NetworkStateInformerDelegate* delegate); | 68 void SetDelegate(NetworkStateInformerDelegate* delegate); |
67 | 69 |
68 // Adds observer to be notified when network state has been changed. | 70 // Adds observer to be notified when network state has been changed. |
69 void AddObserver(NetworkStateInformerObserver* observer); | 71 void AddObserver(NetworkStateInformerObserver* observer); |
70 | 72 |
71 // Removes observer. | 73 // Removes observer. |
72 void RemoveObserver(NetworkStateInformerObserver* observer); | 74 void RemoveObserver(NetworkStateInformerObserver* observer); |
73 | 75 |
74 // NetworkLibrary::NetworkManagerObserver implementation: | 76 // NetworkStateHandlerObserver implementation: |
75 virtual void OnNetworkManagerChanged(chromeos::NetworkLibrary* cros) OVERRIDE; | 77 virtual void NetworkManagerChanged() OVERRIDE; |
78 virtual void DefaultNetworkChanged(const NetworkState* network) OVERRIDE; | |
76 | 79 |
77 // NetworkPortalDetector::Observer implementation: | 80 // NetworkPortalDetector::Observer implementation: |
78 virtual void OnPortalDetectionCompleted( | 81 virtual void OnPortalDetectionCompleted( |
79 const Network* network, | 82 const NetworkState* network, |
80 const NetworkPortalDetector::CaptivePortalState& state) OVERRIDE; | 83 const NetworkPortalDetector::CaptivePortalState& state) OVERRIDE; |
81 | 84 |
82 // content::NotificationObserver implementation. | 85 // content::NotificationObserver implementation. |
83 virtual void Observe(int type, | 86 virtual void Observe(int type, |
84 const content::NotificationSource& source, | 87 const content::NotificationSource& source, |
85 const content::NotificationDetails& details) OVERRIDE; | 88 const content::NotificationDetails& details) OVERRIDE; |
86 | 89 |
87 // CaptivePortalWindowProxyDelegate implementation: | 90 // CaptivePortalWindowProxyDelegate implementation: |
88 virtual void OnPortalDetected() OVERRIDE; | 91 virtual void OnPortalDetected() OVERRIDE; |
89 | 92 |
90 // Returns active network's service path. It can be used to uniquely | 93 // Returns active network's service path. It can be used to uniquely |
91 // identify the network. | 94 // identify the network. |
92 std::string active_network_service_path() { | 95 std::string active_network_service_path() { |
93 return last_online_service_path_; | 96 return last_online_service_path_; |
94 } | 97 } |
95 | 98 |
96 bool is_online() { return state_ == ONLINE; } | 99 bool is_online() { return state_ == ONLINE; } |
97 State state() const { return state_; } | 100 State state() const { return state_; } |
98 std::string last_network_service_path() const { | 101 std::string last_network_service_path() const { |
99 return last_network_service_path_; | 102 return last_network_service_path_; |
100 } | 103 } |
101 ConnectionType last_network_type() const { return last_network_type_; } | 104 std::string last_network_type() const { return last_network_type_; } |
102 | 105 |
103 private: | 106 private: |
104 struct ProxyState { | 107 struct ProxyState { |
105 ProxyState() : configured(false) { | 108 ProxyState() : configured(false) { |
106 } | 109 } |
107 | 110 |
108 ProxyState(const std::string& proxy_config, bool configured) | 111 ProxyState(const std::string& proxy_config, bool configured) |
109 : proxy_config(proxy_config), | 112 : proxy_config(proxy_config), |
110 configured(configured) { | 113 configured(configured) { |
111 } | 114 } |
112 | 115 |
113 std::string proxy_config; | 116 std::string proxy_config; |
114 bool configured; | 117 bool configured; |
115 }; | 118 }; |
116 | 119 |
117 typedef std::map<std::string, ProxyState> ProxyStateMap; | 120 typedef std::map<std::string, ProxyState> ProxyStateMap; |
118 | 121 |
119 friend class base::RefCounted<NetworkStateInformer>; | 122 friend class base::RefCounted<NetworkStateInformer>; |
120 | 123 |
121 virtual ~NetworkStateInformer(); | 124 virtual ~NetworkStateInformer(); |
122 | 125 |
123 bool UpdateState(chromeos::NetworkLibrary* cros); | 126 bool UpdateState(); |
124 | 127 |
125 void UpdateStateAndNotify(); | 128 void UpdateStateAndNotify(); |
126 | 129 |
127 void SendStateToObservers(const std::string& reason); | 130 void SendStateToObservers(const std::string& reason); |
128 | 131 |
129 State GetNetworkState(const Network* network); | 132 State GetNetworkState(const NetworkState* network); |
130 bool IsProxyConfigured(const Network* network); | 133 bool IsProxyConfigured(const NetworkState* network); |
131 | 134 |
132 content::NotificationRegistrar registrar_; | 135 content::NotificationRegistrar registrar_; |
133 State state_; | 136 State state_; |
134 NetworkStateInformerDelegate* delegate_; | 137 NetworkStateInformerDelegate* delegate_; |
135 ObserverList<NetworkStateInformerObserver> observers_; | 138 ObserverList<NetworkStateInformerObserver> observers_; |
136 std::string last_online_service_path_; | 139 std::string last_online_service_path_; |
137 std::string last_connected_service_path_; | 140 std::string last_connected_service_path_; |
138 std::string last_network_service_path_; | 141 std::string last_network_service_path_; |
139 ConnectionType last_network_type_; | 142 std::string last_network_type_; |
140 base::CancelableClosure check_state_; | 143 base::CancelableClosure check_state_; |
141 | 144 |
142 // Caches proxy state for active networks. | 145 // Caches proxy state for active networks. |
143 ProxyStateMap proxy_state_map_; | 146 ProxyStateMap proxy_state_map_; |
144 }; | 147 }; |
145 | 148 |
146 } // namespace chromeos | 149 } // namespace chromeos |
147 | 150 |
148 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_NETWORK_STATE_INFORMER_H_ | 151 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_NETWORK_STATE_INFORMER_H_ |
OLD | NEW |