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