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

Side by Side Diff: device/bluetooth/bluetooth_low_energy_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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_low_energy_win.h" 5 #include "device/bluetooth/bluetooth_low_energy_win.h"
6 6
7 #include "base/files/file.h" 7 #include "base/files/file.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 address.ullLong = BLUETOOTH_NULL_ADDRESS; 645 address.ullLong = BLUETOOTH_NULL_ADDRESS;
646 } 646 }
647 647
648 BluetoothLowEnergyDeviceInfo::~BluetoothLowEnergyDeviceInfo() { 648 BluetoothLowEnergyDeviceInfo::~BluetoothLowEnergyDeviceInfo() {
649 } 649 }
650 650
651 bool IsBluetoothLowEnergySupported() { 651 bool IsBluetoothLowEnergySupported() {
652 return base::win::GetVersion() >= base::win::VERSION_WIN8; 652 return base::win::GetVersion() >= base::win::VERSION_WIN8;
653 } 653 }
654 654
655 bool EnumerateKnownBluetoothLowEnergyDevices( 655 bool ExtractBluetoothAddressFromDeviceInstanceIdForTesting(
656 const std::string& instance_id,
657 BLUETOOTH_ADDRESS* btha,
658 std::string* error) {
659 return ExtractBluetoothAddressFromDeviceInstanceId(instance_id, btha, error);
660 }
661
662 static BluetoothLowEnergyWrapper* instance_ = nullptr;
663 BluetoothLowEnergyWrapper* BluetoothLowEnergyWrapper::GetInstance() {
664 if (instance_ == nullptr) {
665 instance_ = new BluetoothLowEnergyWrapper();
666 }
667 return instance_;
668 }
669
670 void BluetoothLowEnergyWrapper::DeleteInstance() {
671 delete instance_;
672 instance_ = nullptr;
673 }
674
675 void BluetoothLowEnergyWrapper::SetInstanceForTest(
676 BluetoothLowEnergyWrapper* instance) {
677 delete instance_;
678 instance_ = instance;
679 }
680
681 BluetoothLowEnergyWrapper::BluetoothLowEnergyWrapper() {}
682 BluetoothLowEnergyWrapper::~BluetoothLowEnergyWrapper() {}
683
684 bool BluetoothLowEnergyWrapper::EnumerateKnownBluetoothLowEnergyDevices(
656 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices, 685 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices,
657 std::string* error) { 686 std::string* error) {
658 if (!IsBluetoothLowEnergySupported()) { 687 if (!IsBluetoothLowEnergySupported()) {
659 *error = kPlatformNotSupported; 688 *error = kPlatformNotSupported;
660 return false; 689 return false;
661 } 690 }
662 691
663 return EnumerateKnownBLEOrBLEGattServiceDevices( 692 return EnumerateKnownBLEOrBLEGattServiceDevices(
664 GUID_BLUETOOTHLE_DEVICE_INTERFACE, devices, error); 693 GUID_BLUETOOTHLE_DEVICE_INTERFACE, devices, error);
665 } 694 }
666 695
667 bool EnumerateKnownBluetoothLowEnergyGattServiceDevices( 696 bool BluetoothLowEnergyWrapper::
668 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices, 697 EnumerateKnownBluetoothLowEnergyGattServiceDevices(
669 std::string* error) { 698 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices,
699 std::string* error) {
670 if (!IsBluetoothLowEnergySupported()) { 700 if (!IsBluetoothLowEnergySupported()) {
671 *error = kPlatformNotSupported; 701 *error = kPlatformNotSupported;
672 return false; 702 return false;
673 } 703 }
674 704
675 return EnumerateKnownBLEOrBLEGattServiceDevices( 705 return EnumerateKnownBLEOrBLEGattServiceDevices(
676 GUID_BLUETOOTH_GATT_SERVICE_DEVICE_INTERFACE, devices, error); 706 GUID_BLUETOOTH_GATT_SERVICE_DEVICE_INTERFACE, devices, error);
677 } 707 }
678 708
679 bool EnumerateKnownBluetoothLowEnergyServices( 709 bool BluetoothLowEnergyWrapper::EnumerateKnownBluetoothLowEnergyServices(
680 const base::FilePath& device_path, 710 const base::FilePath& device_path,
681 ScopedVector<BluetoothLowEnergyServiceInfo>* services, 711 ScopedVector<BluetoothLowEnergyServiceInfo>* services,
682 std::string* error) { 712 std::string* error) {
683 if (!IsBluetoothLowEnergySupported()) { 713 if (!IsBluetoothLowEnergySupported()) {
684 *error = kPlatformNotSupported; 714 *error = kPlatformNotSupported;
685 return false; 715 return false;
686 } 716 }
687 717
688 return CollectBluetoothLowEnergyDeviceServices(device_path, services, error); 718 return CollectBluetoothLowEnergyDeviceServices(device_path, services, error);
689 } 719 }
690 720
691 bool ExtractBluetoothAddressFromDeviceInstanceIdForTesting(
692 const std::string& instance_id,
693 BLUETOOTH_ADDRESS* btha,
694 std::string* error) {
695 return ExtractBluetoothAddressFromDeviceInstanceId(instance_id, btha, error);
696 }
697
698 } // namespace win 721 } // namespace win
699 } // namespace device 722 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_low_energy_win.h ('k') | device/bluetooth/bluetooth_low_energy_win_fake.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698