Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(492)

Unified Diff: components/arc/bluetooth/arc_bluetooth_bridge.cc

Issue 2354933003: arc: bluetooth: Clean up arc_bluetooth_bridge (Closed)
Patch Set: Rebase Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 79f375d7e19eee765b9887638a04f75fb81827ba..6b0f191ff1e1f918172f742da2daa617f2df7e43 100644
--- a/components/arc/bluetooth/arc_bluetooth_bridge.cc
+++ b/components/arc/bluetooth/arc_bluetooth_bridge.cc
@@ -312,8 +312,7 @@ void ArcBluetoothBridge::OnInstanceClosed() {
bluetooth_adapter_->RemoveObserver(this);
}
-void ArcBluetoothBridge::DeviceAdded(BluetoothAdapter* adapter,
- BluetoothDevice* device) {
+void ArcBluetoothBridge::SendDevice(const BluetoothDevice* device) const {
auto* bluetooth_instance =
arc_bridge_service()->bluetooth()->GetInstanceForMethod("OnDeviceFound");
if (!bluetooth_instance)
@@ -324,22 +323,29 @@ void ArcBluetoothBridge::DeviceAdded(BluetoothAdapter* adapter,
bluetooth_instance->OnDeviceFound(std::move(properties));
- auto* btle_instance = arc_bridge_service()->bluetooth()->GetInstanceForMethod(
- "OnLEDeviceFound", kMinBtleVersion);
- if (!btle_instance)
- return;
if (!(device->GetType() & device::BLUETOOTH_TRANSPORT_LE))
return;
- mojom::BluetoothAddressPtr addr =
- mojom::BluetoothAddress::From(device->GetAddress());
base::Optional<int8_t> rssi = device->GetInquiryRSSI();
- mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data =
- GetAdvertisingData(device);
- btle_instance->OnLEDeviceFound(std::move(addr),
- rssi.value_or(mojom::kUnknownPower),
- std::move(adv_data));
+ mojom::BluetoothAddressPtr addr;
+
+ // We only want to send updated advertise data to Android only when we are
+ // scanning which is checked by the validity of rssi. Here are the 2 cases
+ // that we don't want to send updated advertise data to Android.
+ // 1) Cached found device and 2) rssi became invalid when we stop scanning.
+ if (rssi.has_value()) {
+ auto* btle_instance =
+ arc_bridge_service()->bluetooth()->GetInstanceForMethod(
+ "OnLEDeviceFound", kMinBtleVersion);
+ if (!btle_instance)
+ return;
+ mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data =
+ GetAdvertisingData(device);
+ addr = mojom::BluetoothAddress::From(device->GetAddress());
+ btle_instance->OnLEDeviceFound(std::move(addr), rssi.value(),
+ std::move(adv_data));
+ }
if (!device->IsConnected())
return;
@@ -348,8 +354,15 @@ void ArcBluetoothBridge::DeviceAdded(BluetoothAdapter* adapter,
OnGattConnectStateChanged(std::move(addr), true);
}
+void ArcBluetoothBridge::DeviceAdded(BluetoothAdapter* adapter,
+ BluetoothDevice* device) {
+ SendDevice(device);
+}
+
void ArcBluetoothBridge::DeviceChanged(BluetoothAdapter* adapter,
BluetoothDevice* device) {
+ SendDevice(device);
+
if (!(device->GetType() & device::BLUETOOTH_TRANSPORT_LE))
return;
@@ -1705,7 +1718,7 @@ void ArcBluetoothBridge::OnForgetError(mojom::BluetoothAddressPtr addr) const {
mojo::Array<mojom::BluetoothPropertyPtr>
ArcBluetoothBridge::GetDeviceProperties(mojom::BluetoothPropertyType type,
- BluetoothDevice* device) const {
+ const BluetoothDevice* device) const {
mojo::Array<mojom::BluetoothPropertyPtr> properties;
if (!device) {
@@ -1726,10 +1739,12 @@ ArcBluetoothBridge::GetDeviceProperties(mojom::BluetoothPropertyType type,
}
if (type == mojom::BluetoothPropertyType::ALL ||
type == mojom::BluetoothPropertyType::UUIDS) {
- mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New();
BluetoothDevice::UUIDSet uuids = device->GetUUIDs();
- btp->set_uuids(std::vector<BluetoothUUID>(uuids.begin(), uuids.end()));
- properties.push_back(std::move(btp));
+ if (uuids.size() > 0) {
+ mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New();
+ btp->set_uuids(std::vector<BluetoothUUID>(uuids.begin(), uuids.end()));
+ properties.push_back(std::move(btp));
+ }
}
if (type == mojom::BluetoothPropertyType::ALL ||
type == mojom::BluetoothPropertyType::CLASS_OF_DEVICE) {
@@ -1752,10 +1767,12 @@ ArcBluetoothBridge::GetDeviceProperties(mojom::BluetoothPropertyType type,
}
if (type == mojom::BluetoothPropertyType::ALL ||
type == mojom::BluetoothPropertyType::REMOTE_RSSI) {
- mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New();
base::Optional<int8_t> rssi = device->GetInquiryRSSI();
- btp->set_remote_rssi(rssi.value_or(mojom::kUnknownPower));
- properties.push_back(std::move(btp));
+ if (rssi.has_value()) {
+ mojom::BluetoothPropertyPtr btp = mojom::BluetoothProperty::New();
+ btp->set_remote_rssi(rssi.value());
+ properties.push_back(std::move(btp));
+ }
}
// TODO(smbarber): Add remote version info
@@ -1869,7 +1886,7 @@ ArcBluetoothBridge::GetAdapterProperties(
// because Android does not support UUID 128 bits there.
// TODO(crbug.com/618442) Make Chrome expose missing data.
mojo::Array<mojom::BluetoothAdvertisingDataPtr>
-ArcBluetoothBridge::GetAdvertisingData(BluetoothDevice* device) const {
+ArcBluetoothBridge::GetAdvertisingData(const BluetoothDevice* device) const {
mojo::Array<mojom::BluetoothAdvertisingDataPtr> advertising_data;
// LocalName
@@ -1913,72 +1930,34 @@ ArcBluetoothBridge::GetAdvertisingData(BluetoothDevice* device) const {
}
void ArcBluetoothBridge::SendCachedDevicesFound() const {
- // Send devices that have already been discovered, but aren't connected.
- auto* bluetooth_instance =
- arc_bridge_service()->bluetooth()->GetInstanceForMethod("OnDeviceFound");
- if (!bluetooth_instance)
- return;
- auto* btle_instance = arc_bridge_service()->bluetooth()->GetInstanceForMethod(
- "OnLEDeviceFound", kMinBtleVersion);
+ DCHECK(bluetooth_adapter_);
+ // Send devices that have already been discovered, but aren't connected.
BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices();
for (auto* device : devices) {
if (device->IsPaired())
continue;
- mojo::Array<mojom::BluetoothPropertyPtr> properties =
- GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device);
-
- bluetooth_instance->OnDeviceFound(std::move(properties));
-
- 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);
- btle_instance->OnLEDeviceFound(std::move(addr),
- rssi.value_or(mojom::kUnknownPower),
- std::move(adv_data));
- }
+ SendDevice(device);
}
}
void ArcBluetoothBridge::SendCachedPairedDevices() const {
DCHECK(bluetooth_adapter_);
- auto* bluetooth_instance =
- arc_bridge_service()->bluetooth()->GetInstanceForMethod("OnDeviceFound");
- if (!bluetooth_instance)
- return;
- auto* btle_instance = arc_bridge_service()->bluetooth()->GetInstanceForMethod(
- "OnLEDeviceFound", kMinBtleVersion);
BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices();
for (auto* device : devices) {
if (!device->IsPaired())
continue;
- mojo::Array<mojom::BluetoothPropertyPtr> properties =
- GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device);
-
- bluetooth_instance->OnDeviceFound(std::move(properties));
-
- mojom::BluetoothAddressPtr addr =
- mojom::BluetoothAddress::From(device->GetAddress());
-
- if (btle_instance) {
- base::Optional<int8_t> rssi = device->GetInquiryRSSI();
- mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data =
- GetAdvertisingData(device);
- btle_instance->OnLEDeviceFound(addr->Clone(),
- rssi.value_or(mojom::kUnknownPower),
- std::move(adv_data));
- }
+ SendDevice(device);
// OnBondStateChanged must be called with mojom::BluetoothBondState::BONDING
// to make sure the bond state machine on Android is ready to take the
// pair-done event. Otherwise the pair-done event will be dropped as an
// invalid change of paired status.
+ mojom::BluetoothAddressPtr addr =
+ mojom::BluetoothAddress::From(device->GetAddress());
OnPairing(addr->Clone());
OnPairedDone(std::move(addr));
}
« no previous file with comments | « components/arc/bluetooth/arc_bluetooth_bridge.h ('k') | components/arc/bluetooth/arc_bluetooth_bridge_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698