assistant_notification_expiry_monitor.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2019 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_ASSISTANT_NOTIFICATION_EXPIRY_MONITOR_H_
  5. #define ASH_ASSISTANT_ASSISTANT_NOTIFICATION_EXPIRY_MONITOR_H_
  6. #include <memory>
  7. #include <string>
  8. #include <vector>
  9. #include "ash/assistant/model/assistant_notification_model_observer.h"
  10. #include "base/timer/timer.h"
  11. #include "third_party/abseil-cpp/absl/types/optional.h"
  12. namespace ash {
  13. class AssistantNotificationControllerImpl;
  14. // Will track all Assistant notifications by subscribing to the given
  15. // |controller| and will call
  16. // |AssistantNotificationController::RemoveNotificationById| when the
  17. // notification expires (i.e. when the current time passes the value in the
  18. // expiry_time| field).
  19. class AssistantNotificationExpiryMonitor {
  20. public:
  21. using AssistantNotification = chromeos::assistant::AssistantNotification;
  22. explicit AssistantNotificationExpiryMonitor(
  23. AssistantNotificationControllerImpl* controller);
  24. AssistantNotificationExpiryMonitor(
  25. const AssistantNotificationExpiryMonitor&) = delete;
  26. AssistantNotificationExpiryMonitor& operator=(
  27. const AssistantNotificationExpiryMonitor&) = delete;
  28. ~AssistantNotificationExpiryMonitor();
  29. private:
  30. using NotificationId = std::string;
  31. class Observer;
  32. // Start/stop the timer waiting for the next expiry time.
  33. // If the timer is already running this will start a new timer with the
  34. // (new) expiry time that will expire first.
  35. void UpdateTimer();
  36. absl::optional<base::TimeDelta> GetTimerTimeout() const;
  37. absl::optional<base::Time> GetTimerEndTime() const;
  38. void RemoveExpiredNotifications();
  39. std::vector<NotificationId> GetExpiredNotifications() const;
  40. std::vector<const AssistantNotification*> GetNotifications() const;
  41. base::OneShotTimer timer_;
  42. AssistantNotificationControllerImpl* const controller_;
  43. std::unique_ptr<Observer> observer_;
  44. };
  45. } // namespace ash
  46. #endif // ASH_ASSISTANT_ASSISTANT_NOTIFICATION_EXPIRY_MONITOR_H_