do_not_disturb_controller.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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_DO_NOT_DISTURB_CONTROLLER_H_
  5. #define ASH_COMPONENTS_PHONEHUB_DO_NOT_DISTURB_CONTROLLER_H_
  6. #include "base/observer_list.h"
  7. #include "base/observer_list_types.h"
  8. namespace ash {
  9. namespace phonehub {
  10. // Provides DND (Do Not Disturb) functionality for the connected phone. Clients
  11. // can check whether DND is enabled and observe when that state has changed;
  12. // additionally, this class provides an API for setting the DND state.
  13. class DoNotDisturbController {
  14. public:
  15. class Observer : public base::CheckedObserver {
  16. public:
  17. ~Observer() override = default;
  18. virtual void OnDndStateChanged() = 0;
  19. };
  20. DoNotDisturbController(const DoNotDisturbController&) = delete;
  21. DoNotDisturbController& operator=(const DoNotDisturbController&) = delete;
  22. virtual ~DoNotDisturbController();
  23. virtual bool IsDndEnabled() const = 0;
  24. // Returns whether a new DoNotDisturb state can be set. If this returns false,
  25. // then we are disabling the DoNotDisturb mode feature on the CrOS device.
  26. virtual bool CanRequestNewDndState() const = 0;
  27. // Note: Setting DND state is not a synchronous operation, since it requires
  28. // sending a message to the connected phone. Use the observer interface to be
  29. // notified of when the state changes.
  30. virtual void RequestNewDoNotDisturbState(bool enabled) = 0;
  31. void AddObserver(Observer* observer);
  32. void RemoveObserver(Observer* observer);
  33. protected:
  34. friend class PhoneStatusProcessor;
  35. DoNotDisturbController();
  36. // This sets the internal state of the DoNotDisturb mode and and whether the
  37. // DoNotDisturb state can be changed. This does not send a request to set the
  38. // state of the remote phone device.
  39. virtual void SetDoNotDisturbStateInternal(bool is_dnd_enabled,
  40. bool can_request_new_dnd_state) = 0;
  41. void NotifyDndStateChanged();
  42. private:
  43. base::ObserverList<Observer> observer_list_;
  44. };
  45. } // namespace phonehub
  46. } // namespace ash
  47. // TODO(https://crbug.com/1164001): remove after the migration is finished.
  48. namespace chromeos {
  49. namespace phonehub {
  50. using ::ash::phonehub::DoNotDisturbController;
  51. }
  52. } // namespace chromeos
  53. #endif // ASH_COMPONENTS_PHONEHUB_DO_NOT_DISTURB_CONTROLLER_H_