Chromium Code Reviews| Index: components/arc/bluetooth/arc_bluetooth_bridge.cc |
| diff --git a/components/arc/bluetooth/arc_bluetooth_bridge.cc b/components/arc/bluetooth/arc_bluetooth_bridge.cc |
| index 1d0a6c5b07c0a400f5904f7cb72ed6cba758154c..83f70655a493ccef325c8d925b5d089d61da1d50 100644 |
| --- a/components/arc/bluetooth/arc_bluetooth_bridge.cc |
| +++ b/components/arc/bluetooth/arc_bluetooth_bridge.cc |
| @@ -72,6 +72,15 @@ ArcBluetoothBridge::ArcBluetoothBridge(ArcBridgeService* bridge_service) |
| arc_bridge_service()->AddObserver(this); |
| } |
| +ArcBluetoothBridge::ArcBluetoothBridge(ArcBridgeService* bridge_service, |
|
rkc
2016/06/19 18:45:43
We don't need this constructor. We never use the t
|
| + bool test_flag) |
| + : ArcService(bridge_service), binding_(this), weak_factory_(this) { |
| + if (!test_flag) { |
| + LOG(ERROR) << "Test Constructor got called with test = false"; |
| + } |
| + arc_bridge_service()->AddObserver(this); |
| +} |
| + |
| ArcBluetoothBridge::~ArcBluetoothBridge() { |
| arc_bridge_service()->RemoveObserver(this); |
| @@ -94,8 +103,9 @@ void ArcBluetoothBridge::OnBluetoothInstanceReady() { |
| return; |
| } |
| - arc_bridge_service()->bluetooth_instance()->Init( |
| - binding_.CreateInterfacePtrAndBind()); |
| + bluetooth_instance_ = base::WrapUnique(bluetooth_instance); |
|
rkc
2016/06/19 18:45:43
None of these changes are needed. This file, in fa
|
| + bluetooth_version_ = arc_bridge_service()->bluetooth_version(); |
| + bluetooth_instance_->Init(binding_.CreateInterfacePtrAndBind()); |
| } |
| void ArcBluetoothBridge::AdapterPresentChanged(BluetoothAdapter* adapter, |
| @@ -127,10 +137,9 @@ void ArcBluetoothBridge::DeviceAdded(BluetoothAdapter* adapter, |
| mojo::Array<mojom::BluetoothPropertyPtr> properties = |
| GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device); |
| - arc_bridge_service()->bluetooth_instance()->OnDeviceFound( |
| - std::move(properties)); |
| + bluetooth_instance_->OnDeviceFound(std::move(properties)); |
| - if (arc_bridge_service()->bluetooth_version() < kMinBtleVersion) { |
| + if (bluetooth_version_ < kMinBtleVersion) { |
| LOG(WARNING) << "Bluetooth instance is too old and does not support BTLE"; |
| return; |
| } |
| @@ -140,8 +149,8 @@ void ArcBluetoothBridge::DeviceAdded(BluetoothAdapter* adapter, |
| int rssi = device->GetInquiryRSSI(); |
| mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data = |
| GetAdvertisingData(device); |
| - arc_bridge_service()->bluetooth_instance()->OnLEDeviceFound( |
| - std::move(addr), rssi, std::move(adv_data)); |
| + bluetooth_instance_->OnLEDeviceFound(std::move(addr), rssi, |
| + std::move(adv_data)); |
| } |
| void ArcBluetoothBridge::DeviceChanged(BluetoothAdapter* adapter, |
| @@ -204,7 +213,7 @@ void ArcBluetoothBridge::GattServicesDiscovered(BluetoothAdapter* adapter, |
| if (!HasBluetoothInstance()) |
| return; |
| - if (arc_bridge_service()->bluetooth_version() < kMinBtleVersion) { |
| + if (bluetooth_version_ < kMinBtleVersion) { |
| LOG(WARNING) << "Bluetooth instance is too old and does not support BTLE"; |
| return; |
| } |
| @@ -212,7 +221,7 @@ void ArcBluetoothBridge::GattServicesDiscovered(BluetoothAdapter* adapter, |
| mojom::BluetoothAddressPtr addr = |
| mojom::BluetoothAddress::From(device->GetAddress()); |
| - arc_bridge_service()->bluetooth_instance()->OnSearchComplete( |
| + bluetooth_instance_->OnSearchComplete( |
| std::move(addr), mojom::BluetoothGattStatus::GATT_SUCCESS); |
| } |
| @@ -298,8 +307,8 @@ void ArcBluetoothBridge::GetAdapterProperty(mojom::BluetoothPropertyType type) { |
| mojo::Array<mojom::BluetoothPropertyPtr> properties = |
| GetAdapterProperties(type); |
| - arc_bridge_service()->bluetooth_instance()->OnAdapterProperties( |
| - mojom::BluetoothStatus::SUCCESS, std::move(properties)); |
| + bluetooth_instance_->OnAdapterProperties(mojom::BluetoothStatus::SUCCESS, |
| + std::move(properties)); |
| } |
| void ArcBluetoothBridge::SetAdapterProperty( |
| @@ -309,7 +318,7 @@ void ArcBluetoothBridge::SetAdapterProperty( |
| return; |
| // TODO(smbarber): Implement SetAdapterProperty |
| - arc_bridge_service()->bluetooth_instance()->OnAdapterProperties( |
| + bluetooth_instance_->OnAdapterProperties( |
| mojom::BluetoothStatus::FAIL, |
| mojo::Array<mojom::BluetoothPropertyPtr>::New(0)); |
| } |
| @@ -333,8 +342,8 @@ void ArcBluetoothBridge::GetRemoteDeviceProperty( |
| status = mojom::BluetoothStatus::FAIL; |
| } |
| - arc_bridge_service()->bluetooth_instance()->OnRemoteDeviceProperties( |
| - status, std::move(remote_addr), std::move(properties)); |
| + bluetooth_instance_->OnRemoteDeviceProperties(status, std::move(remote_addr), |
| + std::move(properties)); |
| } |
| void ArcBluetoothBridge::SetRemoteDeviceProperty( |
| @@ -345,7 +354,7 @@ void ArcBluetoothBridge::SetRemoteDeviceProperty( |
| return; |
| // TODO(smbarber): Implement SetRemoteDeviceProperty |
| - arc_bridge_service()->bluetooth_instance()->OnRemoteDeviceProperties( |
| + bluetooth_instance_->OnRemoteDeviceProperties( |
| mojom::BluetoothStatus::FAIL, std::move(remote_addr), |
| mojo::Array<mojom::BluetoothPropertyPtr>::New(0)); |
| } |
| @@ -415,7 +424,7 @@ void ArcBluetoothBridge::OnDiscoveryStarted( |
| discovery_session_ = std::move(session); |
| - arc_bridge_service()->bluetooth_instance()->OnDiscoveryStateChanged( |
| + bluetooth_instance_->OnDiscoveryStateChanged( |
| mojom::BluetoothDiscoveryState::STARTED); |
| SendCachedDevicesFound(); |
| @@ -427,7 +436,7 @@ void ArcBluetoothBridge::OnDiscoveryStopped() { |
| discovery_session_.reset(); |
| - arc_bridge_service()->bluetooth_instance()->OnDiscoveryStateChanged( |
| + bluetooth_instance_->OnDiscoveryStateChanged( |
| mojom::BluetoothDiscoveryState::STOPPED); |
| } |
| @@ -536,14 +545,14 @@ void ArcBluetoothBridge::OnGattConnectStateChanged( |
| if (!HasBluetoothInstance()) |
| return; |
| - if (arc_bridge_service()->bluetooth_version() < kMinBtleVersion) { |
| + if (bluetooth_version_ < kMinBtleVersion) { |
| LOG(WARNING) << "Bluetooth instance is too old and does not support BTLE"; |
| return; |
| } |
| DCHECK(addr); |
| - arc_bridge_service()->bluetooth_instance()->OnLEConnectionStateChange( |
| + bluetooth_instance_->OnLEConnectionStateChange( |
| std::move(addr), connected); |
| } |
| @@ -574,8 +583,8 @@ void ArcBluetoothBridge::ConnectLEDevice( |
| DCHECK(device); |
| if (device->IsConnected()) { |
| - arc_bridge_service()->bluetooth_instance()->OnLEConnectionStateChange( |
| - std::move(remote_addr), true); |
| + bluetooth_instance_->OnLEConnectionStateChange(std::move(remote_addr), |
| + true); |
| return; |
| } |
| @@ -599,8 +608,8 @@ void ArcBluetoothBridge::DisconnectLEDevice( |
| DCHECK(device); |
| if (!device->IsConnected()) { |
| - arc_bridge_service()->bluetooth_instance()->OnLEConnectionStateChange( |
| - std::move(remote_addr), false); |
| + bluetooth_instance_->OnLEConnectionStateChange(std::move(remote_addr), |
| + false); |
| return; |
| } |
| @@ -622,7 +631,7 @@ void ArcBluetoothBridge::SearchService(mojom::BluetoothAddressPtr remote_addr) { |
| // Call the callback if discovery is completed |
| if (device->IsGattServicesDiscoveryComplete()) { |
| - arc_bridge_service()->bluetooth_instance()->OnSearchComplete( |
| + bluetooth_instance_->OnSearchComplete( |
| std::move(remote_addr), mojom::BluetoothGattStatus::GATT_SUCCESS); |
| return; |
| } |
| @@ -748,8 +757,7 @@ void ArcBluetoothBridge::GetGattDB(mojom::BluetoothAddressPtr remote_addr) { |
| } |
| } |
| - arc_bridge_service()->bluetooth_instance()->OnGetGattDB( |
| - std::move(remote_addr), std::move(db)); |
| + bluetooth_instance_->OnGetGattDB(std::move(remote_addr), std::move(db)); |
| } |
| // Find Gatt Service/Characteristic/Descriptor from std::vector from UUID. |
| @@ -997,18 +1005,18 @@ void ArcBluetoothBridge::OnPairing(mojom::BluetoothAddressPtr addr) const { |
| if (!HasBluetoothInstance()) |
| return; |
| - arc_bridge_service()->bluetooth_instance()->OnBondStateChanged( |
| - mojom::BluetoothStatus::SUCCESS, std::move(addr), |
| - mojom::BluetoothBondState::BONDING); |
| + bluetooth_instance_->OnBondStateChanged(mojom::BluetoothStatus::SUCCESS, |
| + std::move(addr), |
| + mojom::BluetoothBondState::BONDING); |
| } |
| void ArcBluetoothBridge::OnPairedDone(mojom::BluetoothAddressPtr addr) const { |
| if (!HasBluetoothInstance()) |
| return; |
| - arc_bridge_service()->bluetooth_instance()->OnBondStateChanged( |
| - mojom::BluetoothStatus::SUCCESS, std::move(addr), |
| - mojom::BluetoothBondState::BONDED); |
| + bluetooth_instance_->OnBondStateChanged(mojom::BluetoothStatus::SUCCESS, |
| + std::move(addr), |
| + mojom::BluetoothBondState::BONDED); |
| } |
| void ArcBluetoothBridge::OnPairedError( |
| @@ -1017,18 +1025,18 @@ void ArcBluetoothBridge::OnPairedError( |
| if (!HasBluetoothInstance()) |
| return; |
| - arc_bridge_service()->bluetooth_instance()->OnBondStateChanged( |
| - mojom::BluetoothStatus::FAIL, std::move(addr), |
| - mojom::BluetoothBondState::NONE); |
| + bluetooth_instance_->OnBondStateChanged(mojom::BluetoothStatus::FAIL, |
| + std::move(addr), |
| + mojom::BluetoothBondState::NONE); |
| } |
| void ArcBluetoothBridge::OnForgetDone(mojom::BluetoothAddressPtr addr) const { |
| if (!HasBluetoothInstance()) |
| return; |
| - arc_bridge_service()->bluetooth_instance()->OnBondStateChanged( |
| - mojom::BluetoothStatus::SUCCESS, std::move(addr), |
| - mojom::BluetoothBondState::NONE); |
| + bluetooth_instance_->OnBondStateChanged(mojom::BluetoothStatus::SUCCESS, |
| + std::move(addr), |
| + mojom::BluetoothBondState::NONE); |
| } |
| void ArcBluetoothBridge::OnForgetError(mojom::BluetoothAddressPtr addr) const { |
| @@ -1041,8 +1049,8 @@ void ArcBluetoothBridge::OnForgetError(mojom::BluetoothAddressPtr addr) const { |
| if (device && device->IsPaired()) { |
| bond_state = mojom::BluetoothBondState::BONDED; |
| } |
| - arc_bridge_service()->bluetooth_instance()->OnBondStateChanged( |
| - mojom::BluetoothStatus::FAIL, std::move(addr), bond_state); |
| + bluetooth_instance_->OnBondStateChanged(mojom::BluetoothStatus::FAIL, |
| + std::move(addr), bond_state); |
| } |
| mojo::Array<mojom::BluetoothPropertyPtr> |
| @@ -1256,23 +1264,22 @@ void ArcBluetoothBridge::SendCachedDevicesFound() const { |
| mojo::Array<mojom::BluetoothPropertyPtr> properties = |
| GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device); |
| - arc_bridge_service()->bluetooth_instance()->OnDeviceFound( |
| - std::move(properties)); |
| + bluetooth_instance_->OnDeviceFound(std::move(properties)); |
| - if (arc_bridge_service()->bluetooth_version() >= kMinBtleVersion) { |
| + if (bluetooth_version_ >= kMinBtleVersion) { |
| mojom::BluetoothAddressPtr addr = |
| mojom::BluetoothAddress::From(device->GetAddress()); |
| int rssi = device->GetInquiryRSSI(); |
| mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data = |
| GetAdvertisingData(device); |
| - arc_bridge_service()->bluetooth_instance()->OnLEDeviceFound( |
| - std::move(addr), rssi, std::move(adv_data)); |
| + bluetooth_instance_->OnLEDeviceFound(std::move(addr), rssi, |
| + std::move(adv_data)); |
| } |
| } |
| } |
| bool ArcBluetoothBridge::HasBluetoothInstance() const { |
| - if (!arc_bridge_service()->bluetooth_instance()) { |
| + if (!bluetooth_instance_) { |
| LOG(WARNING) << "no Bluetooth instance available"; |
| return false; |
| } |
| @@ -1293,18 +1300,17 @@ void ArcBluetoothBridge::SendCachedPairedDevices() const { |
| mojo::Array<mojom::BluetoothPropertyPtr> properties = |
| GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device); |
| - arc_bridge_service()->bluetooth_instance()->OnDeviceFound( |
| - std::move(properties)); |
| + bluetooth_instance_->OnDeviceFound(std::move(properties)); |
| mojom::BluetoothAddressPtr addr = |
| mojom::BluetoothAddress::From(device->GetAddress()); |
| - if (arc_bridge_service()->bluetooth_version() >= kMinBtleVersion) { |
| + if (bluetooth_version_ >= kMinBtleVersion) { |
| int rssi = device->GetInquiryRSSI(); |
| mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data = |
| GetAdvertisingData(device); |
| - arc_bridge_service()->bluetooth_instance()->OnLEDeviceFound( |
| - addr->Clone(), rssi, std::move(adv_data)); |
| + bluetooth_instance_->OnLEDeviceFound(addr->Clone(), rssi, |
| + std::move(adv_data)); |
| } |
| // OnBondStateChanged must be called with mojom::BluetoothBondState::BONDING |