OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" | 5 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 &BluetoothRemoteGattCharacteristic::OnStopNotifySessionSuccess, | 271 &BluetoothRemoteGattCharacteristic::OnStopNotifySessionSuccess, |
272 GetWeakPtr(), session, callback)); | 272 GetWeakPtr(), session, callback)); |
273 return; | 273 return; |
274 } | 274 } |
275 | 275 |
276 // After we migrate each platform to the new way of starting and stopping | 276 // After we migrate each platform to the new way of starting and stopping |
277 // notifications, we can remove them from this #if check. The goal is to get | 277 // notifications, we can remove them from this #if check. The goal is to get |
278 // rid of the entire check, and run SubscribeToNotifications on all | 278 // rid of the entire check, and run SubscribeToNotifications on all |
279 // platforms. | 279 // platforms. |
280 // | 280 // |
281 // TODO(http://crbug.com/633191): Remove OS_MACOSX from this check. | |
282 // TODO(http://crbug.com/636270): Remove OS_WIN from this check. | 281 // TODO(http://crbug.com/636270): Remove OS_WIN from this check. |
283 #if defined(OS_MACOSX) || defined(OS_WIN) | 282 #if defined(OS_WIN) |
284 base::ThreadTaskRunnerHandle::Get()->PostTask( | 283 base::ThreadTaskRunnerHandle::Get()->PostTask( |
285 FROM_HERE, | 284 FROM_HERE, |
286 base::Bind(&BluetoothRemoteGattCharacteristic::OnStopNotifySessionError, | 285 base::Bind(&BluetoothRemoteGattCharacteristic::OnStopNotifySessionError, |
287 GetWeakPtr(), session, callback, | 286 GetWeakPtr(), session, callback, |
288 BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED)); | 287 BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED)); |
289 #else // !(defined(OS_MACOSX) || defined(OS_WIN)) | 288 #else // defined(OS_WIN)) |
290 // Find the Client Characteristic Configuration descriptor. | 289 // Find the Client Characteristic Configuration descriptor. |
291 std::vector<BluetoothRemoteGattDescriptor*> ccc_descriptor = | 290 std::vector<BluetoothRemoteGattDescriptor*> ccc_descriptor = |
292 GetDescriptorsByUUID(BluetoothRemoteGattDescriptor:: | 291 GetDescriptorsByUUID(BluetoothRemoteGattDescriptor:: |
293 ClientCharacteristicConfigurationUuid()); | 292 ClientCharacteristicConfigurationUuid()); |
294 | 293 |
295 if (ccc_descriptor.size() != 1u) { | 294 if (ccc_descriptor.size() != 1u) { |
296 LOG(ERROR) << "Found " << ccc_descriptor.size() | 295 LOG(ERROR) << "Found " << ccc_descriptor.size() |
297 << " client characteristic configuration descriptors."; | 296 << " client characteristic configuration descriptors."; |
298 base::ThreadTaskRunnerHandle::Get()->PostTask( | 297 base::ThreadTaskRunnerHandle::Get()->PostTask( |
299 FROM_HERE, | 298 FROM_HERE, |
300 base::Bind(&BluetoothRemoteGattCharacteristic::OnStopNotifySessionError, | 299 base::Bind(&BluetoothRemoteGattCharacteristic::OnStopNotifySessionError, |
301 GetWeakPtr(), session, callback, | 300 GetWeakPtr(), session, callback, |
302 BluetoothRemoteGattService::GATT_ERROR_FAILED)); | 301 BluetoothRemoteGattService::GATT_ERROR_FAILED)); |
303 return; | 302 return; |
304 } | 303 } |
305 | 304 |
306 UnsubscribeFromNotifications( | 305 UnsubscribeFromNotifications( |
307 ccc_descriptor[0], | 306 ccc_descriptor[0], |
308 base::Bind(&BluetoothRemoteGattCharacteristic::OnStopNotifySessionSuccess, | 307 base::Bind(&BluetoothRemoteGattCharacteristic::OnStopNotifySessionSuccess, |
309 GetWeakPtr(), session, callback), | 308 GetWeakPtr(), session, callback), |
310 base::Bind(&BluetoothRemoteGattCharacteristic::OnStopNotifySessionError, | 309 base::Bind(&BluetoothRemoteGattCharacteristic::OnStopNotifySessionError, |
311 GetWeakPtr(), session, callback)); | 310 GetWeakPtr(), session, callback)); |
312 #endif // defined(OS_MACOSX) || defined(OS_WIN) | 311 #endif // defined(OS_WIN) |
313 } | 312 } |
314 | 313 |
315 void BluetoothRemoteGattCharacteristic::CancelStopNotifySession( | 314 void BluetoothRemoteGattCharacteristic::CancelStopNotifySession( |
316 base::Closure callback) { | 315 base::Closure callback) { |
317 std::unique_ptr<NotifySessionCommand> command = | 316 std::unique_ptr<NotifySessionCommand> command = |
318 std::move(pending_notify_commands_.front()); | 317 std::move(pending_notify_commands_.front()); |
319 pending_notify_commands_.pop(); | 318 pending_notify_commands_.pop(); |
320 callback.Run(); | 319 callback.Run(); |
321 } | 320 } |
322 | 321 |
(...skipping 29 matching lines...) Expand all Loading... |
352 | 351 |
353 pending_notify_commands_.pop(); | 352 pending_notify_commands_.pop(); |
354 if (!pending_notify_commands_.empty()) { | 353 if (!pending_notify_commands_.empty()) { |
355 pending_notify_commands_.front()->Execute( | 354 pending_notify_commands_.front()->Execute( |
356 NotifySessionCommand::COMMAND_STOP, NotifySessionCommand::RESULT_ERROR, | 355 NotifySessionCommand::COMMAND_STOP, NotifySessionCommand::RESULT_ERROR, |
357 error); | 356 error); |
358 } | 357 } |
359 } | 358 } |
360 | 359 |
361 } // namespace device | 360 } // namespace device |
OLD | NEW |