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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 // "Provider.Type", etc keys (which are used only to set the values). | 371 // "Provider.Type", etc keys (which are used only to set the values). |
384 const base::DictionaryValue* provider_properties; | 372 const base::DictionaryValue* provider_properties; |
385 if (service_properties.GetDictionaryWithoutPathExpansion( | 373 if (service_properties.GetDictionaryWithoutPathExpansion( |
386 flimflam::kProviderProperty, &provider_properties)) { | 374 flimflam::kProviderProperty, &provider_properties)) { |
387 provider_properties->GetStringWithoutPathExpansion( | 375 provider_properties->GetStringWithoutPathExpansion( |
388 flimflam::kTypeProperty, &vpn_provider_type); | 376 flimflam::kTypeProperty, &vpn_provider_type); |
389 provider_properties->GetStringWithoutPathExpansion( | 377 provider_properties->GetStringWithoutPathExpansion( |
390 flimflam::kHostProperty, &vpn_provider_host); | 378 flimflam::kHostProperty, &vpn_provider_host); |
391 } | 379 } |
392 if (vpn_provider_type.empty() || vpn_provider_host.empty()) { | 380 if (vpn_provider_type.empty() || vpn_provider_host.empty()) { |
393 ErrorCallbackForPendingRequest(service_path, kErrorMissingProvider); | 381 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); |
394 return; | 382 return; |
395 } | 383 } |
396 // VPN requires a host and username to be set. | 384 // VPN requires a host and username to be set. |
397 if (!VPNIsConfigured( | 385 if (!VPNIsConfigured( |
398 service_path, vpn_provider_type, *provider_properties)) { | 386 service_path, vpn_provider_type, *provider_properties)) { |
399 NET_LOG_ERROR("VPN Not Configured", service_path); | 387 NET_LOG_ERROR("VPN Not Configured", service_path); |
400 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); | 388 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); |
401 return; | 389 return; |
402 } | 390 } |
403 } | 391 } |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 const std::string& dbus_error_message) { | 544 const std::string& dbus_error_message) { |
557 ConnectRequest* request = GetPendingRequest(service_path); | 545 ConnectRequest* request = GetPendingRequest(service_path); |
558 if (!request) { | 546 if (!request) { |
559 NET_LOG_ERROR("HandleShillConnectFailure called with no pending request.", | 547 NET_LOG_ERROR("HandleShillConnectFailure called with no pending request.", |
560 service_path); | 548 service_path); |
561 return; | 549 return; |
562 } | 550 } |
563 network_handler::ErrorCallback error_callback = request->error_callback; | 551 network_handler::ErrorCallback error_callback = request->error_callback; |
564 pending_requests_.erase(service_path); | 552 pending_requests_.erase(service_path); |
565 network_handler::ShillErrorCallbackFunction( | 553 network_handler::ShillErrorCallbackFunction( |
566 kErrorConnectFailed, service_path, error_callback, | 554 flimflam::kErrorConnectFailed, service_path, error_callback, |
567 dbus_error_name, dbus_error_message); | 555 dbus_error_name, dbus_error_message); |
568 } | 556 } |
569 | 557 |
570 void NetworkConnectionHandler::CheckPendingRequest( | 558 void NetworkConnectionHandler::CheckPendingRequest( |
571 const std::string service_path) { | 559 const std::string service_path) { |
572 ConnectRequest* request = GetPendingRequest(service_path); | 560 ConnectRequest* request = GetPendingRequest(service_path); |
573 DCHECK(request); | 561 DCHECK(request); |
574 if (request->connect_state == ConnectRequest::CONNECT_REQUESTED) | 562 if (request->connect_state == ConnectRequest::CONNECT_REQUESTED) |
575 return; // Request has not started, ignore update | 563 return; // Request has not started, ignore update |
576 const NetworkState* network = | 564 const NetworkState* network = |
(...skipping 19 matching lines...) Expand all Loading... |
596 } | 584 } |
597 | 585 |
598 // Network is neither connecting or connected; an error occurred. | 586 // Network is neither connecting or connected; an error occurred. |
599 std::string error_name, error_detail; | 587 std::string error_name, error_detail; |
600 if (network->connection_state() == flimflam::kStateIdle && | 588 if (network->connection_state() == flimflam::kStateIdle && |
601 pending_requests_.size() > 1) { | 589 pending_requests_.size() > 1) { |
602 // Another connect request canceled this one. | 590 // Another connect request canceled this one. |
603 error_name = kErrorConnectCanceled; | 591 error_name = kErrorConnectCanceled; |
604 error_detail = ""; | 592 error_detail = ""; |
605 } else { | 593 } else { |
606 error_name = kErrorConnectFailed; | 594 error_name = flimflam::kErrorConnectFailed; |
607 error_detail = network->error(); | 595 error_detail = network->error(); |
608 if (error_detail.empty()) { | 596 if (error_detail.empty()) { |
609 if (network->connection_state() == flimflam::kStateFailure) | 597 if (network->connection_state() == flimflam::kStateFailure) |
610 error_detail = flimflam::kUnknownString; | 598 error_detail = flimflam::kUnknownString; |
611 else | 599 else |
612 error_detail = "Unexpected State: " + network->connection_state(); | 600 error_detail = "Unexpected State: " + network->connection_state(); |
613 } | 601 } |
614 } | 602 } |
615 std::string error_msg = error_name + ": " + error_detail; | 603 std::string error_msg = error_name + ": " + error_detail; |
616 NET_LOG_ERROR(error_msg, service_path); | 604 NET_LOG_ERROR(error_msg, service_path); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 | 663 |
676 void NetworkConnectionHandler::HandleShillDisconnectSuccess( | 664 void NetworkConnectionHandler::HandleShillDisconnectSuccess( |
677 const std::string& service_path, | 665 const std::string& service_path, |
678 const base::Closure& success_callback) { | 666 const base::Closure& success_callback) { |
679 NET_LOG_EVENT("Disconnect Request Sent", service_path); | 667 NET_LOG_EVENT("Disconnect Request Sent", service_path); |
680 if (!success_callback.is_null()) | 668 if (!success_callback.is_null()) |
681 success_callback.Run(); | 669 success_callback.Run(); |
682 } | 670 } |
683 | 671 |
684 } // namespace chromeos | 672 } // namespace chromeos |
OLD | NEW |