bluetooth_hid_detector.cc 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // Copyright 2022 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 "ash/components/hid_detection/bluetooth_hid_detector.h"
  5. #include "ash/constants/ash_features.h"
  6. namespace ash::hid_detection {
  7. BluetoothHidPairingState::BluetoothHidPairingState(const std::string& code,
  8. uint8_t num_keys_entered)
  9. : code(code), num_keys_entered(num_keys_entered) {}
  10. BluetoothHidPairingState::BluetoothHidPairingState(
  11. BluetoothHidPairingState&& other) {
  12. code = std::move(other.code);
  13. num_keys_entered = other.num_keys_entered;
  14. }
  15. BluetoothHidPairingState& BluetoothHidPairingState::operator=(
  16. BluetoothHidPairingState&& other) {
  17. code = std::move(other.code);
  18. num_keys_entered = other.num_keys_entered;
  19. return *this;
  20. }
  21. BluetoothHidPairingState::~BluetoothHidPairingState() = default;
  22. BluetoothHidDetector::BluetoothHidMetadata::BluetoothHidMetadata(
  23. std::string name,
  24. BluetoothHidType type)
  25. : name(std::move(name)), type(type) {}
  26. BluetoothHidDetector::BluetoothHidMetadata::BluetoothHidMetadata(
  27. BluetoothHidMetadata&& other) {
  28. name = std::move(other.name);
  29. type = other.type;
  30. }
  31. BluetoothHidDetector::BluetoothHidMetadata&
  32. BluetoothHidDetector::BluetoothHidMetadata::operator=(
  33. BluetoothHidMetadata&& other) {
  34. name = std::move(other.name);
  35. type = other.type;
  36. return *this;
  37. }
  38. BluetoothHidDetector::BluetoothHidMetadata::~BluetoothHidMetadata() = default;
  39. BluetoothHidDetector::BluetoothHidDetectionStatus::BluetoothHidDetectionStatus(
  40. absl::optional<BluetoothHidDetector::BluetoothHidMetadata>
  41. current_pairing_device,
  42. absl::optional<BluetoothHidPairingState> pairing_state)
  43. : current_pairing_device(std::move(current_pairing_device)),
  44. pairing_state(std::move(pairing_state)) {}
  45. BluetoothHidDetector::BluetoothHidDetectionStatus::BluetoothHidDetectionStatus(
  46. BluetoothHidDetectionStatus&& other) {
  47. current_pairing_device = std::move(other.current_pairing_device);
  48. pairing_state = std::move(other.pairing_state);
  49. }
  50. BluetoothHidDetector::BluetoothHidDetectionStatus&
  51. BluetoothHidDetector::BluetoothHidDetectionStatus::operator=(
  52. BluetoothHidDetectionStatus&& other) {
  53. current_pairing_device = std::move(other.current_pairing_device);
  54. pairing_state = std::move(other.pairing_state);
  55. return *this;
  56. }
  57. BluetoothHidDetector::BluetoothHidDetectionStatus::
  58. ~BluetoothHidDetectionStatus() = default;
  59. BluetoothHidDetector::BluetoothHidDetector() {
  60. DCHECK(ash::features::IsOobeHidDetectionRevampEnabled());
  61. }
  62. BluetoothHidDetector::~BluetoothHidDetector() {
  63. DCHECK(!delegate_) << " Bluetooth HID detection must be stopped before "
  64. << "BluetoothHidDetector is destroyed.";
  65. }
  66. void BluetoothHidDetector::StartBluetoothHidDetection(
  67. Delegate* delegate,
  68. InputDevicesStatus input_devices_status) {
  69. DCHECK(!delegate_);
  70. delegate_ = delegate;
  71. PerformStartBluetoothHidDetection(input_devices_status);
  72. }
  73. void BluetoothHidDetector::StopBluetoothHidDetection(bool is_using_bluetooth) {
  74. DCHECK(delegate_);
  75. PerformStopBluetoothHidDetection(is_using_bluetooth);
  76. delegate_ = nullptr;
  77. }
  78. void BluetoothHidDetector::NotifyBluetoothHidDetectionStatusChanged() {
  79. delegate_->OnBluetoothHidStatusChanged();
  80. }
  81. } // namespace ash::hid_detection