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

Unified Diff: device/bluetooth/bluetooth_remote_gatt_characteristic_android.cc

Issue 1712593002: bluetooth: android: Confirm the notify session after the descriptor has been written. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added the comment that Gio requested 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 d8d029900367defb7a0fc01af7d8895132b876fe..53e9509a4404caabf16936c783be82aacb2b71ab 100644
--- a/device/bluetooth/bluetooth_remote_gatt_characteristic_android.cc
+++ b/device/bluetooth/bluetooth_remote_gatt_characteristic_android.cc
@@ -136,20 +136,18 @@ bool BluetoothRemoteGattCharacteristicAndroid::UpdateValue(
void BluetoothRemoteGattCharacteristicAndroid::StartNotifySession(
const NotifySessionCallback& callback,
const ErrorCallback& error_callback) {
- if (Java_ChromeBluetoothRemoteGattCharacteristic_startNotifySession(
- AttachCurrentThread(), j_characteristic_.obj())) {
- // TODO(crbug.com/569664): Wait until descriptor write completes before
- // reporting success via calling |callback|.
- scoped_ptr<device::BluetoothGattNotifySession> notify_session(
- new BluetoothGattNotifySessionAndroid(instance_id_));
- base::MessageLoop::current()->PostTask(
- FROM_HERE, base::Bind(callback, base::Passed(&notify_session)));
- } else {
- base::MessageLoop::current()->PostTask(
- FROM_HERE,
- base::Bind(error_callback,
- BluetoothRemoteGattServiceAndroid::GATT_ERROR_FAILED));
+ if (pending_start_notify_calls_.empty()) {
scheib 2016/02/26 04:27:01 Starting notify, reading & writing the CCC descrip
tommyt 2016/03/01 14:45:14 I agree with moving this to C++. My newest changes
+ if (!Java_ChromeBluetoothRemoteGattCharacteristic_startNotifySession(
+ AttachCurrentThread(), j_characteristic_.obj())) {
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(error_callback,
+ BluetoothRemoteGattServiceAndroid::GATT_ERROR_FAILED));
+ return;
+ }
}
+
+ pending_start_notify_calls_.push(std::make_pair(callback, error_callback));
}
void BluetoothRemoteGattCharacteristicAndroid::ReadRemoteCharacteristic(
@@ -211,6 +209,24 @@ void BluetoothRemoteGattCharacteristicAndroid::OnChanged(
adapter_->NotifyGattCharacteristicValueChanged(this, value_);
}
+void BluetoothRemoteGattCharacteristicAndroid::OnStartNotifySession(
+ JNIEnv* env,
+ const JavaParamRef<jobject>& jcaller,
+ int32_t status) {
+ while (!pending_start_notify_calls_.empty()) {
+ PendingStartNotifyCall callbacks = pending_start_notify_calls_.front();
+ pending_start_notify_calls_.pop();
+ if (status == 0) { // android.bluetooth.BluetoothGatt.GATT_SUCCESS
+ scoped_ptr<device::BluetoothGattNotifySession> notify_session(
+ new BluetoothGattNotifySessionAndroid(instance_id_));
+ callbacks.first.Run(std::move(notify_session));
+ } else {
+ callbacks.second.Run(
+ BluetoothRemoteGattServiceAndroid::GetGattErrorCode(status));
+ }
+ }
+}
+
void BluetoothRemoteGattCharacteristicAndroid::OnRead(
JNIEnv* env,
const JavaParamRef<jobject>& jcaller,

Powered by Google App Engine
This is Rietveld 408576698