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

Unified Diff: device/bluetooth/bluetooth_low_energy_device_mac.mm

Issue 2641133003: Bluetooth: macOS: Adding counter for service discovery callbacks. (Closed)
Patch Set: Adding logs Created 3 years, 11 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 a52d2bcf618f00e0e6c18768ed6259e400a02219..00c1475926ffb1b9d82458f2b7fd761f8f0eb80a 100644
--- a/device/bluetooth/bluetooth_low_energy_device_mac.mm
+++ b/device/bluetooth/bluetooth_low_energy_device_mac.mm
@@ -25,7 +25,8 @@ BluetoothLowEnergyDeviceMac::BluetoothLowEnergyDeviceMac(
BluetoothAdapterMac* adapter,
CBPeripheral* peripheral)
: BluetoothDeviceMac(adapter),
- peripheral_(peripheral, base::scoped_policy::RETAIN) {
+ peripheral_(peripheral, base::scoped_policy::RETAIN),
+ discovery_pending_count_(0) {
DCHECK(BluetoothAdapterMac::IsLowEnergyAvailable());
DCHECK(peripheral_.get());
peripheral_delegate_.reset([[BluetoothLowEnergyPeripheralDelegate alloc]
@@ -193,7 +194,8 @@ void BluetoothLowEnergyDeviceMac::DidDiscoverPrimaryServices(NSError* error) {
<< ": " << error.code << ")";
return;
}
- VLOG(1) << "DidDiscoverPrimaryServices.";
+ VLOG(1) << "DidDiscoverPrimaryServices, pending count: "
+ << discovery_pending_count_;
if (!IsGattConnected()) {
// Don't create services if the device disconnected.
@@ -212,11 +214,16 @@ void BluetoothLowEnergyDeviceMac::DidDiscoverPrimaryServices(NSError* error) {
adapter_->NotifyGattServiceAdded(gatt_service);
}
}
- for (auto it = gatt_services_.begin(); it != gatt_services_.end(); ++it) {
- device::BluetoothRemoteGattService* gatt_service = it->second.get();
- device::BluetoothRemoteGattServiceMac* gatt_service_mac =
- static_cast<BluetoothRemoteGattServiceMac*>(gatt_service);
- gatt_service_mac->DiscoverCharacteristics();
+ --discovery_pending_count_;
+ DCHECK(discovery_pending_count_ >= 0);
ortuno 2017/01/22 20:39:14 Looking at the code it seems we are calling Discov
jlebel 2017/01/22 21:23:33 discovery_pending_count_ should never be -1. Do yo
ortuno 2017/01/23 00:18:23 I'm not sure that solves the problem. For example:
+ if (discovery_pending_count_ == 0) {
+ for (auto it = gatt_services_.begin(); it != gatt_services_.end(); ++it) {
+ device::BluetoothRemoteGattService* gatt_service = it->second.get();
+ device::BluetoothRemoteGattServiceMac* gatt_service_mac =
+ static_cast<BluetoothRemoteGattServiceMac*>(gatt_service);
+ gatt_service_mac->DiscoverCharacteristics();
+ }
+ SendNotificationIfDiscoveryComplete();
}
}
@@ -261,7 +268,7 @@ void BluetoothLowEnergyDeviceMac::DidModifyServices(
device_uuids_.ClearServiceUUIDs();
SetGattServicesDiscoveryComplete(false);
adapter_->NotifyDeviceChanged(this);
- [GetPeripheral() discoverServices:nil];
+ DiscoverPrimaryServices();
}
void BluetoothLowEnergyDeviceMac::DidUpdateValue(
@@ -337,9 +344,16 @@ std::string BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(
return BluetoothDevice::CanonicalizeAddress(hash);
}
+void BluetoothLowEnergyDeviceMac::DiscoverPrimaryServices() {
+ [GetPeripheral() discoverServices:nil];
+ VLOG(1) << "DidDiscoverDescriptors pending count" << discovery_pending_count_;
+ ++discovery_pending_count_;
+}
+
void BluetoothLowEnergyDeviceMac::SendNotificationIfDiscoveryComplete() {
// Notify when all services have been discovered.
bool discovery_complete =
+ discovery_pending_count_ == 0 &&
std::find_if_not(
gatt_services_.begin(), gatt_services_.end(),
[](GattServiceMap::value_type& pair) {

Powered by Google App Engine
This is Rietveld 408576698