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

Unified Diff: device/bluetooth/bluetooth_low_energy_device_mac.mm

Issue 2244693002: bluetooth: Refactor how we update based on Advertising Data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 4 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: device/bluetooth/bluetooth_low_energy_device_mac.mm
diff --git a/device/bluetooth/bluetooth_low_energy_device_mac.mm b/device/bluetooth/bluetooth_low_energy_device_mac.mm
index de9ceeee9b28cd576d818d3b26687856ed4a8fe7..2dfaeef16d010f9401021a97d34097b813be0348 100644
--- a/device/bluetooth/bluetooth_low_energy_device_mac.mm
+++ b/device/bluetooth/bluetooth_low_energy_device_mac.mm
@@ -23,9 +23,7 @@ using device::BluetoothLowEnergyDeviceMac;
BluetoothLowEnergyDeviceMac::BluetoothLowEnergyDeviceMac(
BluetoothAdapterMac* adapter,
- CBPeripheral* peripheral,
- NSDictionary* advertisement_data,
- int rssi)
+ CBPeripheral* peripheral)
: BluetoothDeviceMac(adapter),
peripheral_(peripheral, base::scoped_policy::RETAIN) {
DCHECK(BluetoothAdapterMac::IsLowEnergyAvailable());
@@ -35,7 +33,6 @@ BluetoothLowEnergyDeviceMac::BluetoothLowEnergyDeviceMac(
[peripheral_ setDelegate:peripheral_delegate_];
identifier_ = GetPeripheralIdentifier(peripheral);
hash_address_ = GetPeripheralHashAddress(peripheral);
- Update(advertisement_data, rssi);
}
BluetoothLowEnergyDeviceMac::~BluetoothLowEnergyDeviceMac() {
@@ -44,39 +41,6 @@ BluetoothLowEnergyDeviceMac::~BluetoothLowEnergyDeviceMac() {
}
}
-void BluetoothLowEnergyDeviceMac::Update(NSDictionary* advertisement_data,
- int rssi) {
- UpdateTimestamp();
- rssi_ = rssi;
- NSNumber* connectable =
- [advertisement_data objectForKey:CBAdvertisementDataIsConnectable];
- connectable_ = [connectable boolValue];
- ClearServiceData();
- NSDictionary* service_data =
- [advertisement_data objectForKey:CBAdvertisementDataServiceDataKey];
- for (CBUUID* uuid in service_data) {
- NSData* data = [service_data objectForKey:uuid];
- BluetoothUUID service_uuid =
- BluetoothAdapterMac::BluetoothUUIDWithCBUUID(uuid);
- SetServiceData(service_uuid, static_cast<const char*>([data bytes]),
- [data length]);
- }
-
- std::unordered_set<BluetoothUUID, BluetoothUUIDHash> uuid_set;
- NSArray* service_uuids =
- [advertisement_data objectForKey:CBAdvertisementDataServiceUUIDsKey];
- for (CBUUID* uuid in service_uuids) {
- uuid_set.emplace([[uuid UUIDString] UTF8String]);
- }
- NSArray* overflow_service_uuids = [advertisement_data
- objectForKey:CBAdvertisementDataOverflowServiceUUIDsKey];
- for (CBUUID* uuid in overflow_service_uuids) {
- uuid_set.emplace([[uuid UUIDString] UTF8String]);
- }
-
- advertised_uuids_ = UUIDList(uuid_set.begin(), uuid_set.end());
-}
-
std::string BluetoothLowEnergyDeviceMac::GetIdentifier() const {
return identifier_;
}
@@ -119,10 +83,6 @@ base::Optional<std::string> BluetoothLowEnergyDeviceMac::GetName() const {
return base::nullopt;
}
-int BluetoothLowEnergyDeviceMac::GetRSSI() const {
- return rssi_;
-}
-
bool BluetoothLowEnergyDeviceMac::IsPaired() const {
return false;
}
@@ -301,9 +261,10 @@ void BluetoothLowEnergyDeviceMac::DidDiscoverCharacteristics(
->IsDiscoveryComplete();
}) == gatt_services_.end();
if (discovery_complete) {
- UpdateServiceUUIDs();
+ device_uuids_.ReplaceServiceUUIDs(gatt_services_);
SetGattServicesDiscoveryComplete(true);
adapter_->NotifyGattServicesDiscovered(this);
+ adapter_->NotifyDeviceChanged(this);
}
}
@@ -317,8 +278,9 @@ void BluetoothLowEnergyDeviceMac::DidModifyServices(
gatt_services_.take_and_erase(gatt_service->GetIdentifier());
adapter_->NotifyGattServiceRemoved(scoped_service.get());
}
- service_uuids_.clear();
+ device_uuids_.ClearServiceUUIDs();
SetGattServicesDiscoveryComplete(false);
+ adapter_->NotifyDeviceChanged(this);
[GetPeripheral() discoverServices:nil];
}
@@ -399,7 +361,7 @@ void BluetoothLowEnergyDeviceMac::DidDisconnectPeripheral(
GattServiceMap gatt_services_swapped;
gatt_services_swapped.swap(gatt_services_);
gatt_services_swapped.clear();
- UpdateServiceUUIDs();
+ device_uuids_.ClearServiceUUIDs();
if (create_gatt_connection_error_callbacks_.empty()) {
// TODO(http://crbug.com/585897): Need to pass the error.
DidDisconnectGatt();

Powered by Google App Engine
This is Rietveld 408576698