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 CHROMEOS_NETWORK_NETWORK_CONNECTION_HANDLER_H_ | 5 #ifndef CHROMEOS_NETWORK_NETWORK_CONNECTION_HANDLER_H_ |
6 #define CHROMEOS_NETWORK_NETWORK_CONNECTION_HANDLER_H_ | 6 #define CHROMEOS_NETWORK_NETWORK_CONNECTION_HANDLER_H_ |
7 | 7 |
| 8 #include <map> |
8 #include <set> | 9 #include <set> |
9 #include <string> | 10 #include <string> |
10 | 11 |
11 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
12 #include "base/callback.h" | 13 #include "base/callback.h" |
13 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/observer_list.h" |
14 #include "base/time/time.h" | 16 #include "base/time/time.h" |
15 #include "base/values.h" | 17 #include "base/values.h" |
16 #include "chromeos/cert_loader.h" | 18 #include "chromeos/cert_loader.h" |
17 #include "chromeos/chromeos_export.h" | 19 #include "chromeos/chromeos_export.h" |
18 #include "chromeos/dbus/dbus_method_call_status.h" | 20 #include "chromeos/dbus/dbus_method_call_status.h" |
19 #include "chromeos/login/login_state.h" | 21 #include "chromeos/login/login_state.h" |
20 #include "chromeos/network/network_handler.h" | 22 #include "chromeos/network/network_handler.h" |
21 #include "chromeos/network/network_handler_callbacks.h" | 23 #include "chromeos/network/network_handler_callbacks.h" |
22 #include "chromeos/network/network_policy_observer.h" | |
23 #include "chromeos/network/network_state_handler_observer.h" | 24 #include "chromeos/network/network_state_handler_observer.h" |
24 | 25 |
25 namespace chromeos { | 26 namespace chromeos { |
26 | 27 |
27 class NetworkState; | 28 class NetworkState; |
28 | 29 |
29 // The NetworkConnectionHandler class is used to manage network connection | 30 // The NetworkConnectionHandler class is used to manage network connection |
30 // requests. This is the only class that should make Shill Connect calls. | 31 // requests. This is the only class that should make Shill Connect calls. |
31 // It handles the following steps: | 32 // It handles the following steps: |
32 // 1. Determine whether or not sufficient information (e.g. passphrase) is | 33 // 1. Determine whether or not sufficient information (e.g. passphrase) is |
33 // known to be available to connect to the network. | 34 // known to be available to connect to the network. |
34 // 2. Request additional information (e.g. user data which contains certificate | 35 // 2. Request additional information (e.g. user data which contains certificate |
35 // information) and determine whether sufficient information is available. | 36 // information) and determine whether sufficient information is available. |
36 // 3. Possibly configure the network certificate info (tpm slot and pkcs11 id). | 37 // 3. Possibly configure the network certificate info (tpm slot and pkcs11 id). |
37 // 4. Send the connect request. | 38 // 4. Send the connect request. |
38 // 5. Wait for the network state to change to a non connecting state. | 39 // 5. Wait for the network state to change to a non connecting state. |
39 // 6. Invoke the appropriate callback (always) on success or failure. | 40 // 6. Invoke the appropriate callback (always) on success or failure. |
40 // | 41 // |
41 // NetworkConnectionHandler depends on NetworkStateHandler for immediately | 42 // NetworkConnectionHandler depends on NetworkStateHandler for immediately |
42 // available State information, and NetworkConfigurationHandler for any | 43 // available State information, and NetworkConfigurationHandler for any |
43 // configuration calls. | 44 // configuration calls. |
44 | 45 |
45 class CHROMEOS_EXPORT NetworkConnectionHandler | 46 class CHROMEOS_EXPORT NetworkConnectionHandler |
46 : public LoginState::Observer, | 47 : public LoginState::Observer, |
47 public CertLoader::Observer, | 48 public CertLoader::Observer, |
48 public NetworkStateHandlerObserver, | 49 public NetworkStateHandlerObserver, |
49 public NetworkPolicyObserver, | |
50 public base::SupportsWeakPtr<NetworkConnectionHandler> { | 50 public base::SupportsWeakPtr<NetworkConnectionHandler> { |
51 public: | 51 public: |
| 52 class Observer { |
| 53 public: |
| 54 // Called every time a connect, by calling ConnectToNetwork, was requested. |
| 55 virtual void ConnectToNetworkRequested() = 0; |
| 56 |
| 57 protected: |
| 58 virtual ~Observer() {} |
| 59 |
| 60 private: |
| 61 DISALLOW_ASSIGN(Observer); |
| 62 }; |
| 63 |
52 // Constants for |error_name| from |error_callback| for Connect. | 64 // Constants for |error_name| from |error_callback| for Connect. |
53 | 65 |
54 // No network matching |service_path| is found (hidden networks must be | 66 // No network matching |service_path| is found (hidden networks must be |
55 // configured before connecting). | 67 // configured before connecting). |
56 static const char kErrorNotFound[]; | 68 static const char kErrorNotFound[]; |
57 | 69 |
58 // Already connected to the network. | 70 // Already connected to the network. |
59 static const char kErrorConnected[]; | 71 static const char kErrorConnected[]; |
60 | 72 |
61 // Already connecting to the network. | 73 // Already connecting to the network. |
(...skipping 24 matching lines...) Expand all Loading... |
86 static const char kErrorConnectCanceled[]; | 98 static const char kErrorConnectCanceled[]; |
87 | 99 |
88 // Constants for |error_name| from |error_callback| for Disconnect. | 100 // Constants for |error_name| from |error_callback| for Disconnect. |
89 static const char kErrorNotConnected[]; | 101 static const char kErrorNotConnected[]; |
90 | 102 |
91 // Certificate load timed out. | 103 // Certificate load timed out. |
92 static const char kErrorCertLoadTimeout[]; | 104 static const char kErrorCertLoadTimeout[]; |
93 | 105 |
94 virtual ~NetworkConnectionHandler(); | 106 virtual ~NetworkConnectionHandler(); |
95 | 107 |
| 108 void AddObserver(Observer* observer); |
| 109 void RemoveObserver(Observer* observer); |
| 110 |
96 // ConnectToNetwork() will start an asynchronous connection attempt. | 111 // ConnectToNetwork() will start an asynchronous connection attempt. |
97 // On success, |success_callback| will be called. | 112 // On success, |success_callback| will be called. |
98 // On failure, |error_callback| will be called with |error_name| one of the | 113 // On failure, |error_callback| will be called with |error_name| one of the |
99 // constants defined above, or shill::kErrorConnectFailed or | 114 // constants defined above, or shill::kErrorConnectFailed or |
100 // shill::kErrorBadPassphrase if the Shill Error property (from a | 115 // shill::kErrorBadPassphrase if the Shill Error property (from a |
101 // previous connect attempt) was set to one of those. | 116 // previous connect attempt) was set to one of those. |
102 // |error_message| will contain an additional error string for debugging. | 117 // |error_message| will contain an additional error string for debugging. |
103 // If |check_error_state| is true, the current state of the network is | 118 // If |check_error_state| is true, the current state of the network is |
104 // checked for errors, otherwise current state is ignored (e.g. for recently | 119 // checked for errors, otherwise current state is ignored (e.g. for recently |
105 // configured networks or repeat attempts). | 120 // configured networks or repeat attempts). |
(...skipping 24 matching lines...) Expand all Loading... |
130 virtual void NetworkListChanged() override; | 145 virtual void NetworkListChanged() override; |
131 virtual void NetworkPropertiesUpdated(const NetworkState* network) override; | 146 virtual void NetworkPropertiesUpdated(const NetworkState* network) override; |
132 | 147 |
133 // LoginState::Observer | 148 // LoginState::Observer |
134 virtual void LoggedInStateChanged() override; | 149 virtual void LoggedInStateChanged() override; |
135 | 150 |
136 // CertLoader::Observer | 151 // CertLoader::Observer |
137 virtual void OnCertificatesLoaded(const net::CertificateList& cert_list, | 152 virtual void OnCertificatesLoaded(const net::CertificateList& cert_list, |
138 bool initial_load) override; | 153 bool initial_load) override; |
139 | 154 |
140 // NetworkPolicyObserver | |
141 virtual void PolicyChanged(const std::string& userhash) override; | |
142 | |
143 private: | 155 private: |
144 friend class NetworkHandler; | 156 friend class NetworkHandler; |
145 friend class NetworkConnectionHandlerTest; | 157 friend class NetworkConnectionHandlerTest; |
146 | 158 |
147 struct ConnectRequest; | 159 struct ConnectRequest; |
148 | 160 |
149 NetworkConnectionHandler(); | 161 NetworkConnectionHandler(); |
150 | 162 |
151 void Init(NetworkStateHandler* network_state_handler, | 163 void Init(NetworkStateHandler* network_state_handler, |
152 NetworkConfigurationHandler* network_configuration_handler, | 164 NetworkConfigurationHandler* network_configuration_handler, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 // Calls Shill.Manager.Disconnect asynchronously. | 211 // Calls Shill.Manager.Disconnect asynchronously. |
200 void CallShillDisconnect( | 212 void CallShillDisconnect( |
201 const std::string& service_path, | 213 const std::string& service_path, |
202 const base::Closure& success_callback, | 214 const base::Closure& success_callback, |
203 const network_handler::ErrorCallback& error_callback); | 215 const network_handler::ErrorCallback& error_callback); |
204 | 216 |
205 // Handle success from Shill.Service.Disconnect. | 217 // Handle success from Shill.Service.Disconnect. |
206 void HandleShillDisconnectSuccess(const std::string& service_path, | 218 void HandleShillDisconnectSuccess(const std::string& service_path, |
207 const base::Closure& success_callback); | 219 const base::Closure& success_callback); |
208 | 220 |
209 // If the policy to prevent unmanaged & shared networks to autoconnect is | 221 ObserverList<Observer> observers_; |
210 // enabled, then disconnect all such networks except wired networks. Does | |
211 // nothing on consecutive calls. | |
212 // This is enforced once after a user logs in 1) to allow mananged networks to | |
213 // autoconnect and 2) to prevent a previous user from foisting a network on | |
214 // the new user. Therefore, this function is called on startup, at login and | |
215 // when the device policy is changed. | |
216 void DisconnectIfPolicyRequires(); | |
217 | |
218 // Disconnects from all unmanaged and shared WiFi networks that are currently | |
219 // connected or connecting. | |
220 void DisconnectFromUnmanagedSharedWiFiNetworks(); | |
221 | |
222 // Requests a connect to the 'best' available network once after login and | |
223 // after any disconnect required by policy is executed (see | |
224 // DisconnectIfPolicyRequires()). To include networks with client | |
225 // certificates, no request is sent until certificates are loaded. Therefore, | |
226 // this function is called on the initial certificate load and by | |
227 // DisconnectIfPolicyRequires(). | |
228 void ConnectToBestNetworkAfterLogin(); | |
229 | 222 |
230 // Local references to the associated handler instances. | 223 // Local references to the associated handler instances. |
231 CertLoader* cert_loader_; | 224 CertLoader* cert_loader_; |
232 NetworkStateHandler* network_state_handler_; | 225 NetworkStateHandler* network_state_handler_; |
233 NetworkConfigurationHandler* configuration_handler_; | 226 NetworkConfigurationHandler* configuration_handler_; |
234 ManagedNetworkConfigurationHandler* managed_configuration_handler_; | 227 ManagedNetworkConfigurationHandler* managed_configuration_handler_; |
235 | 228 |
236 // Map of pending connect requests, used to prevent repeated attempts while | 229 // Map of pending connect requests, used to prevent repeated attempts while |
237 // waiting for Shill and to trigger callbacks on eventual success or failure. | 230 // waiting for Shill and to trigger callbacks on eventual success or failure. |
238 std::map<std::string, ConnectRequest> pending_requests_; | 231 std::map<std::string, ConnectRequest> pending_requests_; |
239 scoped_ptr<ConnectRequest> queued_connect_; | 232 scoped_ptr<ConnectRequest> queued_connect_; |
240 | 233 |
241 // Track certificate loading state. | 234 // Track certificate loading state. |
242 bool logged_in_; | 235 bool logged_in_; |
243 bool certificates_loaded_; | 236 bool certificates_loaded_; |
244 base::TimeTicks logged_in_time_; | 237 base::TimeTicks logged_in_time_; |
245 | 238 |
246 // Whether the autoconnect policy was applied already, see | |
247 // DisconnectIfPolicyRequires(). | |
248 bool applied_autoconnect_policy_; | |
249 | |
250 // Whether the handler already requested a 'ConnectToBestNetwork' after login, | |
251 // see ConnectToBestNetworkAfterLogin(). | |
252 bool requested_connect_to_best_network_; | |
253 | |
254 DISALLOW_COPY_AND_ASSIGN(NetworkConnectionHandler); | 239 DISALLOW_COPY_AND_ASSIGN(NetworkConnectionHandler); |
255 }; | 240 }; |
256 | 241 |
257 } // namespace chromeos | 242 } // namespace chromeos |
258 | 243 |
259 #endif // CHROMEOS_NETWORK_NETWORK_CONNECTION_HANDLER_H_ | 244 #endif // CHROMEOS_NETWORK_NETWORK_CONNECTION_HANDLER_H_ |
OLD | NEW |