Index: chromeos/network/network_device_handler_impl.cc |
diff --git a/chromeos/network/network_device_handler_impl.cc b/chromeos/network/network_device_handler_impl.cc |
index 6728546c99004c502fbe21773461959ca279d610..35577539b829239325a9cf703366bfce997b8ee1 100644 |
--- a/chromeos/network/network_device_handler_impl.cc |
+++ b/chromeos/network/network_device_handler_impl.cc |
@@ -6,6 +6,8 @@ |
#include "base/bind.h" |
#include "base/location.h" |
+#include "base/message_loop/message_loop_proxy.h" |
+#include "base/time/time.h" |
#include "base/values.h" |
#include "chromeos/dbus/dbus_thread_manager.h" |
#include "chromeos/dbus/shill_device_client.h" |
@@ -134,6 +136,89 @@ void SetDevicePropertyInternal( |
base::Bind(&HandleShillCallFailure, device_path, error_callback)); |
} |
+// Forward declare for PostDelayedTask. |
+void CallPerformTDLSOperation( |
+ const std::string& device_path, |
+ const std::string& operation, |
+ int retry_count, |
+ const std::string& ip_or_mac_address, |
+ const network_handler::StringResultCallback& callback, |
+ const network_handler::ErrorCallback& error_callback); |
+ |
+void TDLSOperationCallback( |
+ const std::string& device_path, |
+ const std::string& operation, |
+ int retry_count, |
+ const std::string& ip_or_mac_address, |
+ const network_handler::StringResultCallback& callback, |
+ const network_handler::ErrorCallback& error_callback, |
+ const std::string& result) { |
+ std::string event_desc = "TDLSOperationCallback: " + operation; |
+ if (!result.empty()) |
+ event_desc += ": " + result; |
+ NET_LOG_EVENT(event_desc, device_path); |
+ if (operation != shill::kTDLSSetupOperation) { |
+ if (!callback.is_null()) |
+ callback.Run(result); |
+ return; |
+ } |
+ |
+ // Handle 'Setup' |
+ std::string next_operation; |
+ base::TimeDelta request_delay; |
+ const int kMaxRetries = 5; |
+ if (result.empty()) { |
+ // Success, request Status after a short delay. |
+ const int64 kRequestStatusDelayMs = 500; |
+ next_operation = shill::kTDLSStatusOperation; |
+ request_delay = base::TimeDelta::FromMilliseconds(kRequestStatusDelayMs); |
+ } else if (result == shill::kErrorResultInProgress && |
Paul Stewart
2014/02/13 19:46:06
I don't think this will work the way you think it
stevenjb
2014/02/13 20:58:27
Ugh, right, I should have realized that. Will a su
Paul Stewart
2014/02/13 21:06:30
The only time PerformTDLSOperation (conventionally
|
+ retry_count < kMaxRetries) { |
+ // InProgress error: retry. |
+ const int64 kReRequestDelayMs = 1000; |
+ next_operation = shill::kTDLSSetupOperation; |
+ request_delay = base::TimeDelta::FromMilliseconds(kReRequestDelayMs); |
+ ++retry_count; |
+ } else { |
+ // Other error: fail. |
+ NET_LOG_ERROR("TDLSOperation Failed: " + result, device_path); |
+ if (!error_callback.is_null()) { |
+ scoped_ptr<base::DictionaryValue> error_data(new base::DictionaryValue); |
+ error_data->SetString(network_handler::kErrorName, result); |
+ error_callback.Run(result, error_data.Pass()); |
+ } |
+ return; |
+ } |
+ |
+ base::MessageLoopProxy::current()->PostDelayedTask( |
+ FROM_HERE, |
+ base::Bind(&CallPerformTDLSOperation, |
+ device_path, next_operation, retry_count, ip_or_mac_address, |
+ callback, error_callback), |
+ request_delay); |
+} |
+ |
+void CallPerformTDLSOperation( |
+ const std::string& device_path, |
+ const std::string& operation, |
+ int retry_count, |
+ const std::string& ip_or_mac_address, |
+ const network_handler::StringResultCallback& callback, |
+ const network_handler::ErrorCallback& error_callback) { |
+ NET_LOG_EVENT("CallPerformTDLSOperation: " + operation, device_path); |
+ DBusThreadManager::Get()->GetShillDeviceClient()->PerformTDLSOperation( |
+ dbus::ObjectPath(device_path), |
+ operation, |
+ ip_or_mac_address, |
+ base::Bind(&TDLSOperationCallback, |
+ device_path, operation, retry_count, ip_or_mac_address, |
+ callback, error_callback), |
+ base::Bind(&network_handler::ShillErrorCallbackFunction, |
+ "Device.PerformTDLSOperation Failed: " + operation, |
+ device_path, |
+ error_callback)); |
+} |
+ |
} // namespace |
NetworkDeviceHandlerImpl::~NetworkDeviceHandlerImpl() { |
@@ -278,6 +363,48 @@ void NetworkDeviceHandlerImpl::SetCellularAllowRoaming( |
ApplyCellularAllowRoamingToShill(); |
} |
+void NetworkDeviceHandlerImpl::SetWifiTDLSEnabled( |
+ const std::string& ip_or_mac_address, |
+ bool enabled, |
+ const network_handler::StringResultCallback& callback, |
+ const network_handler::ErrorCallback& error_callback) { |
+ const DeviceState* device_state = |
+ network_state_handler_->GetDeviceStateByType(NetworkTypePattern::WiFi()); |
+ if (!device_state) { |
+ if (error_callback.is_null()) |
+ return; |
+ scoped_ptr<base::DictionaryValue> error_data(new base::DictionaryValue); |
+ error_data->SetString(network_handler::kErrorName, kErrorDeviceMissing); |
+ error_callback.Run(kErrorDeviceMissing, error_data.Pass()); |
+ return; |
+ } |
+ std::string operation = enabled ? shill::kTDLSSetupOperation |
+ : shill::kTDLSTeardownOperation; |
+ CallPerformTDLSOperation(device_state->path(), |
+ operation, 0, ip_or_mac_address, |
+ callback, error_callback); |
+} |
+ |
+void NetworkDeviceHandlerImpl::GetWifiTDLSStatus( |
+ const std::string& ip_or_mac_address, |
+ const network_handler::StringResultCallback& callback, |
+ const network_handler::ErrorCallback& error_callback) { |
+ const DeviceState* device_state = |
+ network_state_handler_->GetDeviceStateByType(NetworkTypePattern::WiFi()); |
+ if (!device_state) { |
+ if (error_callback.is_null()) |
+ return; |
+ scoped_ptr<base::DictionaryValue> error_data(new base::DictionaryValue); |
+ error_data->SetString(network_handler::kErrorName, kErrorDeviceMissing); |
+ error_callback.Run(kErrorDeviceMissing, error_data.Pass()); |
+ return; |
+ } |
+ std::string operation = shill::kTDLSStatusOperation; |
+ CallPerformTDLSOperation(device_state->path(), |
+ operation, 0, ip_or_mac_address, |
+ callback, error_callback); |
+} |
+ |
void NetworkDeviceHandlerImpl::DeviceListChanged() { |
ApplyCellularAllowRoamingToShill(); |
} |