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

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

Issue 2632253003: Bluetooth: macOS: Replacing BluetoothRemoteGattCharacteristicMac::StartNotifySession() by Bluetooth… (Closed)
Patch Set: Comments from Giovanni Created 3 years, 11 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"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 &BluetoothRemoteGattCharacteristic::OnStartNotifySessionSuccess, 138 &BluetoothRemoteGattCharacteristic::OnStartNotifySessionSuccess,
139 GetWeakPtr(), callback)); 139 GetWeakPtr(), callback));
140 return; 140 return;
141 } 141 }
142 142
143 // After we migrate each platform to the new way of starting and stopping 143 // After we migrate each platform to the new way of starting and stopping
144 // notifications, we can remove them from this #if check. The goal is to get 144 // notifications, we can remove them from this #if check. The goal is to get
145 // rid of the entire check, and run SubscribeToNotifications on all 145 // rid of the entire check, and run SubscribeToNotifications on all
146 // platforms. 146 // platforms.
147 // 147 //
148 // TODO(http://crbug.com/633191): Remove OS_MACOSX from this check.
149 // TODO(http://crbug.com/636270): Remove OS_WIN from this check. 148 // TODO(http://crbug.com/636270): Remove OS_WIN from this check.
150 #if defined(OS_MACOSX) || defined(OS_WIN) 149 #if defined(OS_WIN)
151 base::ThreadTaskRunnerHandle::Get()->PostTask( 150 base::ThreadTaskRunnerHandle::Get()->PostTask(
152 FROM_HERE, 151 FROM_HERE,
153 base::Bind(&BluetoothRemoteGattCharacteristic::OnStartNotifySessionError, 152 base::Bind(&BluetoothRemoteGattCharacteristic::OnStartNotifySessionError,
154 GetWeakPtr(), error_callback, 153 GetWeakPtr(), error_callback,
155 BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED)); 154 BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED));
156 #else // !(defined(OS_MACOSX) || defined(OS_WIN)) 155 #else // defined(OS_WIN))
157 // Find the Client Characteristic Configuration descriptor. 156 // Find the Client Characteristic Configuration descriptor.
158 std::vector<BluetoothRemoteGattDescriptor*> ccc_descriptor = 157 std::vector<BluetoothRemoteGattDescriptor*> ccc_descriptor =
159 GetDescriptorsByUUID(BluetoothRemoteGattDescriptor:: 158 GetDescriptorsByUUID(BluetoothRemoteGattDescriptor::
160 ClientCharacteristicConfigurationUuid()); 159 ClientCharacteristicConfigurationUuid());
161 160
162 if (ccc_descriptor.size() != 1u) { 161 if (ccc_descriptor.size() != 1u) {
163 LOG(ERROR) << "Found " << ccc_descriptor.size() 162 LOG(ERROR) << "Found " << ccc_descriptor.size()
164 << " client characteristic configuration descriptors."; 163 << " client characteristic configuration descriptors.";
165 base::ThreadTaskRunnerHandle::Get()->PostTask( 164 base::ThreadTaskRunnerHandle::Get()->PostTask(
166 FROM_HERE, 165 FROM_HERE,
167 base::Bind( 166 base::Bind(
168 &BluetoothRemoteGattCharacteristic::OnStartNotifySessionError, 167 &BluetoothRemoteGattCharacteristic::OnStartNotifySessionError,
169 GetWeakPtr(), error_callback, 168 GetWeakPtr(), error_callback,
170 (ccc_descriptor.size() == 0) 169 (ccc_descriptor.size() == 0)
171 ? BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED 170 ? BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED
172 : BluetoothRemoteGattService::GATT_ERROR_FAILED)); 171 : BluetoothRemoteGattService::GATT_ERROR_FAILED));
173 return; 172 return;
174 } 173 }
175 174
176 // Pass the Client Characteristic Configuration descriptor to 175 // Pass the Client Characteristic Configuration descriptor to
177 // SubscribetoNotifications, which will write the correct value to it, and 176 // SubscribetoNotifications, which will write the correct value to it, and
178 // do whatever else is needed to get the notifications flowing. 177 // do whatever else is needed to get the notifications flowing.
179 SubscribeToNotifications( 178 SubscribeToNotifications(
180 ccc_descriptor[0], 179 ccc_descriptor[0],
181 base::Bind( 180 base::Bind(
182 &BluetoothRemoteGattCharacteristic::OnStartNotifySessionSuccess, 181 &BluetoothRemoteGattCharacteristic::OnStartNotifySessionSuccess,
183 GetWeakPtr(), callback), 182 GetWeakPtr(), callback),
184 base::Bind(&BluetoothRemoteGattCharacteristic::OnStartNotifySessionError, 183 base::Bind(&BluetoothRemoteGattCharacteristic::OnStartNotifySessionError,
185 GetWeakPtr(), error_callback)); 184 GetWeakPtr(), error_callback));
186 #endif // defined(OS_MACOSX) || defined(OS_WIN) 185 #endif // defined(OS_WIN)
187 } 186 }
188 187
189 void BluetoothRemoteGattCharacteristic::CancelStartNotifySession( 188 void BluetoothRemoteGattCharacteristic::CancelStartNotifySession(
190 base::Closure callback) { 189 base::Closure callback) {
191 std::unique_ptr<NotifySessionCommand> command = 190 std::unique_ptr<NotifySessionCommand> command =
192 std::move(pending_notify_commands_.front()); 191 std::move(pending_notify_commands_.front());
193 pending_notify_commands_.pop(); 192 pending_notify_commands_.pop();
194 callback.Run(); 193 callback.Run();
195 } 194 }
196 195
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698