| 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/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "chromeos/network/network_state_handler.h" | 25 #include "chromeos/network/network_state_handler.h" |
| 26 #include "chromeos/network/shill_property_util.h" | 26 #include "chromeos/network/shill_property_util.h" |
| 27 #include "dbus/object_path.h" | 27 #include "dbus/object_path.h" |
| 28 #include "net/cert/x509_certificate.h" | 28 #include "net/cert/x509_certificate.h" |
| 29 #include "third_party/cros_system_api/dbus/service_constants.h" | 29 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 30 | 30 |
| 31 namespace chromeos { | 31 namespace chromeos { |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 void InvokeErrorCallback(const std::string& service_path, | |
| 36 const network_handler::ErrorCallback& error_callback, | |
| 37 const std::string& error_name) { | |
| 38 NET_LOG_ERROR("Connect Error: " + error_name, service_path); | |
| 39 network_handler::RunErrorCallback( | |
| 40 error_callback, service_path, error_name, ""); | |
| 41 } | |
| 42 | |
| 43 bool IsAuthenticationError(const std::string& error) { | 35 bool IsAuthenticationError(const std::string& error) { |
| 44 return (error == shill::kErrorBadWEPKey || | 36 return (error == shill::kErrorBadWEPKey || |
| 45 error == shill::kErrorPppAuthFailed || | 37 error == shill::kErrorPppAuthFailed || |
| 46 error == shill::kErrorEapLocalTlsFailed || | 38 error == shill::kErrorEapLocalTlsFailed || |
| 47 error == shill::kErrorEapRemoteTlsFailed || | 39 error == shill::kErrorEapRemoteTlsFailed || |
| 48 error == shill::kErrorEapAuthenticationFailed); | 40 error == shill::kErrorEapAuthenticationFailed); |
| 49 } | 41 } |
| 50 | 42 |
| 51 bool VPNRequiresCredentials(const std::string& service_path, | 43 bool VPNRequiresCredentials(const std::string& service_path, |
| 52 const std::string& provider_type, | 44 const std::string& provider_type, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 } | 93 } |
| 102 | 94 |
| 103 } // namespace | 95 } // namespace |
| 104 | 96 |
| 105 const char NetworkConnectionHandler::kErrorNotFound[] = "not-found"; | 97 const char NetworkConnectionHandler::kErrorNotFound[] = "not-found"; |
| 106 const char NetworkConnectionHandler::kErrorConnected[] = "connected"; | 98 const char NetworkConnectionHandler::kErrorConnected[] = "connected"; |
| 107 const char NetworkConnectionHandler::kErrorConnecting[] = "connecting"; | 99 const char NetworkConnectionHandler::kErrorConnecting[] = "connecting"; |
| 108 const char NetworkConnectionHandler::kErrorNotConnected[] = "not-connected"; | 100 const char NetworkConnectionHandler::kErrorNotConnected[] = "not-connected"; |
| 109 const char NetworkConnectionHandler::kErrorPassphraseRequired[] = | 101 const char NetworkConnectionHandler::kErrorPassphraseRequired[] = |
| 110 "passphrase-required"; | 102 "passphrase-required"; |
| 111 const char NetworkConnectionHandler::kErrorActivationRequired[] = | 103 const char NetworkConnectionHandler::kErrorBadPassphrase[] = "bad-passphrase"; |
| 112 "activation-required"; | |
| 113 const char NetworkConnectionHandler::kErrorCertificateRequired[] = | 104 const char NetworkConnectionHandler::kErrorCertificateRequired[] = |
| 114 "certificate-required"; | 105 "certificate-required"; |
| 115 const char NetworkConnectionHandler::kErrorConfigurationRequired[] = | 106 const char NetworkConnectionHandler::kErrorConfigurationRequired[] = |
| 116 "configuration-required"; | 107 "configuration-required"; |
| 117 const char NetworkConnectionHandler::kErrorAuthenticationRequired[] = | 108 const char NetworkConnectionHandler::kErrorAuthenticationRequired[] = |
| 118 "authentication-required"; | 109 "authentication-required"; |
| 119 const char NetworkConnectionHandler::kErrorShillError[] = "shill-error"; | 110 const char NetworkConnectionHandler::kErrorConnectFailed[] = "connect-failed"; |
| 111 const char NetworkConnectionHandler::kErrorDisconnectFailed[] = |
| 112 "disconnect-failed"; |
| 120 const char NetworkConnectionHandler::kErrorConfigureFailed[] = | 113 const char NetworkConnectionHandler::kErrorConfigureFailed[] = |
| 121 "configure-failed"; | 114 "configure-failed"; |
| 122 const char NetworkConnectionHandler::kErrorConnectCanceled[] = | 115 const char NetworkConnectionHandler::kErrorConnectCanceled[] = |
| 123 "connect-canceled"; | 116 "connect-canceled"; |
| 124 const char NetworkConnectionHandler::kErrorCertLoadTimeout[] = | 117 const char NetworkConnectionHandler::kErrorCertLoadTimeout[] = |
| 125 "cert-load-timeout"; | 118 "cert-load-timeout"; |
| 126 | 119 |
| 127 struct NetworkConnectionHandler::ConnectRequest { | 120 struct NetworkConnectionHandler::ConnectRequest { |
| 128 ConnectRequest(const std::string& service_path, | 121 ConnectRequest(const std::string& service_path, |
| 129 const std::string& profile_path, | 122 const std::string& profile_path, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 configuration_handler_ = network_configuration_handler; | 184 configuration_handler_ = network_configuration_handler; |
| 192 managed_configuration_handler_ = managed_network_configuration_handler; | 185 managed_configuration_handler_ = managed_network_configuration_handler; |
| 193 | 186 |
| 194 // After this point, the NetworkConnectionHandler is fully initialized (all | 187 // After this point, the NetworkConnectionHandler is fully initialized (all |
| 195 // handler references set, observers registered, ...). | 188 // handler references set, observers registered, ...). |
| 196 | 189 |
| 197 if (LoginState::IsInitialized()) | 190 if (LoginState::IsInitialized()) |
| 198 LoggedInStateChanged(); | 191 LoggedInStateChanged(); |
| 199 } | 192 } |
| 200 | 193 |
| 201 void NetworkConnectionHandler::AddObserver(Observer* observer) { | 194 void NetworkConnectionHandler::AddObserver( |
| 195 NetworkConnectionObserver* observer) { |
| 202 observers_.AddObserver(observer); | 196 observers_.AddObserver(observer); |
| 203 } | 197 } |
| 204 | 198 |
| 205 void NetworkConnectionHandler::RemoveObserver(Observer* observer) { | 199 void NetworkConnectionHandler::RemoveObserver( |
| 200 NetworkConnectionObserver* observer) { |
| 206 observers_.RemoveObserver(observer); | 201 observers_.RemoveObserver(observer); |
| 207 } | 202 } |
| 208 | 203 |
| 209 void NetworkConnectionHandler::LoggedInStateChanged() { | 204 void NetworkConnectionHandler::LoggedInStateChanged() { |
| 210 LoginState* login_state = LoginState::Get(); | 205 LoginState* login_state = LoginState::Get(); |
| 211 if (logged_in_ || !login_state->IsUserLoggedIn()) | 206 if (logged_in_ || !login_state->IsUserLoggedIn()) |
| 212 return; | 207 return; |
| 213 | 208 |
| 214 NET_LOG_EVENT("Logged In", ""); | 209 NET_LOG_EVENT("Logged In", ""); |
| 215 logged_in_ = true; | 210 logged_in_ = true; |
| 216 logged_in_time_ = base::TimeTicks::Now(); | 211 logged_in_time_ = base::TimeTicks::Now(); |
| 217 } | 212 } |
| 218 | 213 |
| 219 void NetworkConnectionHandler::OnCertificatesLoaded( | 214 void NetworkConnectionHandler::OnCertificatesLoaded( |
| 220 const net::CertificateList& cert_list, | 215 const net::CertificateList& cert_list, |
| 221 bool initial_load) { | 216 bool initial_load) { |
| 222 certificates_loaded_ = true; | 217 certificates_loaded_ = true; |
| 223 NET_LOG_EVENT("Certificates Loaded", ""); | 218 NET_LOG_EVENT("Certificates Loaded", ""); |
| 224 if (queued_connect_) | 219 if (queued_connect_) |
| 225 ConnectToQueuedNetwork(); | 220 ConnectToQueuedNetwork(); |
| 226 } | 221 } |
| 227 | 222 |
| 228 void NetworkConnectionHandler::ConnectToNetwork( | 223 void NetworkConnectionHandler::ConnectToNetwork( |
| 229 const std::string& service_path, | 224 const std::string& service_path, |
| 230 const base::Closure& success_callback, | 225 const base::Closure& success_callback, |
| 231 const network_handler::ErrorCallback& error_callback, | 226 const network_handler::ErrorCallback& error_callback, |
| 232 bool check_error_state) { | 227 bool check_error_state) { |
| 233 NET_LOG_USER("ConnectToNetwork", service_path); | 228 NET_LOG_USER("ConnectToNetwork", service_path); |
| 234 FOR_EACH_OBSERVER(Observer, observers_, | 229 FOR_EACH_OBSERVER(NetworkConnectionObserver, observers_, |
| 235 ConnectToNetworkRequested(service_path)); | 230 ConnectToNetworkRequested(service_path)); |
| 236 | 231 |
| 237 // Clear any existing queued connect request. | 232 // Clear any existing queued connect request. |
| 238 queued_connect_.reset(); | 233 queued_connect_.reset(); |
| 239 if (HasConnectingNetwork(service_path)) { | 234 if (HasConnectingNetwork(service_path)) { |
| 240 NET_LOG_USER("Connect Request While Pending", service_path); | 235 NET_LOG_USER("Connect Request While Pending", service_path); |
| 241 InvokeErrorCallback(service_path, error_callback, kErrorConnecting); | 236 InvokeErrorCallback(service_path, error_callback, kErrorConnecting); |
| 242 return; | 237 return; |
| 243 } | 238 } |
| 244 | 239 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 256 return; | 251 return; |
| 257 } | 252 } |
| 258 if (network->IsConnectingState()) { | 253 if (network->IsConnectingState()) { |
| 259 InvokeErrorCallback(service_path, error_callback, kErrorConnecting); | 254 InvokeErrorCallback(service_path, error_callback, kErrorConnecting); |
| 260 return; | 255 return; |
| 261 } | 256 } |
| 262 | 257 |
| 263 if (check_error_state) { | 258 if (check_error_state) { |
| 264 const std::string& error = network->last_error(); | 259 const std::string& error = network->last_error(); |
| 265 if (error == shill::kErrorBadPassphrase) { | 260 if (error == shill::kErrorBadPassphrase) { |
| 266 InvokeErrorCallback(service_path, error_callback, error); | 261 InvokeErrorCallback(service_path, error_callback, kErrorBadPassphrase); |
| 267 return; | 262 return; |
| 268 } | 263 } |
| 269 if (IsAuthenticationError(error)) { | 264 if (IsAuthenticationError(error)) { |
| 270 InvokeErrorCallback( | 265 InvokeErrorCallback( |
| 271 service_path, error_callback, kErrorAuthenticationRequired); | 266 service_path, error_callback, kErrorAuthenticationRequired); |
| 272 return; | 267 return; |
| 273 } | 268 } |
| 274 } | 269 } |
| 275 } | 270 } |
| 276 | 271 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 303 AsWeakPtr(), check_error_state), | 298 AsWeakPtr(), check_error_state), |
| 304 base::Bind(&NetworkConnectionHandler::HandleConfigurationFailure, | 299 base::Bind(&NetworkConnectionHandler::HandleConfigurationFailure, |
| 305 AsWeakPtr(), service_path)); | 300 AsWeakPtr(), service_path)); |
| 306 } | 301 } |
| 307 | 302 |
| 308 void NetworkConnectionHandler::DisconnectNetwork( | 303 void NetworkConnectionHandler::DisconnectNetwork( |
| 309 const std::string& service_path, | 304 const std::string& service_path, |
| 310 const base::Closure& success_callback, | 305 const base::Closure& success_callback, |
| 311 const network_handler::ErrorCallback& error_callback) { | 306 const network_handler::ErrorCallback& error_callback) { |
| 312 NET_LOG_USER("DisconnectNetwork", service_path); | 307 NET_LOG_USER("DisconnectNetwork", service_path); |
| 308 FOR_EACH_OBSERVER(NetworkConnectionObserver, observers_, |
| 309 DiconnectRequested(service_path)); |
| 310 |
| 313 const NetworkState* network = | 311 const NetworkState* network = |
| 314 network_state_handler_->GetNetworkState(service_path); | 312 network_state_handler_->GetNetworkState(service_path); |
| 315 if (!network) { | 313 if (!network) { |
| 316 InvokeErrorCallback(service_path, error_callback, kErrorNotFound); | 314 NET_LOG_ERROR("Disconnect Error: Not Found", service_path); |
| 315 network_handler::RunErrorCallback( |
| 316 error_callback, service_path, kErrorNotFound, ""); |
| 317 return; | 317 return; |
| 318 } | 318 } |
| 319 if (!network->IsConnectedState() && !network->IsConnectingState()) { | 319 if (!network->IsConnectedState() && !network->IsConnectingState()) { |
| 320 InvokeErrorCallback(service_path, error_callback, kErrorNotConnected); | 320 NET_LOG_ERROR("Disconnect Error: Not Connected", service_path); |
| 321 network_handler::RunErrorCallback( |
| 322 error_callback, service_path, kErrorNotConnected, ""); |
| 321 return; | 323 return; |
| 322 } | 324 } |
| 323 pending_requests_.erase(service_path); | 325 pending_requests_.erase(service_path); |
| 324 CallShillDisconnect(service_path, success_callback, error_callback); | 326 CallShillDisconnect(service_path, success_callback, error_callback); |
| 325 } | 327 } |
| 326 | 328 |
| 327 bool NetworkConnectionHandler::HasConnectingNetwork( | 329 bool NetworkConnectionHandler::HasConnectingNetwork( |
| 328 const std::string& service_path) { | 330 const std::string& service_path) { |
| 329 return pending_requests_.count(service_path) != 0; | 331 return pending_requests_.count(service_path) != 0; |
| 330 } | 332 } |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 const std::string& error_name, | 606 const std::string& error_name, |
| 605 scoped_ptr<base::DictionaryValue> error_data) { | 607 scoped_ptr<base::DictionaryValue> error_data) { |
| 606 ConnectRequest* request = GetPendingRequest(service_path); | 608 ConnectRequest* request = GetPendingRequest(service_path); |
| 607 if (!request) { | 609 if (!request) { |
| 608 NET_LOG_ERROR("HandleConfigurationFailure called with no pending request.", | 610 NET_LOG_ERROR("HandleConfigurationFailure called with no pending request.", |
| 609 service_path); | 611 service_path); |
| 610 return; | 612 return; |
| 611 } | 613 } |
| 612 network_handler::ErrorCallback error_callback = request->error_callback; | 614 network_handler::ErrorCallback error_callback = request->error_callback; |
| 613 pending_requests_.erase(service_path); | 615 pending_requests_.erase(service_path); |
| 614 if (!error_callback.is_null()) | 616 InvokeErrorCallback(service_path, error_callback, kErrorConfigureFailed); |
| 615 error_callback.Run(kErrorConfigureFailed, error_data.Pass()); | |
| 616 } | 617 } |
| 617 | 618 |
| 618 void NetworkConnectionHandler::HandleShillConnectSuccess( | 619 void NetworkConnectionHandler::HandleShillConnectSuccess( |
| 619 const std::string& service_path) { | 620 const std::string& service_path) { |
| 620 ConnectRequest* request = GetPendingRequest(service_path); | 621 ConnectRequest* request = GetPendingRequest(service_path); |
| 621 if (!request) { | 622 if (!request) { |
| 622 NET_LOG_ERROR("HandleShillConnectSuccess called with no pending request.", | 623 NET_LOG_ERROR("HandleShillConnectSuccess called with no pending request.", |
| 623 service_path); | 624 service_path); |
| 624 return; | 625 return; |
| 625 } | 626 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 637 const std::string& dbus_error_name, | 638 const std::string& dbus_error_name, |
| 638 const std::string& dbus_error_message) { | 639 const std::string& dbus_error_message) { |
| 639 ConnectRequest* request = GetPendingRequest(service_path); | 640 ConnectRequest* request = GetPendingRequest(service_path); |
| 640 if (!request) { | 641 if (!request) { |
| 641 NET_LOG_ERROR("HandleShillConnectFailure called with no pending request.", | 642 NET_LOG_ERROR("HandleShillConnectFailure called with no pending request.", |
| 642 service_path); | 643 service_path); |
| 643 return; | 644 return; |
| 644 } | 645 } |
| 645 network_handler::ErrorCallback error_callback = request->error_callback; | 646 network_handler::ErrorCallback error_callback = request->error_callback; |
| 646 pending_requests_.erase(service_path); | 647 pending_requests_.erase(service_path); |
| 647 network_handler::ShillErrorCallbackFunction( | 648 std::string error; |
| 648 shill::kErrorConnectFailed, service_path, error_callback, | 649 if (dbus_error_name == shill::kErrorResultAlreadyConnected) { |
| 649 dbus_error_name, dbus_error_message); | 650 error = kErrorConnected; |
| 651 } else if (dbus_error_name == shill::kErrorResultInProgress) { |
| 652 error = kErrorConnecting; |
| 653 } else { |
| 654 NET_LOG_ERROR("Connect Failure, Shill error: " + dbus_error_name, |
| 655 service_path); |
| 656 error = kErrorConnectFailed; |
| 657 } |
| 658 InvokeErrorCallback(service_path, error_callback, error); |
| 650 } | 659 } |
| 651 | 660 |
| 652 void NetworkConnectionHandler::CheckPendingRequest( | 661 void NetworkConnectionHandler::CheckPendingRequest( |
| 653 const std::string service_path) { | 662 const std::string service_path) { |
| 654 ConnectRequest* request = GetPendingRequest(service_path); | 663 ConnectRequest* request = GetPendingRequest(service_path); |
| 655 DCHECK(request); | 664 DCHECK(request); |
| 656 if (request->connect_state == ConnectRequest::CONNECT_REQUESTED) | 665 if (request->connect_state == ConnectRequest::CONNECT_REQUESTED) |
| 657 return; // Request has not started, ignore update | 666 return; // Request has not started, ignore update |
| 658 const NetworkState* network = | 667 const NetworkState* network = |
| 659 network_state_handler_->GetNetworkState(service_path); | 668 network_state_handler_->GetNetworkState(service_path); |
| 660 if (!network) | 669 if (!network) |
| 661 return; // NetworkState may not be be updated yet. | 670 return; // NetworkState may not be be updated yet. |
| 662 | 671 |
| 663 if (network->IsConnectingState()) { | 672 if (network->IsConnectingState()) { |
| 664 request->connect_state = ConnectRequest::CONNECT_CONNECTING; | 673 request->connect_state = ConnectRequest::CONNECT_CONNECTING; |
| 665 return; | 674 return; |
| 666 } | 675 } |
| 667 if (network->IsConnectedState()) { | 676 if (network->IsConnectedState()) { |
| 668 NET_LOG_EVENT("Connect Request Succeeded", service_path); | |
| 669 if (!request->profile_path.empty()) { | 677 if (!request->profile_path.empty()) { |
| 670 // If a profile path was specified, set it on a successful connection. | 678 // If a profile path was specified, set it on a successful connection. |
| 671 configuration_handler_->SetNetworkProfile( | 679 configuration_handler_->SetNetworkProfile( |
| 672 service_path, | 680 service_path, |
| 673 request->profile_path, | 681 request->profile_path, |
| 674 NetworkConfigurationObserver::SOURCE_USER_ACTION, | 682 NetworkConfigurationObserver::SOURCE_USER_ACTION, |
| 675 base::Bind(&base::DoNothing), | 683 base::Bind(&base::DoNothing), |
| 676 chromeos::network_handler::ErrorCallback()); | 684 chromeos::network_handler::ErrorCallback()); |
| 677 } | 685 } |
| 678 if (!request->success_callback.is_null()) | 686 InvokeSuccessCallback(request->service_path, request->success_callback); |
| 679 request->success_callback.Run(); | |
| 680 pending_requests_.erase(service_path); | 687 pending_requests_.erase(service_path); |
| 681 return; | 688 return; |
| 682 } | 689 } |
| 683 if (network->connection_state() == shill::kStateIdle && | 690 if (network->connection_state() == shill::kStateIdle && |
| 684 request->connect_state != ConnectRequest::CONNECT_CONNECTING) { | 691 request->connect_state != ConnectRequest::CONNECT_CONNECTING) { |
| 685 // Connection hasn't started yet, keep waiting. | 692 // Connection hasn't started yet, keep waiting. |
| 686 return; | 693 return; |
| 687 } | 694 } |
| 688 | 695 |
| 689 // Network is neither connecting or connected; an error occurred. | 696 // Network is neither connecting or connected; an error occurred. |
| 690 std::string error_name; // 'Canceled' or 'Failed' | 697 std::string error_name; // 'Canceled' or 'Failed' |
| 691 if (network->connection_state() == shill::kStateIdle && | 698 if (network->connection_state() == shill::kStateIdle && |
| 692 pending_requests_.size() > 1) { | 699 pending_requests_.size() > 1) { |
| 693 // Another connect request canceled this one. | 700 // Another connect request canceled this one. |
| 694 error_name = kErrorConnectCanceled; | 701 error_name = kErrorConnectCanceled; |
| 695 } else { | 702 } else { |
| 696 error_name = shill::kErrorConnectFailed; | 703 error_name = kErrorConnectFailed; |
| 697 if (network->connection_state() != shill::kStateFailure) { | 704 if (network->connection_state() != shill::kStateFailure) { |
| 698 NET_LOG_ERROR("Unexpected State: " + network->connection_state(), | 705 NET_LOG_ERROR("Unexpected State: " + network->connection_state(), |
| 699 service_path); | 706 service_path); |
| 700 } | 707 } |
| 701 } | 708 } |
| 702 | 709 |
| 703 network_handler::ErrorCallback error_callback = request->error_callback; | 710 network_handler::ErrorCallback error_callback = request->error_callback; |
| 704 pending_requests_.erase(service_path); | 711 pending_requests_.erase(service_path); |
| 705 if (error_callback.is_null()) { | |
| 706 NET_LOG_ERROR("Connect Error, no callback: " + error_name, service_path); | |
| 707 return; | |
| 708 } | |
| 709 InvokeErrorCallback(service_path, error_callback, error_name); | 712 InvokeErrorCallback(service_path, error_callback, error_name); |
| 710 } | 713 } |
| 711 | 714 |
| 712 void NetworkConnectionHandler::CheckAllPendingRequests() { | 715 void NetworkConnectionHandler::CheckAllPendingRequests() { |
| 713 for (std::map<std::string, ConnectRequest>::iterator iter = | 716 for (std::map<std::string, ConnectRequest>::iterator iter = |
| 714 pending_requests_.begin(); iter != pending_requests_.end(); ++iter) { | 717 pending_requests_.begin(); iter != pending_requests_.end(); ++iter) { |
| 715 CheckPendingRequest(iter->first); | 718 CheckPendingRequest(iter->first); |
| 716 } | 719 } |
| 717 } | 720 } |
| 718 | 721 |
| 722 // Connect callbacks |
| 723 |
| 724 void NetworkConnectionHandler::InvokeSuccessCallback( |
| 725 const std::string& service_path, |
| 726 const base::Closure& success_callback) { |
| 727 NET_LOG_EVENT("Connect Request Succeeded", service_path); |
| 728 if (!success_callback.is_null()) |
| 729 success_callback.Run(); |
| 730 FOR_EACH_OBSERVER(NetworkConnectionObserver, observers_, |
| 731 ConnectSucceeded(service_path)); |
| 732 } |
| 733 |
| 719 void NetworkConnectionHandler::ErrorCallbackForPendingRequest( | 734 void NetworkConnectionHandler::ErrorCallbackForPendingRequest( |
| 720 const std::string& service_path, | 735 const std::string& service_path, |
| 721 const std::string& error_name) { | 736 const std::string& error_name) { |
| 722 ConnectRequest* request = GetPendingRequest(service_path); | 737 ConnectRequest* request = GetPendingRequest(service_path); |
| 723 if (!request) { | 738 if (!request) { |
| 724 NET_LOG_ERROR("ErrorCallbackForPendingRequest with no pending request.", | 739 NET_LOG_ERROR("ErrorCallbackForPendingRequest with no pending request.", |
| 725 service_path); | 740 service_path); |
| 726 return; | 741 return; |
| 727 } | 742 } |
| 728 // Remove the entry before invoking the callback in case it triggers a retry. | 743 // Remove the entry before invoking the callback in case it triggers a retry. |
| 729 network_handler::ErrorCallback error_callback = request->error_callback; | 744 network_handler::ErrorCallback error_callback = request->error_callback; |
| 730 pending_requests_.erase(service_path); | 745 pending_requests_.erase(service_path); |
| 731 InvokeErrorCallback(service_path, error_callback, error_name); | 746 InvokeErrorCallback(service_path, error_callback, error_name); |
| 732 } | 747 } |
| 733 | 748 |
| 749 void NetworkConnectionHandler::InvokeErrorCallback( |
| 750 const std::string& service_path, |
| 751 const network_handler::ErrorCallback& error_callback, |
| 752 const std::string& error_name) { |
| 753 NET_LOG_ERROR("Connect Failure: " + error_name, service_path); |
| 754 network_handler::RunErrorCallback( |
| 755 error_callback, service_path, error_name, ""); |
| 756 FOR_EACH_OBSERVER(NetworkConnectionObserver, observers_, |
| 757 ConnectFailed(service_path, error_name)); |
| 758 } |
| 759 |
| 734 // Disconnect | 760 // Disconnect |
| 735 | 761 |
| 736 void NetworkConnectionHandler::CallShillDisconnect( | 762 void NetworkConnectionHandler::CallShillDisconnect( |
| 737 const std::string& service_path, | 763 const std::string& service_path, |
| 738 const base::Closure& success_callback, | 764 const base::Closure& success_callback, |
| 739 const network_handler::ErrorCallback& error_callback) { | 765 const network_handler::ErrorCallback& error_callback) { |
| 740 NET_LOG_USER("Disconnect Request", service_path); | 766 NET_LOG_USER("Disconnect Request", service_path); |
| 741 DBusThreadManager::Get()->GetShillServiceClient()->Disconnect( | 767 DBusThreadManager::Get()->GetShillServiceClient()->Disconnect( |
| 742 dbus::ObjectPath(service_path), | 768 dbus::ObjectPath(service_path), |
| 743 base::Bind(&NetworkConnectionHandler::HandleShillDisconnectSuccess, | 769 base::Bind(&NetworkConnectionHandler::HandleShillDisconnectSuccess, |
| 744 AsWeakPtr(), service_path, success_callback), | 770 AsWeakPtr(), service_path, success_callback), |
| 745 base::Bind(&network_handler::ShillErrorCallbackFunction, | 771 base::Bind(&network_handler::ShillErrorCallbackFunction, |
| 746 kErrorShillError, service_path, error_callback)); | 772 kErrorDisconnectFailed, service_path, error_callback)); |
| 747 } | 773 } |
| 748 | 774 |
| 749 void NetworkConnectionHandler::HandleShillDisconnectSuccess( | 775 void NetworkConnectionHandler::HandleShillDisconnectSuccess( |
| 750 const std::string& service_path, | 776 const std::string& service_path, |
| 751 const base::Closure& success_callback) { | 777 const base::Closure& success_callback) { |
| 752 NET_LOG_EVENT("Disconnect Request Sent", service_path); | 778 NET_LOG_EVENT("Disconnect Request Sent", service_path); |
| 753 if (!success_callback.is_null()) | 779 if (!success_callback.is_null()) |
| 754 success_callback.Run(); | 780 success_callback.Run(); |
| 755 } | 781 } |
| 756 | 782 |
| 757 } // namespace chromeos | 783 } // namespace chromeos |
| OLD | NEW |