| 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_win.h" | 5 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_win.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 read_characteristic_value_callbacks_ = | 226 read_characteristic_value_callbacks_ = |
| 227 std::make_pair(callback, error_callback); | 227 std::make_pair(callback, error_callback); |
| 228 task_manager_->PostReadGattCharacteristicValue( | 228 task_manager_->PostReadGattCharacteristicValue( |
| 229 parent_service_->GetServicePath(), characteristic_info_.get(), | 229 parent_service_->GetServicePath(), characteristic_info_.get(), |
| 230 base::Bind(&BluetoothRemoteGattCharacteristicWin:: | 230 base::Bind(&BluetoothRemoteGattCharacteristicWin:: |
| 231 OnReadRemoteCharacteristicValueCallback, | 231 OnReadRemoteCharacteristicValueCallback, |
| 232 weak_ptr_factory_.GetWeakPtr())); | 232 weak_ptr_factory_.GetWeakPtr())); |
| 233 } | 233 } |
| 234 | 234 |
| 235 void BluetoothRemoteGattCharacteristicWin::WriteRemoteCharacteristic( | 235 void BluetoothRemoteGattCharacteristicWin::WriteRemoteCharacteristic( |
| 236 const std::vector<uint8_t>& new_value, | 236 const std::vector<uint8_t>& value, |
| 237 const base::Closure& callback, | 237 const base::Closure& callback, |
| 238 const ErrorCallback& error_callback) { | 238 const ErrorCallback& error_callback) { |
| 239 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 239 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 240 | 240 |
| 241 if (!characteristic_info_.get()->IsWritable) { | 241 if (!characteristic_info_.get()->IsWritable) { |
| 242 error_callback.Run(BluetoothRemoteGattService::GATT_ERROR_NOT_PERMITTED); | 242 error_callback.Run(BluetoothRemoteGattService::GATT_ERROR_NOT_PERMITTED); |
| 243 return; | 243 return; |
| 244 } | 244 } |
| 245 | 245 |
| 246 if (characteristic_value_read_or_write_in_progress_) { | 246 if (characteristic_value_read_or_write_in_progress_) { |
| 247 error_callback.Run(BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS); | 247 error_callback.Run(BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS); |
| 248 return; | 248 return; |
| 249 } | 249 } |
| 250 | 250 |
| 251 characteristic_value_read_or_write_in_progress_ = true; | 251 characteristic_value_read_or_write_in_progress_ = true; |
| 252 write_characteristic_value_callbacks_ = | 252 write_characteristic_value_callbacks_ = |
| 253 std::make_pair(callback, error_callback); | 253 std::make_pair(callback, error_callback); |
| 254 task_manager_->PostWriteGattCharacteristicValue( | 254 task_manager_->PostWriteGattCharacteristicValue( |
| 255 parent_service_->GetServicePath(), characteristic_info_.get(), new_value, | 255 parent_service_->GetServicePath(), characteristic_info_.get(), value, |
| 256 base::Bind(&BluetoothRemoteGattCharacteristicWin:: | 256 base::Bind(&BluetoothRemoteGattCharacteristicWin:: |
| 257 OnWriteRemoteCharacteristicValueCallback, | 257 OnWriteRemoteCharacteristicValueCallback, |
| 258 weak_ptr_factory_.GetWeakPtr())); | 258 weak_ptr_factory_.GetWeakPtr())); |
| 259 } | 259 } |
| 260 | 260 |
| 261 void BluetoothRemoteGattCharacteristicWin::Update() { | 261 void BluetoothRemoteGattCharacteristicWin::Update() { |
| 262 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 262 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 263 | 263 |
| 264 task_manager_->PostGetGattIncludedDescriptors( | 264 task_manager_->PostGetGattIncludedDescriptors( |
| 265 parent_service_->GetServicePath(), characteristic_info_.get(), | 265 parent_service_->GetServicePath(), characteristic_info_.get(), |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 | 458 |
| 459 void BluetoothRemoteGattCharacteristicWin::ClearIncludedDescriptors() { | 459 void BluetoothRemoteGattCharacteristicWin::ClearIncludedDescriptors() { |
| 460 // Explicitly reset to null to ensure that calling GetDescriptor() on the | 460 // Explicitly reset to null to ensure that calling GetDescriptor() on the |
| 461 // removed descriptor in GattDescriptorRemoved() returns null. | 461 // removed descriptor in GattDescriptorRemoved() returns null. |
| 462 for (auto& entry : included_descriptors_) | 462 for (auto& entry : included_descriptors_) |
| 463 entry.second.reset(); | 463 entry.second.reset(); |
| 464 included_descriptors_.clear(); | 464 included_descriptors_.clear(); |
| 465 } | 465 } |
| 466 | 466 |
| 467 } // namespace device. | 467 } // namespace device. |
| OLD | NEW |