Chromium Code Reviews| 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 111 "passphrase-required"; | 111 "passphrase-required"; |
| 112 const char NetworkConnectionHandler::kErrorActivationRequired[] = | 112 const char NetworkConnectionHandler::kErrorActivationRequired[] = |
| 113 "activation-required"; | 113 "activation-required"; |
| 114 const char NetworkConnectionHandler::kErrorCertificateRequired[] = | 114 const char NetworkConnectionHandler::kErrorCertificateRequired[] = |
| 115 "certificate-required"; | 115 "certificate-required"; |
| 116 const char NetworkConnectionHandler::kErrorConfigurationRequired[] = | 116 const char NetworkConnectionHandler::kErrorConfigurationRequired[] = |
| 117 "configuration-required"; | 117 "configuration-required"; |
| 118 const char NetworkConnectionHandler::kErrorAuthenticationRequired[] = | 118 const char NetworkConnectionHandler::kErrorAuthenticationRequired[] = |
| 119 "authentication-required"; | 119 "authentication-required"; |
| 120 const char NetworkConnectionHandler::kErrorShillError[] = "shill-error"; | 120 const char NetworkConnectionHandler::kErrorShillError[] = "shill-error"; |
| 121 const char NetworkConnectionHandler::kErrorConnectFailed[] = "connect-failed"; | |
| 122 const char NetworkConnectionHandler::kErrorConfigureFailed[] = | 121 const char NetworkConnectionHandler::kErrorConfigureFailed[] = |
| 123 "configure-failed"; | 122 "configure-failed"; |
| 124 const char NetworkConnectionHandler::kErrorActivateFailed[] = | |
| 125 "activate-failed"; | |
| 126 const char NetworkConnectionHandler::kErrorMissingProvider[] = | |
| 127 "missing-provider"; | |
| 128 const char NetworkConnectionHandler::kErrorConnectCanceled[] = | 123 const char NetworkConnectionHandler::kErrorConnectCanceled[] = |
| 129 "connect-canceled"; | 124 "connect-canceled"; |
| 130 const char NetworkConnectionHandler::kErrorUnknown[] = "unknown-error"; | |
| 131 | 125 |
| 132 struct NetworkConnectionHandler::ConnectRequest { | 126 struct NetworkConnectionHandler::ConnectRequest { |
| 133 ConnectRequest(const std::string& service_path, | 127 ConnectRequest(const std::string& service_path, |
| 134 const base::Closure& success, | 128 const base::Closure& success, |
| 135 const network_handler::ErrorCallback& error) | 129 const network_handler::ErrorCallback& error) |
| 136 : service_path(service_path), | 130 : service_path(service_path), |
| 137 connect_state(CONNECT_REQUESTED), | 131 connect_state(CONNECT_REQUESTED), |
| 138 success_callback(success), | 132 success_callback(success), |
| 139 error_callback(error) { | 133 error_callback(error) { |
| 140 } | 134 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 return; | 241 return; |
| 248 } | 242 } |
| 249 if (NetworkRequiresActivation(network)) { | 243 if (NetworkRequiresActivation(network)) { |
| 250 InvokeErrorCallback(service_path, error_callback, | 244 InvokeErrorCallback(service_path, error_callback, |
| 251 kErrorActivationRequired); | 245 kErrorActivationRequired); |
| 252 return; | 246 return; |
| 253 } | 247 } |
| 254 | 248 |
| 255 if (check_error_state) { | 249 if (check_error_state) { |
| 256 const std::string& error = network->error(); | 250 const std::string& error = network->error(); |
| 257 if (error == flimflam::kErrorConnectFailed) { | |
|
pneubeck (no reviews)
2013/08/26 08:14:11
for non-VPN this looks fine, as it's handled later
stevenjb
2013/08/27 15:52:08
The purpose of this code was to try to guess the u
pneubeck (no reviews)
2013/08/28 10:02:35
My bad.. I should have placed this comment to the
| |
| 258 InvokeErrorCallback( | |
| 259 service_path, error_callback, kErrorPassphraseRequired); | |
| 260 return; | |
| 261 } | |
| 262 if (error == flimflam::kErrorBadPassphrase) { | 251 if (error == flimflam::kErrorBadPassphrase) { |
| 263 InvokeErrorCallback( | 252 InvokeErrorCallback(service_path, error_callback, error); |
| 264 service_path, error_callback, kErrorPassphraseRequired); | |
| 265 return; | 253 return; |
| 266 } | 254 } |
| 267 if (IsAuthenticationError(error)) { | 255 if (IsAuthenticationError(error)) { |
| 268 InvokeErrorCallback( | 256 InvokeErrorCallback( |
| 269 service_path, error_callback, kErrorAuthenticationRequired); | 257 service_path, error_callback, kErrorAuthenticationRequired); |
| 270 return; | 258 return; |
| 271 } | 259 } |
| 272 } | 260 } |
| 273 } | 261 } |
| 274 | 262 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 // "Provider.Type", etc keys (which are used only to set the values). | 386 // "Provider.Type", etc keys (which are used only to set the values). |
| 399 const base::DictionaryValue* provider_properties; | 387 const base::DictionaryValue* provider_properties; |
| 400 if (service_properties.GetDictionaryWithoutPathExpansion( | 388 if (service_properties.GetDictionaryWithoutPathExpansion( |
| 401 flimflam::kProviderProperty, &provider_properties)) { | 389 flimflam::kProviderProperty, &provider_properties)) { |
| 402 provider_properties->GetStringWithoutPathExpansion( | 390 provider_properties->GetStringWithoutPathExpansion( |
| 403 flimflam::kTypeProperty, &vpn_provider_type); | 391 flimflam::kTypeProperty, &vpn_provider_type); |
| 404 provider_properties->GetStringWithoutPathExpansion( | 392 provider_properties->GetStringWithoutPathExpansion( |
| 405 flimflam::kHostProperty, &vpn_provider_host); | 393 flimflam::kHostProperty, &vpn_provider_host); |
| 406 } | 394 } |
| 407 if (vpn_provider_type.empty() || vpn_provider_host.empty()) { | 395 if (vpn_provider_type.empty() || vpn_provider_host.empty()) { |
| 408 ErrorCallbackForPendingRequest(service_path, kErrorMissingProvider); | 396 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); |
| 409 return; | 397 return; |
| 410 } | 398 } |
| 411 // VPN requires a host and username to be set. | 399 // VPN requires a host and username to be set. |
| 412 if (!VPNIsConfigured( | 400 if (!VPNIsConfigured( |
| 413 service_path, vpn_provider_type, *provider_properties)) { | 401 service_path, vpn_provider_type, *provider_properties)) { |
| 414 NET_LOG_ERROR("VPN Not Configured", service_path); | 402 NET_LOG_ERROR("VPN Not Configured", service_path); |
| 415 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); | 403 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); |
| 416 return; | 404 return; |
| 417 } | 405 } |
| 418 } | 406 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 466 ErrorCallbackForPendingRequest(service_path, kErrorCertificateRequired); | 454 ErrorCallbackForPendingRequest(service_path, kErrorCertificateRequired); |
| 467 return; | 455 return; |
| 468 } | 456 } |
| 469 } | 457 } |
| 470 | 458 |
| 471 // The network may not be 'Connectable' because the TPM properties are not | 459 // The network may not be 'Connectable' because the TPM properties are not |
| 472 // set up, so configure tpm slot/pin before connecting. | 460 // set up, so configure tpm slot/pin before connecting. |
| 473 if (cert_loader_ && cert_loader_->IsHardwareBacked()) { | 461 if (cert_loader_ && cert_loader_->IsHardwareBacked()) { |
| 474 // Pass NULL if pkcs11_id is empty, so that it doesn't clear any | 462 // Pass NULL if pkcs11_id is empty, so that it doesn't clear any |
| 475 // previously configured client cert. | 463 // previously configured client cert. |
| 476 client_cert::SetShillProperties(client_cert_type, | 464 client_cert::SetShillProperties(client_cert_type, |
|
pneubeck (no reviews)
2013/08/26 08:14:11
For VPN with certs, we will always reach this poin
| |
| 477 cert_loader_->tpm_token_slot(), | 465 cert_loader_->tpm_token_slot(), |
| 478 cert_loader_->tpm_user_pin(), | 466 cert_loader_->tpm_user_pin(), |
| 479 pkcs11_id.empty() ? NULL : &pkcs11_id, | 467 pkcs11_id.empty() ? NULL : &pkcs11_id, |
| 480 &config_properties); | 468 &config_properties); |
| 481 } | 469 } |
| 482 } | 470 } |
| 483 | 471 |
| 484 if (!config_properties.empty()) { | 472 if (!config_properties.empty()) { |
| 485 NET_LOG_EVENT("Configuring Network", service_path); | 473 NET_LOG_EVENT("Configuring Network", service_path); |
| 486 | 474 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 501 flimflam::kSecurityProperty, security); | 489 flimflam::kSecurityProperty, security); |
| 502 } | 490 } |
| 503 | 491 |
| 504 network_configuration_handler_->SetProperties( | 492 network_configuration_handler_->SetProperties( |
| 505 service_path, | 493 service_path, |
| 506 config_properties, | 494 config_properties, |
| 507 base::Bind(&NetworkConnectionHandler::CallShillConnect, | 495 base::Bind(&NetworkConnectionHandler::CallShillConnect, |
| 508 AsWeakPtr(), service_path), | 496 AsWeakPtr(), service_path), |
| 509 base::Bind(&NetworkConnectionHandler::HandleConfigurationFailure, | 497 base::Bind(&NetworkConnectionHandler::HandleConfigurationFailure, |
| 510 AsWeakPtr(), service_path)); | 498 AsWeakPtr(), service_path)); |
| 511 return; | 499 return; |
|
pneubeck (no reviews)
2013/08/26 08:14:11
...and then call CallShillConnect/return here.
In
stevenjb
2013/08/27 15:52:08
I'm not sure that we can rely on 'connect-failed'
pneubeck (no reviews)
2013/08/28 10:02:35
Still, it doesn't look right to change control flo
| |
| 512 } | 500 } |
| 513 | 501 |
| 514 // Otherwise, we probably still need to configure the network since | 502 // Otherwise, we probably still need to configure the network since |
| 515 // 'Connectable' is false. If |check_error_state| is true, signal an | 503 // 'Connectable' is false. If |check_error_state| is true, signal an |
| 516 // error, otherwise attempt to connect to possibly gain additional error | 504 // error, otherwise attempt to connect to possibly gain additional error |
| 517 // state from Shill (or in case 'Connectable' is improperly unset). | 505 // state from Shill (or in case 'Connectable' is improperly unset). |
| 518 if (check_error_state) | 506 if (check_error_state) |
| 519 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); | 507 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); |
| 520 else | 508 else |
| 521 CallShillConnect(service_path); | 509 CallShillConnect(service_path); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 571 const std::string& dbus_error_message) { | 559 const std::string& dbus_error_message) { |
| 572 ConnectRequest* request = GetPendingRequest(service_path); | 560 ConnectRequest* request = GetPendingRequest(service_path); |
| 573 if (!request) { | 561 if (!request) { |
| 574 NET_LOG_ERROR("HandleShillConnectFailure called with no pending request.", | 562 NET_LOG_ERROR("HandleShillConnectFailure called with no pending request.", |
| 575 service_path); | 563 service_path); |
| 576 return; | 564 return; |
| 577 } | 565 } |
| 578 network_handler::ErrorCallback error_callback = request->error_callback; | 566 network_handler::ErrorCallback error_callback = request->error_callback; |
| 579 pending_requests_.erase(service_path); | 567 pending_requests_.erase(service_path); |
| 580 network_handler::ShillErrorCallbackFunction( | 568 network_handler::ShillErrorCallbackFunction( |
| 581 kErrorConnectFailed, service_path, error_callback, | 569 flimflam::kErrorConnectFailed, service_path, error_callback, |
| 582 dbus_error_name, dbus_error_message); | 570 dbus_error_name, dbus_error_message); |
| 583 } | 571 } |
| 584 | 572 |
| 585 void NetworkConnectionHandler::CheckPendingRequest( | 573 void NetworkConnectionHandler::CheckPendingRequest( |
| 586 const std::string service_path) { | 574 const std::string service_path) { |
| 587 ConnectRequest* request = GetPendingRequest(service_path); | 575 ConnectRequest* request = GetPendingRequest(service_path); |
| 588 DCHECK(request); | 576 DCHECK(request); |
| 589 if (request->connect_state == ConnectRequest::CONNECT_REQUESTED) | 577 if (request->connect_state == ConnectRequest::CONNECT_REQUESTED) |
| 590 return; // Request has not started, ignore update | 578 return; // Request has not started, ignore update |
| 591 const NetworkState* network = | 579 const NetworkState* network = |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 611 } | 599 } |
| 612 | 600 |
| 613 // Network is neither connecting or connected; an error occurred. | 601 // Network is neither connecting or connected; an error occurred. |
| 614 std::string error_name, error_detail; | 602 std::string error_name, error_detail; |
| 615 if (network->connection_state() == flimflam::kStateIdle && | 603 if (network->connection_state() == flimflam::kStateIdle && |
| 616 pending_requests_.size() > 1) { | 604 pending_requests_.size() > 1) { |
| 617 // Another connect request canceled this one. | 605 // Another connect request canceled this one. |
| 618 error_name = kErrorConnectCanceled; | 606 error_name = kErrorConnectCanceled; |
| 619 error_detail = ""; | 607 error_detail = ""; |
| 620 } else { | 608 } else { |
| 621 error_name = kErrorConnectFailed; | 609 error_name = flimflam::kErrorConnectFailed; |
| 622 error_detail = network->error(); | 610 error_detail = network->error(); |
| 623 if (error_detail.empty()) { | 611 if (error_detail.empty()) { |
| 624 if (network->connection_state() == flimflam::kStateFailure) | 612 if (network->connection_state() == flimflam::kStateFailure) |
| 625 error_detail = flimflam::kUnknownString; | 613 error_detail = flimflam::kUnknownString; |
| 626 else | 614 else |
| 627 error_detail = "Unexpected State: " + network->connection_state(); | 615 error_detail = "Unexpected State: " + network->connection_state(); |
| 628 } | 616 } |
| 629 } | 617 } |
| 630 std::string error_msg = error_name + ": " + error_detail; | 618 std::string error_msg = error_name + ": " + error_detail; |
| 631 NET_LOG_ERROR(error_msg, service_path); | 619 NET_LOG_ERROR(error_msg, service_path); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 715 | 703 |
| 716 void NetworkConnectionHandler::HandleShillActivateSuccess( | 704 void NetworkConnectionHandler::HandleShillActivateSuccess( |
| 717 const std::string& service_path, | 705 const std::string& service_path, |
| 718 const base::Closure& success_callback) { | 706 const base::Closure& success_callback) { |
| 719 NET_LOG_EVENT("Activate Request Sent", service_path); | 707 NET_LOG_EVENT("Activate Request Sent", service_path); |
| 720 if (!success_callback.is_null()) | 708 if (!success_callback.is_null()) |
| 721 success_callback.Run(); | 709 success_callback.Run(); |
| 722 } | 710 } |
| 723 | 711 |
| 724 } // namespace chromeos | 712 } // namespace chromeos |
| OLD | NEW |