Chromium Code Reviews| 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..d31bd59a4d419499bc083314b28682421037e4a5 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); |
|
ortuno
2016/03/25 02:07:31
Talked offline. This can happen when we call start
scheib
2016/03/25 02:35:00
Acknowledged.
|
| + } |
| } |
| // 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; |
| } |
| @@ -150,7 +155,9 @@ void BluetoothRemoteGattCharacteristicAndroid::StartNotifySession( |
| LOG(ERROR) << "Characteristic needs NOTIFY or INDICATE"; |
| base::MessageLoop::current()->PostTask( |
| FROM_HERE, |
| - base::Bind(error_callback, BluetoothGattService::GATT_ERROR_FAILED)); |
| + |
|
ortuno
2016/03/25 02:07:31
remove new line.
scheib
2016/03/25 02:35:01
Done.
|
| + base::Bind(error_callback, |
| + BluetoothGattService::GATT_ERROR_NOT_SUPPORTED)); |
| return; |
| } |
| @@ -178,11 +185,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 +257,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); |
| } |
| } |