bluetooth_classic_win.cc 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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
  3. // found in the LICENSE file.
  4. #include "device/bluetooth/bluetooth_classic_win.h"
  5. #include "base/threading/scoped_thread_priority.h"
  6. namespace device {
  7. namespace win {
  8. BluetoothClassicWrapper::BluetoothClassicWrapper() {}
  9. BluetoothClassicWrapper::~BluetoothClassicWrapper() {}
  10. HBLUETOOTH_RADIO_FIND BluetoothClassicWrapper::FindFirstRadio(
  11. const BLUETOOTH_FIND_RADIO_PARAMS* params) {
  12. // Mitigate the issues caused by loading DLLs on a background thread
  13. // (http://crbug/973868). There is evidence from slow reports that this
  14. // method can acquire the loader lock each time it's invoked.
  15. SCOPED_MAY_LOAD_LIBRARY_AT_BACKGROUND_PRIORITY_REPEATEDLY();
  16. HANDLE radio_handle = INVALID_HANDLE_VALUE;
  17. HBLUETOOTH_RADIO_FIND radio_find_handle =
  18. BluetoothFindFirstRadio(params, &radio_handle);
  19. if (radio_find_handle) {
  20. DCHECK_NE(radio_handle, INVALID_HANDLE_VALUE);
  21. opened_radio_handle_.Set(radio_handle);
  22. }
  23. return radio_find_handle;
  24. }
  25. DWORD BluetoothClassicWrapper::GetRadioInfo(
  26. PBLUETOOTH_RADIO_INFO out_radio_info) {
  27. DCHECK(opened_radio_handle_.IsValid());
  28. return BluetoothGetRadioInfo(opened_radio_handle_.Get(), out_radio_info);
  29. }
  30. BOOL BluetoothClassicWrapper::FindRadioClose(HBLUETOOTH_RADIO_FIND handle) {
  31. return BluetoothFindRadioClose(handle);
  32. }
  33. BOOL BluetoothClassicWrapper::IsConnectable() {
  34. DCHECK(opened_radio_handle_.IsValid());
  35. return BluetoothIsConnectable(opened_radio_handle_.Get());
  36. }
  37. HBLUETOOTH_DEVICE_FIND BluetoothClassicWrapper::FindFirstDevice(
  38. const BLUETOOTH_DEVICE_SEARCH_PARAMS* params,
  39. BLUETOOTH_DEVICE_INFO* out_device_info) {
  40. return BluetoothFindFirstDevice(params, out_device_info);
  41. }
  42. BOOL BluetoothClassicWrapper::FindNextDevice(
  43. HBLUETOOTH_DEVICE_FIND handle,
  44. BLUETOOTH_DEVICE_INFO* out_device_info) {
  45. return BluetoothFindNextDevice(handle, out_device_info);
  46. }
  47. BOOL BluetoothClassicWrapper::FindDeviceClose(HBLUETOOTH_DEVICE_FIND handle) {
  48. return BluetoothFindDeviceClose(handle);
  49. }
  50. BOOL BluetoothClassicWrapper::EnableDiscovery(BOOL is_enable) {
  51. DCHECK(opened_radio_handle_.IsValid());
  52. return BluetoothEnableDiscovery(opened_radio_handle_.Get(), is_enable);
  53. }
  54. BOOL BluetoothClassicWrapper::EnableIncomingConnections(BOOL is_enable) {
  55. DCHECK(opened_radio_handle_.IsValid());
  56. return BluetoothEnableIncomingConnections(opened_radio_handle_.Get(),
  57. is_enable);
  58. }
  59. DWORD BluetoothClassicWrapper::LastError() {
  60. return GetLastError();
  61. }
  62. bool BluetoothClassicWrapper::HasHandle() {
  63. return opened_radio_handle_.IsValid();
  64. }
  65. } // namespace win
  66. } // namespace device