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

Unified Diff: device/bluetooth/bluetooth_remote_gatt_characteristic_android.cc

Issue 1779083002: bluetooth: Test & make StartNotifySession reentrant. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bta-notify-followup-descriptors-
Patch Set: addressed ortuno comments Created 4 years, 9 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 c4a73ff1ea552be81bcd9c7288b04a107128f581..6ad56f601f557ec386a4cddf6d76f28caf040fd0 100644
--- a/device/bluetooth/bluetooth_remote_gatt_characteristic_android.cc
+++ b/device/bluetooth/bluetooth_remote_gatt_characteristic_android.cc
@@ -48,6 +48,10 @@ BluetoothRemoteGattCharacteristicAndroid::
~BluetoothRemoteGattCharacteristicAndroid() {
Java_ChromeBluetoothRemoteGattCharacteristic_onBluetoothRemoteGattCharacteristicAndroidDestruction(
AttachCurrentThread(), j_characteristic_.obj());
+
+ if (pending_start_notify_calls_.size()) {
+ OnStartNotifySessionError(device::BluetoothGattService::GATT_ERROR_FAILED);
+ }
}
// static
@@ -137,7 +141,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;
}
@@ -149,8 +154,8 @@ void BluetoothRemoteGattCharacteristicAndroid::StartNotifySession(
if (!hasNotify && !hasIndicate) {
LOG(ERROR) << "Characteristic needs NOTIFY or INDICATE";
base::MessageLoop::current()->PostTask(
- FROM_HERE,
- base::Bind(error_callback, BluetoothGattService::GATT_ERROR_FAILED));
+ FROM_HERE, base::Bind(error_callback,
+ BluetoothGattService::GATT_ERROR_NOT_SUPPORTED));
return;
}
@@ -178,11 +183,11 @@ void BluetoothRemoteGattCharacteristicAndroid::StartNotifySession(
return;
}
- std::vector<uint8_t> value;
- value.push_back(hasNotify ? 1 : 2);
- value.push_back(0);
+ std::vector<uint8_t> value(2);
+ value[0] = hasNotify ? 1 : 2;
- pending_start_notify_calls_.push(std::make_pair(callback, error_callback));
+ pending_start_notify_calls_.push_back(
+ std::make_pair(callback, error_callback));
ccc_descriptor[0]->WriteRemoteDescriptor(
value, base::Bind(&BluetoothRemoteGattCharacteristicAndroid::
OnStartNotifySessionSuccess,
@@ -250,21 +255,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);
}
}
« no previous file with comments | « device/bluetooth/bluetooth_remote_gatt_characteristic_android.h ('k') | device/bluetooth/test/bluetooth_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698