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

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

Issue 2891853003: Rename TaskRunner::RunsTasksOnCurrentThread() in //device, //services (Closed)
Patch Set: fixed build error Created 3 years, 7 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_task_manager_win.h" 5 #include "device/bluetooth/bluetooth_task_manager_win.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <winsock2.h> 8 #include <winsock2.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 bth_le_uuid.Value.LongUuid.Data4[3], 236 bth_le_uuid.Value.LongUuid.Data4[3],
237 bth_le_uuid.Value.LongUuid.Data4[4], 237 bth_le_uuid.Value.LongUuid.Data4[4],
238 bth_le_uuid.Value.LongUuid.Data4[5], 238 bth_le_uuid.Value.LongUuid.Data4[5],
239 bth_le_uuid.Value.LongUuid.Data4[6], 239 bth_le_uuid.Value.LongUuid.Data4[6],
240 bth_le_uuid.Value.LongUuid.Data4[7])); 240 bth_le_uuid.Value.LongUuid.Data4[7]));
241 } 241 }
242 } 242 }
243 243
244 void BluetoothTaskManagerWin::AddObserver(Observer* observer) { 244 void BluetoothTaskManagerWin::AddObserver(Observer* observer) {
245 DCHECK(observer); 245 DCHECK(observer);
246 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); 246 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence());
247 observers_.AddObserver(observer); 247 observers_.AddObserver(observer);
248 } 248 }
249 249
250 void BluetoothTaskManagerWin::RemoveObserver(Observer* observer) { 250 void BluetoothTaskManagerWin::RemoveObserver(Observer* observer) {
251 DCHECK(observer); 251 DCHECK(observer);
252 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); 252 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence());
253 observers_.RemoveObserver(observer); 253 observers_.RemoveObserver(observer);
254 } 254 }
255 255
256 void BluetoothTaskManagerWin::Initialize() { 256 void BluetoothTaskManagerWin::Initialize() {
257 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); 257 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence());
258 InitializeWithBluetoothTaskRunner(base::CreateSequencedTaskRunnerWithTraits( 258 InitializeWithBluetoothTaskRunner(base::CreateSequencedTaskRunnerWithTraits(
259 {base::MayBlock(), base::TaskPriority::BACKGROUND, 259 {base::MayBlock(), base::TaskPriority::BACKGROUND,
260 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN})); 260 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN}));
261 } 261 }
262 262
263 void BluetoothTaskManagerWin::InitializeWithBluetoothTaskRunner( 263 void BluetoothTaskManagerWin::InitializeWithBluetoothTaskRunner(
264 scoped_refptr<base::SequencedTaskRunner> bluetooth_task_runner) { 264 scoped_refptr<base::SequencedTaskRunner> bluetooth_task_runner) {
265 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); 265 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence());
266 bluetooth_task_runner_ = bluetooth_task_runner; 266 bluetooth_task_runner_ = bluetooth_task_runner;
267 bluetooth_task_runner_->PostTask( 267 bluetooth_task_runner_->PostTask(
268 FROM_HERE, 268 FROM_HERE,
269 base::Bind(&BluetoothTaskManagerWin::StartPolling, this)); 269 base::Bind(&BluetoothTaskManagerWin::StartPolling, this));
270 } 270 }
271 271
272 void BluetoothTaskManagerWin::StartPolling() { 272 void BluetoothTaskManagerWin::StartPolling() {
273 DCHECK(bluetooth_task_runner_->RunsTasksOnCurrentThread()); 273 DCHECK(bluetooth_task_runner_->RunsTasksInCurrentSequence());
274 274
275 if (device::bluetooth_init_win::HasBluetoothStack()) { 275 if (device::bluetooth_init_win::HasBluetoothStack()) {
276 PollAdapter(); 276 PollAdapter();
277 } else { 277 } else {
278 // IF the bluetooth stack is not available, we still send an empty state 278 // IF the bluetooth stack is not available, we still send an empty state
279 // to BluetoothAdapter so that it is marked initialized, but the adapter 279 // to BluetoothAdapter so that it is marked initialized, but the adapter
280 // will not be present. 280 // will not be present.
281 AdapterState* state = new AdapterState(); 281 AdapterState* state = new AdapterState();
282 ui_task_runner_->PostTask( 282 ui_task_runner_->PostTask(
283 FROM_HERE, 283 FROM_HERE,
284 base::Bind(&BluetoothTaskManagerWin::OnAdapterStateChanged, 284 base::Bind(&BluetoothTaskManagerWin::OnAdapterStateChanged,
285 this, 285 this,
286 base::Owned(state))); 286 base::Owned(state)));
287 } 287 }
288 } 288 }
289 289
290 void BluetoothTaskManagerWin::PostSetPoweredBluetoothTask( 290 void BluetoothTaskManagerWin::PostSetPoweredBluetoothTask(
291 bool powered, 291 bool powered,
292 const base::Closure& callback, 292 const base::Closure& callback,
293 const BluetoothAdapter::ErrorCallback& error_callback) { 293 const BluetoothAdapter::ErrorCallback& error_callback) {
294 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); 294 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence());
295 bluetooth_task_runner_->PostTask( 295 bluetooth_task_runner_->PostTask(
296 FROM_HERE, 296 FROM_HERE,
297 base::Bind(&BluetoothTaskManagerWin::SetPowered, 297 base::Bind(&BluetoothTaskManagerWin::SetPowered,
298 this, 298 this,
299 powered, 299 powered,
300 callback, 300 callback,
301 error_callback)); 301 error_callback));
302 } 302 }
303 303
304 void BluetoothTaskManagerWin::PostStartDiscoveryTask() { 304 void BluetoothTaskManagerWin::PostStartDiscoveryTask() {
305 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); 305 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence());
306 bluetooth_task_runner_->PostTask( 306 bluetooth_task_runner_->PostTask(
307 FROM_HERE, 307 FROM_HERE,
308 base::Bind(&BluetoothTaskManagerWin::StartDiscovery, this)); 308 base::Bind(&BluetoothTaskManagerWin::StartDiscovery, this));
309 } 309 }
310 310
311 void BluetoothTaskManagerWin::PostStopDiscoveryTask() { 311 void BluetoothTaskManagerWin::PostStopDiscoveryTask() {
312 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); 312 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence());
313 bluetooth_task_runner_->PostTask( 313 bluetooth_task_runner_->PostTask(
314 FROM_HERE, 314 FROM_HERE,
315 base::Bind(&BluetoothTaskManagerWin::StopDiscovery, this)); 315 base::Bind(&BluetoothTaskManagerWin::StopDiscovery, this));
316 } 316 }
317 317
318 void BluetoothTaskManagerWin::LogPollingError(const char* message, 318 void BluetoothTaskManagerWin::LogPollingError(const char* message,
319 int win32_error) { 319 int win32_error) {
320 const int kLogPeriodInMilliseconds = 60 * 1000; 320 const int kLogPeriodInMilliseconds = 60 * 1000;
321 const int kMaxMessagesPerLogPeriod = 10; 321 const int kMaxMessagesPerLogPeriod = 10;
322 322
(...skipping 18 matching lines...) Expand all
341 341
342 // Log the message 342 // Log the message
343 if (win32_error == 0) 343 if (win32_error == 0)
344 LOG(WARNING) << message; 344 LOG(WARNING) << message;
345 else 345 else
346 LOG(WARNING) << message << ": " 346 LOG(WARNING) << message << ": "
347 << logging::SystemErrorCodeToString(win32_error); 347 << logging::SystemErrorCodeToString(win32_error);
348 } 348 }
349 349
350 void BluetoothTaskManagerWin::OnAdapterStateChanged(const AdapterState* state) { 350 void BluetoothTaskManagerWin::OnAdapterStateChanged(const AdapterState* state) {
351 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); 351 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence());
352 for (auto& observer : observers_) 352 for (auto& observer : observers_)
353 observer.AdapterStateChanged(*state); 353 observer.AdapterStateChanged(*state);
354 } 354 }
355 355
356 void BluetoothTaskManagerWin::OnDiscoveryStarted(bool success) { 356 void BluetoothTaskManagerWin::OnDiscoveryStarted(bool success) {
357 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); 357 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence());
358 for (auto& observer : observers_) 358 for (auto& observer : observers_)
359 observer.DiscoveryStarted(success); 359 observer.DiscoveryStarted(success);
360 } 360 }
361 361
362 void BluetoothTaskManagerWin::OnDiscoveryStopped() { 362 void BluetoothTaskManagerWin::OnDiscoveryStopped() {
363 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); 363 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence());
364 for (auto& observer : observers_) 364 for (auto& observer : observers_)
365 observer.DiscoveryStopped(); 365 observer.DiscoveryStopped();
366 } 366 }
367 367
368 void BluetoothTaskManagerWin::OnDevicesPolled( 368 void BluetoothTaskManagerWin::OnDevicesPolled(
369 std::vector<std::unique_ptr<DeviceState>> devices) { 369 std::vector<std::unique_ptr<DeviceState>> devices) {
370 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); 370 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence());
371 for (auto& observer : observers_) 371 for (auto& observer : observers_)
372 observer.DevicesPolled(devices); 372 observer.DevicesPolled(devices);
373 } 373 }
374 374
375 void BluetoothTaskManagerWin::PollAdapter() { 375 void BluetoothTaskManagerWin::PollAdapter() {
376 DCHECK(bluetooth_task_runner_->RunsTasksOnCurrentThread()); 376 DCHECK(bluetooth_task_runner_->RunsTasksInCurrentSequence());
377 377
378 // Skips updating the adapter info if the adapter is in discovery mode. 378 // Skips updating the adapter info if the adapter is in discovery mode.
379 if (!discovering_) { 379 if (!discovering_) {
380 const BLUETOOTH_FIND_RADIO_PARAMS adapter_param = 380 const BLUETOOTH_FIND_RADIO_PARAMS adapter_param =
381 { sizeof(BLUETOOTH_FIND_RADIO_PARAMS) }; 381 { sizeof(BLUETOOTH_FIND_RADIO_PARAMS) };
382 HANDLE temp_adapter_handle; 382 HANDLE temp_adapter_handle;
383 HBLUETOOTH_RADIO_FIND handle = 383 HBLUETOOTH_RADIO_FIND handle =
384 win::BluetoothClassicWrapper::GetInstance()->FindFirstRadio( 384 win::BluetoothClassicWrapper::GetInstance()->FindFirstRadio(
385 &adapter_param, &temp_adapter_handle); 385 &adapter_param, &temp_adapter_handle);
386 386
387 if (handle) { 387 if (handle) {
388 adapter_handle_ = temp_adapter_handle; 388 adapter_handle_ = temp_adapter_handle;
389 GetKnownDevices(); 389 GetKnownDevices();
390 win::BluetoothClassicWrapper::GetInstance()->FindRadioClose(handle); 390 win::BluetoothClassicWrapper::GetInstance()->FindRadioClose(handle);
391 } 391 }
392 392
393 PostAdapterStateToUi(); 393 PostAdapterStateToUi();
394 } 394 }
395 395
396 // Re-poll. 396 // Re-poll.
397 bluetooth_task_runner_->PostDelayedTask( 397 bluetooth_task_runner_->PostDelayedTask(
398 FROM_HERE, 398 FROM_HERE,
399 base::Bind(&BluetoothTaskManagerWin::PollAdapter, 399 base::Bind(&BluetoothTaskManagerWin::PollAdapter,
400 this), 400 this),
401 base::TimeDelta::FromMilliseconds(kPollIntervalMs)); 401 base::TimeDelta::FromMilliseconds(kPollIntervalMs));
402 } 402 }
403 403
404 void BluetoothTaskManagerWin::PostAdapterStateToUi() { 404 void BluetoothTaskManagerWin::PostAdapterStateToUi() {
405 DCHECK(bluetooth_task_runner_->RunsTasksOnCurrentThread()); 405 DCHECK(bluetooth_task_runner_->RunsTasksInCurrentSequence());
406 AdapterState* state = new AdapterState(); 406 AdapterState* state = new AdapterState();
407 GetAdapterState(adapter_handle_, state); 407 GetAdapterState(adapter_handle_, state);
408 ui_task_runner_->PostTask( 408 ui_task_runner_->PostTask(
409 FROM_HERE, 409 FROM_HERE,
410 base::Bind(&BluetoothTaskManagerWin::OnAdapterStateChanged, 410 base::Bind(&BluetoothTaskManagerWin::OnAdapterStateChanged,
411 this, 411 this,
412 base::Owned(state))); 412 base::Owned(state)));
413 } 413 }
414 414
415 void BluetoothTaskManagerWin::SetPowered( 415 void BluetoothTaskManagerWin::SetPowered(
416 bool powered, 416 bool powered,
417 const base::Closure& callback, 417 const base::Closure& callback,
418 const BluetoothAdapter::ErrorCallback& error_callback) { 418 const BluetoothAdapter::ErrorCallback& error_callback) {
419 DCHECK(bluetooth_task_runner_->RunsTasksOnCurrentThread()); 419 DCHECK(bluetooth_task_runner_->RunsTasksInCurrentSequence());
420 bool success = false; 420 bool success = false;
421 if (adapter_handle_) { 421 if (adapter_handle_) {
422 if (!powered) { 422 if (!powered) {
423 win::BluetoothClassicWrapper::GetInstance()->EnableDiscovery( 423 win::BluetoothClassicWrapper::GetInstance()->EnableDiscovery(
424 adapter_handle_, false); 424 adapter_handle_, false);
425 } 425 }
426 success = !!win::BluetoothClassicWrapper::GetInstance() 426 success = !!win::BluetoothClassicWrapper::GetInstance()
427 ->EnableIncomingConnections(adapter_handle_, powered); 427 ->EnableIncomingConnections(adapter_handle_, powered);
428 } 428 }
429 429
430 if (success) { 430 if (success) {
431 PostAdapterStateToUi(); 431 PostAdapterStateToUi();
432 ui_task_runner_->PostTask(FROM_HERE, callback); 432 ui_task_runner_->PostTask(FROM_HERE, callback);
433 } else { 433 } else {
434 ui_task_runner_->PostTask(FROM_HERE, error_callback); 434 ui_task_runner_->PostTask(FROM_HERE, error_callback);
435 } 435 }
436 } 436 }
437 437
438 void BluetoothTaskManagerWin::StartDiscovery() { 438 void BluetoothTaskManagerWin::StartDiscovery() {
439 DCHECK(bluetooth_task_runner_->RunsTasksOnCurrentThread()); 439 DCHECK(bluetooth_task_runner_->RunsTasksInCurrentSequence());
440 ui_task_runner_->PostTask( 440 ui_task_runner_->PostTask(
441 FROM_HERE, base::Bind(&BluetoothTaskManagerWin::OnDiscoveryStarted, this, 441 FROM_HERE, base::Bind(&BluetoothTaskManagerWin::OnDiscoveryStarted, this,
442 !!adapter_handle_)); 442 !!adapter_handle_));
443 if (!adapter_handle_) 443 if (!adapter_handle_)
444 return; 444 return;
445 discovering_ = true; 445 discovering_ = true;
446 446
447 DiscoverDevices(1); 447 DiscoverDevices(1);
448 } 448 }
449 449
450 void BluetoothTaskManagerWin::StopDiscovery() { 450 void BluetoothTaskManagerWin::StopDiscovery() {
451 DCHECK(bluetooth_task_runner_->RunsTasksOnCurrentThread()); 451 DCHECK(bluetooth_task_runner_->RunsTasksInCurrentSequence());
452 discovering_ = false; 452 discovering_ = false;
453 ui_task_runner_->PostTask( 453 ui_task_runner_->PostTask(
454 FROM_HERE, 454 FROM_HERE,
455 base::Bind(&BluetoothTaskManagerWin::OnDiscoveryStopped, this)); 455 base::Bind(&BluetoothTaskManagerWin::OnDiscoveryStopped, this));
456 } 456 }
457 457
458 void BluetoothTaskManagerWin::DiscoverDevices(int timeout_multiplier) { 458 void BluetoothTaskManagerWin::DiscoverDevices(int timeout_multiplier) {
459 DCHECK(bluetooth_task_runner_->RunsTasksOnCurrentThread()); 459 DCHECK(bluetooth_task_runner_->RunsTasksInCurrentSequence());
460 if (!discovering_ || !adapter_handle_) { 460 if (!discovering_ || !adapter_handle_) {
461 ui_task_runner_->PostTask( 461 ui_task_runner_->PostTask(
462 FROM_HERE, 462 FROM_HERE,
463 base::Bind(&BluetoothTaskManagerWin::OnDiscoveryStopped, this)); 463 base::Bind(&BluetoothTaskManagerWin::OnDiscoveryStopped, this));
464 return; 464 return;
465 } 465 }
466 466
467 std::vector<std::unique_ptr<DeviceState>> device_list; 467 std::vector<std::unique_ptr<DeviceState>> device_list;
468 if (SearchDevices(timeout_multiplier, false, &device_list)) { 468 if (SearchDevices(timeout_multiplier, false, &device_list)) {
469 ui_task_runner_->PostTask( 469 ui_task_runner_->PostTask(
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 device_state->connected = device_info->connected; 583 device_state->connected = device_info->connected;
584 device_state->path = device_info->path; 584 device_state->path = device_info->path;
585 device_list->push_back(std::move(device_state)); 585 device_list->push_back(std::move(device_state));
586 } 586 }
587 return true; 587 return true;
588 } 588 }
589 589
590 bool BluetoothTaskManagerWin::DiscoverServices( 590 bool BluetoothTaskManagerWin::DiscoverServices(
591 std::vector<std::unique_ptr<DeviceState>>* device_list, 591 std::vector<std::unique_ptr<DeviceState>>* device_list,
592 bool search_cached_services_only) { 592 bool search_cached_services_only) {
593 DCHECK(bluetooth_task_runner_->RunsTasksOnCurrentThread()); 593 DCHECK(bluetooth_task_runner_->RunsTasksInCurrentSequence());
594 net::EnsureWinsockInit(); 594 net::EnsureWinsockInit();
595 for (const auto& device : *device_list) { 595 for (const auto& device : *device_list) {
596 std::vector<std::unique_ptr<ServiceRecordState>>* service_record_states = 596 std::vector<std::unique_ptr<ServiceRecordState>>* service_record_states =
597 &device->service_record_states; 597 &device->service_record_states;
598 598
599 if (device->is_bluetooth_classic()) { 599 if (device->is_bluetooth_classic()) {
600 if (!DiscoverClassicDeviceServices(device->address, 600 if (!DiscoverClassicDeviceServices(device->address,
601 L2CAP_PROTOCOL_UUID, 601 L2CAP_PROTOCOL_UUID,
602 search_cached_services_only, 602 search_cached_services_only,
603 service_record_states)) { 603 service_record_states)) {
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 877
878 ui_task_runner_->PostTask(FROM_HERE, base::Bind(callback, hr)); 878 ui_task_runner_->PostTask(FROM_HERE, base::Bind(callback, hr));
879 } 879 }
880 880
881 void BluetoothTaskManagerWin::RegisterGattCharacteristicValueChangedEvent( 881 void BluetoothTaskManagerWin::RegisterGattCharacteristicValueChangedEvent(
882 base::FilePath service_path, 882 base::FilePath service_path,
883 BTH_LE_GATT_CHARACTERISTIC characteristic, 883 BTH_LE_GATT_CHARACTERISTIC characteristic,
884 BTH_LE_GATT_DESCRIPTOR ccc_descriptor, 884 BTH_LE_GATT_DESCRIPTOR ccc_descriptor,
885 const GattEventRegistrationCallback& callback, 885 const GattEventRegistrationCallback& callback,
886 const GattCharacteristicValueChangedCallback& registered_callback) { 886 const GattCharacteristicValueChangedCallback& registered_callback) {
887 DCHECK(bluetooth_task_runner_->RunsTasksOnCurrentThread()); 887 DCHECK(bluetooth_task_runner_->RunsTasksInCurrentSequence());
888 BLUETOOTH_GATT_EVENT_HANDLE win_event_handle = NULL; 888 BLUETOOTH_GATT_EVENT_HANDLE win_event_handle = NULL;
889 889
890 BLUETOOTH_GATT_VALUE_CHANGED_EVENT_REGISTRATION win_event_parameter; 890 BLUETOOTH_GATT_VALUE_CHANGED_EVENT_REGISTRATION win_event_parameter;
891 memcpy(&(win_event_parameter.Characteristics[0]), &characteristic, 891 memcpy(&(win_event_parameter.Characteristics[0]), &characteristic,
892 sizeof(BTH_LE_GATT_CHARACTERISTIC)); 892 sizeof(BTH_LE_GATT_CHARACTERISTIC));
893 win_event_parameter.NumCharacteristics = 1; 893 win_event_parameter.NumCharacteristics = 1;
894 PVOID user_event_handle = (PVOID)&registered_callback; 894 PVOID user_event_handle = (PVOID)&registered_callback;
895 HRESULT hr = 895 HRESULT hr =
896 win::BluetoothLowEnergyWrapper::GetInstance()->RegisterGattEvents( 896 win::BluetoothLowEnergyWrapper::GetInstance()->RegisterGattEvents(
897 service_path, CharacteristicValueChangedEvent, &win_event_parameter, 897 service_path, CharacteristicValueChangedEvent, &win_event_parameter,
(...skipping 27 matching lines...) Expand all
925 g_characteristic_value_changed_registrations[user_event_handle] = 925 g_characteristic_value_changed_registrations[user_event_handle] =
926 std::move(registration); 926 std::move(registration);
927 } 927 }
928 928
929 ui_task_runner_->PostTask(FROM_HERE, 929 ui_task_runner_->PostTask(FROM_HERE,
930 base::Bind(callback, user_event_handle, hr)); 930 base::Bind(callback, user_event_handle, hr));
931 } 931 }
932 932
933 void BluetoothTaskManagerWin::UnregisterGattCharacteristicValueChangedEvent( 933 void BluetoothTaskManagerWin::UnregisterGattCharacteristicValueChangedEvent(
934 PVOID event_handle) { 934 PVOID event_handle) {
935 DCHECK(bluetooth_task_runner_->RunsTasksOnCurrentThread()); 935 DCHECK(bluetooth_task_runner_->RunsTasksInCurrentSequence());
936 936
937 base::AutoLock auto_lock(g_characteristic_value_changed_registrations_lock); 937 base::AutoLock auto_lock(g_characteristic_value_changed_registrations_lock);
938 CharacteristicValueChangedRegistrationMap::const_iterator it = 938 CharacteristicValueChangedRegistrationMap::const_iterator it =
939 g_characteristic_value_changed_registrations.find(event_handle); 939 g_characteristic_value_changed_registrations.find(event_handle);
940 if (it != g_characteristic_value_changed_registrations.end()) { 940 if (it != g_characteristic_value_changed_registrations.end()) {
941 win::BluetoothLowEnergyWrapper::GetInstance()->UnregisterGattEvent( 941 win::BluetoothLowEnergyWrapper::GetInstance()->UnregisterGattEvent(
942 it->second->win_event_handle); 942 it->second->win_event_handle);
943 g_characteristic_value_changed_registrations.erase(event_handle); 943 g_characteristic_value_changed_registrations.erase(event_handle);
944 } 944 }
945 } 945 }
946 946
947 void BluetoothTaskManagerWin::PostGetGattIncludedCharacteristics( 947 void BluetoothTaskManagerWin::PostGetGattIncludedCharacteristics(
948 const base::FilePath& service_path, 948 const base::FilePath& service_path,
949 const BluetoothUUID& uuid, 949 const BluetoothUUID& uuid,
950 uint16_t attribute_handle, 950 uint16_t attribute_handle,
951 const GetGattIncludedCharacteristicsCallback& callback) { 951 const GetGattIncludedCharacteristicsCallback& callback) {
952 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); 952 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence());
953 bluetooth_task_runner_->PostTask( 953 bluetooth_task_runner_->PostTask(
954 FROM_HERE, 954 FROM_HERE,
955 base::Bind(&BluetoothTaskManagerWin::GetGattIncludedCharacteristics, this, 955 base::Bind(&BluetoothTaskManagerWin::GetGattIncludedCharacteristics, this,
956 service_path, uuid, attribute_handle, callback)); 956 service_path, uuid, attribute_handle, callback));
957 } 957 }
958 958
959 void BluetoothTaskManagerWin::PostGetGattIncludedDescriptors( 959 void BluetoothTaskManagerWin::PostGetGattIncludedDescriptors(
960 const base::FilePath& service_path, 960 const base::FilePath& service_path,
961 const PBTH_LE_GATT_CHARACTERISTIC characteristic, 961 const PBTH_LE_GATT_CHARACTERISTIC characteristic,
962 const GetGattIncludedDescriptorsCallback& callback) { 962 const GetGattIncludedDescriptorsCallback& callback) {
963 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); 963 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence());
964 bluetooth_task_runner_->PostTask( 964 bluetooth_task_runner_->PostTask(
965 FROM_HERE, 965 FROM_HERE,
966 base::Bind(&BluetoothTaskManagerWin::GetGattIncludedDescriptors, this, 966 base::Bind(&BluetoothTaskManagerWin::GetGattIncludedDescriptors, this,
967 service_path, *characteristic, callback)); 967 service_path, *characteristic, callback));
968 } 968 }
969 969
970 void BluetoothTaskManagerWin::PostReadGattCharacteristicValue( 970 void BluetoothTaskManagerWin::PostReadGattCharacteristicValue(
971 const base::FilePath& service_path, 971 const base::FilePath& service_path,
972 const PBTH_LE_GATT_CHARACTERISTIC characteristic, 972 const PBTH_LE_GATT_CHARACTERISTIC characteristic,
973 const ReadGattCharacteristicValueCallback& callback) { 973 const ReadGattCharacteristicValueCallback& callback) {
974 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); 974 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence());
975 bluetooth_task_runner_->PostTask( 975 bluetooth_task_runner_->PostTask(
976 FROM_HERE, 976 FROM_HERE,
977 base::Bind(&BluetoothTaskManagerWin::ReadGattCharacteristicValue, this, 977 base::Bind(&BluetoothTaskManagerWin::ReadGattCharacteristicValue, this,
978 service_path, *characteristic, callback)); 978 service_path, *characteristic, callback));
979 } 979 }
980 980
981 void BluetoothTaskManagerWin::PostWriteGattCharacteristicValue( 981 void BluetoothTaskManagerWin::PostWriteGattCharacteristicValue(
982 const base::FilePath& service_path, 982 const base::FilePath& service_path,
983 const PBTH_LE_GATT_CHARACTERISTIC characteristic, 983 const PBTH_LE_GATT_CHARACTERISTIC characteristic,
984 const std::vector<uint8_t>& new_value, 984 const std::vector<uint8_t>& new_value,
985 const HResultCallback& callback) { 985 const HResultCallback& callback) {
986 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); 986 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence());
987 bluetooth_task_runner_->PostTask( 987 bluetooth_task_runner_->PostTask(
988 FROM_HERE, 988 FROM_HERE,
989 base::Bind(&BluetoothTaskManagerWin::WriteGattCharacteristicValue, this, 989 base::Bind(&BluetoothTaskManagerWin::WriteGattCharacteristicValue, this,
990 service_path, *characteristic, new_value, callback)); 990 service_path, *characteristic, new_value, callback));
991 } 991 }
992 992
993 void BluetoothTaskManagerWin::PostRegisterGattCharacteristicValueChangedEvent( 993 void BluetoothTaskManagerWin::PostRegisterGattCharacteristicValueChangedEvent(
994 const base::FilePath& service_path, 994 const base::FilePath& service_path,
995 const PBTH_LE_GATT_CHARACTERISTIC characteristic, 995 const PBTH_LE_GATT_CHARACTERISTIC characteristic,
996 const PBTH_LE_GATT_DESCRIPTOR ccc_descriptor, 996 const PBTH_LE_GATT_DESCRIPTOR ccc_descriptor,
997 const GattEventRegistrationCallback& callback, 997 const GattEventRegistrationCallback& callback,
998 const GattCharacteristicValueChangedCallback& registered_callback) { 998 const GattCharacteristicValueChangedCallback& registered_callback) {
999 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); 999 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence());
1000 bluetooth_task_runner_->PostTask( 1000 bluetooth_task_runner_->PostTask(
1001 FROM_HERE, 1001 FROM_HERE,
1002 base::Bind( 1002 base::Bind(
1003 &BluetoothTaskManagerWin::RegisterGattCharacteristicValueChangedEvent, 1003 &BluetoothTaskManagerWin::RegisterGattCharacteristicValueChangedEvent,
1004 this, service_path, *characteristic, *ccc_descriptor, callback, 1004 this, service_path, *characteristic, *ccc_descriptor, callback,
1005 registered_callback)); 1005 registered_callback));
1006 } 1006 }
1007 1007
1008 void BluetoothTaskManagerWin::PostUnregisterGattCharacteristicValueChangedEvent( 1008 void BluetoothTaskManagerWin::PostUnregisterGattCharacteristicValueChangedEvent(
1009 PVOID event_handle) { 1009 PVOID event_handle) {
1010 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); 1010 DCHECK(ui_task_runner_->RunsTasksInCurrentSequence());
1011 bluetooth_task_runner_->PostTask( 1011 bluetooth_task_runner_->PostTask(
1012 FROM_HERE, base::Bind(&BluetoothTaskManagerWin:: 1012 FROM_HERE, base::Bind(&BluetoothTaskManagerWin::
1013 UnregisterGattCharacteristicValueChangedEvent, 1013 UnregisterGattCharacteristicValueChangedEvent,
1014 this, event_handle)); 1014 this, event_handle));
1015 } 1015 }
1016 1016
1017 } // namespace device 1017 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_socket_win.cc ('k') | device/bluetooth/bluez/bluetooth_socket_bluez.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698