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

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

Issue 722043004: Clean up wake on wifi handling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
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" 9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 const bool allow_roaming) { 391 const bool allow_roaming) {
392 cellular_allow_roaming_ = allow_roaming; 392 cellular_allow_roaming_ = allow_roaming;
393 ApplyCellularAllowRoamingToShill(); 393 ApplyCellularAllowRoamingToShill();
394 } 394 }
395 395
396 void NetworkDeviceHandlerImpl::SetWifiTDLSEnabled( 396 void NetworkDeviceHandlerImpl::SetWifiTDLSEnabled(
397 const std::string& ip_or_mac_address, 397 const std::string& ip_or_mac_address,
398 bool enabled, 398 bool enabled,
399 const network_handler::StringResultCallback& callback, 399 const network_handler::StringResultCallback& callback,
400 const network_handler::ErrorCallback& error_callback) { 400 const network_handler::ErrorCallback& error_callback) {
401 const DeviceState* device_state = 401 const DeviceState* device_state = GetWifiDeviceState(error_callback);
402 network_state_handler_->GetDeviceStateByType(NetworkTypePattern::WiFi()); 402 if (!device_state)
403 if (!device_state) {
404 if (error_callback.is_null())
405 return;
406 scoped_ptr<base::DictionaryValue> error_data(new base::DictionaryValue);
407 error_data->SetString(network_handler::kErrorName, kErrorDeviceMissing);
408 error_callback.Run(kErrorDeviceMissing, error_data.Pass());
409 return; 403 return;
410 } 404
411 TDLSOperationParams params; 405 TDLSOperationParams params;
412 params.operation = enabled ? shill::kTDLSSetupOperation 406 params.operation = enabled ? shill::kTDLSSetupOperation
413 : shill::kTDLSTeardownOperation; 407 : shill::kTDLSTeardownOperation;
414 params.ip_or_mac_address = ip_or_mac_address; 408 params.ip_or_mac_address = ip_or_mac_address;
415 CallPerformTDLSOperation( 409 CallPerformTDLSOperation(
416 device_state->path(), params, callback, error_callback); 410 device_state->path(), params, callback, error_callback);
417 } 411 }
418 412
419 void NetworkDeviceHandlerImpl::GetWifiTDLSStatus( 413 void NetworkDeviceHandlerImpl::GetWifiTDLSStatus(
420 const std::string& ip_or_mac_address, 414 const std::string& ip_or_mac_address,
421 const network_handler::StringResultCallback& callback, 415 const network_handler::StringResultCallback& callback,
422 const network_handler::ErrorCallback& error_callback) { 416 const network_handler::ErrorCallback& error_callback) {
423 const DeviceState* device_state = 417 const DeviceState* device_state = GetWifiDeviceState(error_callback);
424 network_state_handler_->GetDeviceStateByType(NetworkTypePattern::WiFi()); 418 if (!device_state)
425 if (!device_state) {
426 if (error_callback.is_null())
427 return;
428 scoped_ptr<base::DictionaryValue> error_data(new base::DictionaryValue);
429 error_data->SetString(network_handler::kErrorName, kErrorDeviceMissing);
430 error_callback.Run(kErrorDeviceMissing, error_data.Pass());
431 return; 419 return;
432 } 420
433 TDLSOperationParams params; 421 TDLSOperationParams params;
434 params.operation = shill::kTDLSStatusOperation; 422 params.operation = shill::kTDLSStatusOperation;
435 params.ip_or_mac_address = ip_or_mac_address; 423 params.ip_or_mac_address = ip_or_mac_address;
436 CallPerformTDLSOperation( 424 CallPerformTDLSOperation(
437 device_state->path(), params, callback, error_callback); 425 device_state->path(), params, callback, error_callback);
438 } 426 }
439 427
428 void NetworkDeviceHandlerImpl::AddWifiWakeOnPacketConnection(
429 const net::IPEndPoint& ip_endpoint,
430 const base::Closure& callback,
431 const network_handler::ErrorCallback& error_callback) {
432 const DeviceState* device_state = GetWifiDeviceState(error_callback);
433 if (!device_state)
434 return;
435
436 DBusThreadManager::Get()->GetShillDeviceClient()->AddWakeOnPacketConnection(
437 dbus::ObjectPath(device_state->path()),
438 ip_endpoint,
439 callback,
440 base::Bind(&HandleShillCallFailure,
441 device_state->path(),
442 error_callback));
443 }
444
445 void NetworkDeviceHandlerImpl::RemoveWifiWakeOnPacketConnection(
446 const net::IPEndPoint& ip_endpoint,
447 const base::Closure& callback,
448 const network_handler::ErrorCallback& error_callback) {
449 const DeviceState* device_state = GetWifiDeviceState(error_callback);
450 if (!device_state)
451 return;
452
453 DBusThreadManager::Get()
454 ->GetShillDeviceClient()
455 ->RemoveWakeOnPacketConnection(dbus::ObjectPath(device_state->path()),
456 ip_endpoint,
457 callback,
458 base::Bind(&HandleShillCallFailure,
459 device_state->path(),
460 error_callback));
461 }
462
463 void NetworkDeviceHandlerImpl::RemoveAllWifiWakeOnPacketConnections(
464 const base::Closure& callback,
465 const network_handler::ErrorCallback& error_callback) {
466 const DeviceState* device_state = GetWifiDeviceState(error_callback);
467 if (!device_state)
468 return;
469
470 DBusThreadManager::Get()
471 ->GetShillDeviceClient()
472 ->RemoveAllWakeOnPacketConnections(dbus::ObjectPath(device_state->path()),
473 callback,
474 base::Bind(&HandleShillCallFailure,
475 device_state->path(),
476 error_callback));
477 }
478
440 void NetworkDeviceHandlerImpl::DeviceListChanged() { 479 void NetworkDeviceHandlerImpl::DeviceListChanged() {
441 ApplyCellularAllowRoamingToShill(); 480 ApplyCellularAllowRoamingToShill();
442 } 481 }
443 482
444 NetworkDeviceHandlerImpl::NetworkDeviceHandlerImpl() 483 NetworkDeviceHandlerImpl::NetworkDeviceHandlerImpl()
445 : network_state_handler_(NULL), 484 : network_state_handler_(NULL),
446 cellular_allow_roaming_(false) {} 485 cellular_allow_roaming_(false) {}
447 486
448 void NetworkDeviceHandlerImpl::Init( 487 void NetworkDeviceHandlerImpl::Init(
449 NetworkStateHandler* network_state_handler) { 488 NetworkStateHandler* network_state_handler) {
(...skipping 26 matching lines...) Expand all
476 continue; 515 continue;
477 516
478 SetDevicePropertyInternal(device_state->path(), 517 SetDevicePropertyInternal(device_state->path(),
479 shill::kCellularAllowRoamingProperty, 518 shill::kCellularAllowRoamingProperty,
480 base::FundamentalValue(new_device_value), 519 base::FundamentalValue(new_device_value),
481 base::Bind(&base::DoNothing), 520 base::Bind(&base::DoNothing),
482 network_handler::ErrorCallback()); 521 network_handler::ErrorCallback());
483 } 522 }
484 } 523 }
485 524
525 const DeviceState* NetworkDeviceHandlerImpl::GetWifiDeviceState(
526 const network_handler::ErrorCallback& error_callback) {
527 const DeviceState* device_state =
528 network_state_handler_->GetDeviceStateByType(NetworkTypePattern::WiFi());
529 if (!device_state) {
530 if (error_callback.is_null())
531 return NULL;
532 scoped_ptr<base::DictionaryValue> error_data(new base::DictionaryValue);
533 error_data->SetString(network_handler::kErrorName, kErrorDeviceMissing);
534 error_callback.Run(kErrorDeviceMissing, error_data.Pass());
535 return NULL;
536 }
537
538 return device_state;
539 }
540
486 } // namespace chromeos 541 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698