| 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 5985783f1ecaa3dc20ee0af2d720fffd4b7a6274..8a88ac3a96051c87ee9b49bb239258455e4a0d63 100644
|
| --- a/components/arc/bluetooth/arc_bluetooth_bridge.cc
|
| +++ b/components/arc/bluetooth/arc_bluetooth_bridge.cc
|
| @@ -330,7 +330,10 @@ void ArcBluetoothBridge::DeviceAdded(BluetoothAdapter* adapter,
|
| arc_bridge_service()->bluetooth()->instance()->OnDeviceFound(
|
| std::move(properties));
|
|
|
| - if (!CheckBluetoothInstanceVersion(kMinBtleVersion))
|
| + auto* btle_instance =
|
| + arc_bridge_service()->bluetooth()->GetInstanceForVersion(
|
| + kMinBtleVersion, "OnLEDeviceFound");
|
| + if (!btle_instance)
|
| return;
|
|
|
| if (!(device->GetType() & device::BLUETOOTH_TRANSPORT_LE))
|
| @@ -390,18 +393,18 @@ void ArcBluetoothBridge::DeviceAddressChanged(BluetoothAdapter* adapter,
|
| gatt_connection_cache_.erase(it);
|
| gatt_connection_cache_.insert(device->GetAddress());
|
|
|
| - if (!HasBluetoothInstance())
|
| - return;
|
| -
|
| - if (!CheckBluetoothInstanceVersion(kMinAddrChangeVersion))
|
| + auto* btle_instance =
|
| + arc_bridge_service()->bluetooth()->GetInstanceForVersion(
|
| + kMinAddrChangeVersion, "OnLEDeviceAddressChange");
|
| + if (!btle_instance)
|
| return;
|
|
|
| mojom::BluetoothAddressPtr old_addr =
|
| mojom::BluetoothAddress::From(old_address);
|
| mojom::BluetoothAddressPtr new_addr =
|
| mojom::BluetoothAddress::From(device->GetAddress());
|
| - arc_bridge_service()->bluetooth()->instance()->OnLEDeviceAddressChange(
|
| - std::move(old_addr), std::move(new_addr));
|
| + btle_instance->OnLEDeviceAddressChange(std::move(old_addr),
|
| + std::move(new_addr));
|
| }
|
|
|
| void ArcBluetoothBridge::DevicePairedChanged(BluetoothAdapter* adapter,
|
| @@ -458,10 +461,10 @@ void ArcBluetoothBridge::GattServiceRemoved(
|
|
|
| void ArcBluetoothBridge::GattServicesDiscovered(BluetoothAdapter* adapter,
|
| BluetoothDevice* device) {
|
| - if (!HasBluetoothInstance())
|
| - return;
|
| -
|
| - if (!CheckBluetoothInstanceVersion(kMinBtleVersion))
|
| + auto* btle_instance =
|
| + arc_bridge_service()->bluetooth()->GetInstanceForVersion(
|
| + kMinBtleVersion, "OnSearchComplete");
|
| + if (!btle_instance)
|
| return;
|
|
|
| mojom::BluetoothAddressPtr addr =
|
| @@ -511,10 +514,10 @@ void ArcBluetoothBridge::GattCharacteristicValueChanged(
|
| BluetoothAdapter* adapter,
|
| BluetoothRemoteGattCharacteristic* characteristic,
|
| const std::vector<uint8_t>& value) {
|
| - if (!HasBluetoothInstance())
|
| - return;
|
| -
|
| - if (!CheckBluetoothInstanceVersion(kMinBtleNotifyVersion))
|
| + auto* btle_instance =
|
| + arc_bridge_service()->bluetooth()->GetInstanceForVersion(
|
| + kMinBtleNotifyVersion, "OnGattNotify");
|
| + if (!btle_instance)
|
| return;
|
|
|
| BluetoothRemoteGattService* service = characteristic->GetService();
|
| @@ -552,16 +555,17 @@ void ArcBluetoothBridge::OnGattAttributeReadRequest(
|
| const ValueCallback& success_callback,
|
| const ErrorCallback& error_callback) {
|
| DCHECK(CalledOnValidThread());
|
| - if (!HasBluetoothInstance() ||
|
| - !CheckBluetoothInstanceVersion(kMinGattServerVersion) ||
|
| - !IsGattOffsetValid(offset)) {
|
| + auto* bluetooth_instance =
|
| + arc_bridge_service()->bluetooth()->GetInstanceForVersion(
|
| + kMinGattServerVersion, "RequestGattRead");
|
| + if (!bluetooth_instance || !IsGattOffsetValid(offset)) {
|
| error_callback.Run();
|
| return;
|
| }
|
|
|
| DCHECK(gatt_handle_.find(attribute->GetIdentifier()) != gatt_handle_.end());
|
|
|
| - arc_bridge_service()->bluetooth()->instance()->RequestGattRead(
|
| + bluetooth_instance->RequestGattRead(
|
| mojom::BluetoothAddress::From(device->GetAddress()),
|
| gatt_handle_[attribute->GetIdentifier()], offset, false /* is_long */,
|
| base::Bind(&OnGattServerRead, success_callback, error_callback));
|
| @@ -576,16 +580,17 @@ void ArcBluetoothBridge::OnGattAttributeWriteRequest(
|
| const base::Closure& success_callback,
|
| const ErrorCallback& error_callback) {
|
| DCHECK(CalledOnValidThread());
|
| - if (!HasBluetoothInstance() ||
|
| - !CheckBluetoothInstanceVersion(kMinGattServerVersion) ||
|
| - !IsGattOffsetValid(offset)) {
|
| + auto* bluetooth_instance =
|
| + arc_bridge_service()->bluetooth()->GetInstanceForVersion(
|
| + kMinGattServerVersion, "RequestGattWrite");
|
| + if (!bluetooth_instance || !IsGattOffsetValid(offset)) {
|
| error_callback.Run();
|
| return;
|
| }
|
|
|
| DCHECK(gatt_handle_.find(attribute->GetIdentifier()) != gatt_handle_.end());
|
|
|
| - arc_bridge_service()->bluetooth()->instance()->RequestGattWrite(
|
| + bluetooth_instance->RequestGattWrite(
|
| mojom::BluetoothAddress::From(device->GetAddress()),
|
| gatt_handle_[attribute->GetIdentifier()], offset,
|
| mojo::Array<uint8_t>::From(value),
|
| @@ -979,16 +984,15 @@ void ArcBluetoothBridge::StopLEScan() {
|
| void ArcBluetoothBridge::OnGattConnectStateChanged(
|
| mojom::BluetoothAddressPtr addr,
|
| bool connected) const {
|
| - if (!HasBluetoothInstance())
|
| - return;
|
| -
|
| - if (!CheckBluetoothInstanceVersion(kMinBtleVersion))
|
| + auto* btle_instance =
|
| + arc_bridge_service()->bluetooth()->GetInstanceForVersion(
|
| + kMinBtleVersion, "OnLEConnectionStateChange");
|
| + if (!btle_instance)
|
| return;
|
|
|
| DCHECK(addr);
|
|
|
| - arc_bridge_service()->bluetooth()->instance()->OnLEConnectionStateChange(
|
| - std::move(addr), connected);
|
| + btle_instance->OnLEConnectionStateChange(std::move(addr), connected);
|
| }
|
|
|
| void ArcBluetoothBridge::OnGattConnected(
|
| @@ -1849,6 +1853,9 @@ void ArcBluetoothBridge::SendCachedDevicesFound() const {
|
| // Send devices that have already been discovered, but aren't connected.
|
| if (!HasBluetoothInstance())
|
| return;
|
| + auto* btle_instance =
|
| + arc_bridge_service()->bluetooth()->GetInstanceForVersion(
|
| + kMinBtleVersion, "OnLEDeviceFound");
|
|
|
| BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices();
|
| for (auto* device : devices) {
|
| @@ -1861,15 +1868,15 @@ void ArcBluetoothBridge::SendCachedDevicesFound() const {
|
| arc_bridge_service()->bluetooth()->instance()->OnDeviceFound(
|
| std::move(properties));
|
|
|
| - if (arc_bridge_service()->bluetooth()->version() >= kMinBtleVersion) {
|
| + if (btle_instance) {
|
| mojom::BluetoothAddressPtr addr =
|
| mojom::BluetoothAddress::From(device->GetAddress());
|
| base::Optional<int8_t> rssi = device->GetInquiryRSSI();
|
| mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data =
|
| GetAdvertisingData(device);
|
| - arc_bridge_service()->bluetooth()->instance()->OnLEDeviceFound(
|
| - std::move(addr), rssi.value_or(mojom::kUnknownPower),
|
| - std::move(adv_data));
|
| + btle_instance->OnLEDeviceFound(std::move(addr),
|
| + rssi.value_or(mojom::kUnknownPower),
|
| + std::move(adv_data));
|
| }
|
| }
|
| }
|
| @@ -1887,6 +1894,9 @@ void ArcBluetoothBridge::SendCachedPairedDevices() const {
|
| DCHECK(bluetooth_adapter_);
|
| if (!HasBluetoothInstance())
|
| return;
|
| + auto* btle_instance =
|
| + arc_bridge_service()->bluetooth()->GetInstanceForVersion(
|
| + kMinBtleVersion, "OnLEDeviceFound");
|
|
|
| BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices();
|
| for (auto* device : devices) {
|
| @@ -1902,13 +1912,13 @@ void ArcBluetoothBridge::SendCachedPairedDevices() const {
|
| mojom::BluetoothAddressPtr addr =
|
| mojom::BluetoothAddress::From(device->GetAddress());
|
|
|
| - if (arc_bridge_service()->bluetooth()->version() >= kMinBtleVersion) {
|
| + if (btle_instance) {
|
| base::Optional<int8_t> rssi = device->GetInquiryRSSI();
|
| mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data =
|
| GetAdvertisingData(device);
|
| - arc_bridge_service()->bluetooth()->instance()->OnLEDeviceFound(
|
| - addr->Clone(), rssi.value_or(mojom::kUnknownPower),
|
| - std::move(adv_data));
|
| + btle_instance->OnLEDeviceFound(addr->Clone(),
|
| + rssi.value_or(mojom::kUnknownPower),
|
| + std::move(adv_data));
|
| }
|
|
|
| // OnBondStateChanged must be called with mojom::BluetoothBondState::BONDING
|
| @@ -1924,13 +1934,13 @@ void ArcBluetoothBridge::OnGetServiceRecordsDone(
|
| mojom::BluetoothAddressPtr remote_addr,
|
| const BluetoothUUID& target_uuid,
|
| const std::vector<bluez::BluetoothServiceRecordBlueZ>& records_bluez) {
|
| - if (!CheckBluetoothInstanceVersion(kMinSdpSupportVersion))
|
| - return;
|
| -
|
| - if (!HasBluetoothInstance())
|
| + auto* sdp_bluetooth_instance =
|
| + arc_bridge_service()->bluetooth()->GetInstanceForVersion(
|
| + kMinSdpSupportVersion, "OnGetSdpRecords");
|
| + if (!sdp_bluetooth_instance)
|
| return;
|
|
|
| - arc_bridge_service()->bluetooth()->instance()->OnGetSdpRecords(
|
| + sdp_bluetooth_instance->OnGetSdpRecords(
|
| mojom::BluetoothStatus::SUCCESS, std::move(remote_addr), target_uuid,
|
| mojo::Array<mojom::BluetoothSdpRecordPtr>::From(records_bluez));
|
| }
|
| @@ -1939,10 +1949,10 @@ void ArcBluetoothBridge::OnGetServiceRecordsError(
|
| mojom::BluetoothAddressPtr remote_addr,
|
| const BluetoothUUID& target_uuid,
|
| bluez::BluetoothServiceRecordBlueZ::ErrorCode error_code) {
|
| - if (!HasBluetoothInstance())
|
| - return;
|
| -
|
| - if (!CheckBluetoothInstanceVersion(kMinSdpSupportVersion))
|
| + auto* sdp_bluetooth_instance =
|
| + arc_bridge_service()->bluetooth()->GetInstanceForVersion(
|
| + kMinSdpSupportVersion, "OnGetSdpRecords");
|
| + if (!sdp_bluetooth_instance)
|
| return;
|
|
|
| mojom::BluetoothStatus status;
|
| @@ -1960,21 +1970,11 @@ void ArcBluetoothBridge::OnGetServiceRecordsError(
|
| break;
|
| }
|
|
|
| - arc_bridge_service()->bluetooth()->instance()->OnGetSdpRecords(
|
| + sdp_bluetooth_instance->OnGetSdpRecords(
|
| status, std::move(remote_addr), target_uuid,
|
| mojo::Array<mojom::BluetoothSdpRecordPtr>::New(0));
|
| }
|
|
|
| -bool ArcBluetoothBridge::CheckBluetoothInstanceVersion(
|
| - uint32_t version_need) const {
|
| - uint32_t version = arc_bridge_service()->bluetooth()->version();
|
| - if (version >= version_need)
|
| - return true;
|
| - LOG(WARNING) << "Bluetooth instance is too old (version " << version
|
| - << ") need version " << version_need;
|
| - return false;
|
| -}
|
| -
|
| bool ArcBluetoothBridge::CalledOnValidThread() {
|
| return thread_checker_.CalledOnValidThread();
|
| }
|
|
|