assistant_notification_model.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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_NOTIFICATION_MODEL_H_
  5. #define ASH_ASSISTANT_MODEL_ASSISTANT_NOTIFICATION_MODEL_H_
  6. #include <map>
  7. #include <string>
  8. #include <vector>
  9. #include "base/component_export.h"
  10. #include "base/observer_list.h"
  11. #include "chromeos/services/libassistant/public/cpp/assistant_notification.h"
  12. namespace ash {
  13. class AssistantNotificationModelObserver;
  14. // The model belonging to AssistantNotificationController which tracks
  15. // notification state and notifies a pool of observers.
  16. class COMPONENT_EXPORT(ASSISTANT_MODEL) AssistantNotificationModel {
  17. public:
  18. using AssistantNotification = chromeos::assistant::AssistantNotification;
  19. AssistantNotificationModel();
  20. AssistantNotificationModel(const AssistantNotificationModel&) = delete;
  21. AssistantNotificationModel& operator=(const AssistantNotificationModel&) =
  22. delete;
  23. ~AssistantNotificationModel();
  24. // Adds/removes the specified notification model |observer|.
  25. void AddObserver(AssistantNotificationModelObserver* observer) const;
  26. void RemoveObserver(AssistantNotificationModelObserver* observer) const;
  27. // Adds or updates the specified |notification| in the model. If there is an
  28. // existing notification with the same |client_id|, an update will occur.
  29. // Otherwise a new notification will be added.
  30. void AddOrUpdateNotification(AssistantNotification&& notification);
  31. // Removes the notification uniquely identified by |id|. If |from_server| is
  32. // true the request to remove was initiated by the server.
  33. void RemoveNotificationById(const std::string& id, bool from_server);
  34. // Removes the notifications identified by |grouping_key|. If |from_server| is
  35. // true the request to remove was initiated by the server.
  36. void RemoveNotificationsByGroupingKey(const std::string& grouping_key,
  37. bool from_server);
  38. // Removes all notifications. If |from_server| is true the request to remove
  39. // was initiated by the server.
  40. void RemoveAllNotifications(bool from_server);
  41. // Returns the notification uniquely identified by |id|.
  42. const AssistantNotification* GetNotificationById(const std::string& id) const;
  43. // Returns all notifications (that have not been removed).
  44. std::vector<const AssistantNotification*> GetNotifications() const;
  45. // Returns true if the model contains a notification uniquely identified by
  46. // |id|, otherwise false.
  47. bool HasNotificationForId(const std::string& id) const;
  48. private:
  49. void NotifyNotificationAdded(const AssistantNotification& notification);
  50. void NotifyNotificationUpdated(const AssistantNotification& notification);
  51. void NotifyNotificationRemoved(const AssistantNotification& notification,
  52. bool from_server);
  53. void NotifyAllNotificationsRemoved(bool from_server);
  54. // Notifications are each mapped to their unique id.
  55. std::map<std::string, AssistantNotification> notifications_;
  56. mutable base::ObserverList<AssistantNotificationModelObserver> observers_;
  57. };
  58. } // namespace ash
  59. #endif // ASH_ASSISTANT_MODEL_ASSISTANT_NOTIFICATION_MODEL_H_