Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(447)

Side by Side Diff: chromeos/network/network_device_handler_impl.cc

Issue 156353002: Implement networkingPrivate.setWifiTDLSEnabledState (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix params passing and add unit test. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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_device_handler_impl.h" 5 #include "chromeos/network/network_device_handler_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/time/time.h"
9 #include "base/values.h" 11 #include "base/values.h"
10 #include "chromeos/dbus/dbus_thread_manager.h" 12 #include "chromeos/dbus/dbus_thread_manager.h"
11 #include "chromeos/dbus/shill_device_client.h" 13 #include "chromeos/dbus/shill_device_client.h"
12 #include "chromeos/dbus/shill_ipconfig_client.h" 14 #include "chromeos/dbus/shill_ipconfig_client.h"
13 #include "chromeos/network/device_state.h" 15 #include "chromeos/network/device_state.h"
14 #include "chromeos/network/network_event_log.h" 16 #include "chromeos/network/network_event_log.h"
15 #include "chromeos/network/network_handler_callbacks.h" 17 #include "chromeos/network/network_handler_callbacks.h"
16 #include "chromeos/network/network_state_handler.h" 18 #include "chromeos/network/network_state_handler.h"
17 #include "chromeos/network/shill_property_util.h" 19 #include "chromeos/network/shill_property_util.h"
18 #include "dbus/object_path.h" 20 #include "dbus/object_path.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 const base::Closure& callback, 129 const base::Closure& callback,
128 const network_handler::ErrorCallback& error_callback) { 130 const network_handler::ErrorCallback& error_callback) {
129 DBusThreadManager::Get()->GetShillDeviceClient()->SetProperty( 131 DBusThreadManager::Get()->GetShillDeviceClient()->SetProperty(
130 dbus::ObjectPath(device_path), 132 dbus::ObjectPath(device_path),
131 property_name, 133 property_name,
132 value, 134 value,
133 callback, 135 callback,
134 base::Bind(&HandleShillCallFailure, device_path, error_callback)); 136 base::Bind(&HandleShillCallFailure, device_path, error_callback));
135 } 137 }
136 138
139 // Struct containing TDLS Operation parameters.
140 struct TDLSOperationParams {
141 TDLSOperationParams() : retry_count(0) {}
142 std::string operation;
143 std::string ip_or_mac_address;
144 int retry_count;
145 };
146
147 // Forward declare for PostDelayedTask.
148 void CallPerformTDLSOperation(
149 const std::string& device_path,
150 const TDLSOperationParams& params,
151 const network_handler::StringResultCallback& callback,
152 const network_handler::ErrorCallback& error_callback);
153
154 void TDLSSuccessCallback(
155 const std::string& device_path,
156 const TDLSOperationParams& params,
157 const network_handler::StringResultCallback& callback,
158 const network_handler::ErrorCallback& error_callback,
159 const std::string& result) {
160 std::string event_desc = "TDLSSuccessCallback: " + params.operation;
161 if (!result.empty())
162 event_desc += ": " + result;
163 NET_LOG_EVENT(event_desc, device_path);
164 if (params.operation != shill::kTDLSSetupOperation) {
165 if (!callback.is_null())
166 callback.Run(result);
167 return;
168 }
169
170 if (!result.empty())
171 NET_LOG_ERROR("Unexpected TDLS result: " + result, device_path);
172
173 // Send a delayed Status request after a successful Setup call.
174 TDLSOperationParams status_params;
175 status_params.operation = shill::kTDLSStatusOperation;
176 status_params.ip_or_mac_address = params.ip_or_mac_address;
177
178 const int64 kRequestStatusDelayMs = 500;
179 base::TimeDelta request_delay;
180 if (!DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface())
181 request_delay = base::TimeDelta::FromMilliseconds(kRequestStatusDelayMs);
182
183 base::MessageLoopProxy::current()->PostDelayedTask(
184 FROM_HERE,
185 base::Bind(&CallPerformTDLSOperation,
186 device_path, status_params, callback, error_callback),
Paul Stewart 2014/02/13 21:58:46 This won't go well. You're passing a reference to
stevenjb 2014/02/13 22:38:46 base::Bind handles that, it's some super subtle/cl
187 request_delay);
188 }
189
190 void TDLSErrorCallback(
191 const std::string& device_path,
192 const TDLSOperationParams& params,
193 const network_handler::StringResultCallback& callback,
194 const network_handler::ErrorCallback& error_callback,
195 const std::string& dbus_error_name,
196 const std::string& dbus_error_message) {
197 // If a Setup operation receives an InProgress error, retry.
198 const int kMaxRetries = 5;
199 if (params.operation == shill::kTDLSSetupOperation &&
200 dbus_error_name == shill::kErrorResultInProgress &&
201 params.retry_count < kMaxRetries) {
202 TDLSOperationParams retry_params = params;
203 ++retry_params.retry_count;
204 NET_LOG_EVENT(base::StringPrintf("TDLS Retry: %d", params.retry_count),
205 device_path);
206 const int64 kReRequestDelayMs = 1000;
207 base::TimeDelta request_delay;
208 if (!DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface())
209 request_delay = base::TimeDelta::FromMilliseconds(kReRequestDelayMs);
210
211 base::MessageLoopProxy::current()->PostDelayedTask(
212 FROM_HERE,
213 base::Bind(&CallPerformTDLSOperation,
214 device_path, retry_params, callback, error_callback),
215 request_delay);
216 return;
217 }
218
219 NET_LOG_ERROR("TDLS Error:" + dbus_error_name + ":" + dbus_error_message,
220 device_path);
221 if (error_callback.is_null())
222 return;
223
224 const std::string error_name =
225 dbus_error_name == shill::kErrorResultInProgress ?
226 NetworkDeviceHandler::kErrorTimeout : NetworkDeviceHandler::kErrorUnknown;
227 const std::string& error_detail = params.ip_or_mac_address;
228 scoped_ptr<base::DictionaryValue> error_data(
229 network_handler::CreateDBusErrorData(
230 device_path, error_name, error_detail,
231 dbus_error_name, dbus_error_message));
232 error_callback.Run(error_name, error_data.Pass());
233 }
234
235 void CallPerformTDLSOperation(
236 const std::string& device_path,
237 const TDLSOperationParams& params,
238 const network_handler::StringResultCallback& callback,
239 const network_handler::ErrorCallback& error_callback) {
240 NET_LOG_EVENT("CallPerformTDLSOperation: " + params.operation, device_path);
241 DBusThreadManager::Get()->GetShillDeviceClient()->PerformTDLSOperation(
242 dbus::ObjectPath(device_path),
243 params.operation,
244 params.ip_or_mac_address,
245 base::Bind(&TDLSSuccessCallback,
246 device_path, params, callback, error_callback),
247 base::Bind(&TDLSErrorCallback,
248 device_path, params, callback, error_callback));
249 }
250
137 } // namespace 251 } // namespace
138 252
139 NetworkDeviceHandlerImpl::~NetworkDeviceHandlerImpl() { 253 NetworkDeviceHandlerImpl::~NetworkDeviceHandlerImpl() {
140 network_state_handler_->RemoveObserver(this, FROM_HERE); 254 network_state_handler_->RemoveObserver(this, FROM_HERE);
141 } 255 }
142 256
143 void NetworkDeviceHandlerImpl::GetDeviceProperties( 257 void NetworkDeviceHandlerImpl::GetDeviceProperties(
144 const std::string& device_path, 258 const std::string& device_path,
145 const network_handler::DictionaryResultCallback& callback, 259 const network_handler::DictionaryResultCallback& callback,
146 const network_handler::ErrorCallback& error_callback) const { 260 const network_handler::ErrorCallback& error_callback) const {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 callback, 385 callback,
272 base::Bind(&HandleShillCallFailure, device_path, error_callback)); 386 base::Bind(&HandleShillCallFailure, device_path, error_callback));
273 } 387 }
274 388
275 void NetworkDeviceHandlerImpl::SetCellularAllowRoaming( 389 void NetworkDeviceHandlerImpl::SetCellularAllowRoaming(
276 const bool allow_roaming) { 390 const bool allow_roaming) {
277 cellular_allow_roaming_ = allow_roaming; 391 cellular_allow_roaming_ = allow_roaming;
278 ApplyCellularAllowRoamingToShill(); 392 ApplyCellularAllowRoamingToShill();
279 } 393 }
280 394
395 void NetworkDeviceHandlerImpl::SetWifiTDLSEnabled(
396 const std::string& ip_or_mac_address,
397 bool enabled,
398 const network_handler::StringResultCallback& callback,
399 const network_handler::ErrorCallback& error_callback) {
400 const DeviceState* device_state =
401 network_state_handler_->GetDeviceStateByType(NetworkTypePattern::WiFi());
402 if (!device_state) {
403 if (error_callback.is_null())
404 return;
405 scoped_ptr<base::DictionaryValue> error_data(new base::DictionaryValue);
406 error_data->SetString(network_handler::kErrorName, kErrorDeviceMissing);
407 error_callback.Run(kErrorDeviceMissing, error_data.Pass());
408 return;
409 }
410 TDLSOperationParams params;
411 params.operation = enabled ? shill::kTDLSSetupOperation
412 : shill::kTDLSTeardownOperation;
413 params.ip_or_mac_address = ip_or_mac_address;
414 CallPerformTDLSOperation(
415 device_state->path(), params, callback, error_callback);
416 }
417
418 void NetworkDeviceHandlerImpl::GetWifiTDLSStatus(
419 const std::string& ip_or_mac_address,
420 const network_handler::StringResultCallback& callback,
421 const network_handler::ErrorCallback& error_callback) {
422 const DeviceState* device_state =
423 network_state_handler_->GetDeviceStateByType(NetworkTypePattern::WiFi());
424 if (!device_state) {
425 if (error_callback.is_null())
426 return;
427 scoped_ptr<base::DictionaryValue> error_data(new base::DictionaryValue);
428 error_data->SetString(network_handler::kErrorName, kErrorDeviceMissing);
429 error_callback.Run(kErrorDeviceMissing, error_data.Pass());
430 return;
431 }
432 TDLSOperationParams params;
433 params.operation = shill::kTDLSStatusOperation;
434 params.ip_or_mac_address = ip_or_mac_address;
435 CallPerformTDLSOperation(
436 device_state->path(), params, callback, error_callback);
437 }
438
281 void NetworkDeviceHandlerImpl::DeviceListChanged() { 439 void NetworkDeviceHandlerImpl::DeviceListChanged() {
282 ApplyCellularAllowRoamingToShill(); 440 ApplyCellularAllowRoamingToShill();
283 } 441 }
284 442
285 NetworkDeviceHandlerImpl::NetworkDeviceHandlerImpl() 443 NetworkDeviceHandlerImpl::NetworkDeviceHandlerImpl()
286 : network_state_handler_(NULL), 444 : network_state_handler_(NULL),
287 cellular_allow_roaming_(false) {} 445 cellular_allow_roaming_(false) {}
288 446
289 void NetworkDeviceHandlerImpl::Init( 447 void NetworkDeviceHandlerImpl::Init(
290 NetworkStateHandler* network_state_handler) { 448 NetworkStateHandler* network_state_handler) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 484
327 SetDevicePropertyInternal(device_state->path(), 485 SetDevicePropertyInternal(device_state->path(),
328 shill::kCellularAllowRoamingProperty, 486 shill::kCellularAllowRoamingProperty,
329 base::FundamentalValue(new_device_value), 487 base::FundamentalValue(new_device_value),
330 base::Bind(&base::DoNothing), 488 base::Bind(&base::DoNothing),
331 network_handler::ErrorCallback()); 489 network_handler::ErrorCallback());
332 } 490 }
333 } 491 }
334 492
335 } // namespace chromeos 493 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/network_device_handler_impl.h ('k') | chromeos/network/network_device_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698