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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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"; | 121 const char NetworkConnectionHandler::kErrorConnectFailed[] = "connect-failed"; |
| 122 const char NetworkConnectionHandler::kErrorConfigureFailed[] = |
| 123 "configure-failed"; |
| 124 const char NetworkConnectionHandler::kErrorActivateFailed[] = |
| 125 "activate-failed"; |
122 const char NetworkConnectionHandler::kErrorMissingProvider[] = | 126 const char NetworkConnectionHandler::kErrorMissingProvider[] = |
123 "missing-provider"; | 127 "missing-provider"; |
| 128 const char NetworkConnectionHandler::kErrorConnectCanceled[] = |
| 129 "connect-canceled"; |
124 const char NetworkConnectionHandler::kErrorUnknown[] = "unknown-error"; | 130 const char NetworkConnectionHandler::kErrorUnknown[] = "unknown-error"; |
125 | 131 |
126 struct NetworkConnectionHandler::ConnectRequest { | 132 struct NetworkConnectionHandler::ConnectRequest { |
127 ConnectRequest(const std::string& service_path, | 133 ConnectRequest(const std::string& service_path, |
128 const base::Closure& success, | 134 const base::Closure& success, |
129 const network_handler::ErrorCallback& error) | 135 const network_handler::ErrorCallback& error) |
130 : service_path(service_path), | 136 : service_path(service_path), |
131 connect_state(CONNECT_REQUESTED), | 137 connect_state(CONNECT_REQUESTED), |
132 success_callback(success), | 138 success_callback(success), |
133 error_callback(error) { | 139 error_callback(error) { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 } | 243 } |
238 if (network->IsConnectingState()) { | 244 if (network->IsConnectingState()) { |
239 InvokeErrorCallback(service_path, error_callback, kErrorConnecting); | 245 InvokeErrorCallback(service_path, error_callback, kErrorConnecting); |
240 return; | 246 return; |
241 } | 247 } |
242 if (NetworkRequiresActivation(network)) { | 248 if (NetworkRequiresActivation(network)) { |
243 InvokeErrorCallback(service_path, error_callback, kErrorActivationRequired); | 249 InvokeErrorCallback(service_path, error_callback, kErrorActivationRequired); |
244 return; | 250 return; |
245 } | 251 } |
246 | 252 |
| 253 if (check_error_state) { |
| 254 const std::string& error = network->error(); |
| 255 if (error == flimflam::kErrorConnectFailed) { |
| 256 InvokeErrorCallback( |
| 257 service_path, error_callback, kErrorPassphraseRequired); |
| 258 return; |
| 259 } |
| 260 if (error == flimflam::kErrorBadPassphrase) { |
| 261 InvokeErrorCallback( |
| 262 service_path, error_callback, kErrorPassphraseRequired); |
| 263 return; |
| 264 } |
| 265 |
| 266 if (IsAuthenticationError(error)) { |
| 267 InvokeErrorCallback( |
| 268 service_path, error_callback, kErrorAuthenticationRequired); |
| 269 return; |
| 270 } |
| 271 } |
| 272 |
247 // All synchronous checks passed, add |service_path| to connecting list. | 273 // All synchronous checks passed, add |service_path| to connecting list. |
248 pending_requests_.insert(std::make_pair( | 274 pending_requests_.insert(std::make_pair( |
249 service_path, | 275 service_path, |
250 ConnectRequest(service_path, success_callback, error_callback))); | 276 ConnectRequest(service_path, success_callback, error_callback))); |
251 | 277 |
252 // Connect immediately to 'connectable' networks. | 278 // Connect immediately to 'connectable' networks. |
253 // TODO(stevenjb): Shill needs to properly set Connectable for VPN. | 279 // TODO(stevenjb): Shill needs to properly set Connectable for VPN. |
254 if (network->connectable() && network->type() != flimflam::kTypeVPN) { | 280 if (network->connectable() && network->type() != flimflam::kTypeVPN) { |
255 CallShillConnect(service_path); | 281 CallShillConnect(service_path); |
256 return; | 282 return; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 } | 359 } |
334 | 360 |
335 // ConnectToNetwork implementation | 361 // ConnectToNetwork implementation |
336 | 362 |
337 void NetworkConnectionHandler::VerifyConfiguredAndConnect( | 363 void NetworkConnectionHandler::VerifyConfiguredAndConnect( |
338 bool check_error_state, | 364 bool check_error_state, |
339 const std::string& service_path, | 365 const std::string& service_path, |
340 const base::DictionaryValue& service_properties) { | 366 const base::DictionaryValue& service_properties) { |
341 NET_LOG_EVENT("VerifyConfiguredAndConnect", service_path); | 367 NET_LOG_EVENT("VerifyConfiguredAndConnect", service_path); |
342 | 368 |
343 std::string type; | |
344 service_properties.GetStringWithoutPathExpansion( | |
345 flimflam::kTypeProperty, &type); | |
346 | |
347 if (check_error_state) { | |
348 std::string error; | |
349 service_properties.GetStringWithoutPathExpansion( | |
350 flimflam::kErrorProperty, &error); | |
351 if (error == flimflam::kErrorConnectFailed) { | |
352 ErrorCallbackForPendingRequest(service_path, kErrorPassphraseRequired); | |
353 return; | |
354 } | |
355 if (error == flimflam::kErrorBadPassphrase) { | |
356 ErrorCallbackForPendingRequest(service_path, kErrorPassphraseRequired); | |
357 return; | |
358 } | |
359 | |
360 if (IsAuthenticationError(error)) { | |
361 ErrorCallbackForPendingRequest(service_path, | |
362 kErrorAuthenticationRequired); | |
363 return; | |
364 } | |
365 } | |
366 | |
367 // If 'passphrase_required' is still true, then the 'Passphrase' property | 369 // If 'passphrase_required' is still true, then the 'Passphrase' property |
368 // has not been set to a minimum length value. | 370 // has not been set to a minimum length value. |
369 bool passphrase_required = false; | 371 bool passphrase_required = false; |
370 service_properties.GetBooleanWithoutPathExpansion( | 372 service_properties.GetBooleanWithoutPathExpansion( |
371 flimflam::kPassphraseRequiredProperty, &passphrase_required); | 373 flimflam::kPassphraseRequiredProperty, &passphrase_required); |
372 if (passphrase_required) { | 374 if (passphrase_required) { |
373 ErrorCallbackForPendingRequest(service_path, kErrorPassphraseRequired); | 375 ErrorCallbackForPendingRequest(service_path, kErrorPassphraseRequired); |
374 return; | 376 return; |
375 } | 377 } |
376 | 378 |
| 379 std::string type; |
| 380 service_properties.GetStringWithoutPathExpansion( |
| 381 flimflam::kTypeProperty, &type); |
| 382 |
377 // Get VPN provider type and host (required for configuration) and ensure | 383 // Get VPN provider type and host (required for configuration) and ensure |
378 // that required VPN non-cert properties are set. | 384 // that required VPN non-cert properties are set. |
379 std::string vpn_provider_type, vpn_provider_host; | 385 std::string vpn_provider_type, vpn_provider_host; |
380 if (type == flimflam::kTypeVPN) { | 386 if (type == flimflam::kTypeVPN) { |
381 // VPN Provider values are read from the "Provider" dictionary, not the | 387 // VPN Provider values are read from the "Provider" dictionary, not the |
382 // "Provider.Type", etc keys (which are used only to set the values). | 388 // "Provider.Type", etc keys (which are used only to set the values). |
383 const base::DictionaryValue* provider_properties; | 389 const base::DictionaryValue* provider_properties; |
384 if (service_properties.GetDictionaryWithoutPathExpansion( | 390 if (service_properties.GetDictionaryWithoutPathExpansion( |
385 flimflam::kProviderProperty, &provider_properties)) { | 391 flimflam::kProviderProperty, &provider_properties)) { |
386 provider_properties->GetStringWithoutPathExpansion( | 392 provider_properties->GetStringWithoutPathExpansion( |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 | 539 |
534 void NetworkConnectionHandler::HandleConfigurationFailure( | 540 void NetworkConnectionHandler::HandleConfigurationFailure( |
535 const std::string& service_path, | 541 const std::string& service_path, |
536 const std::string& error_name, | 542 const std::string& error_name, |
537 scoped_ptr<base::DictionaryValue> error_data) { | 543 scoped_ptr<base::DictionaryValue> error_data) { |
538 ConnectRequest* request = pending_request(service_path); | 544 ConnectRequest* request = pending_request(service_path); |
539 DCHECK(request); | 545 DCHECK(request); |
540 network_handler::ErrorCallback error_callback = request->error_callback; | 546 network_handler::ErrorCallback error_callback = request->error_callback; |
541 pending_requests_.erase(service_path); | 547 pending_requests_.erase(service_path); |
542 if (!error_callback.is_null()) | 548 if (!error_callback.is_null()) |
543 error_callback.Run(error_name, error_data.Pass()); | 549 error_callback.Run(kErrorConfigureFailed, error_data.Pass()); |
544 } | 550 } |
545 | 551 |
546 void NetworkConnectionHandler::HandleShillConnectSuccess( | 552 void NetworkConnectionHandler::HandleShillConnectSuccess( |
547 const std::string& service_path) { | 553 const std::string& service_path) { |
548 ConnectRequest* request = pending_request(service_path); | 554 ConnectRequest* request = pending_request(service_path); |
549 DCHECK(request); | 555 DCHECK(request); |
550 request->connect_state = ConnectRequest::CONNECT_STARTED; | 556 request->connect_state = ConnectRequest::CONNECT_STARTED; |
551 NET_LOG_EVENT("Connect Request Acknowledged", service_path); | 557 NET_LOG_EVENT("Connect Request Acknowledged", service_path); |
552 // Do not call success_callback here, wait for one of the following | 558 // Do not call success_callback here, wait for one of the following |
553 // conditions: | 559 // conditions: |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 pending_requests_.erase(service_path); | 598 pending_requests_.erase(service_path); |
593 return; | 599 return; |
594 } | 600 } |
595 if (network->connection_state() == flimflam::kStateIdle && | 601 if (network->connection_state() == flimflam::kStateIdle && |
596 request->connect_state != ConnectRequest::CONNECT_CONNECTING) { | 602 request->connect_state != ConnectRequest::CONNECT_CONNECTING) { |
597 // Connection hasn't started yet, keep waiting. | 603 // Connection hasn't started yet, keep waiting. |
598 return; | 604 return; |
599 } | 605 } |
600 | 606 |
601 // Network is neither connecting or connected; an error occurred. | 607 // Network is neither connecting or connected; an error occurred. |
602 std::string error_name = kErrorConnectFailed; | 608 std::string error_name, error_detail; |
603 std::string error_detail = network->error(); | 609 if (network->connection_state() == flimflam::kStateIdle && |
604 if (error_detail.empty()) { | 610 pending_requests_.size() > 1) { |
605 if (network->connection_state() == flimflam::kStateFailure) | 611 // Another connect request canceled this one. |
606 error_detail = flimflam::kUnknownString; | 612 error_name = kErrorConnectCanceled; |
607 else | 613 error_detail = ""; |
608 error_detail = "Unexpected State: " + network->connection_state(); | 614 } else { |
| 615 error_name = kErrorConnectFailed; |
| 616 error_detail = network->error(); |
| 617 if (error_detail.empty()) { |
| 618 if (network->connection_state() == flimflam::kStateFailure) |
| 619 error_detail = flimflam::kUnknownString; |
| 620 else |
| 621 error_detail = "Unexpected State: " + network->connection_state(); |
| 622 } |
609 } | 623 } |
610 std::string error_msg = error_name + ": " + error_detail; | 624 std::string error_msg = error_name + ": " + error_detail; |
611 NET_LOG_ERROR(error_msg, service_path); | 625 NET_LOG_ERROR(error_msg, service_path); |
612 | 626 |
613 network_handler::ErrorCallback error_callback = request->error_callback; | 627 network_handler::ErrorCallback error_callback = request->error_callback; |
614 pending_requests_.erase(service_path); | 628 pending_requests_.erase(service_path); |
615 if (error_callback.is_null()) | 629 if (error_callback.is_null()) |
616 return; | 630 return; |
617 scoped_ptr<base::DictionaryValue> error_data( | 631 scoped_ptr<base::DictionaryValue> error_data( |
618 network_handler::CreateErrorData(service_path, error_name, error_msg)); | 632 network_handler::CreateErrorData(service_path, error_name, error_msg)); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 | 707 |
694 void NetworkConnectionHandler::HandleShillActivateSuccess( | 708 void NetworkConnectionHandler::HandleShillActivateSuccess( |
695 const std::string& service_path, | 709 const std::string& service_path, |
696 const base::Closure& success_callback) { | 710 const base::Closure& success_callback) { |
697 NET_LOG_EVENT("Activate Request Sent", service_path); | 711 NET_LOG_EVENT("Activate Request Sent", service_path); |
698 if (!success_callback.is_null()) | 712 if (!success_callback.is_null()) |
699 success_callback.Run(); | 713 success_callback.Run(); |
700 } | 714 } |
701 | 715 |
702 } // namespace chromeos | 716 } // namespace chromeos |
OLD | NEW |