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

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

Issue 1646023002: Refactor bluetooth_low_energy_win to prepare for new Bluetooth test fixture (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: export class BluetoothLowEnergyWrapper for test Created 4 years, 10 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
« no previous file with comments | « device/bluetooth/bluetooth_low_energy_win_fake.cc ('k') | device/device_tests.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <string> 10 #include <string>
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 } 135 }
136 136
137 BluetoothTaskManagerWin::BluetoothTaskManagerWin( 137 BluetoothTaskManagerWin::BluetoothTaskManagerWin(
138 scoped_refptr<base::SequencedTaskRunner> ui_task_runner) 138 scoped_refptr<base::SequencedTaskRunner> ui_task_runner)
139 : ui_task_runner_(ui_task_runner), 139 : ui_task_runner_(ui_task_runner),
140 discovering_(false), 140 discovering_(false),
141 current_logging_batch_count_(0) { 141 current_logging_batch_count_(0) {
142 } 142 }
143 143
144 BluetoothTaskManagerWin::~BluetoothTaskManagerWin() { 144 BluetoothTaskManagerWin::~BluetoothTaskManagerWin() {
145 win::BluetoothLowEnergyWrapper::DeleteInstance();
145 } 146 }
146 147
147 void BluetoothTaskManagerWin::AddObserver(Observer* observer) { 148 void BluetoothTaskManagerWin::AddObserver(Observer* observer) {
148 DCHECK(observer); 149 DCHECK(observer);
149 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); 150 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
150 observers_.AddObserver(observer); 151 observers_.AddObserver(observer);
151 } 152 }
152 153
153 void BluetoothTaskManagerWin::RemoveObserver(Observer* observer) { 154 void BluetoothTaskManagerWin::RemoveObserver(Observer* observer) {
154 DCHECK(observer); 155 DCHECK(observer);
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 } 474 }
474 475
475 bool BluetoothTaskManagerWin::SearchLowEnergyDevices( 476 bool BluetoothTaskManagerWin::SearchLowEnergyDevices(
476 ScopedVector<DeviceState>* device_list) { 477 ScopedVector<DeviceState>* device_list) {
477 if (!win::IsBluetoothLowEnergySupported()) 478 if (!win::IsBluetoothLowEnergySupported())
478 return true; // Bluetooth LE not supported is not an error. 479 return true; // Bluetooth LE not supported is not an error.
479 480
480 ScopedVector<win::BluetoothLowEnergyDeviceInfo> btle_devices; 481 ScopedVector<win::BluetoothLowEnergyDeviceInfo> btle_devices;
481 std::string error; 482 std::string error;
482 bool success = 483 bool success =
483 win::EnumerateKnownBluetoothLowEnergyDevices(&btle_devices, &error); 484 win::BluetoothLowEnergyWrapper::GetInstance()
485 ->EnumerateKnownBluetoothLowEnergyDevices(&btle_devices, &error);
484 if (!success) { 486 if (!success) {
485 LogPollingError(error.c_str(), 0); 487 LogPollingError(error.c_str(), 0);
486 return false; 488 return false;
487 } 489 }
488 490
489 for (ScopedVector<win::BluetoothLowEnergyDeviceInfo>::iterator iter = 491 for (ScopedVector<win::BluetoothLowEnergyDeviceInfo>::iterator iter =
490 btle_devices.begin(); 492 btle_devices.begin();
491 iter != btle_devices.end(); 493 iter != btle_devices.end();
492 ++iter) { 494 ++iter) {
493 win::BluetoothLowEnergyDeviceInfo* device_info = (*iter); 495 win::BluetoothLowEnergyDeviceInfo* device_info = (*iter);
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 } 632 }
631 633
632 bool BluetoothTaskManagerWin::DiscoverLowEnergyDeviceServices( 634 bool BluetoothTaskManagerWin::DiscoverLowEnergyDeviceServices(
633 const base::FilePath& device_path, 635 const base::FilePath& device_path,
634 ScopedVector<ServiceRecordState>* service_record_states) { 636 ScopedVector<ServiceRecordState>* service_record_states) {
635 if (!win::IsBluetoothLowEnergySupported()) 637 if (!win::IsBluetoothLowEnergySupported())
636 return true; // Bluetooth LE not supported is not an error. 638 return true; // Bluetooth LE not supported is not an error.
637 639
638 std::string error; 640 std::string error;
639 ScopedVector<win::BluetoothLowEnergyServiceInfo> services; 641 ScopedVector<win::BluetoothLowEnergyServiceInfo> services;
640 bool success = win::EnumerateKnownBluetoothLowEnergyServices( 642 bool success = win::BluetoothLowEnergyWrapper::GetInstance()
641 device_path, &services, &error); 643 ->EnumerateKnownBluetoothLowEnergyServices(
644 device_path, &services, &error);
642 if (!success) { 645 if (!success) {
643 LogPollingError(error.c_str(), 0); 646 LogPollingError(error.c_str(), 0);
644 return false; 647 return false;
645 } 648 }
646 649
647 for (ScopedVector<win::BluetoothLowEnergyServiceInfo>::iterator iter2 = 650 for (ScopedVector<win::BluetoothLowEnergyServiceInfo>::iterator iter2 =
648 services.begin(); 651 services.begin();
649 iter2 != services.end(); 652 iter2 != services.end();
650 ++iter2) { 653 ++iter2) {
651 ServiceRecordState* service_state = new ServiceRecordState(); 654 ServiceRecordState* service_state = new ServiceRecordState();
(...skipping 10 matching lines...) Expand all
662 // lists all GATT service devices and matches them back to correspond GATT 665 // lists all GATT service devices and matches them back to correspond GATT
663 // service of the BLE device according to their address and included service 666 // service of the BLE device according to their address and included service
664 // attribute handles, as we did not find a more neat way to bond them. 667 // attribute handles, as we did not find a more neat way to bond them.
665 bool BluetoothTaskManagerWin::SearchForGattServiceDevicePaths( 668 bool BluetoothTaskManagerWin::SearchForGattServiceDevicePaths(
666 const std::string device_address, 669 const std::string device_address,
667 ScopedVector<ServiceRecordState>* service_record_states) { 670 ScopedVector<ServiceRecordState>* service_record_states) {
668 std::string error; 671 std::string error;
669 672
670 // List all known GATT service devices on the machine. 673 // List all known GATT service devices on the machine.
671 ScopedVector<win::BluetoothLowEnergyDeviceInfo> gatt_service_devices; 674 ScopedVector<win::BluetoothLowEnergyDeviceInfo> gatt_service_devices;
672 bool success = win::EnumerateKnownBluetoothLowEnergyGattServiceDevices( 675 bool success = win::BluetoothLowEnergyWrapper::GetInstance()
673 &gatt_service_devices, &error); 676 ->EnumerateKnownBluetoothLowEnergyGattServiceDevices(
677 &gatt_service_devices, &error);
674 if (!success) { 678 if (!success) {
675 LogPollingError(error.c_str(), 0); 679 LogPollingError(error.c_str(), 0);
676 return false; 680 return false;
677 } 681 }
678 682
679 for (auto gatt_service_device : gatt_service_devices) { 683 for (auto gatt_service_device : gatt_service_devices) {
680 // Only care about the service devices with |device_address|. 684 // Only care about the service devices with |device_address|.
681 if (BluetoothAddressToCanonicalString(gatt_service_device->address) != 685 if (BluetoothAddressToCanonicalString(gatt_service_device->address) !=
682 device_address) { 686 device_address) {
683 continue; 687 continue;
684 } 688 }
685 689
686 // Discover this service device's contained services. 690 // Discover this service device's contained services.
687 ScopedVector<win::BluetoothLowEnergyServiceInfo> gatt_services; 691 ScopedVector<win::BluetoothLowEnergyServiceInfo> gatt_services;
688 if (!win::EnumerateKnownBluetoothLowEnergyServices( 692 if (!win::BluetoothLowEnergyWrapper::GetInstance()
689 gatt_service_device->path, &gatt_services, &error)) { 693 ->EnumerateKnownBluetoothLowEnergyServices(
694 gatt_service_device->path, &gatt_services, &error)) {
690 LogPollingError(error.c_str(), 0); 695 LogPollingError(error.c_str(), 0);
691 continue; 696 continue;
692 } 697 }
693 698
694 // Usually each service device correspond to one Gatt service. 699 // Usually each service device correspond to one Gatt service.
695 if (gatt_services.size() > 1) { 700 if (gatt_services.size() > 1) {
696 LOG(WARNING) << "This GATT service device contains more than one (" 701 LOG(WARNING) << "This GATT service device contains more than one ("
697 << gatt_services.size() << ") services"; 702 << gatt_services.size() << ") services";
698 } 703 }
699 704
700 // Associate service device to corresponding service record. Attribute 705 // Associate service device to corresponding service record. Attribute
701 // handle is unique on one device. 706 // handle is unique on one device.
702 for (auto gatt_service : gatt_services) { 707 for (auto gatt_service : gatt_services) {
703 for (auto service_record_state : *service_record_states) { 708 for (auto service_record_state : *service_record_states) {
704 if (service_record_state->attribute_handle == 709 if (service_record_state->attribute_handle ==
705 gatt_service->attribute_handle) { 710 gatt_service->attribute_handle) {
706 service_record_state->path = gatt_service_device->path; 711 service_record_state->path = gatt_service_device->path;
707 break; 712 break;
708 } 713 }
709 } 714 }
710 } 715 }
711 } 716 }
712 717
713 return true; 718 return true;
714 } 719 }
715 720
716 } // namespace device 721 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_low_energy_win_fake.cc ('k') | device/device_tests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698