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