find_my_device_controller.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright 2020 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. #ifndef ASH_COMPONENTS_PHONEHUB_FIND_MY_DEVICE_CONTROLLER_H_
  5. #define ASH_COMPONENTS_PHONEHUB_FIND_MY_DEVICE_CONTROLLER_H_
  6. #include "base/observer_list.h"
  7. #include "base/observer_list_types.h"
  8. namespace ash {
  9. namespace phonehub {
  10. // Provides functionality for ringing the connected phone via the Find My Device
  11. // feature.
  12. class FindMyDeviceController {
  13. public:
  14. class Observer : public base::CheckedObserver {
  15. public:
  16. ~Observer() override = default;
  17. virtual void OnPhoneRingingStateChanged() = 0;
  18. };
  19. enum class Status {
  20. // Ringing is not available if the phone's DoNotDisturb mode is enabled.
  21. // To re-enable ringing, DoNotDisturb mode must be disabled.
  22. kRingingNotAvailable = 0,
  23. // The connected phone is not currently ringing.
  24. kRingingOff = 1,
  25. // The connected phone is currently ringing.
  26. kRingingOn = 2,
  27. };
  28. FindMyDeviceController(const FindMyDeviceController&) = delete;
  29. FindMyDeviceController& operator=(const FindMyDeviceController&) = delete;
  30. virtual ~FindMyDeviceController();
  31. // Note: Ringing the phone via Find My Device is not a synchronous operation,
  32. // since it requires sending a message to the connected phone. Use the
  33. // observer interface to be notified of when the state changes.
  34. virtual void RequestNewPhoneRingingState(bool ringing) = 0;
  35. // Returns the current ringing state of the connected phone. There are three
  36. // possible states (on, off, disabled). The status is a result of Find My
  37. // Device Functionality. Note that this function does not return true if the
  38. // phone is ringing for another reason (e.g., a normal phone call)
  39. virtual Status GetPhoneRingingStatus() = 0;
  40. void AddObserver(Observer* observer);
  41. void RemoveObserver(Observer* observer);
  42. protected:
  43. friend class PhoneStatusProcessor;
  44. FindMyDeviceController();
  45. // This only sets the internal state of the whether the phone is ringing
  46. // and does not send a request to start ringing the the remote phone device.
  47. virtual void SetPhoneRingingStatusInternal(Status status) = 0;
  48. void NotifyPhoneRingingStateChanged();
  49. private:
  50. base::ObserverList<Observer> observer_list_;
  51. };
  52. std::ostream& operator<<(std::ostream& stream,
  53. FindMyDeviceController::Status status);
  54. } // namespace phonehub
  55. } // namespace ash
  56. // TODO(https://crbug.com/1164001): remove after the migration is finished.
  57. namespace chromeos {
  58. namespace phonehub {
  59. using ::ash::phonehub::FindMyDeviceController;
  60. }
  61. } // namespace chromeos
  62. #endif // ASH_COMPONENTS_PHONEHUB_FIND_MY_DEVICE_CONTROLLER_H_