| 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 // Note: NetworkState may not exist for a network that was recently |
| 235 // configured, in which case these checks do not apply anyway. |
| 234 const NetworkState* network = | 236 const NetworkState* network = |
| 235 network_state_handler_->GetNetworkState(service_path); | 237 network_state_handler_->GetNetworkState(service_path); |
| 236 if (!network) { | |
| 237 InvokeErrorCallback(service_path, error_callback, kErrorNotFound); | |
| 238 return; | |
| 239 } | |
| 240 if (network->IsConnectedState()) { | |
| 241 InvokeErrorCallback(service_path, error_callback, kErrorConnected); | |
| 242 return; | |
| 243 } | |
| 244 if (network->IsConnectingState()) { | |
| 245 InvokeErrorCallback(service_path, error_callback, kErrorConnecting); | |
| 246 return; | |
| 247 } | |
| 248 if (NetworkRequiresActivation(network)) { | |
| 249 InvokeErrorCallback(service_path, error_callback, kErrorActivationRequired); | |
| 250 return; | |
| 251 } | |
| 252 | 238 |
| 253 if (check_error_state) { | 239 if (network) { |
| 254 const std::string& error = network->error(); | 240 // For existing networks, perform some immediate consistency checks. |
| 255 if (error == flimflam::kErrorConnectFailed) { | 241 if (network->IsConnectedState()) { |
| 256 InvokeErrorCallback( | 242 InvokeErrorCallback(service_path, error_callback, kErrorConnected); |
| 257 service_path, error_callback, kErrorPassphraseRequired); | |
| 258 return; | 243 return; |
| 259 } | 244 } |
| 260 if (error == flimflam::kErrorBadPassphrase) { | 245 if (network->IsConnectingState()) { |
| 261 InvokeErrorCallback( | 246 InvokeErrorCallback(service_path, error_callback, kErrorConnecting); |
| 262 service_path, error_callback, kErrorPassphraseRequired); | 247 return; |
| 248 } |
| 249 if (NetworkRequiresActivation(network)) { |
| 250 InvokeErrorCallback(service_path, error_callback, |
| 251 kErrorActivationRequired); |
| 263 return; | 252 return; |
| 264 } | 253 } |
| 265 | 254 |
| 266 if (IsAuthenticationError(error)) { | 255 if (check_error_state) { |
| 267 InvokeErrorCallback( | 256 const std::string& error = network->error(); |
| 268 service_path, error_callback, kErrorAuthenticationRequired); | 257 if (error == flimflam::kErrorConnectFailed) { |
| 269 return; | 258 InvokeErrorCallback( |
| 259 service_path, error_callback, kErrorPassphraseRequired); |
| 260 return; |
| 261 } |
| 262 if (error == flimflam::kErrorBadPassphrase) { |
| 263 InvokeErrorCallback( |
| 264 service_path, error_callback, kErrorPassphraseRequired); |
| 265 return; |
| 266 } |
| 267 if (IsAuthenticationError(error)) { |
| 268 InvokeErrorCallback( |
| 269 service_path, error_callback, kErrorAuthenticationRequired); |
| 270 return; |
| 271 } |
| 270 } | 272 } |
| 271 } | 273 } |
| 272 | 274 |
| 273 // All synchronous checks passed, add |service_path| to connecting list. | 275 // All synchronous checks passed, add |service_path| to connecting list. |
| 274 pending_requests_.insert(std::make_pair( | 276 pending_requests_.insert(std::make_pair( |
| 275 service_path, | 277 service_path, |
| 276 ConnectRequest(service_path, success_callback, error_callback))); | 278 ConnectRequest(service_path, success_callback, error_callback))); |
| 277 | 279 |
| 278 // Connect immediately to 'connectable' networks. | 280 // Connect immediately to 'connectable' networks. |
| 279 // TODO(stevenjb): Shill needs to properly set Connectable for VPN. | 281 // TODO(stevenjb): Shill needs to properly set Connectable for VPN. |
| 280 if (network->connectable() && network->type() != flimflam::kTypeVPN) { | 282 if (network && |
| 283 network->connectable() && network->type() != flimflam::kTypeVPN) { |
| 281 CallShillConnect(service_path); | 284 CallShillConnect(service_path); |
| 282 return; | 285 return; |
| 283 } | 286 } |
| 284 | |
| 285 if (network->type() == flimflam::kTypeCellular || | |
| 286 (network->type() == flimflam::kTypeWifi && | |
| 287 network->security() == flimflam::kSecurityNone)) { | |
| 288 NET_LOG_ERROR("Network has no security but is not 'Connectable'", | |
| 289 service_path); | |
| 290 CallShillConnect(service_path); | |
| 291 return; | |
| 292 } | |
| 293 | 287 |
| 294 // Request additional properties to check. VerifyConfiguredAndConnect will | 288 // Request additional properties to check. VerifyConfiguredAndConnect will |
| 295 // use only these properties, not cached properties, to ensure that they | 289 // use only these properties, not cached properties, to ensure that they |
| 296 // are up to date after any recent configuration. | 290 // are up to date after any recent configuration. |
| 297 network_configuration_handler_->GetProperties( | 291 network_configuration_handler_->GetProperties( |
| 298 network->path(), | 292 service_path, |
| 299 base::Bind(&NetworkConnectionHandler::VerifyConfiguredAndConnect, | 293 base::Bind(&NetworkConnectionHandler::VerifyConfiguredAndConnect, |
| 300 AsWeakPtr(), check_error_state), | 294 AsWeakPtr(), check_error_state), |
| 301 base::Bind(&NetworkConnectionHandler::HandleConfigurationFailure, | 295 base::Bind(&NetworkConnectionHandler::HandleConfigurationFailure, |
| 302 AsWeakPtr(), service_path)); | 296 AsWeakPtr(), service_path)); |
| 303 } | 297 } |
| 304 | 298 |
| 305 void NetworkConnectionHandler::DisconnectNetwork( | 299 void NetworkConnectionHandler::DisconnectNetwork( |
| 306 const std::string& service_path, | 300 const std::string& service_path, |
| 307 const base::Closure& success_callback, | 301 const base::Closure& success_callback, |
| 308 const network_handler::ErrorCallback& error_callback) { | 302 const network_handler::ErrorCallback& error_callback) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 CheckAllPendingRequests(); | 338 CheckAllPendingRequests(); |
| 345 } | 339 } |
| 346 | 340 |
| 347 void NetworkConnectionHandler::NetworkPropertiesUpdated( | 341 void NetworkConnectionHandler::NetworkPropertiesUpdated( |
| 348 const NetworkState* network) { | 342 const NetworkState* network) { |
| 349 if (HasConnectingNetwork(network->path())) | 343 if (HasConnectingNetwork(network->path())) |
| 350 CheckPendingRequest(network->path()); | 344 CheckPendingRequest(network->path()); |
| 351 } | 345 } |
| 352 | 346 |
| 353 NetworkConnectionHandler::ConnectRequest* | 347 NetworkConnectionHandler::ConnectRequest* |
| 354 NetworkConnectionHandler::pending_request( | 348 NetworkConnectionHandler::GetPendingRequest(const std::string& service_path) { |
| 355 const std::string& service_path) { | |
| 356 std::map<std::string, ConnectRequest>::iterator iter = | 349 std::map<std::string, ConnectRequest>::iterator iter = |
| 357 pending_requests_.find(service_path); | 350 pending_requests_.find(service_path); |
| 358 return iter != pending_requests_.end() ? &(iter->second) : NULL; | 351 return iter != pending_requests_.end() ? &(iter->second) : NULL; |
| 359 } | 352 } |
| 360 | 353 |
| 361 // ConnectToNetwork implementation | 354 // ConnectToNetwork implementation |
| 362 | 355 |
| 363 void NetworkConnectionHandler::VerifyConfiguredAndConnect( | 356 void NetworkConnectionHandler::VerifyConfiguredAndConnect( |
| 364 bool check_error_state, | 357 bool check_error_state, |
| 365 const std::string& service_path, | 358 const std::string& service_path, |
| 366 const base::DictionaryValue& service_properties) { | 359 const base::DictionaryValue& service_properties) { |
| 367 NET_LOG_EVENT("VerifyConfiguredAndConnect", service_path); | 360 NET_LOG_EVENT("VerifyConfiguredAndConnect", service_path); |
| 368 | 361 |
| 369 // If 'passphrase_required' is still true, then the 'Passphrase' property | 362 // If 'passphrase_required' is still true, then the 'Passphrase' property |
| 370 // has not been set to a minimum length value. | 363 // has not been set to a minimum length value. |
| 371 bool passphrase_required = false; | 364 bool passphrase_required = false; |
| 372 service_properties.GetBooleanWithoutPathExpansion( | 365 service_properties.GetBooleanWithoutPathExpansion( |
| 373 flimflam::kPassphraseRequiredProperty, &passphrase_required); | 366 flimflam::kPassphraseRequiredProperty, &passphrase_required); |
| 374 if (passphrase_required) { | 367 if (passphrase_required) { |
| 375 ErrorCallbackForPendingRequest(service_path, kErrorPassphraseRequired); | 368 ErrorCallbackForPendingRequest(service_path, kErrorPassphraseRequired); |
| 376 return; | 369 return; |
| 377 } | 370 } |
| 378 | 371 |
| 379 std::string type; | 372 std::string type, security; |
| 380 service_properties.GetStringWithoutPathExpansion( | 373 service_properties.GetStringWithoutPathExpansion( |
| 381 flimflam::kTypeProperty, &type); | 374 flimflam::kTypeProperty, &type); |
| 375 service_properties.GetStringWithoutPathExpansion( |
| 376 flimflam::kSecurityProperty, &security); |
| 377 bool connectable = false; |
| 378 service_properties.GetBooleanWithoutPathExpansion( |
| 379 flimflam::kConnectableProperty, &connectable); |
| 380 |
| 381 // In case NetworkState was not available in ConnectToNetwork (e.g. it had |
| 382 // been recently configured), we need to check Connectable again. |
| 383 if (connectable && type != flimflam::kTypeVPN) { |
| 384 // TODO(stevenjb): Shill needs to properly set Connectable for VPN. |
| 385 CallShillConnect(service_path); |
| 386 return; |
| 387 } |
| 382 | 388 |
| 383 // Get VPN provider type and host (required for configuration) and ensure | 389 // Get VPN provider type and host (required for configuration) and ensure |
| 384 // that required VPN non-cert properties are set. | 390 // that required VPN non-cert properties are set. |
| 385 std::string vpn_provider_type, vpn_provider_host; | 391 std::string vpn_provider_type, vpn_provider_host; |
| 386 if (type == flimflam::kTypeVPN) { | 392 if (type == flimflam::kTypeVPN) { |
| 387 // VPN Provider values are read from the "Provider" dictionary, not the | 393 // VPN Provider values are read from the "Provider" dictionary, not the |
| 388 // "Provider.Type", etc keys (which are used only to set the values). | 394 // "Provider.Type", etc keys (which are used only to set the values). |
| 389 const base::DictionaryValue* provider_properties; | 395 const base::DictionaryValue* provider_properties; |
| 390 if (service_properties.GetDictionaryWithoutPathExpansion( | 396 if (service_properties.GetDictionaryWithoutPathExpansion( |
| 391 flimflam::kProviderProperty, &provider_properties)) { | 397 flimflam::kProviderProperty, &provider_properties)) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 402 if (!VPNIsConfigured( | 408 if (!VPNIsConfigured( |
| 403 service_path, vpn_provider_type, *provider_properties)) { | 409 service_path, vpn_provider_type, *provider_properties)) { |
| 404 NET_LOG_ERROR("VPN Not Configured", service_path); | 410 NET_LOG_ERROR("VPN Not Configured", service_path); |
| 405 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); | 411 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); |
| 406 return; | 412 return; |
| 407 } | 413 } |
| 408 } | 414 } |
| 409 | 415 |
| 410 client_cert::ConfigType client_cert_type = client_cert::CONFIG_TYPE_NONE; | 416 client_cert::ConfigType client_cert_type = client_cert::CONFIG_TYPE_NONE; |
| 411 if (type == flimflam::kTypeVPN) { | 417 if (type == flimflam::kTypeVPN) { |
| 412 if (vpn_provider_type == flimflam::kProviderOpenVpn) | 418 if (vpn_provider_type == flimflam::kProviderOpenVpn) |
| 413 client_cert_type = client_cert::CONFIG_TYPE_OPENVPN; | 419 client_cert_type = client_cert::CONFIG_TYPE_OPENVPN; |
| 414 else | 420 else |
| 415 client_cert_type = client_cert::CONFIG_TYPE_IPSEC; | 421 client_cert_type = client_cert::CONFIG_TYPE_IPSEC; |
| 416 } else if (type == flimflam::kTypeWifi) { | 422 } else if (type == flimflam::kTypeWifi && |
| 423 security == flimflam::kSecurity8021x) { |
| 417 client_cert_type = client_cert::CONFIG_TYPE_EAP; | 424 client_cert_type = client_cert::CONFIG_TYPE_EAP; |
| 418 } | 425 } |
| 419 | 426 |
| 420 base::DictionaryValue config_properties; | 427 base::DictionaryValue config_properties; |
| 421 if (client_cert_type != client_cert::CONFIG_TYPE_NONE) { | 428 if (client_cert_type != client_cert::CONFIG_TYPE_NONE) { |
| 422 // If the client certificate must be configured, this will be set to a | 429 // If the client certificate must be configured, this will be set to a |
| 423 // non-empty string. | 430 // non-empty string. |
| 424 std::string pkcs11_id; | 431 std::string pkcs11_id; |
| 425 | 432 |
| 426 // Check certificate properties in kUIDataProperty if configured. | 433 // Check certificate properties in kUIDataProperty if configured. |
| 427 // Note: Wifi/VPNConfigView set these properties explicitly, in which case | 434 // Note: Wifi/VPNConfigView set these properties explicitly, in which case |
| 428 // only the TPM must be configured. | 435 // only the TPM must be configured. |
| 429 scoped_ptr<NetworkUIData> ui_data = | 436 scoped_ptr<NetworkUIData> ui_data = |
| 430 ManagedNetworkConfigurationHandler::GetUIData(service_properties); | 437 ManagedNetworkConfigurationHandler::GetUIData(service_properties); |
| 431 if (ui_data && ui_data->certificate_type() == CLIENT_CERT_TYPE_PATTERN) { | 438 if (ui_data && ui_data->certificate_type() == CLIENT_CERT_TYPE_PATTERN) { |
| 432 // User must be logged in to connect to a network requiring a certificate. | 439 // User must be logged in to connect to a network requiring a certificate. |
| 433 if (!logged_in_ || !cert_loader_) { | 440 if (!logged_in_ || !cert_loader_) { |
| 434 ErrorCallbackForPendingRequest(service_path, kErrorCertificateRequired); | 441 ErrorCallbackForPendingRequest(service_path, kErrorCertificateRequired); |
| 435 return; | 442 return; |
| 436 } | 443 } |
| 437 | 444 |
| 438 // If certificates have not been loaded yet, queue the connect request. | 445 // If certificates have not been loaded yet, queue the connect request. |
| 439 if (!certificates_loaded_) { | 446 if (!certificates_loaded_) { |
| 440 ConnectRequest* request = pending_request(service_path); | 447 ConnectRequest* request = GetPendingRequest(service_path); |
| 441 DCHECK(request); | 448 if (!request) { |
| 449 NET_LOG_ERROR("No pending request to queue", service_path); |
| 450 return; |
| 451 } |
| 442 NET_LOG_EVENT("Connect Request Queued", service_path); | 452 NET_LOG_EVENT("Connect Request Queued", service_path); |
| 443 queued_connect_.reset(new ConnectRequest( | 453 queued_connect_.reset(new ConnectRequest( |
| 444 service_path, request->success_callback, request->error_callback)); | 454 service_path, request->success_callback, request->error_callback)); |
| 445 pending_requests_.erase(service_path); | 455 pending_requests_.erase(service_path); |
| 446 return; | 456 return; |
| 447 } | 457 } |
| 448 | 458 |
| 449 pkcs11_id = CertificateIsConfigured(ui_data.get()); | 459 pkcs11_id = CertificateIsConfigured(ui_data.get()); |
| 450 // Ensure the certificate is available and configured. | 460 // Ensure the certificate is available and configured. |
| 451 if (!cert_loader_->IsHardwareBacked() || pkcs11_id.empty()) { | 461 if (!cert_loader_->IsHardwareBacked() || pkcs11_id.empty()) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 476 CopyStringFromDictionary(service_properties, flimflam::kNameProperty, | 486 CopyStringFromDictionary(service_properties, flimflam::kNameProperty, |
| 477 &config_properties); | 487 &config_properties); |
| 478 CopyStringFromDictionary(service_properties, flimflam::kGuidProperty, | 488 CopyStringFromDictionary(service_properties, flimflam::kGuidProperty, |
| 479 &config_properties); | 489 &config_properties); |
| 480 if (type == flimflam::kTypeVPN) { | 490 if (type == flimflam::kTypeVPN) { |
| 481 config_properties.SetStringWithoutPathExpansion( | 491 config_properties.SetStringWithoutPathExpansion( |
| 482 flimflam::kProviderTypeProperty, vpn_provider_type); | 492 flimflam::kProviderTypeProperty, vpn_provider_type); |
| 483 config_properties.SetStringWithoutPathExpansion( | 493 config_properties.SetStringWithoutPathExpansion( |
| 484 flimflam::kProviderHostProperty, vpn_provider_host); | 494 flimflam::kProviderHostProperty, vpn_provider_host); |
| 485 } else if (type == flimflam::kTypeWifi) { | 495 } else if (type == flimflam::kTypeWifi) { |
| 486 CopyStringFromDictionary(service_properties, flimflam::kSecurityProperty, | 496 config_properties.SetStringWithoutPathExpansion( |
| 487 &config_properties); | 497 flimflam::kSecurityProperty, security); |
| 488 } | 498 } |
| 489 | 499 |
| 490 network_configuration_handler_->SetProperties( | 500 network_configuration_handler_->SetProperties( |
| 491 service_path, | 501 service_path, |
| 492 config_properties, | 502 config_properties, |
| 493 base::Bind(&NetworkConnectionHandler::CallShillConnect, | 503 base::Bind(&NetworkConnectionHandler::CallShillConnect, |
| 494 AsWeakPtr(), service_path), | 504 AsWeakPtr(), service_path), |
| 495 base::Bind(&NetworkConnectionHandler::HandleConfigurationFailure, | 505 base::Bind(&NetworkConnectionHandler::HandleConfigurationFailure, |
| 496 AsWeakPtr(), service_path)); | 506 AsWeakPtr(), service_path)); |
| 497 return; | 507 return; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 515 base::Bind(&NetworkConnectionHandler::HandleShillConnectSuccess, | 525 base::Bind(&NetworkConnectionHandler::HandleShillConnectSuccess, |
| 516 AsWeakPtr(), service_path), | 526 AsWeakPtr(), service_path), |
| 517 base::Bind(&NetworkConnectionHandler::HandleShillConnectFailure, | 527 base::Bind(&NetworkConnectionHandler::HandleShillConnectFailure, |
| 518 AsWeakPtr(), service_path)); | 528 AsWeakPtr(), service_path)); |
| 519 } | 529 } |
| 520 | 530 |
| 521 void NetworkConnectionHandler::HandleConfigurationFailure( | 531 void NetworkConnectionHandler::HandleConfigurationFailure( |
| 522 const std::string& service_path, | 532 const std::string& service_path, |
| 523 const std::string& error_name, | 533 const std::string& error_name, |
| 524 scoped_ptr<base::DictionaryValue> error_data) { | 534 scoped_ptr<base::DictionaryValue> error_data) { |
| 525 ConnectRequest* request = pending_request(service_path); | 535 ConnectRequest* request = GetPendingRequest(service_path); |
| 526 DCHECK(request); | 536 if (!request) { |
| 537 NET_LOG_ERROR("HandleConfigurationFailure called with no pending request.", |
| 538 service_path); |
| 539 return; |
| 540 } |
| 527 network_handler::ErrorCallback error_callback = request->error_callback; | 541 network_handler::ErrorCallback error_callback = request->error_callback; |
| 528 pending_requests_.erase(service_path); | 542 pending_requests_.erase(service_path); |
| 529 if (!error_callback.is_null()) | 543 if (!error_callback.is_null()) |
| 530 error_callback.Run(kErrorConfigureFailed, error_data.Pass()); | 544 error_callback.Run(kErrorConfigureFailed, error_data.Pass()); |
| 531 } | 545 } |
| 532 | 546 |
| 533 void NetworkConnectionHandler::HandleShillConnectSuccess( | 547 void NetworkConnectionHandler::HandleShillConnectSuccess( |
| 534 const std::string& service_path) { | 548 const std::string& service_path) { |
| 535 ConnectRequest* request = pending_request(service_path); | 549 ConnectRequest* request = GetPendingRequest(service_path); |
| 536 DCHECK(request); | 550 if (!request) { |
| 551 NET_LOG_ERROR("HandleShillConnectSuccess called with no pending request.", |
| 552 service_path); |
| 553 return; |
| 554 } |
| 537 request->connect_state = ConnectRequest::CONNECT_STARTED; | 555 request->connect_state = ConnectRequest::CONNECT_STARTED; |
| 538 NET_LOG_EVENT("Connect Request Acknowledged", service_path); | 556 NET_LOG_EVENT("Connect Request Acknowledged", service_path); |
| 539 // Do not call success_callback here, wait for one of the following | 557 // Do not call success_callback here, wait for one of the following |
| 540 // conditions: | 558 // conditions: |
| 541 // * State transitions to a non connecting state indicating succes or failure | 559 // * State transitions to a non connecting state indicating succes or failure |
| 542 // * Network is no longer in the visible list, indicating failure | 560 // * Network is no longer in the visible list, indicating failure |
| 543 CheckPendingRequest(service_path); | 561 CheckPendingRequest(service_path); |
| 544 } | 562 } |
| 545 | 563 |
| 546 void NetworkConnectionHandler::HandleShillConnectFailure( | 564 void NetworkConnectionHandler::HandleShillConnectFailure( |
| 547 const std::string& service_path, | 565 const std::string& service_path, |
| 548 const std::string& dbus_error_name, | 566 const std::string& dbus_error_name, |
| 549 const std::string& dbus_error_message) { | 567 const std::string& dbus_error_message) { |
| 550 ConnectRequest* request = pending_request(service_path); | 568 ConnectRequest* request = GetPendingRequest(service_path); |
| 551 DCHECK(request); | 569 if (!request) { |
| 570 NET_LOG_ERROR("HandleShillConnectFailure called with no pending request.", |
| 571 service_path); |
| 572 return; |
| 573 } |
| 552 network_handler::ErrorCallback error_callback = request->error_callback; | 574 network_handler::ErrorCallback error_callback = request->error_callback; |
| 553 pending_requests_.erase(service_path); | 575 pending_requests_.erase(service_path); |
| 554 network_handler::ShillErrorCallbackFunction( | 576 network_handler::ShillErrorCallbackFunction( |
| 555 kErrorConnectFailed, service_path, error_callback, | 577 kErrorConnectFailed, service_path, error_callback, |
| 556 dbus_error_name, dbus_error_message); | 578 dbus_error_name, dbus_error_message); |
| 557 } | 579 } |
| 558 | 580 |
| 559 void NetworkConnectionHandler::CheckPendingRequest( | 581 void NetworkConnectionHandler::CheckPendingRequest( |
| 560 const std::string service_path) { | 582 const std::string service_path) { |
| 561 ConnectRequest* request = pending_request(service_path); | 583 ConnectRequest* request = GetPendingRequest(service_path); |
| 562 DCHECK(request); | 584 DCHECK(request); |
| 563 if (request->connect_state == ConnectRequest::CONNECT_REQUESTED) | 585 if (request->connect_state == ConnectRequest::CONNECT_REQUESTED) |
| 564 return; // Request has not started, ignore update | 586 return; // Request has not started, ignore update |
| 565 const NetworkState* network = | 587 const NetworkState* network = |
| 566 network_state_handler_->GetNetworkState(service_path); | 588 network_state_handler_->GetNetworkState(service_path); |
| 567 if (!network) { | 589 if (!network) |
| 568 ErrorCallbackForPendingRequest(service_path, kErrorNotFound); | 590 return; // NetworkState may not be be updated yet. |
| 569 return; | 591 |
| 570 } | |
| 571 if (network->IsConnectingState()) { | 592 if (network->IsConnectingState()) { |
| 572 request->connect_state = ConnectRequest::CONNECT_CONNECTING; | 593 request->connect_state = ConnectRequest::CONNECT_CONNECTING; |
| 573 return; | 594 return; |
| 574 } | 595 } |
| 575 if (network->IsConnectedState()) { | 596 if (network->IsConnectedState()) { |
| 576 NET_LOG_EVENT("Connect Request Succeeded", service_path); | 597 NET_LOG_EVENT("Connect Request Succeeded", service_path); |
| 577 if (!request->success_callback.is_null()) | 598 if (!request->success_callback.is_null()) |
| 578 request->success_callback.Run(); | 599 request->success_callback.Run(); |
| 579 pending_requests_.erase(service_path); | 600 pending_requests_.erase(service_path); |
| 580 return; | 601 return; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 scoped_refptr<net::X509Certificate> matching_cert = | 650 scoped_refptr<net::X509Certificate> matching_cert = |
| 630 client_cert::GetCertificateMatch(ui_data->certificate_pattern()); | 651 client_cert::GetCertificateMatch(ui_data->certificate_pattern()); |
| 631 if (!matching_cert.get()) | 652 if (!matching_cert.get()) |
| 632 return std::string(); | 653 return std::string(); |
| 633 return CertLoader::GetPkcs11IdForCert(*matching_cert.get()); | 654 return CertLoader::GetPkcs11IdForCert(*matching_cert.get()); |
| 634 } | 655 } |
| 635 | 656 |
| 636 void NetworkConnectionHandler::ErrorCallbackForPendingRequest( | 657 void NetworkConnectionHandler::ErrorCallbackForPendingRequest( |
| 637 const std::string& service_path, | 658 const std::string& service_path, |
| 638 const std::string& error_name) { | 659 const std::string& error_name) { |
| 639 ConnectRequest* request = pending_request(service_path); | 660 ConnectRequest* request = GetPendingRequest(service_path); |
| 640 DCHECK(request); | 661 if (!request) { |
| 662 NET_LOG_ERROR("ErrorCallbackForPendingRequest with no pending request.", |
| 663 service_path); |
| 664 return; |
| 665 } |
| 641 // Remove the entry before invoking the callback in case it triggers a retry. | 666 // Remove the entry before invoking the callback in case it triggers a retry. |
| 642 network_handler::ErrorCallback error_callback = request->error_callback; | 667 network_handler::ErrorCallback error_callback = request->error_callback; |
| 643 pending_requests_.erase(service_path); | 668 pending_requests_.erase(service_path); |
| 644 InvokeErrorCallback(service_path, error_callback, error_name); | 669 InvokeErrorCallback(service_path, error_callback, error_name); |
| 645 } | 670 } |
| 646 | 671 |
| 647 // Disconnect | 672 // Disconnect |
| 648 | 673 |
| 649 void NetworkConnectionHandler::CallShillDisconnect( | 674 void NetworkConnectionHandler::CallShillDisconnect( |
| 650 const std::string& service_path, | 675 const std::string& service_path, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 | 711 |
| 687 void NetworkConnectionHandler::HandleShillActivateSuccess( | 712 void NetworkConnectionHandler::HandleShillActivateSuccess( |
| 688 const std::string& service_path, | 713 const std::string& service_path, |
| 689 const base::Closure& success_callback) { | 714 const base::Closure& success_callback) { |
| 690 NET_LOG_EVENT("Activate Request Sent", service_path); | 715 NET_LOG_EVENT("Activate Request Sent", service_path); |
| 691 if (!success_callback.is_null()) | 716 if (!success_callback.is_null()) |
| 692 success_callback.Run(); | 717 success_callback.Run(); |
| 693 } | 718 } |
| 694 | 719 |
| 695 } // namespace chromeos | 720 } // namespace chromeos |
| OLD | NEW |