hid_detection_manager.cc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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/hid_detection_manager.h"
  5. #include "ash/constants/ash_features.h"
  6. namespace ash::hid_detection {
  7. HidDetectionManager::HidDetectionStatus::HidDetectionStatus(
  8. InputMetadata pointer_metadata,
  9. InputMetadata keyboard_metadata,
  10. bool touchscreen_detected,
  11. absl::optional<BluetoothHidPairingState> pairing_state)
  12. : pointer_metadata(pointer_metadata),
  13. keyboard_metadata(keyboard_metadata),
  14. touchscreen_detected(touchscreen_detected),
  15. pairing_state(std::move(pairing_state)) {}
  16. HidDetectionManager::HidDetectionStatus::HidDetectionStatus(
  17. HidDetectionStatus&& other) {
  18. pointer_metadata = other.pointer_metadata;
  19. keyboard_metadata = other.keyboard_metadata;
  20. touchscreen_detected = other.touchscreen_detected;
  21. pairing_state = std::move(other.pairing_state);
  22. }
  23. HidDetectionManager::HidDetectionStatus&
  24. HidDetectionManager::HidDetectionStatus::operator=(HidDetectionStatus&& other) {
  25. pointer_metadata = other.pointer_metadata;
  26. keyboard_metadata = other.keyboard_metadata;
  27. touchscreen_detected = other.touchscreen_detected;
  28. pairing_state = std::move(other.pairing_state);
  29. return *this;
  30. }
  31. HidDetectionManager::HidDetectionStatus::~HidDetectionStatus() = default;
  32. HidDetectionManager::HidDetectionManager() {
  33. DCHECK(ash::features::IsOobeHidDetectionRevampEnabled());
  34. }
  35. HidDetectionManager::~HidDetectionManager() {
  36. DCHECK(!delegate_) << " HID detection must be stopped before "
  37. << "HidDetectionManager is destroyed";
  38. }
  39. void HidDetectionManager::StartHidDetection(Delegate* delegate) {
  40. DCHECK(!delegate_);
  41. delegate_ = delegate;
  42. PerformStartHidDetection();
  43. }
  44. void HidDetectionManager::StopHidDetection() {
  45. DCHECK(delegate_);
  46. PerformStopHidDetection();
  47. delegate_ = nullptr;
  48. }
  49. void HidDetectionManager::NotifyHidDetectionStatusChanged() {
  50. delegate_->OnHidDetectionStatusChanged(ComputeHidDetectionStatus());
  51. }
  52. } // namespace ash::hid_detection