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) {} | |
536 | 537 |
537 void NetworkDeviceHandlerImpl::Init( | 538 void NetworkDeviceHandlerImpl::Init( |
538 NetworkStateHandler* network_state_handler) { | 539 NetworkStateHandler* network_state_handler) { |
539 DCHECK(network_state_handler); | 540 DCHECK(network_state_handler); |
540 network_state_handler_ = network_state_handler; | 541 network_state_handler_ = network_state_handler; |
541 network_state_handler_->AddObserver(this, FROM_HERE); | 542 network_state_handler_->AddObserver(this, FROM_HERE); |
542 } | 543 } |
543 | 544 |
544 void NetworkDeviceHandlerImpl::ApplyCellularAllowRoamingToShill() { | 545 void NetworkDeviceHandlerImpl::ApplyCellularAllowRoamingToShill() { |
545 NetworkStateHandler::DeviceStateList list; | 546 NetworkStateHandler::DeviceStateList list; |
(...skipping 20 matching lines...) Expand all Loading... | |
566 | 567 |
567 SetDevicePropertyInternal(device_state->path(), | 568 SetDevicePropertyInternal(device_state->path(), |
568 shill::kCellularAllowRoamingProperty, | 569 shill::kCellularAllowRoamingProperty, |
569 base::FundamentalValue(new_device_value), | 570 base::FundamentalValue(new_device_value), |
570 base::Bind(&base::DoNothing), | 571 base::Bind(&base::DoNothing), |
571 network_handler::ErrorCallback()); | 572 network_handler::ErrorCallback()); |
572 } | 573 } |
573 } | 574 } |
574 | 575 |
575 void NetworkDeviceHandlerImpl::ApplyMACAddressRandomizationToShill() { | 576 void NetworkDeviceHandlerImpl::ApplyMACAddressRandomizationToShill() { |
577 if (!mac_addr_randomization_supported_) | |
578 return; | |
579 | |
576 const DeviceState* device_state = | 580 const DeviceState* device_state = |
577 GetWifiDeviceState(network_handler::ErrorCallback()); | 581 GetWifiDeviceState(network_handler::ErrorCallback()); |
578 if (!device_state) | 582 if (!device_state) |
579 return; | 583 return; |
580 | 584 |
581 SetDevicePropertyInternal(device_state->path(), | 585 SetDevicePropertyInternal( |
582 shill::kMACAddressRandomizationProperty, | 586 device_state->path(), shill::kMACAddressRandomizationProperty, |
583 base::FundamentalValue(mac_addr_randomization_), | 587 base::FundamentalValue(mac_addr_randomization_enabled_), |
584 base::Bind(&base::DoNothing), | 588 base::Bind(&base::DoNothing), |
585 network_handler::ErrorCallback()); | 589 base::Bind( |
590 &NetworkDeviceHandlerImpl::SetMACAddressRandomizationErrorCallback, | |
591 base::Unretained(this))); | |
stevenjb
2016/08/02 22:42:34
We need to use a weak ptr here, otherwise the erro
| |
592 } | |
593 | |
594 void NetworkDeviceHandlerImpl::SetMACAddressRandomizationErrorCallback( | |
595 const std::string& error_name, | |
596 std::unique_ptr<base::DictionaryValue> error_data) { | |
597 if (error_name == NetworkDeviceHandler::kErrorNotSupported) | |
598 mac_addr_randomization_supported_ = false; | |
586 } | 599 } |
587 | 600 |
588 const DeviceState* NetworkDeviceHandlerImpl::GetWifiDeviceState( | 601 const DeviceState* NetworkDeviceHandlerImpl::GetWifiDeviceState( |
589 const network_handler::ErrorCallback& error_callback) { | 602 const network_handler::ErrorCallback& error_callback) { |
590 const DeviceState* device_state = | 603 const DeviceState* device_state = |
591 network_state_handler_->GetDeviceStateByType(NetworkTypePattern::WiFi()); | 604 network_state_handler_->GetDeviceStateByType(NetworkTypePattern::WiFi()); |
592 if (!device_state) { | 605 if (!device_state) { |
593 if (error_callback.is_null()) | 606 if (error_callback.is_null()) |
594 return NULL; | 607 return NULL; |
595 std::unique_ptr<base::DictionaryValue> error_data( | 608 std::unique_ptr<base::DictionaryValue> error_data( |
596 new base::DictionaryValue); | 609 new base::DictionaryValue); |
597 error_data->SetString(network_handler::kErrorName, kErrorDeviceMissing); | 610 error_data->SetString(network_handler::kErrorName, kErrorDeviceMissing); |
598 error_callback.Run(kErrorDeviceMissing, std::move(error_data)); | 611 error_callback.Run(kErrorDeviceMissing, std::move(error_data)); |
599 return NULL; | 612 return NULL; |
600 } | 613 } |
601 | 614 |
602 return device_state; | 615 return device_state; |
603 } | 616 } |
604 | 617 |
605 } // namespace chromeos | 618 } // namespace chromeos |
OLD | NEW |