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 c04df6af94cbf836232feccfe1a9b6dd85743118..c5b2b14a4c50feaabb385535e89bb0cf898842b9 100644 |
--- a/device/bluetooth/bluetooth_remote_gatt_characteristic_mac.mm |
+++ b/device/bluetooth/bluetooth_remote_gatt_characteristic_mac.mm |
@@ -150,50 +150,6 @@ BluetoothRemoteGattCharacteristicMac::GetDescriptor( |
searched_pair->second.get()); |
} |
-void BluetoothRemoteGattCharacteristicMac::StartNotifySession( |
- const NotifySessionCallback& callback, |
- const ErrorCallback& error_callback) { |
- if (IsNotifying()) { |
- VLOG(2) << "Already notifying. Creating notify session."; |
- std::unique_ptr<BluetoothGattNotifySession> notify_session( |
- new BluetoothGattNotifySession(weak_ptr_factory_.GetWeakPtr())); |
- base::ThreadTaskRunnerHandle::Get()->PostTask( |
- FROM_HERE, |
- base::Bind(callback, base::Passed(std::move(notify_session)))); |
- return; |
- } |
- |
- if (!SupportsNotificationsOrIndications()) { |
- base::ThreadTaskRunnerHandle::Get()->PostTask( |
- FROM_HERE, |
- base::Bind(error_callback, |
- BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED)); |
- return; |
- } |
- |
- start_notify_session_callbacks_.push_back( |
- std::make_pair(callback, error_callback)); |
- |
- if (start_notifications_in_progress_) { |
- VLOG(2) << "Start Notifications already in progress. " |
- << "Request has been queued."; |
- return; |
- } |
- |
- [GetCBPeripheral() setNotifyValue:YES |
- forCharacteristic:cb_characteristic_.get()]; |
- start_notifications_in_progress_ = true; |
-} |
- |
-void BluetoothRemoteGattCharacteristicMac::StopNotifySession( |
- BluetoothGattNotifySession* session, |
- const base::Closure& callback) { |
- // TODO(http://crbug.com/633191): Remove this method and use the base version. |
- // Instead, we should implement SubscribeToNotifications and |
- // UnsubscribeFromNotifications. |
- base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); |
-} |
- |
void BluetoothRemoteGattCharacteristicMac::ReadRemoteCharacteristic( |
const ValueCallback& callback, |
const ErrorCallback& error_callback) { |
@@ -256,8 +212,34 @@ void BluetoothRemoteGattCharacteristicMac::SubscribeToNotifications( |
BluetoothRemoteGattDescriptor* ccc_descriptor, |
const base::Closure& callback, |
const ErrorCallback& error_callback) { |
- // TODO(http://crbug.com/633191): Implement this method |
- NOTIMPLEMENTED(); |
+ if (IsNotifying()) { |
ortuno
2017/01/16 22:56:26
No need for this check. This is already handled by
jlebel
2017/01/20 14:04:58
Done.
|
+ VLOG(2) << "Already notifying. Creating notify session."; |
+ std::unique_ptr<BluetoothGattNotifySession> notify_session( |
+ new BluetoothGattNotifySession(weak_ptr_factory_.GetWeakPtr())); |
+ callback.Run(); |
+ return; |
+ } |
+ |
+ if (!SupportsNotificationsOrIndications()) { |
ortuno
2017/01/16 22:56:26
Same here this is already handled by StartNotifySe
jlebel
2017/01/20 14:04:58
Done.
|
+ base::ThreadTaskRunnerHandle::Get()->PostTask( |
+ FROM_HERE, |
+ base::Bind(error_callback, |
+ BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED)); |
+ return; |
+ } |
+ |
+ start_notify_session_callbacks_.push_back( |
ortuno
2017/01/16 22:56:26
We should just DCHECK that the pair is empty.
|
+ std::make_pair(callback, error_callback)); |
+ |
+ if (start_notifications_in_progress_) { |
+ VLOG(2) << "Start Notifications already in progress. " |
+ << "Request has been queued."; |
+ return; |
+ } |
+ |
+ [GetCBPeripheral() setNotifyValue:YES |
+ forCharacteristic:cb_characteristic_.get()]; |
+ start_notifications_in_progress_ = true; |
} |
void BluetoothRemoteGattCharacteristicMac::UnsubscribeFromNotifications( |
@@ -336,8 +318,7 @@ void BluetoothRemoteGattCharacteristicMac::DidWriteValue(NSError* error) { |
void BluetoothRemoteGattCharacteristicMac::DidUpdateNotificationState( |
NSError* error) { |
- std::vector<std::pair<NotifySessionCallback, ErrorCallback>> |
- reentrant_safe_callbacks; |
+ std::vector<PendingStartNotifyCall> reentrant_safe_callbacks; |
reentrant_safe_callbacks.swap(start_notify_session_callbacks_); |
start_notifications_in_progress_ = false; |
if (error) { |
@@ -354,8 +335,7 @@ void BluetoothRemoteGattCharacteristicMac::DidUpdateNotificationState( |
return; |
} |
for (const auto& callback : reentrant_safe_callbacks) { |
- callback.first.Run(base::MakeUnique<BluetoothGattNotifySession>( |
- weak_ptr_factory_.GetWeakPtr())); |
+ callback.first.Run(); |
} |
} |