assistant_alarm_timer_model.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright 2018 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_ASSISTANT_MODEL_ASSISTANT_ALARM_TIMER_MODEL_H_
  5. #define ASH_ASSISTANT_MODEL_ASSISTANT_ALARM_TIMER_MODEL_H_
  6. #include <map>
  7. #include <string>
  8. #include <vector>
  9. #include "base/component_export.h"
  10. #include "base/observer_list.h"
  11. namespace chromeos {
  12. namespace assistant {
  13. struct AssistantTimer;
  14. } // namespace assistant
  15. } // namespace chromeos
  16. namespace ash {
  17. class AssistantAlarmTimerModelObserver;
  18. // The model belonging to AssistantAlarmTimerController which tracks alarm/timer
  19. // state and notifies a pool of observers.
  20. class COMPONENT_EXPORT(ASSISTANT_MODEL) AssistantAlarmTimerModel {
  21. public:
  22. AssistantAlarmTimerModel();
  23. AssistantAlarmTimerModel(const AssistantAlarmTimerModel&) = delete;
  24. AssistantAlarmTimerModel& operator=(const AssistantAlarmTimerModel&) = delete;
  25. ~AssistantAlarmTimerModel();
  26. // Adds/removes the specified alarm/timer model |observer|.
  27. void AddObserver(AssistantAlarmTimerModelObserver* observer) const;
  28. void RemoveObserver(AssistantAlarmTimerModelObserver* observer) const;
  29. // Adds or updates the timer specified by |timer.id| in the model.
  30. void AddOrUpdateTimer(const chromeos::assistant::AssistantTimer& timer);
  31. // Removes the timer uniquely identified by |id|.
  32. void RemoveTimer(const std::string& id);
  33. // Remove all timers from the model.
  34. void RemoveAllTimers();
  35. // Returns all timers from the model.
  36. std::vector<const chromeos::assistant::AssistantTimer*> GetAllTimers() const;
  37. // Returns the timer uniquely identified by |id|.
  38. const chromeos::assistant::AssistantTimer* GetTimerById(
  39. const std::string& id) const;
  40. // Returns |true| if the model contains no timers, |false| otherwise.
  41. bool empty() const { return timers_.empty(); }
  42. private:
  43. void NotifyTimerAdded(const chromeos::assistant::AssistantTimer& timer);
  44. void NotifyTimerUpdated(const chromeos::assistant::AssistantTimer& timer);
  45. void NotifyTimerRemoved(const chromeos::assistant::AssistantTimer& timer);
  46. std::map<std::string, chromeos::assistant::AssistantTimer> timers_;
  47. mutable base::ObserverList<AssistantAlarmTimerModelObserver> observers_;
  48. };
  49. } // namespace ash
  50. #endif // ASH_ASSISTANT_MODEL_ASSISTANT_ALARM_TIMER_MODEL_H_