OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #include "ash/system/chromeos/network/network_connect.h" | 5 #include "ash/system/chromeos/network/network_connect.h" |
6 | 6 |
7 #include "ash/session/session_state_delegate.h" | 7 #include "ash/session/session_state_delegate.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/system/chromeos/network/network_state_notifier.h" | 9 #include "ash/system/chromeos/network/network_state_notifier.h" |
10 #include "ash/system/system_notifier.h" | 10 #include "ash/system/system_notifier.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 return true; | 58 return true; |
59 return false; | 59 return false; |
60 } | 60 } |
61 | 61 |
62 void ShowErrorNotification(const std::string& error_name, | 62 void ShowErrorNotification(const std::string& error_name, |
63 const std::string& service_path) { | 63 const std::string& service_path) { |
64 Shell::GetInstance()->system_tray_notifier()->network_state_notifier()-> | 64 Shell::GetInstance()->system_tray_notifier()->network_state_notifier()-> |
65 ShowNetworkConnectError(error_name, service_path); | 65 ShowNetworkConnectError(error_name, service_path); |
66 } | 66 } |
67 | 67 |
68 void HandleUnconfiguredNetwork(const std::string& service_path, | 68 void HandleUnconfiguredNetwork(const std::string& service_path) { |
69 gfx::NativeWindow parent_window) { | |
70 const NetworkState* network = NetworkHandler::Get()->network_state_handler()-> | 69 const NetworkState* network = NetworkHandler::Get()->network_state_handler()-> |
71 GetNetworkState(service_path); | 70 GetNetworkState(service_path); |
72 if (!network) { | 71 if (!network) { |
73 NET_LOG_ERROR("Configuring unknown network", service_path); | 72 NET_LOG_ERROR("Configuring unknown network", service_path); |
74 return; | 73 return; |
75 } | 74 } |
76 | 75 |
77 if (network->type() == shill::kTypeWifi) { | 76 if (network->type() == shill::kTypeWifi) { |
78 // Only show the config view for secure networks, otherwise do nothing. | 77 // Only show the config view for secure networks, otherwise do nothing. |
79 if (network->security() != shill::kSecurityNone) { | 78 if (network->security() != shill::kSecurityNone) { |
80 ash::Shell::GetInstance()->system_tray_delegate()-> | 79 ash::Shell::GetInstance()->system_tray_delegate()-> |
81 ShowNetworkConfigure(service_path, parent_window); | 80 ShowNetworkConfigure(service_path); |
82 } | 81 } |
83 return; | 82 return; |
84 } | 83 } |
85 | 84 |
86 if (network->type() == shill::kTypeWimax || | 85 if (network->type() == shill::kTypeWimax || |
87 network->type() == shill::kTypeVPN) { | 86 network->type() == shill::kTypeVPN) { |
88 ash::Shell::GetInstance()->system_tray_delegate()-> | 87 ash::Shell::GetInstance()->system_tray_delegate()-> |
89 ShowNetworkConfigure(service_path, parent_window); | 88 ShowNetworkConfigure(service_path); |
90 return; | 89 return; |
91 } | 90 } |
92 | 91 |
93 if (network->type() == shill::kTypeCellular) { | 92 if (network->type() == shill::kTypeCellular) { |
94 if (network->RequiresActivation()) { | 93 if (network->RequiresActivation()) { |
95 ash::network_connect::ActivateCellular(service_path); | 94 ash::network_connect::ActivateCellular(service_path); |
96 return; | 95 return; |
97 } | 96 } |
98 if (network->cellular_out_of_credits()) { | 97 if (network->cellular_out_of_credits()) { |
99 ash::network_connect::ShowMobileSetup(service_path); | 98 ash::network_connect::ShowMobileSetup(service_path); |
(...skipping 29 matching lines...) Expand all Loading... |
129 if (!profile) { | 128 if (!profile) { |
130 NET_LOG_ERROR("No user profile for unshared network configuration", ""); | 129 NET_LOG_ERROR("No user profile for unshared network configuration", ""); |
131 return false; | 130 return false; |
132 } | 131 } |
133 | 132 |
134 *profile_path = profile->path; | 133 *profile_path = profile->path; |
135 return true; | 134 return true; |
136 } | 135 } |
137 | 136 |
138 void OnConnectFailed(const std::string& service_path, | 137 void OnConnectFailed(const std::string& service_path, |
139 gfx::NativeWindow parent_window, | |
140 const std::string& error_name, | 138 const std::string& error_name, |
141 scoped_ptr<base::DictionaryValue> error_data) { | 139 scoped_ptr<base::DictionaryValue> error_data) { |
142 NET_LOG_ERROR("Connect Failed: " + error_name, service_path); | 140 NET_LOG_ERROR("Connect Failed: " + error_name, service_path); |
143 | 141 |
144 if (!ash::Shell::HasInstance()) | 142 if (!ash::Shell::HasInstance()) |
145 return; | 143 return; |
146 | 144 |
147 // If a new connect attempt canceled this connect, no need to notify the user. | 145 // If a new connect attempt canceled this connect, no need to notify the user. |
148 if (error_name == NetworkConnectionHandler::kErrorConnectCanceled) | 146 if (error_name == NetworkConnectionHandler::kErrorConnectCanceled) |
149 return; | 147 return; |
150 | 148 |
151 if (error_name == shill::kErrorBadPassphrase || | 149 if (error_name == shill::kErrorBadPassphrase || |
152 error_name == NetworkConnectionHandler::kErrorPassphraseRequired || | 150 error_name == NetworkConnectionHandler::kErrorPassphraseRequired || |
153 error_name == NetworkConnectionHandler::kErrorConfigurationRequired || | 151 error_name == NetworkConnectionHandler::kErrorConfigurationRequired || |
154 error_name == NetworkConnectionHandler::kErrorAuthenticationRequired) { | 152 error_name == NetworkConnectionHandler::kErrorAuthenticationRequired) { |
155 HandleUnconfiguredNetwork(service_path, parent_window); | 153 HandleUnconfiguredNetwork(service_path); |
156 return; | 154 return; |
157 } | 155 } |
158 | 156 |
159 if (error_name == NetworkConnectionHandler::kErrorCertificateRequired) { | 157 if (error_name == NetworkConnectionHandler::kErrorCertificateRequired) { |
160 if (!ash::Shell::GetInstance()->system_tray_delegate()->EnrollNetwork( | 158 if (!ash::Shell::GetInstance()->system_tray_delegate()->EnrollNetwork( |
161 service_path, parent_window)) { | 159 service_path)) { |
162 HandleUnconfiguredNetwork(service_path, parent_window); | 160 HandleUnconfiguredNetwork(service_path); |
163 } | 161 } |
164 return; | 162 return; |
165 } | 163 } |
166 | 164 |
167 if (error_name == NetworkConnectionHandler::kErrorActivationRequired) { | 165 if (error_name == NetworkConnectionHandler::kErrorActivationRequired) { |
168 network_connect::ActivateCellular(service_path); | 166 network_connect::ActivateCellular(service_path); |
169 return; | 167 return; |
170 } | 168 } |
171 | 169 |
172 if (error_name == NetworkConnectionHandler::kErrorConnected || | 170 if (error_name == NetworkConnectionHandler::kErrorConnected || |
(...skipping 11 matching lines...) Expand all Loading... |
184 Shell::GetInstance()->session_state_delegate()->IsScreenLocked()) | 182 Shell::GetInstance()->session_state_delegate()->IsScreenLocked()) |
185 return; | 183 return; |
186 | 184 |
187 // If Shill reports an InProgress error, don't try to configure the network. | 185 // If Shill reports an InProgress error, don't try to configure the network. |
188 std::string dbus_error_name; | 186 std::string dbus_error_name; |
189 error_data.get()->GetString( | 187 error_data.get()->GetString( |
190 chromeos::network_handler::kDbusErrorName, &dbus_error_name); | 188 chromeos::network_handler::kDbusErrorName, &dbus_error_name); |
191 if (dbus_error_name == kErrorInProgress) | 189 if (dbus_error_name == kErrorInProgress) |
192 return; | 190 return; |
193 | 191 |
194 HandleUnconfiguredNetwork(service_path, parent_window); | 192 HandleUnconfiguredNetwork(service_path); |
195 } | 193 } |
196 | 194 |
197 void OnConnectSucceeded(const std::string& service_path) { | 195 void OnConnectSucceeded(const std::string& service_path) { |
198 NET_LOG_USER("Connect Succeeded", service_path); | 196 NET_LOG_USER("Connect Succeeded", service_path); |
199 if (!ash::Shell::HasInstance()) | 197 if (!ash::Shell::HasInstance()) |
200 return; | 198 return; |
201 message_center::MessageCenter::Get()->RemoveNotification( | 199 message_center::MessageCenter::Get()->RemoveNotification( |
202 network_connect::kNetworkConnectNotificationId, false /* not by user */); | 200 network_connect::kNetworkConnectNotificationId, false /* not by user */); |
203 } | 201 } |
204 | 202 |
205 // If |check_error_state| is true, error state for the network is checked, | 203 // If |check_error_state| is true, error state for the network is checked, |
206 // otherwise any current error state is ignored (e.g. for recently configured | 204 // otherwise any current error state is ignored (e.g. for recently configured |
207 // networks or repeat connect attempts). |parent_window| will be used to parent | 205 // networks or repeat connect attempts). |
208 // any configuration UI on failure and may be NULL (in which case the default | |
209 // window will be used). | |
210 void CallConnectToNetwork(const std::string& service_path, | 206 void CallConnectToNetwork(const std::string& service_path, |
211 bool check_error_state, | 207 bool check_error_state) { |
212 gfx::NativeWindow parent_window) { | |
213 if (!ash::Shell::HasInstance()) | 208 if (!ash::Shell::HasInstance()) |
214 return; | 209 return; |
215 message_center::MessageCenter::Get()->RemoveNotification( | 210 message_center::MessageCenter::Get()->RemoveNotification( |
216 network_connect::kNetworkConnectNotificationId, false /* not by user */); | 211 network_connect::kNetworkConnectNotificationId, false /* not by user */); |
217 | 212 |
218 NetworkHandler::Get()->network_connection_handler()->ConnectToNetwork( | 213 NetworkHandler::Get()->network_connection_handler()->ConnectToNetwork( |
219 service_path, | 214 service_path, |
220 base::Bind(&OnConnectSucceeded, service_path), | 215 base::Bind(&OnConnectSucceeded, service_path), |
221 base::Bind(&OnConnectFailed, service_path, parent_window), | 216 base::Bind(&OnConnectFailed, service_path), |
222 check_error_state); | 217 check_error_state); |
223 } | 218 } |
224 | 219 |
225 void OnActivateFailed(const std::string& service_path, | 220 void OnActivateFailed(const std::string& service_path, |
226 const std::string& error_name, | 221 const std::string& error_name, |
227 scoped_ptr<base::DictionaryValue> error_data) { | 222 scoped_ptr<base::DictionaryValue> error_data) { |
228 NET_LOG_ERROR("Unable to activate network", service_path); | 223 NET_LOG_ERROR("Unable to activate network", service_path); |
229 ShowErrorNotification(network_connect::kErrorActivateFailed, service_path); | 224 ShowErrorNotification(network_connect::kErrorActivateFailed, service_path); |
230 } | 225 } |
231 | 226 |
232 void OnActivateSucceeded(const std::string& service_path) { | 227 void OnActivateSucceeded(const std::string& service_path) { |
233 NET_LOG_USER("Activation Succeeded", service_path); | 228 NET_LOG_USER("Activation Succeeded", service_path); |
234 } | 229 } |
235 | 230 |
236 void OnConfigureFailed(const std::string& error_name, | 231 void OnConfigureFailed(const std::string& error_name, |
237 scoped_ptr<base::DictionaryValue> error_data) { | 232 scoped_ptr<base::DictionaryValue> error_data) { |
238 NET_LOG_ERROR("Unable to configure network", ""); | 233 NET_LOG_ERROR("Unable to configure network", ""); |
239 ShowErrorNotification(NetworkConnectionHandler::kErrorConfigureFailed, ""); | 234 ShowErrorNotification(NetworkConnectionHandler::kErrorConfigureFailed, ""); |
240 } | 235 } |
241 | 236 |
242 void OnConfigureSucceeded(bool connect_on_configure, | 237 void OnConfigureSucceeded(bool connect_on_configure, |
243 const std::string& service_path) { | 238 const std::string& service_path) { |
244 NET_LOG_USER("Configure Succeeded", service_path); | 239 NET_LOG_USER("Configure Succeeded", service_path); |
245 if (!connect_on_configure) | 240 if (!connect_on_configure) |
246 return; | 241 return; |
247 // After configuring a network, ignore any (possibly stale) error state. | 242 // After configuring a network, ignore any (possibly stale) error state. |
248 const bool check_error_state = false; | 243 const bool check_error_state = false; |
249 const gfx::NativeWindow parent_window = NULL; | 244 CallConnectToNetwork(service_path, check_error_state); |
250 CallConnectToNetwork(service_path, check_error_state, parent_window); | |
251 } | 245 } |
252 | 246 |
253 void CallCreateConfiguration(base::DictionaryValue* properties, | 247 void CallCreateConfiguration(base::DictionaryValue* properties, |
254 bool shared, | 248 bool shared, |
255 bool connect_on_configure) { | 249 bool connect_on_configure) { |
256 std::string profile_path; | 250 std::string profile_path; |
257 if (!GetNetworkProfilePath(shared, &profile_path)) { | 251 if (!GetNetworkProfilePath(shared, &profile_path)) { |
258 ShowErrorNotification(NetworkConnectionHandler::kErrorConfigureFailed, ""); | 252 ShowErrorNotification(NetworkConnectionHandler::kErrorConfigureFailed, ""); |
259 return; | 253 return; |
260 } | 254 } |
(...skipping 29 matching lines...) Expand all Loading... |
290 properties_to_set->RemoveWithoutPathExpansion(*iter, NULL); | 284 properties_to_set->RemoveWithoutPathExpansion(*iter, NULL); |
291 } | 285 } |
292 } | 286 } |
293 | 287 |
294 void ClearPropertiesAndConnect( | 288 void ClearPropertiesAndConnect( |
295 const std::string& service_path, | 289 const std::string& service_path, |
296 const std::vector<std::string>& properties_to_clear) { | 290 const std::vector<std::string>& properties_to_clear) { |
297 NET_LOG_USER("ClearPropertiesAndConnect", service_path); | 291 NET_LOG_USER("ClearPropertiesAndConnect", service_path); |
298 // After configuring a network, ignore any (possibly stale) error state. | 292 // After configuring a network, ignore any (possibly stale) error state. |
299 const bool check_error_state = false; | 293 const bool check_error_state = false; |
300 const gfx::NativeWindow parent_window = NULL; | |
301 NetworkHandler::Get()->network_configuration_handler()->ClearProperties( | 294 NetworkHandler::Get()->network_configuration_handler()->ClearProperties( |
302 service_path, | 295 service_path, |
303 properties_to_clear, | 296 properties_to_clear, |
304 base::Bind(&CallConnectToNetwork, | 297 base::Bind(&CallConnectToNetwork, |
305 service_path, check_error_state, | 298 service_path, check_error_state), |
306 parent_window), | |
307 base::Bind(&SetPropertiesFailed, "ClearProperties", service_path)); | 299 base::Bind(&SetPropertiesFailed, "ClearProperties", service_path)); |
308 } | 300 } |
309 | 301 |
310 void ConfigureSetProfileSucceeded( | 302 void ConfigureSetProfileSucceeded( |
311 const std::string& service_path, | 303 const std::string& service_path, |
312 scoped_ptr<base::DictionaryValue> properties_to_set) { | 304 scoped_ptr<base::DictionaryValue> properties_to_set) { |
313 std::vector<std::string> properties_to_clear; | 305 std::vector<std::string> properties_to_clear; |
314 SetPropertiesToClear(properties_to_set.get(), &properties_to_clear); | 306 SetPropertiesToClear(properties_to_set.get(), &properties_to_clear); |
315 NetworkHandler::Get()->network_configuration_handler()->SetProperties( | 307 NetworkHandler::Get()->network_configuration_handler()->SetProperties( |
316 service_path, | 308 service_path, |
(...skipping 13 matching lines...) Expand all Loading... |
330 | 322 |
331 namespace network_connect { | 323 namespace network_connect { |
332 | 324 |
333 const char kNetworkConnectNotificationId[] = | 325 const char kNetworkConnectNotificationId[] = |
334 "chrome://settings/internet/connect"; | 326 "chrome://settings/internet/connect"; |
335 const char kNetworkActivateNotificationId[] = | 327 const char kNetworkActivateNotificationId[] = |
336 "chrome://settings/internet/activate"; | 328 "chrome://settings/internet/activate"; |
337 | 329 |
338 const char kErrorActivateFailed[] = "activate-failed"; | 330 const char kErrorActivateFailed[] = "activate-failed"; |
339 | 331 |
340 void ConnectToNetwork(const std::string& service_path, | 332 void ConnectToNetwork(const std::string& service_path) { |
341 gfx::NativeWindow parent_window) { | |
342 NET_LOG_USER("ConnectToNetwork", service_path); | 333 NET_LOG_USER("ConnectToNetwork", service_path); |
343 const NetworkState* network = GetNetworkState(service_path); | 334 const NetworkState* network = GetNetworkState(service_path); |
344 if (network) { | 335 if (network) { |
345 if (!network->error().empty() && !network->security().empty()) { | 336 if (!network->error().empty() && !network->security().empty()) { |
346 NET_LOG_USER("Configure: " + network->error(), service_path); | 337 NET_LOG_USER("Configure: " + network->error(), service_path); |
347 // If the network is in an error state, show the configuration UI directly | 338 // If the network is in an error state, show the configuration UI directly |
348 // to avoid a spurious notification. | 339 // to avoid a spurious notification. |
349 HandleUnconfiguredNetwork(service_path, parent_window); | 340 HandleUnconfiguredNetwork(service_path); |
350 return; | 341 return; |
351 } else if (network->RequiresActivation()) { | 342 } else if (network->RequiresActivation()) { |
352 ActivateCellular(service_path); | 343 ActivateCellular(service_path); |
353 return; | 344 return; |
354 } | 345 } |
355 } | 346 } |
356 const bool check_error_state = true; | 347 const bool check_error_state = true; |
357 CallConnectToNetwork(service_path, check_error_state, parent_window); | 348 CallConnectToNetwork(service_path, check_error_state); |
358 } | 349 } |
359 | 350 |
360 void SetTechnologyEnabled(const NetworkTypePattern& technology, | 351 void SetTechnologyEnabled(const NetworkTypePattern& technology, |
361 bool enabled_state) { | 352 bool enabled_state) { |
362 std::string log_string = | 353 std::string log_string = |
363 base::StringPrintf("technology %s, target state: %s", | 354 base::StringPrintf("technology %s, target state: %s", |
364 technology.ToDebugString().c_str(), | 355 technology.ToDebugString().c_str(), |
365 (enabled_state ? "ENABLED" : "DISABLED")); | 356 (enabled_state ? "ENABLED" : "DISABLED")); |
366 NET_LOG_USER("SetTechnologyEnabled", log_string); | 357 NET_LOG_USER("SetTechnologyEnabled", log_string); |
367 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); | 358 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 | 574 |
584 void ShowNetworkSettings(const std::string& service_path) { | 575 void ShowNetworkSettings(const std::string& service_path) { |
585 if (!ash::Shell::HasInstance()) | 576 if (!ash::Shell::HasInstance()) |
586 return; | 577 return; |
587 ash::Shell::GetInstance()->system_tray_delegate()->ShowNetworkSettings( | 578 ash::Shell::GetInstance()->system_tray_delegate()->ShowNetworkSettings( |
588 service_path); | 579 service_path); |
589 } | 580 } |
590 | 581 |
591 } // network_connect | 582 } // network_connect |
592 } // ash | 583 } // ash |
OLD | NEW |