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