silence_phone_quick_action_controller.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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_SYSTEM_PHONEHUB_SILENCE_PHONE_QUICK_ACTION_CONTROLLER_H_
  5. #define ASH_SYSTEM_PHONEHUB_SILENCE_PHONE_QUICK_ACTION_CONTROLLER_H_
  6. #include "ash/components/phonehub/do_not_disturb_controller.h"
  7. #include "ash/system/phonehub/quick_action_controller_base.h"
  8. namespace base {
  9. class OneShotTimer;
  10. } // namespace base
  11. namespace ash {
  12. // Controller of a quick action item that toggles silence phone mode.
  13. class ASH_EXPORT SilencePhoneQuickActionController
  14. : public QuickActionControllerBase,
  15. public phonehub::DoNotDisturbController::Observer {
  16. public:
  17. explicit SilencePhoneQuickActionController(
  18. phonehub::DoNotDisturbController* dnd_controller);
  19. ~SilencePhoneQuickActionController() override;
  20. SilencePhoneQuickActionController(SilencePhoneQuickActionController&) =
  21. delete;
  22. SilencePhoneQuickActionController operator=(
  23. SilencePhoneQuickActionController&) = delete;
  24. // Return true if the item is enabled/toggled.
  25. bool IsItemEnabled();
  26. // QuickActionControllerBase:
  27. QuickActionItem* CreateItem() override;
  28. void OnButtonPressed(bool is_now_enabled) override;
  29. // phonehub::DoNotDisturbController::Observer:
  30. void OnDndStateChanged() override;
  31. private:
  32. friend class SilencePhoneQuickActionControllerTest;
  33. // All the possible states that the silence phone button can be viewed. Each
  34. // state has a corresponding icon, labels and tooltip view.
  35. enum class ActionState { kOff, kOn, kDisabled };
  36. // Set the item (including icon, label and tooltips) to a certain state.
  37. void SetItemState(ActionState state);
  38. // Retrieves the current state of the QuickActionItem. Used only for testing.
  39. ActionState GetItemState();
  40. // Check to see if the requested state is similar to current state of the
  41. // phone. Make changes to item's state if necessary.
  42. void CheckRequestedState();
  43. phonehub::DoNotDisturbController* dnd_controller_ = nullptr;
  44. QuickActionItem* item_ = nullptr;
  45. // Keep track the current state of the item.
  46. ActionState state_;
  47. // State that user requests when clicking the button.
  48. absl::optional<ActionState> requested_state_;
  49. // Timer that fires to prevent showing wrong state in the item. It will check
  50. // if the requested state is similar to the current state after the button is
  51. // pressed for a certain time.
  52. std::unique_ptr<base::OneShotTimer> check_requested_state_timer_;
  53. };
  54. } // namespace ash
  55. #endif // ASH_SYSTEM_PHONEHUB_SILENCE_PHONE_QUICK_ACTION_CONTROLLER_H_