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

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

Issue 2567903004: Replace ScopedVector/ScopedPtrHashMap with std::vector and std::unordered_map (Closed)
Patch Set: Mac bustage Created 3 years, 12 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 <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/files/file.h" 10 #include "base/files/file.h"
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 // Windows 8 exposes BLE devices only if they are visible and paired. This 365 // Windows 8 exposes BLE devices only if they are visible and paired. This
366 // might change in the future if Windows offers a public API for discovering 366 // might change in the future if Windows offers a public API for discovering
367 // and pairing BLE devices. 367 // and pairing BLE devices.
368 device_info->visible = true; 368 device_info->visible = true;
369 device_info->authenticated = true; 369 device_info->authenticated = true;
370 return true; 370 return true;
371 } 371 }
372 372
373 bool CollectBluetoothLowEnergyDeviceServices( 373 bool CollectBluetoothLowEnergyDeviceServices(
374 const base::FilePath& device_path, 374 const base::FilePath& device_path,
375 ScopedVector<BluetoothLowEnergyServiceInfo>* services, 375 std::vector<std::unique_ptr<BluetoothLowEnergyServiceInfo>>* services,
376 std::string* error) { 376 std::string* error) {
377 base::File file(device_path, base::File::FLAG_OPEN | base::File::FLAG_READ); 377 base::File file(device_path, base::File::FLAG_OPEN | base::File::FLAG_READ);
378 if (!file.IsValid()) { 378 if (!file.IsValid()) {
379 *error = file.ErrorToString(file.error_details()); 379 *error = file.ErrorToString(file.error_details());
380 return false; 380 return false;
381 } 381 }
382 382
383 USHORT required_length; 383 USHORT required_length;
384 HRESULT hr = BluetoothGATTGetServices(file.GetPlatformFile(), 384 HRESULT hr = BluetoothGATTGetServices(file.GetPlatformFile(),
385 0, 385 0,
(...skipping 15 matching lines...) Expand all
401 BLUETOOTH_GATT_FLAG_NONE); 401 BLUETOOTH_GATT_FLAG_NONE);
402 if (!CheckHResult(hr, kDeviceInfoError, error)) 402 if (!CheckHResult(hr, kDeviceInfoError, error))
403 return false; 403 return false;
404 if (!CheckExpectedLength( 404 if (!CheckExpectedLength(
405 actual_length, required_length, kDeviceInfoError, error)) { 405 actual_length, required_length, kDeviceInfoError, error)) {
406 return false; 406 return false;
407 } 407 }
408 408
409 for (USHORT i = 0; i < actual_length; ++i) { 409 for (USHORT i = 0; i < actual_length; ++i) {
410 BTH_LE_GATT_SERVICE& gatt_service(gatt_services.get()[i]); 410 BTH_LE_GATT_SERVICE& gatt_service(gatt_services.get()[i]);
411 BluetoothLowEnergyServiceInfo* service_info = 411 std::unique_ptr<BluetoothLowEnergyServiceInfo> service_info(
412 new BluetoothLowEnergyServiceInfo(); 412 new BluetoothLowEnergyServiceInfo());
413 service_info->uuid = gatt_service.ServiceUuid; 413 service_info->uuid = gatt_service.ServiceUuid;
414 service_info->attribute_handle = gatt_service.AttributeHandle; 414 service_info->attribute_handle = gatt_service.AttributeHandle;
415 services->push_back(service_info); 415 services->push_back(std::move(service_info));
416 } 416 }
417 417
418 return true; 418 return true;
419 } 419 }
420 420
421 bool CollectBluetoothLowEnergyDeviceInfo( 421 bool CollectBluetoothLowEnergyDeviceInfo(
422 const ScopedDeviceInfoSetHandle& device_info_handle, 422 const ScopedDeviceInfoSetHandle& device_info_handle,
423 PSP_DEVICE_INTERFACE_DATA device_interface_data, 423 PSP_DEVICE_INTERFACE_DATA device_interface_data,
424 std::unique_ptr<device::win::BluetoothLowEnergyDeviceInfo>* device_info, 424 std::unique_ptr<device::win::BluetoothLowEnergyDeviceInfo>* device_info,
425 std::string* error) { 425 std::string* error) {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 } 535 }
536 536
537 // Enumerate known Bluetooth low energy devices or Bluetooth low energy GATT 537 // Enumerate known Bluetooth low energy devices or Bluetooth low energy GATT
538 // service devices according to |device_interface_guid|. 538 // service devices according to |device_interface_guid|.
539 // Note: |device_interface_guid| = GUID_BLUETOOTHLE_DEVICE_INTERFACE corresponds 539 // Note: |device_interface_guid| = GUID_BLUETOOTHLE_DEVICE_INTERFACE corresponds
540 // Bluetooth low energy devices. |device_interface_guid| = 540 // Bluetooth low energy devices. |device_interface_guid| =
541 // GUID_BLUETOOTH_GATT_SERVICE_DEVICE_INTERFACE corresponds Bluetooth low energy 541 // GUID_BLUETOOTH_GATT_SERVICE_DEVICE_INTERFACE corresponds Bluetooth low energy
542 // Gatt service devices. 542 // Gatt service devices.
543 bool EnumerateKnownBLEOrBLEGattServiceDevices( 543 bool EnumerateKnownBLEOrBLEGattServiceDevices(
544 GUID guid, 544 GUID guid,
545 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices, 545 std::vector<std::unique_ptr<BluetoothLowEnergyDeviceInfo>>* devices,
546 std::string* error) { 546 std::string* error) {
547 ScopedDeviceInfoSetHandle info_set_handle; 547 ScopedDeviceInfoSetHandle info_set_handle;
548 HRESULT hr = OpenBluetoothLowEnergyDevices(guid, &info_set_handle); 548 HRESULT hr = OpenBluetoothLowEnergyDevices(guid, &info_set_handle);
549 if (FAILED(hr)) { 549 if (FAILED(hr)) {
550 *error = FormatBluetoothError(kDeviceEnumError, hr); 550 *error = FormatBluetoothError(kDeviceEnumError, hr);
551 return false; 551 return false;
552 } 552 }
553 553
554 for (DWORD i = 0;; ++i) { 554 for (DWORD i = 0;; ++i) {
555 std::unique_ptr<BluetoothLowEnergyDeviceInfo> device_info; 555 std::unique_ptr<BluetoothLowEnergyDeviceInfo> device_info;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 } 671 }
672 672
673 BluetoothLowEnergyWrapper::BluetoothLowEnergyWrapper() {} 673 BluetoothLowEnergyWrapper::BluetoothLowEnergyWrapper() {}
674 BluetoothLowEnergyWrapper::~BluetoothLowEnergyWrapper() {} 674 BluetoothLowEnergyWrapper::~BluetoothLowEnergyWrapper() {}
675 675
676 bool BluetoothLowEnergyWrapper::IsBluetoothLowEnergySupported() { 676 bool BluetoothLowEnergyWrapper::IsBluetoothLowEnergySupported() {
677 return base::win::GetVersion() >= base::win::VERSION_WIN8; 677 return base::win::GetVersion() >= base::win::VERSION_WIN8;
678 } 678 }
679 679
680 bool BluetoothLowEnergyWrapper::EnumerateKnownBluetoothLowEnergyDevices( 680 bool BluetoothLowEnergyWrapper::EnumerateKnownBluetoothLowEnergyDevices(
681 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices, 681 std::vector<std::unique_ptr<BluetoothLowEnergyDeviceInfo>>* devices,
682 std::string* error) { 682 std::string* error) {
683 if (!IsBluetoothLowEnergySupported()) { 683 if (!IsBluetoothLowEnergySupported()) {
684 *error = kPlatformNotSupported; 684 *error = kPlatformNotSupported;
685 return false; 685 return false;
686 } 686 }
687 687
688 return EnumerateKnownBLEOrBLEGattServiceDevices( 688 return EnumerateKnownBLEOrBLEGattServiceDevices(
689 GUID_BLUETOOTHLE_DEVICE_INTERFACE, devices, error); 689 GUID_BLUETOOTHLE_DEVICE_INTERFACE, devices, error);
690 } 690 }
691 691
692 bool BluetoothLowEnergyWrapper:: 692 bool BluetoothLowEnergyWrapper::
693 EnumerateKnownBluetoothLowEnergyGattServiceDevices( 693 EnumerateKnownBluetoothLowEnergyGattServiceDevices(
694 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices, 694 std::vector<std::unique_ptr<BluetoothLowEnergyDeviceInfo>>* devices,
695 std::string* error) { 695 std::string* error) {
696 if (!IsBluetoothLowEnergySupported()) { 696 if (!IsBluetoothLowEnergySupported()) {
697 *error = kPlatformNotSupported; 697 *error = kPlatformNotSupported;
698 return false; 698 return false;
699 } 699 }
700 700
701 return EnumerateKnownBLEOrBLEGattServiceDevices( 701 return EnumerateKnownBLEOrBLEGattServiceDevices(
702 GUID_BLUETOOTH_GATT_SERVICE_DEVICE_INTERFACE, devices, error); 702 GUID_BLUETOOTH_GATT_SERVICE_DEVICE_INTERFACE, devices, error);
703 } 703 }
704 704
705 bool BluetoothLowEnergyWrapper::EnumerateKnownBluetoothLowEnergyServices( 705 bool BluetoothLowEnergyWrapper::EnumerateKnownBluetoothLowEnergyServices(
706 const base::FilePath& device_path, 706 const base::FilePath& device_path,
707 ScopedVector<BluetoothLowEnergyServiceInfo>* services, 707 std::vector<std::unique_ptr<BluetoothLowEnergyServiceInfo>>* services,
708 std::string* error) { 708 std::string* error) {
709 if (!IsBluetoothLowEnergySupported()) { 709 if (!IsBluetoothLowEnergySupported()) {
710 *error = kPlatformNotSupported; 710 *error = kPlatformNotSupported;
711 return false; 711 return false;
712 } 712 }
713 713
714 return CollectBluetoothLowEnergyDeviceServices(device_path, services, error); 714 return CollectBluetoothLowEnergyDeviceServices(device_path, services, error);
715 } 715 }
716 716
717 HRESULT BluetoothLowEnergyWrapper::ReadCharacteristicsOfAService( 717 HRESULT BluetoothLowEnergyWrapper::ReadCharacteristicsOfAService(
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 base::File file(service_path, base::File::FLAG_OPEN | base::File::FLAG_READ | 864 base::File file(service_path, base::File::FLAG_OPEN | base::File::FLAG_READ |
865 base::File::FLAG_WRITE); 865 base::File::FLAG_WRITE);
866 if (!file.IsValid()) 866 if (!file.IsValid())
867 return HRESULT_FROM_WIN32(ERROR_OPEN_FAILED); 867 return HRESULT_FROM_WIN32(ERROR_OPEN_FAILED);
868 return BluetoothGATTSetDescriptorValue(file.GetPlatformFile(), descriptor, 868 return BluetoothGATTSetDescriptorValue(file.GetPlatformFile(), descriptor,
869 new_value, BLUETOOTH_GATT_FLAG_NONE); 869 new_value, BLUETOOTH_GATT_FLAG_NONE);
870 } 870 }
871 871
872 } // namespace win 872 } // namespace win
873 } // namespace device 873 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698