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 "chromeos/network/network_connection_handler.h" | 5 #include "chromeos/network/network_connection_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "chromeos/chromeos_switches.h" | 10 #include "chromeos/chromeos_switches.h" |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
224 // Clear any existing queued connect request. | 224 // Clear any existing queued connect request. |
225 queued_connect_.reset(); | 225 queued_connect_.reset(); |
226 if (HasConnectingNetwork(service_path)) { | 226 if (HasConnectingNetwork(service_path)) { |
227 NET_LOG_USER("Connect Request While Pending", service_path); | 227 NET_LOG_USER("Connect Request While Pending", service_path); |
228 InvokeErrorCallback(service_path, error_callback, kErrorConnecting); | 228 InvokeErrorCallback(service_path, error_callback, kErrorConnecting); |
229 return; | 229 return; |
230 } | 230 } |
231 | 231 |
232 // Check cached network state for connected, connecting, or unactivated | 232 // Check cached network state for connected, connecting, or unactivated |
233 // networks. These states will not be affected by a recent configuration. | 233 // networks. These states will not be affected by a recent configuration. |
234 const NetworkState* network = | 234 const NetworkState* network = |
pneubeck (no reviews)
2013/08/10 19:44:11
add a comment somewhere what it means if network==
stevenjb
2013/08/12 17:48:29
This should only happen if we call ConnectToNetwor
pneubeck (no reviews)
2013/08/12 18:35:01
Sounds reasonable. In particular c) is IMO very im
| |
235 network_state_handler_->GetNetworkState(service_path); | 235 network_state_handler_->GetNetworkState(service_path); |
236 if (!network) { | 236 |
237 InvokeErrorCallback(service_path, error_callback, kErrorNotFound); | 237 if (network) { |
238 return; | 238 // For existing networks, perform some immediate consistency checks. |
239 } | 239 if (network->IsConnectedState()) { |
240 if (network->IsConnectedState()) { | 240 InvokeErrorCallback(service_path, error_callback, kErrorConnected); |
241 InvokeErrorCallback(service_path, error_callback, kErrorConnected); | 241 return; |
242 return; | 242 } |
243 } | 243 if (network->IsConnectingState()) { |
244 if (network->IsConnectingState()) { | 244 InvokeErrorCallback(service_path, error_callback, kErrorConnecting); |
245 InvokeErrorCallback(service_path, error_callback, kErrorConnecting); | 245 return; |
246 return; | 246 } |
247 } | 247 if (NetworkRequiresActivation(network)) { |
248 if (NetworkRequiresActivation(network)) { | 248 InvokeErrorCallback(service_path, error_callback, |
249 InvokeErrorCallback(service_path, error_callback, kErrorActivationRequired); | 249 kErrorActivationRequired); |
250 return; | 250 return; |
251 } | |
251 } | 252 } |
252 | 253 |
253 if (check_error_state) { | 254 if (check_error_state) { |
255 if (!network) { | |
pneubeck (no reviews)
2013/08/10 19:44:11
this looks a bit contradicting to the handling if
stevenjb
2013/08/12 17:48:29
Yeah, this just ends up being confusing, and reall
| |
256 InvokeErrorCallback(service_path, error_callback, kErrorNotFound); | |
257 return; | |
258 } | |
254 const std::string& error = network->error(); | 259 const std::string& error = network->error(); |
255 if (error == flimflam::kErrorConnectFailed) { | 260 if (error == flimflam::kErrorConnectFailed) { |
256 InvokeErrorCallback( | 261 InvokeErrorCallback( |
257 service_path, error_callback, kErrorPassphraseRequired); | 262 service_path, error_callback, kErrorPassphraseRequired); |
258 return; | 263 return; |
259 } | 264 } |
260 if (error == flimflam::kErrorBadPassphrase) { | 265 if (error == flimflam::kErrorBadPassphrase) { |
261 InvokeErrorCallback( | 266 InvokeErrorCallback( |
262 service_path, error_callback, kErrorPassphraseRequired); | 267 service_path, error_callback, kErrorPassphraseRequired); |
263 return; | 268 return; |
264 } | 269 } |
265 | |
266 if (IsAuthenticationError(error)) { | 270 if (IsAuthenticationError(error)) { |
267 InvokeErrorCallback( | 271 InvokeErrorCallback( |
268 service_path, error_callback, kErrorAuthenticationRequired); | 272 service_path, error_callback, kErrorAuthenticationRequired); |
269 return; | 273 return; |
270 } | 274 } |
271 } | 275 } |
272 | 276 |
273 // All synchronous checks passed, add |service_path| to connecting list. | 277 // All synchronous checks passed, add |service_path| to connecting list. |
274 pending_requests_.insert(std::make_pair( | 278 pending_requests_.insert(std::make_pair( |
275 service_path, | 279 service_path, |
276 ConnectRequest(service_path, success_callback, error_callback))); | 280 ConnectRequest(service_path, success_callback, error_callback))); |
277 | 281 |
278 // Connect immediately to 'connectable' networks. | 282 if (network) { |
279 // TODO(stevenjb): Shill needs to properly set Connectable for VPN. | 283 // Connect immediately to 'connectable' networks. |
280 if (network->connectable() && network->type() != flimflam::kTypeVPN) { | 284 // TODO(stevenjb): Shill needs to properly set Connectable for VPN. |
281 CallShillConnect(service_path); | 285 if (network->connectable() && network->type() != flimflam::kTypeVPN) { |
pneubeck (no reviews)
2013/08/10 19:44:11
For network==NULL, the connectable property will n
stevenjb
2013/08/12 17:48:29
Yes, I should add that there.
Done.
| |
282 return; | 286 CallShillConnect(service_path); |
283 } | 287 return; |
288 } | |
284 | 289 |
285 if (network->type() == flimflam::kTypeCellular || | 290 if (network->type() == flimflam::kTypeCellular || |
286 (network->type() == flimflam::kTypeWifi && | 291 (network->type() == flimflam::kTypeWifi && |
287 network->security() == flimflam::kSecurityNone)) { | 292 network->security() == flimflam::kSecurityNone)) { |
288 NET_LOG_ERROR("Network has no security but is not 'Connectable'", | 293 NET_LOG_ERROR("Network has no security but is not 'Connectable'", |
289 service_path); | 294 service_path); |
290 CallShillConnect(service_path); | 295 // Try to connect anyway. Failure may succeed anyway, or provide a |
pneubeck (no reviews)
2013/08/10 19:44:11
"Failure may succeed"
sounds wrong to me.
stevenjb
2013/08/12 17:48:29
Oops, bad edit.
Looking at the code, I actually r
| |
291 return; | 296 // helpful error from Shill. |
297 CallShillConnect(service_path); | |
298 return; | |
299 } | |
292 } | 300 } |
293 | 301 |
294 // Request additional properties to check. VerifyConfiguredAndConnect will | 302 // Request additional properties to check. VerifyConfiguredAndConnect will |
295 // use only these properties, not cached properties, to ensure that they | 303 // use only these properties, not cached properties, to ensure that they |
296 // are up to date after any recent configuration. | 304 // are up to date after any recent configuration. |
297 network_configuration_handler_->GetProperties( | 305 network_configuration_handler_->GetProperties( |
298 network->path(), | 306 service_path, |
299 base::Bind(&NetworkConnectionHandler::VerifyConfiguredAndConnect, | 307 base::Bind(&NetworkConnectionHandler::VerifyConfiguredAndConnect, |
300 AsWeakPtr(), check_error_state), | 308 AsWeakPtr(), check_error_state), |
301 base::Bind(&NetworkConnectionHandler::HandleConfigurationFailure, | 309 base::Bind(&NetworkConnectionHandler::HandleConfigurationFailure, |
302 AsWeakPtr(), service_path)); | 310 AsWeakPtr(), service_path)); |
303 } | 311 } |
304 | 312 |
305 void NetworkConnectionHandler::DisconnectNetwork( | 313 void NetworkConnectionHandler::DisconnectNetwork( |
306 const std::string& service_path, | 314 const std::string& service_path, |
307 const base::Closure& success_callback, | 315 const base::Closure& success_callback, |
308 const network_handler::ErrorCallback& error_callback) { | 316 const network_handler::ErrorCallback& error_callback) { |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
535 AsWeakPtr(), service_path), | 543 AsWeakPtr(), service_path), |
536 base::Bind(&NetworkConnectionHandler::HandleShillConnectFailure, | 544 base::Bind(&NetworkConnectionHandler::HandleShillConnectFailure, |
537 AsWeakPtr(), service_path)); | 545 AsWeakPtr(), service_path)); |
538 } | 546 } |
539 | 547 |
540 void NetworkConnectionHandler::HandleConfigurationFailure( | 548 void NetworkConnectionHandler::HandleConfigurationFailure( |
541 const std::string& service_path, | 549 const std::string& service_path, |
542 const std::string& error_name, | 550 const std::string& error_name, |
543 scoped_ptr<base::DictionaryValue> error_data) { | 551 scoped_ptr<base::DictionaryValue> error_data) { |
544 ConnectRequest* request = pending_request(service_path); | 552 ConnectRequest* request = pending_request(service_path); |
545 DCHECK(request); | 553 DCHECK(request); |
pneubeck (no reviews)
2013/08/10 19:44:11
considering the complexity of the overall logic an
stevenjb
2013/08/12 17:48:29
Hmm, definitely an edge case, but possible. Good c
| |
546 network_handler::ErrorCallback error_callback = request->error_callback; | 554 network_handler::ErrorCallback error_callback = request->error_callback; |
547 pending_requests_.erase(service_path); | 555 pending_requests_.erase(service_path); |
548 if (!error_callback.is_null()) | 556 if (!error_callback.is_null()) |
549 error_callback.Run(kErrorConfigureFailed, error_data.Pass()); | 557 error_callback.Run(kErrorConfigureFailed, error_data.Pass()); |
550 } | 558 } |
551 | 559 |
552 void NetworkConnectionHandler::HandleShillConnectSuccess( | 560 void NetworkConnectionHandler::HandleShillConnectSuccess( |
553 const std::string& service_path) { | 561 const std::string& service_path) { |
554 ConnectRequest* request = pending_request(service_path); | 562 ConnectRequest* request = pending_request(service_path); |
555 DCHECK(request); | 563 DCHECK(request); |
(...skipping 14 matching lines...) Expand all Loading... | |
570 DCHECK(request); | 578 DCHECK(request); |
571 network_handler::ErrorCallback error_callback = request->error_callback; | 579 network_handler::ErrorCallback error_callback = request->error_callback; |
572 pending_requests_.erase(service_path); | 580 pending_requests_.erase(service_path); |
573 network_handler::ShillErrorCallbackFunction( | 581 network_handler::ShillErrorCallbackFunction( |
574 kErrorConnectFailed, service_path, error_callback, | 582 kErrorConnectFailed, service_path, error_callback, |
575 dbus_error_name, dbus_error_message); | 583 dbus_error_name, dbus_error_message); |
576 } | 584 } |
577 | 585 |
578 void NetworkConnectionHandler::CheckPendingRequest( | 586 void NetworkConnectionHandler::CheckPendingRequest( |
579 const std::string service_path) { | 587 const std::string service_path) { |
580 ConnectRequest* request = pending_request(service_path); | 588 ConnectRequest* request = pending_request(service_path); |
pneubeck (no reviews)
2013/08/10 19:44:11
Every time I read "pending_request", I wonder what
stevenjb
2013/08/12 17:48:29
Done.
| |
581 DCHECK(request); | 589 DCHECK(request); |
582 if (request->connect_state == ConnectRequest::CONNECT_REQUESTED) | 590 if (request->connect_state == ConnectRequest::CONNECT_REQUESTED) |
583 return; // Request has not started, ignore update | 591 return; // Request has not started, ignore update |
584 const NetworkState* network = | 592 const NetworkState* network = |
585 network_state_handler_->GetNetworkState(service_path); | 593 network_state_handler_->GetNetworkState(service_path); |
586 if (!network) { | 594 if (!network) |
587 ErrorCallbackForPendingRequest(service_path, kErrorNotFound); | 595 return; // NetworkState may not be be updated yet. |
588 return; | 596 |
589 } | |
590 if (network->IsConnectingState()) { | 597 if (network->IsConnectingState()) { |
591 request->connect_state = ConnectRequest::CONNECT_CONNECTING; | 598 request->connect_state = ConnectRequest::CONNECT_CONNECTING; |
592 return; | 599 return; |
593 } | 600 } |
594 if (network->IsConnectedState()) { | 601 if (network->IsConnectedState()) { |
595 NET_LOG_EVENT("Connect Request Succeeded", service_path); | 602 NET_LOG_EVENT("Connect Request Succeeded", service_path); |
596 if (!request->success_callback.is_null()) | 603 if (!request->success_callback.is_null()) |
597 request->success_callback.Run(); | 604 request->success_callback.Run(); |
598 pending_requests_.erase(service_path); | 605 pending_requests_.erase(service_path); |
599 return; | 606 return; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
707 | 714 |
708 void NetworkConnectionHandler::HandleShillActivateSuccess( | 715 void NetworkConnectionHandler::HandleShillActivateSuccess( |
709 const std::string& service_path, | 716 const std::string& service_path, |
710 const base::Closure& success_callback) { | 717 const base::Closure& success_callback) { |
711 NET_LOG_EVENT("Activate Request Sent", service_path); | 718 NET_LOG_EVENT("Activate Request Sent", service_path); |
712 if (!success_callback.is_null()) | 719 if (!success_callback.is_null()) |
713 success_callback.Run(); | 720 success_callback.Run(); |
714 } | 721 } |
715 | 722 |
716 } // namespace chromeos | 723 } // namespace chromeos |
OLD | NEW |