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

Unified Diff: device/bluetooth/bluetooth_remote_gatt_characteristic_android.cc

Issue 1765773002: bluetooth: Refactor GetDescriptorForUUID to GetDescriptorsForUUID. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bta-notify-tommyt-
Patch Set: Created 4 years, 10 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_remote_gatt_characteristic_android.cc
diff --git a/device/bluetooth/bluetooth_remote_gatt_characteristic_android.cc b/device/bluetooth/bluetooth_remote_gatt_characteristic_android.cc
index bb7e6696e7e55bfd7a930321243befbdd1541970..ae2c304d6216a5c7cb74629846bdcb64f9aa1773 100644
--- a/device/bluetooth/bluetooth_remote_gatt_characteristic_android.cc
+++ b/device/bluetooth/bluetooth_remote_gatt_characteristic_android.cc
@@ -137,7 +137,8 @@ void BluetoothRemoteGattCharacteristicAndroid::StartNotifySession(
const NotifySessionCallback& callback,
const ErrorCallback& error_callback) {
if (!pending_start_notify_calls_.empty()) {
- pending_start_notify_calls_.push(std::make_pair(callback, error_callback));
+ pending_start_notify_calls_.push_back(
+ std::make_pair(callback, error_callback));
return;
}
@@ -182,7 +183,8 @@ void BluetoothRemoteGattCharacteristicAndroid::StartNotifySession(
value.push_back(hasNotify ? 1 : 2);
value.push_back(0);
- pending_start_notify_calls_.push(std::make_pair(callback, error_callback));
+ pending_start_notify_calls_.push_back(
+ std::make_pair(callback, error_callback));
descriptor->WriteRemoteDescriptor(
value, base::Bind(&BluetoothRemoteGattCharacteristicAndroid::
OnStartNotifySessionSuccess,
@@ -252,21 +254,23 @@ void BluetoothRemoteGattCharacteristicAndroid::OnChanged(
}
void BluetoothRemoteGattCharacteristicAndroid::OnStartNotifySessionSuccess() {
- while (!pending_start_notify_calls_.empty()) {
- PendingStartNotifyCall callbacks = pending_start_notify_calls_.front();
- pending_start_notify_calls_.pop();
+ std::vector<PendingStartNotifyCall> reentrant_safe_callbacks;
+ reentrant_safe_callbacks.swap(pending_start_notify_calls_);
+
+ for (const auto& callback_pair : reentrant_safe_callbacks) {
scoped_ptr<device::BluetoothGattNotifySession> notify_session(
new BluetoothGattNotifySessionAndroid(instance_id_));
- callbacks.first.Run(std::move(notify_session));
+ callback_pair.first.Run(std::move(notify_session));
}
}
void BluetoothRemoteGattCharacteristicAndroid::OnStartNotifySessionError(
BluetoothGattService::GattErrorCode error) {
- while (!pending_start_notify_calls_.empty()) {
- PendingStartNotifyCall callbacks = pending_start_notify_calls_.front();
- pending_start_notify_calls_.pop();
- callbacks.second.Run(error);
+ std::vector<PendingStartNotifyCall> reentrant_safe_callbacks;
+ reentrant_safe_callbacks.swap(pending_start_notify_calls_);
+
+ for (auto const& callback_pair : reentrant_safe_callbacks) {
+ callback_pair.second.Run(error);
}
}

Powered by Google App Engine
This is Rietveld 408576698