| 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/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 if (queued_connect_) | 219 if (queued_connect_) |
| 220 ConnectToQueuedNetwork(); | 220 ConnectToQueuedNetwork(); |
| 221 } | 221 } |
| 222 | 222 |
| 223 void NetworkConnectionHandler::ConnectToNetwork( | 223 void NetworkConnectionHandler::ConnectToNetwork( |
| 224 const std::string& service_path, | 224 const std::string& service_path, |
| 225 const base::Closure& success_callback, | 225 const base::Closure& success_callback, |
| 226 const network_handler::ErrorCallback& error_callback, | 226 const network_handler::ErrorCallback& error_callback, |
| 227 bool check_error_state) { | 227 bool check_error_state) { |
| 228 NET_LOG_USER("ConnectToNetwork", service_path); | 228 NET_LOG_USER("ConnectToNetwork", service_path); |
| 229 FOR_EACH_OBSERVER(NetworkConnectionObserver, observers_, | 229 for (auto& observer : observers_) |
| 230 ConnectToNetworkRequested(service_path)); | 230 observer.ConnectToNetworkRequested(service_path); |
| 231 | 231 |
| 232 // Clear any existing queued connect request. | 232 // Clear any existing queued connect request. |
| 233 queued_connect_.reset(); | 233 queued_connect_.reset(); |
| 234 if (HasConnectingNetwork(service_path)) { | 234 if (HasConnectingNetwork(service_path)) { |
| 235 NET_LOG_USER("Connect Request While Pending", service_path); | 235 NET_LOG_USER("Connect Request While Pending", service_path); |
| 236 InvokeConnectErrorCallback(service_path, error_callback, kErrorConnecting); | 236 InvokeConnectErrorCallback(service_path, error_callback, kErrorConnecting); |
| 237 return; | 237 return; |
| 238 } | 238 } |
| 239 | 239 |
| 240 // Check cached network state for connected, connecting, or unactivated | 240 // Check cached network state for connected, connecting, or unactivated |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 AsWeakPtr(), check_error_state), | 306 AsWeakPtr(), check_error_state), |
| 307 base::Bind(&NetworkConnectionHandler::HandleConfigurationFailure, | 307 base::Bind(&NetworkConnectionHandler::HandleConfigurationFailure, |
| 308 AsWeakPtr(), service_path)); | 308 AsWeakPtr(), service_path)); |
| 309 } | 309 } |
| 310 | 310 |
| 311 void NetworkConnectionHandler::DisconnectNetwork( | 311 void NetworkConnectionHandler::DisconnectNetwork( |
| 312 const std::string& service_path, | 312 const std::string& service_path, |
| 313 const base::Closure& success_callback, | 313 const base::Closure& success_callback, |
| 314 const network_handler::ErrorCallback& error_callback) { | 314 const network_handler::ErrorCallback& error_callback) { |
| 315 NET_LOG_USER("DisconnectNetwork", service_path); | 315 NET_LOG_USER("DisconnectNetwork", service_path); |
| 316 FOR_EACH_OBSERVER(NetworkConnectionObserver, observers_, | 316 for (auto& observer : observers_) |
| 317 DisconnectRequested(service_path)); | 317 observer.DisconnectRequested(service_path); |
| 318 | 318 |
| 319 const NetworkState* network = | 319 const NetworkState* network = |
| 320 network_state_handler_->GetNetworkState(service_path); | 320 network_state_handler_->GetNetworkState(service_path); |
| 321 if (!network) { | 321 if (!network) { |
| 322 NET_LOG_ERROR("Disconnect Error: Not Found", service_path); | 322 NET_LOG_ERROR("Disconnect Error: Not Found", service_path); |
| 323 network_handler::RunErrorCallback(error_callback, service_path, | 323 network_handler::RunErrorCallback(error_callback, service_path, |
| 324 kErrorNotFound, ""); | 324 kErrorNotFound, ""); |
| 325 return; | 325 return; |
| 326 } | 326 } |
| 327 if (!network->IsConnectedState() && !network->IsConnectingState()) { | 327 if (!network->IsConnectedState() && !network->IsConnectingState()) { |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 } | 755 } |
| 756 | 756 |
| 757 // Connect callbacks | 757 // Connect callbacks |
| 758 | 758 |
| 759 void NetworkConnectionHandler::InvokeConnectSuccessCallback( | 759 void NetworkConnectionHandler::InvokeConnectSuccessCallback( |
| 760 const std::string& service_path, | 760 const std::string& service_path, |
| 761 const base::Closure& success_callback) { | 761 const base::Closure& success_callback) { |
| 762 NET_LOG_EVENT("Connect Request Succeeded", service_path); | 762 NET_LOG_EVENT("Connect Request Succeeded", service_path); |
| 763 if (!success_callback.is_null()) | 763 if (!success_callback.is_null()) |
| 764 success_callback.Run(); | 764 success_callback.Run(); |
| 765 FOR_EACH_OBSERVER(NetworkConnectionObserver, observers_, | 765 for (auto& observer : observers_) |
| 766 ConnectSucceeded(service_path)); | 766 observer.ConnectSucceeded(service_path); |
| 767 } | 767 } |
| 768 | 768 |
| 769 void NetworkConnectionHandler::ErrorCallbackForPendingRequest( | 769 void NetworkConnectionHandler::ErrorCallbackForPendingRequest( |
| 770 const std::string& service_path, | 770 const std::string& service_path, |
| 771 const std::string& error_name) { | 771 const std::string& error_name) { |
| 772 ConnectRequest* request = GetPendingRequest(service_path); | 772 ConnectRequest* request = GetPendingRequest(service_path); |
| 773 if (!request) { | 773 if (!request) { |
| 774 NET_LOG_ERROR("ErrorCallbackForPendingRequest with no pending request.", | 774 NET_LOG_ERROR("ErrorCallbackForPendingRequest with no pending request.", |
| 775 service_path); | 775 service_path); |
| 776 return; | 776 return; |
| 777 } | 777 } |
| 778 // Remove the entry before invoking the callback in case it triggers a retry. | 778 // Remove the entry before invoking the callback in case it triggers a retry. |
| 779 network_handler::ErrorCallback error_callback = request->error_callback; | 779 network_handler::ErrorCallback error_callback = request->error_callback; |
| 780 pending_requests_.erase(service_path); | 780 pending_requests_.erase(service_path); |
| 781 InvokeConnectErrorCallback(service_path, error_callback, error_name); | 781 InvokeConnectErrorCallback(service_path, error_callback, error_name); |
| 782 } | 782 } |
| 783 | 783 |
| 784 void NetworkConnectionHandler::InvokeConnectErrorCallback( | 784 void NetworkConnectionHandler::InvokeConnectErrorCallback( |
| 785 const std::string& service_path, | 785 const std::string& service_path, |
| 786 const network_handler::ErrorCallback& error_callback, | 786 const network_handler::ErrorCallback& error_callback, |
| 787 const std::string& error_name) { | 787 const std::string& error_name) { |
| 788 NET_LOG_ERROR("Connect Failure: " + error_name, service_path); | 788 NET_LOG_ERROR("Connect Failure: " + error_name, service_path); |
| 789 network_handler::RunErrorCallback(error_callback, service_path, error_name, | 789 network_handler::RunErrorCallback(error_callback, service_path, error_name, |
| 790 ""); | 790 ""); |
| 791 FOR_EACH_OBSERVER(NetworkConnectionObserver, observers_, | 791 for (auto& observer : observers_) |
| 792 ConnectFailed(service_path, error_name)); | 792 observer.ConnectFailed(service_path, error_name); |
| 793 } | 793 } |
| 794 | 794 |
| 795 // Disconnect | 795 // Disconnect |
| 796 | 796 |
| 797 void NetworkConnectionHandler::CallShillDisconnect( | 797 void NetworkConnectionHandler::CallShillDisconnect( |
| 798 const std::string& service_path, | 798 const std::string& service_path, |
| 799 const base::Closure& success_callback, | 799 const base::Closure& success_callback, |
| 800 const network_handler::ErrorCallback& error_callback) { | 800 const network_handler::ErrorCallback& error_callback) { |
| 801 NET_LOG_USER("Disconnect Request", service_path); | 801 NET_LOG_USER("Disconnect Request", service_path); |
| 802 DBusThreadManager::Get()->GetShillServiceClient()->Disconnect( | 802 DBusThreadManager::Get()->GetShillServiceClient()->Disconnect( |
| 803 dbus::ObjectPath(service_path), | 803 dbus::ObjectPath(service_path), |
| 804 base::Bind(&NetworkConnectionHandler::HandleShillDisconnectSuccess, | 804 base::Bind(&NetworkConnectionHandler::HandleShillDisconnectSuccess, |
| 805 AsWeakPtr(), service_path, success_callback), | 805 AsWeakPtr(), service_path, success_callback), |
| 806 base::Bind(&network_handler::ShillErrorCallbackFunction, | 806 base::Bind(&network_handler::ShillErrorCallbackFunction, |
| 807 kErrorDisconnectFailed, service_path, error_callback)); | 807 kErrorDisconnectFailed, service_path, error_callback)); |
| 808 } | 808 } |
| 809 | 809 |
| 810 void NetworkConnectionHandler::HandleShillDisconnectSuccess( | 810 void NetworkConnectionHandler::HandleShillDisconnectSuccess( |
| 811 const std::string& service_path, | 811 const std::string& service_path, |
| 812 const base::Closure& success_callback) { | 812 const base::Closure& success_callback) { |
| 813 NET_LOG_EVENT("Disconnect Request Sent", service_path); | 813 NET_LOG_EVENT("Disconnect Request Sent", service_path); |
| 814 if (!success_callback.is_null()) | 814 if (!success_callback.is_null()) |
| 815 success_callback.Run(); | 815 success_callback.Run(); |
| 816 } | 816 } |
| 817 | 817 |
| 818 } // namespace chromeos | 818 } // namespace chromeos |
| OLD | NEW |