| Index: device/bluetooth/bluetooth_remote_gatt_characteristic_mac.mm
|
| diff --git a/device/bluetooth/bluetooth_remote_gatt_characteristic_mac.mm b/device/bluetooth/bluetooth_remote_gatt_characteristic_mac.mm
|
| index 8e4a14dd52d75dfdf3866ffe1f357e58f7fb30ca..f72a177565a7885de99718395187b0e94ac42356 100644
|
| --- a/device/bluetooth/bluetooth_remote_gatt_characteristic_mac.mm
|
| +++ b/device/bluetooth/bluetooth_remote_gatt_characteristic_mac.mm
|
| @@ -69,7 +69,9 @@ static BluetoothGattCharacteristic::Properties ConvertProperties(
|
| BluetoothRemoteGattCharacteristicMac::BluetoothRemoteGattCharacteristicMac(
|
| BluetoothRemoteGattServiceMac* gatt_service,
|
| CBCharacteristic* cb_characteristic)
|
| - : gatt_service_(gatt_service),
|
| + : is_discovery_complete_(false),
|
| + discovery_pending_count_(0),
|
| + gatt_service_(gatt_service),
|
| cb_characteristic_(cb_characteristic, base::scoped_policy::RETAIN),
|
| characteristic_value_read_or_write_in_progress_(false) {
|
| uuid_ = BluetoothAdapterMac::BluetoothUUIDWithCBUUID(
|
| @@ -245,6 +247,7 @@ void BluetoothRemoteGattCharacteristicMac::UnsubscribeFromNotifications(
|
| void BluetoothRemoteGattCharacteristicMac::DiscoverDescriptors() {
|
| VLOG(1) << *this << ": Discover descriptors.";
|
| is_discovery_complete_ = false;
|
| + ++discovery_pending_count_;
|
| [GetCBPeripheral()
|
| discoverDescriptorsForCharacteristic:cb_characteristic_.get()];
|
| }
|
| @@ -345,8 +348,15 @@ void BluetoothRemoteGattCharacteristicMac::DidUpdateNotificationState(
|
| }
|
|
|
| void BluetoothRemoteGattCharacteristicMac::DidDiscoverDescriptors() {
|
| - DCHECK(!is_discovery_complete_);
|
| + if (discovery_pending_count_ == 0) {
|
| + // This should never happen, just in case it happens with a device, this
|
| + // notification should be ignored.
|
| + VLOG(1) << *this
|
| + << ": Unmatch DiscoverDescriptors and DidDiscoverDescriptors.";
|
| + return;
|
| + }
|
| VLOG(1) << *this << ": Did discover descriptors.";
|
| + --discovery_pending_count_;
|
| std::unordered_set<std::string> descriptor_identifier_to_remove;
|
| for (const auto& iter : gatt_descriptor_macs_) {
|
| descriptor_identifier_to_remove.insert(iter.first);
|
| @@ -379,7 +389,7 @@ void BluetoothRemoteGattCharacteristicMac::DidDiscoverDescriptors() {
|
| gatt_descriptor_macs_.erase(pair_to_remove);
|
| GetMacAdapter()->NotifyGattDescriptorRemoved(descriptor_to_remove.get());
|
| }
|
| - is_discovery_complete_ = true;
|
| + is_discovery_complete_ = discovery_pending_count_ == 0;
|
| }
|
|
|
| bool BluetoothRemoteGattCharacteristicMac::IsReadable() const {
|
|
|