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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 } | 427 } |
428 | 428 |
429 void NetworkDeviceHandlerImpl::SetCellularAllowRoaming( | 429 void NetworkDeviceHandlerImpl::SetCellularAllowRoaming( |
430 const bool allow_roaming) { | 430 const bool allow_roaming) { |
431 cellular_allow_roaming_ = allow_roaming; | 431 cellular_allow_roaming_ = allow_roaming; |
432 ApplyCellularAllowRoamingToShill(); | 432 ApplyCellularAllowRoamingToShill(); |
433 } | 433 } |
434 | 434 |
435 void NetworkDeviceHandlerImpl::SetMACAddressRandomizationEnabled( | 435 void NetworkDeviceHandlerImpl::SetMACAddressRandomizationEnabled( |
436 const bool enabled) { | 436 const bool enabled) { |
437 mac_addr_randomization_ = enabled; | 437 mac_addr_randomization_enabled_ = enabled; |
438 ApplyMACAddressRandomizationToShill(); | 438 ApplyMACAddressRandomizationToShill(); |
439 } | 439 } |
440 | 440 |
441 void NetworkDeviceHandlerImpl::SetWifiTDLSEnabled( | 441 void NetworkDeviceHandlerImpl::SetWifiTDLSEnabled( |
442 const std::string& ip_or_mac_address, | 442 const std::string& ip_or_mac_address, |
443 bool enabled, | 443 bool enabled, |
444 const network_handler::StringResultCallback& callback, | 444 const network_handler::StringResultCallback& callback, |
445 const network_handler::ErrorCallback& error_callback) { | 445 const network_handler::ErrorCallback& error_callback) { |
446 const DeviceState* device_state = GetWifiDeviceState(error_callback); | 446 const DeviceState* device_state = GetWifiDeviceState(error_callback); |
447 if (!device_state) | 447 if (!device_state) |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 } | 525 } |
526 | 526 |
527 void NetworkDeviceHandlerImpl::DeviceListChanged() { | 527 void NetworkDeviceHandlerImpl::DeviceListChanged() { |
528 ApplyCellularAllowRoamingToShill(); | 528 ApplyCellularAllowRoamingToShill(); |
529 ApplyMACAddressRandomizationToShill(); | 529 ApplyMACAddressRandomizationToShill(); |
530 } | 530 } |
531 | 531 |
532 NetworkDeviceHandlerImpl::NetworkDeviceHandlerImpl() | 532 NetworkDeviceHandlerImpl::NetworkDeviceHandlerImpl() |
533 : network_state_handler_(NULL), | 533 : network_state_handler_(NULL), |
534 cellular_allow_roaming_(false), | 534 cellular_allow_roaming_(false), |
535 mac_addr_randomization_(false) {} | 535 mac_addr_randomization_supported_(true), |
| 536 mac_addr_randomization_enabled_(false), |
| 537 weak_ptr_factory_(this) {} |
536 | 538 |
537 void NetworkDeviceHandlerImpl::Init( | 539 void NetworkDeviceHandlerImpl::Init( |
538 NetworkStateHandler* network_state_handler) { | 540 NetworkStateHandler* network_state_handler) { |
539 DCHECK(network_state_handler); | 541 DCHECK(network_state_handler); |
540 network_state_handler_ = network_state_handler; | 542 network_state_handler_ = network_state_handler; |
541 network_state_handler_->AddObserver(this, FROM_HERE); | 543 network_state_handler_->AddObserver(this, FROM_HERE); |
542 } | 544 } |
543 | 545 |
544 void NetworkDeviceHandlerImpl::ApplyCellularAllowRoamingToShill() { | 546 void NetworkDeviceHandlerImpl::ApplyCellularAllowRoamingToShill() { |
545 NetworkStateHandler::DeviceStateList list; | 547 NetworkStateHandler::DeviceStateList list; |
(...skipping 20 matching lines...) Expand all Loading... |
566 | 568 |
567 SetDevicePropertyInternal(device_state->path(), | 569 SetDevicePropertyInternal(device_state->path(), |
568 shill::kCellularAllowRoamingProperty, | 570 shill::kCellularAllowRoamingProperty, |
569 base::FundamentalValue(new_device_value), | 571 base::FundamentalValue(new_device_value), |
570 base::Bind(&base::DoNothing), | 572 base::Bind(&base::DoNothing), |
571 network_handler::ErrorCallback()); | 573 network_handler::ErrorCallback()); |
572 } | 574 } |
573 } | 575 } |
574 | 576 |
575 void NetworkDeviceHandlerImpl::ApplyMACAddressRandomizationToShill() { | 577 void NetworkDeviceHandlerImpl::ApplyMACAddressRandomizationToShill() { |
| 578 if (!mac_addr_randomization_supported_) |
| 579 return; |
| 580 |
576 const DeviceState* device_state = | 581 const DeviceState* device_state = |
577 GetWifiDeviceState(network_handler::ErrorCallback()); | 582 GetWifiDeviceState(network_handler::ErrorCallback()); |
578 if (!device_state) | 583 if (!device_state) |
579 return; | 584 return; |
580 | 585 |
581 SetDevicePropertyInternal(device_state->path(), | 586 SetDevicePropertyInternal( |
582 shill::kMACAddressRandomizationProperty, | 587 device_state->path(), shill::kMACAddressRandomizationProperty, |
583 base::FundamentalValue(mac_addr_randomization_), | 588 base::FundamentalValue(mac_addr_randomization_enabled_), |
584 base::Bind(&base::DoNothing), | 589 base::Bind(&base::DoNothing), |
585 network_handler::ErrorCallback()); | 590 base::Bind( |
| 591 &NetworkDeviceHandlerImpl::SetMACAddressRandomizationErrorCallback, |
| 592 weak_ptr_factory_.GetWeakPtr())); |
| 593 } |
| 594 |
| 595 void NetworkDeviceHandlerImpl::SetMACAddressRandomizationErrorCallback( |
| 596 const std::string& error_name, |
| 597 std::unique_ptr<base::DictionaryValue> error_data) { |
| 598 if (error_name == NetworkDeviceHandler::kErrorNotSupported) |
| 599 mac_addr_randomization_supported_ = false; |
586 } | 600 } |
587 | 601 |
588 const DeviceState* NetworkDeviceHandlerImpl::GetWifiDeviceState( | 602 const DeviceState* NetworkDeviceHandlerImpl::GetWifiDeviceState( |
589 const network_handler::ErrorCallback& error_callback) { | 603 const network_handler::ErrorCallback& error_callback) { |
590 const DeviceState* device_state = | 604 const DeviceState* device_state = |
591 network_state_handler_->GetDeviceStateByType(NetworkTypePattern::WiFi()); | 605 network_state_handler_->GetDeviceStateByType(NetworkTypePattern::WiFi()); |
592 if (!device_state) { | 606 if (!device_state) { |
593 if (error_callback.is_null()) | 607 if (error_callback.is_null()) |
594 return NULL; | 608 return NULL; |
595 std::unique_ptr<base::DictionaryValue> error_data( | 609 std::unique_ptr<base::DictionaryValue> error_data( |
596 new base::DictionaryValue); | 610 new base::DictionaryValue); |
597 error_data->SetString(network_handler::kErrorName, kErrorDeviceMissing); | 611 error_data->SetString(network_handler::kErrorName, kErrorDeviceMissing); |
598 error_callback.Run(kErrorDeviceMissing, std::move(error_data)); | 612 error_callback.Run(kErrorDeviceMissing, std::move(error_data)); |
599 return NULL; | 613 return NULL; |
600 } | 614 } |
601 | 615 |
602 return device_state; | 616 return device_state; |
603 } | 617 } |
604 | 618 |
605 } // namespace chromeos | 619 } // namespace chromeos |
OLD | NEW |