assistant_notification_controller_impl.h 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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_ASSISTANT_NOTIFICATION_CONTROLLER_IMPL_H_
  5. #define ASH_ASSISTANT_ASSISTANT_NOTIFICATION_CONTROLLER_IMPL_H_
  6. #include <string>
  7. #include "ash/ash_export.h"
  8. #include "ash/assistant/assistant_notification_expiry_monitor.h"
  9. #include "ash/assistant/model/assistant_notification_model.h"
  10. #include "ash/assistant/model/assistant_notification_model_observer.h"
  11. #include "ash/public/cpp/assistant/controller/assistant_notification_controller.h"
  12. #include "chromeos/ash/services/assistant/public/cpp/assistant_service.h"
  13. #include "chromeos/services/libassistant/public/cpp/assistant_notification.h"
  14. #include "chromeos/services/libassistant/public/mojom/notification_delegate.mojom.h"
  15. #include "mojo/public/cpp/bindings/pending_receiver.h"
  16. #include "mojo/public/cpp/bindings/receiver.h"
  17. #include "ui/message_center/message_center_observer.h"
  18. #include "ui/message_center/public/cpp/notifier_id.h"
  19. namespace ash {
  20. // The class to manage Assistant notifications.
  21. class ASH_EXPORT AssistantNotificationControllerImpl
  22. : public AssistantNotificationController,
  23. public AssistantNotificationModelObserver,
  24. public message_center::MessageCenterObserver,
  25. public chromeos::libassistant::mojom::NotificationDelegate {
  26. public:
  27. using AssistantNotification = chromeos::assistant::AssistantNotification;
  28. AssistantNotificationControllerImpl();
  29. AssistantNotificationControllerImpl(
  30. const AssistantNotificationControllerImpl&) = delete;
  31. AssistantNotificationControllerImpl& operator=(
  32. const AssistantNotificationControllerImpl&) = delete;
  33. ~AssistantNotificationControllerImpl() override;
  34. // Returns the underlying model.
  35. const AssistantNotificationModel* model() const { return &model_; }
  36. // Provides a pointer to the |assistant| owned by AssistantController.
  37. void SetAssistant(assistant::Assistant* assistant);
  38. // AssistantNotificationController:
  39. void RemoveNotificationById(const std::string& id, bool from_server) override;
  40. void SetQuietMode(bool enabled) override;
  41. // chromeos::libassistant::mojom::NotificationDelegate:
  42. void AddOrUpdateNotification(AssistantNotification notification) override;
  43. void RemoveNotificationByGroupingKey(const std::string& grouping_id,
  44. bool from_server) override;
  45. void RemoveAllNotifications(bool from_server) override;
  46. // AssistantNotificationModelObserver:
  47. void OnNotificationAdded(const AssistantNotification& notification) override;
  48. void OnNotificationUpdated(
  49. const AssistantNotification& notification) override;
  50. void OnNotificationRemoved(const AssistantNotification& notification,
  51. bool from_server) override;
  52. void OnAllNotificationsRemoved(bool from_server) override;
  53. // message_center::MessageCenterObserver:
  54. void OnNotificationAdded(const std::string& id) override {}
  55. void OnNotificationClicked(
  56. const std::string& id,
  57. const absl::optional<int>& button_index,
  58. const absl::optional<std::u16string>& reply) override;
  59. void OnNotificationUpdated(const std::string& notification) override {}
  60. void OnNotificationRemoved(const std::string& notification_id,
  61. bool by_user) override;
  62. private:
  63. AssistantNotificationModel model_;
  64. AssistantNotificationExpiryMonitor expiry_monitor_;
  65. // Owned by AssistantService
  66. assistant::Assistant* assistant_ = nullptr;
  67. const message_center::NotifierId notifier_id_;
  68. mojo::Receiver<chromeos::libassistant::mojom::NotificationDelegate> receiver_{
  69. this};
  70. };
  71. } // namespace ash
  72. #endif // ASH_ASSISTANT_ASSISTANT_NOTIFICATION_CONTROLLER_IMPL_H_