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

Side by Side Diff: device/bluetooth/bluetooth_remote_gatt_characteristic.cc

Issue 2826383002: bluetooth: Make in progress errors consistent across android
Patch Set: Fix windows Created 3 years, 8 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 unified diff | Download patch
OLDNEW
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"
11 #include "device/bluetooth/bluetooth_device.h"
11 #include "device/bluetooth/bluetooth_gatt_notify_session.h" 12 #include "device/bluetooth/bluetooth_gatt_notify_session.h"
12 #include "device/bluetooth/bluetooth_remote_gatt_descriptor.h" 13 #include "device/bluetooth/bluetooth_remote_gatt_descriptor.h"
13 14
14 namespace device { 15 namespace device {
15 16
16 BluetoothRemoteGattCharacteristic::BluetoothRemoteGattCharacteristic() 17 BluetoothRemoteGattCharacteristic::BluetoothRemoteGattCharacteristic()
17 : weak_ptr_factory_(this) {} 18 : weak_ptr_factory_(this) {}
18 19
19 BluetoothRemoteGattCharacteristic::~BluetoothRemoteGattCharacteristic() { 20 BluetoothRemoteGattCharacteristic::~BluetoothRemoteGattCharacteristic() {
20 while (!pending_notify_commands_.empty()) { 21 while (!pending_notify_commands_.empty()) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 GetWeakPtr(), 79 GetWeakPtr(),
79 base::Bind(error_callback, 80 base::Bind(error_callback,
80 BluetoothRemoteGattService::GATT_ERROR_FAILED))); 81 BluetoothRemoteGattService::GATT_ERROR_FAILED)));
81 82
82 pending_notify_commands_.push(std::unique_ptr<NotifySessionCommand>(command)); 83 pending_notify_commands_.push(std::unique_ptr<NotifySessionCommand>(command));
83 if (pending_notify_commands_.size() == 1) { 84 if (pending_notify_commands_.size() == 1) {
84 command->Execute(); 85 command->Execute();
85 } 86 }
86 } 87 }
87 88
89 void BluetoothRemoteGattCharacteristic::ReadRemoteCharacteristic(
scheib 2017/04/21 23:33:10 Consider keeping all logic in the base classes, ne
ortuno 2017/04/28 03:47:12 I was exploring something like that at some point
90 const ValueCallback& callback,
91 const ErrorCallback& error_callback) {
92 if (HasPendingGattOperation()) {
93 base::ThreadTaskRunnerHandle::Get()->PostTask(
94 FROM_HERE,
95 base::Bind(error_callback,
96 BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS));
97 return;
98 }
99 ReadRemoteCharacteristicImpl(callback, error_callback);
100 }
101
102 void BluetoothRemoteGattCharacteristic::WriteRemoteCharacteristic(
103 const std::vector<uint8_t>& value,
104 const base::Closure& callback,
105 const ErrorCallback& error_callback) {
106 if (HasPendingGattOperation()) {
107 base::ThreadTaskRunnerHandle::Get()->PostTask(
108 FROM_HERE,
109 base::Bind(error_callback,
110 BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS));
111 return;
112 }
113 WriteRemoteCharacteristicImpl(value, callback, error_callback);
114 }
115
88 void BluetoothRemoteGattCharacteristic::ExecuteStartNotifySession( 116 void BluetoothRemoteGattCharacteristic::ExecuteStartNotifySession(
89 NotifySessionCallback callback, 117 NotifySessionCallback callback,
90 ErrorCallback error_callback, 118 ErrorCallback error_callback,
91 NotifySessionCommand::Type previous_command_type, 119 NotifySessionCommand::Type previous_command_type,
92 NotifySessionCommand::Result previous_command_result, 120 NotifySessionCommand::Result previous_command_result,
93 BluetoothRemoteGattService::GattErrorCode previous_command_error_code) { 121 BluetoothRemoteGattService::GattErrorCode previous_command_error_code) {
94 // If the command that was resolved immediately before this command was run, 122 // If the command that was resolved immediately before this command was run,
95 // this command should be resolved with the same result. 123 // this command should be resolved with the same result.
96 if (previous_command_type == NotifySessionCommand::COMMAND_START) { 124 if (previous_command_type == NotifySessionCommand::COMMAND_START) {
97 if (previous_command_result == NotifySessionCommand::RESULT_SUCCESS) { 125 if (previous_command_result == NotifySessionCommand::RESULT_SUCCESS) {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 error_callback.Run(error); 249 error_callback.Run(error);
222 250
223 pending_notify_commands_.pop(); 251 pending_notify_commands_.pop();
224 if (!pending_notify_commands_.empty()) { 252 if (!pending_notify_commands_.empty()) {
225 pending_notify_commands_.front()->Execute( 253 pending_notify_commands_.front()->Execute(
226 NotifySessionCommand::COMMAND_START, NotifySessionCommand::RESULT_ERROR, 254 NotifySessionCommand::COMMAND_START, NotifySessionCommand::RESULT_ERROR,
227 error); 255 error);
228 } 256 }
229 } 257 }
230 258
259 bool BluetoothRemoteGattCharacteristic::HasPendingGattOperation() {
260 return GetService()->GetDevice()->HasPendingGattOperation();
261 }
262 void BluetoothRemoteGattCharacteristic::SetPendingGattOperation(bool pending) {
263 GetService()->GetDevice()->SetPendingGattOperation(pending);
264 }
265
231 void BluetoothRemoteGattCharacteristic::StopNotifySession( 266 void BluetoothRemoteGattCharacteristic::StopNotifySession(
232 BluetoothGattNotifySession* session, 267 BluetoothGattNotifySession* session,
233 const base::Closure& callback) { 268 const base::Closure& callback) {
234 NotifySessionCommand* command = new NotifySessionCommand( 269 NotifySessionCommand* command = new NotifySessionCommand(
235 base::Bind(&BluetoothRemoteGattCharacteristic::ExecuteStopNotifySession, 270 base::Bind(&BluetoothRemoteGattCharacteristic::ExecuteStopNotifySession,
236 GetWeakPtr(), session, callback), 271 GetWeakPtr(), session, callback),
237 base::Bind(&BluetoothRemoteGattCharacteristic::CancelStopNotifySession, 272 base::Bind(&BluetoothRemoteGattCharacteristic::CancelStopNotifySession,
238 GetWeakPtr(), callback)); 273 GetWeakPtr(), callback));
239 274
240 pending_notify_commands_.push(std::unique_ptr<NotifySessionCommand>(command)); 275 pending_notify_commands_.push(std::unique_ptr<NotifySessionCommand>(command));
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 386
352 pending_notify_commands_.pop(); 387 pending_notify_commands_.pop();
353 if (!pending_notify_commands_.empty()) { 388 if (!pending_notify_commands_.empty()) {
354 pending_notify_commands_.front()->Execute( 389 pending_notify_commands_.front()->Execute(
355 NotifySessionCommand::COMMAND_STOP, NotifySessionCommand::RESULT_ERROR, 390 NotifySessionCommand::COMMAND_STOP, NotifySessionCommand::RESULT_ERROR,
356 error); 391 error);
357 } 392 }
358 } 393 }
359 394
360 } // namespace device 395 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698