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) { | |
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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 // "Provider.Type", etc keys (which are used only to set the values). | 382 // "Provider.Type", etc keys (which are used only to set the values). |
395 const base::DictionaryValue* provider_properties; | 383 const base::DictionaryValue* provider_properties; |
396 if (service_properties.GetDictionaryWithoutPathExpansion( | 384 if (service_properties.GetDictionaryWithoutPathExpansion( |
397 flimflam::kProviderProperty, &provider_properties)) { | 385 flimflam::kProviderProperty, &provider_properties)) { |
398 provider_properties->GetStringWithoutPathExpansion( | 386 provider_properties->GetStringWithoutPathExpansion( |
399 flimflam::kTypeProperty, &vpn_provider_type); | 387 flimflam::kTypeProperty, &vpn_provider_type); |
400 provider_properties->GetStringWithoutPathExpansion( | 388 provider_properties->GetStringWithoutPathExpansion( |
401 flimflam::kHostProperty, &vpn_provider_host); | 389 flimflam::kHostProperty, &vpn_provider_host); |
402 } | 390 } |
403 if (vpn_provider_type.empty() || vpn_provider_host.empty()) { | 391 if (vpn_provider_type.empty() || vpn_provider_host.empty()) { |
404 ErrorCallbackForPendingRequest(service_path, kErrorMissingProvider); | 392 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); |
405 return; | 393 return; |
406 } | 394 } |
407 // VPN requires a host and username to be set. | 395 // VPN requires a host and username to be set. |
408 if (!VPNIsConfigured( | 396 if (!VPNIsConfigured( |
409 service_path, vpn_provider_type, *provider_properties)) { | 397 service_path, vpn_provider_type, *provider_properties)) { |
410 NET_LOG_ERROR("VPN Not Configured", service_path); | 398 NET_LOG_ERROR("VPN Not Configured", service_path); |
411 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); | 399 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); |
412 return; | 400 return; |
413 } | 401 } |
414 } | 402 } |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 const std::string& dbus_error_message) { | 555 const std::string& dbus_error_message) { |
568 ConnectRequest* request = GetPendingRequest(service_path); | 556 ConnectRequest* request = GetPendingRequest(service_path); |
569 if (!request) { | 557 if (!request) { |
570 NET_LOG_ERROR("HandleShillConnectFailure called with no pending request.", | 558 NET_LOG_ERROR("HandleShillConnectFailure called with no pending request.", |
571 service_path); | 559 service_path); |
572 return; | 560 return; |
573 } | 561 } |
574 network_handler::ErrorCallback error_callback = request->error_callback; | 562 network_handler::ErrorCallback error_callback = request->error_callback; |
575 pending_requests_.erase(service_path); | 563 pending_requests_.erase(service_path); |
576 network_handler::ShillErrorCallbackFunction( | 564 network_handler::ShillErrorCallbackFunction( |
577 kErrorConnectFailed, service_path, error_callback, | 565 flimflam::kErrorConnectFailed, service_path, error_callback, |
578 dbus_error_name, dbus_error_message); | 566 dbus_error_name, dbus_error_message); |
579 } | 567 } |
580 | 568 |
581 void NetworkConnectionHandler::CheckPendingRequest( | 569 void NetworkConnectionHandler::CheckPendingRequest( |
582 const std::string service_path) { | 570 const std::string service_path) { |
583 ConnectRequest* request = GetPendingRequest(service_path); | 571 ConnectRequest* request = GetPendingRequest(service_path); |
584 DCHECK(request); | 572 DCHECK(request); |
585 if (request->connect_state == ConnectRequest::CONNECT_REQUESTED) | 573 if (request->connect_state == ConnectRequest::CONNECT_REQUESTED) |
586 return; // Request has not started, ignore update | 574 return; // Request has not started, ignore update |
587 const NetworkState* network = | 575 const NetworkState* network = |
(...skipping 19 matching lines...) Expand all Loading... |
607 } | 595 } |
608 | 596 |
609 // Network is neither connecting or connected; an error occurred. | 597 // Network is neither connecting or connected; an error occurred. |
610 std::string error_name, error_detail; | 598 std::string error_name, error_detail; |
611 if (network->connection_state() == flimflam::kStateIdle && | 599 if (network->connection_state() == flimflam::kStateIdle && |
612 pending_requests_.size() > 1) { | 600 pending_requests_.size() > 1) { |
613 // Another connect request canceled this one. | 601 // Another connect request canceled this one. |
614 error_name = kErrorConnectCanceled; | 602 error_name = kErrorConnectCanceled; |
615 error_detail = ""; | 603 error_detail = ""; |
616 } else { | 604 } else { |
617 error_name = kErrorConnectFailed; | 605 error_name = flimflam::kErrorConnectFailed; |
618 error_detail = network->error(); | 606 error_detail = network->error(); |
619 if (error_detail.empty()) { | 607 if (error_detail.empty()) { |
620 if (network->connection_state() == flimflam::kStateFailure) | 608 if (network->connection_state() == flimflam::kStateFailure) |
621 error_detail = flimflam::kUnknownString; | 609 error_detail = flimflam::kUnknownString; |
622 else | 610 else |
623 error_detail = "Unexpected State: " + network->connection_state(); | 611 error_detail = "Unexpected State: " + network->connection_state(); |
624 } | 612 } |
625 } | 613 } |
626 std::string error_msg = error_name + ": " + error_detail; | 614 std::string error_msg = error_name + ": " + error_detail; |
627 NET_LOG_ERROR(error_msg, service_path); | 615 NET_LOG_ERROR(error_msg, service_path); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 | 699 |
712 void NetworkConnectionHandler::HandleShillActivateSuccess( | 700 void NetworkConnectionHandler::HandleShillActivateSuccess( |
713 const std::string& service_path, | 701 const std::string& service_path, |
714 const base::Closure& success_callback) { | 702 const base::Closure& success_callback) { |
715 NET_LOG_EVENT("Activate Request Sent", service_path); | 703 NET_LOG_EVENT("Activate Request Sent", service_path); |
716 if (!success_callback.is_null()) | 704 if (!success_callback.is_null()) |
717 success_callback.Run(); | 705 success_callback.Run(); |
718 } | 706 } |
719 | 707 |
720 } // namespace chromeos | 708 } // namespace chromeos |
OLD | NEW |