phone_hub_notification_controller.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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_PHONE_HUB_NOTIFICATION_CONTROLLER_H_
  5. #define ASH_SYSTEM_PHONEHUB_PHONE_HUB_NOTIFICATION_CONTROLLER_H_
  6. #include <map>
  7. #include <memory>
  8. #include <string>
  9. #include <unordered_map>
  10. #include <unordered_set>
  11. #include "ash/ash_export.h"
  12. #include "ash/components/phonehub/camera_roll_manager.h"
  13. #include "ash/components/phonehub/feature_status_provider.h"
  14. #include "ash/components/phonehub/notification_manager.h"
  15. #include "ash/components/phonehub/tether_controller.h"
  16. #include "base/gtest_prod_util.h"
  17. namespace message_center {
  18. class MessageView;
  19. class Notification;
  20. } // namespace message_center
  21. namespace ash {
  22. namespace phonehub {
  23. class Notification;
  24. class NotificationInteractionHandler;
  25. class PhoneHubManager;
  26. class PhoneModel;
  27. namespace proto {
  28. class CameraRollItemMetadata;
  29. } // namespace proto
  30. } // namespace phonehub
  31. // This controller creates and manages a message_center::Notification for each
  32. // PhoneHub corresponding notification.
  33. class ASH_EXPORT PhoneHubNotificationController
  34. : public phonehub::CameraRollManager::Observer,
  35. public phonehub::NotificationManager::Observer,
  36. public phonehub::TetherController::Observer {
  37. public:
  38. PhoneHubNotificationController();
  39. ~PhoneHubNotificationController() override;
  40. PhoneHubNotificationController(const PhoneHubNotificationController&) =
  41. delete;
  42. PhoneHubNotificationController& operator=(
  43. const PhoneHubNotificationController&) = delete;
  44. // Sets the NotifictionManager that provides the underlying PhoneHub
  45. // notifications.
  46. void SetManager(phonehub::PhoneHubManager* phone_hub_manager);
  47. const std::u16string GetPhoneName() const;
  48. private:
  49. FRIEND_TEST_ALL_PREFIXES(PhoneHubNotificationControllerTest,
  50. CustomActionRowExpanded);
  51. FRIEND_TEST_ALL_PREFIXES(PhoneHubNotificationControllerTest,
  52. ReplyBrieflyDisabled);
  53. FRIEND_TEST_ALL_PREFIXES(PhoneHubNotificationControllerTest,
  54. NotificationHasPhoneName);
  55. class NotificationDelegate;
  56. // phonehub::NotificationManager::Observer:
  57. void OnNotificationsAdded(
  58. const base::flat_set<int64_t>& notification_ids) override;
  59. void OnNotificationsUpdated(
  60. const base::flat_set<int64_t>& notification_ids) override;
  61. void OnNotificationsRemoved(
  62. const base::flat_set<int64_t>& notification_ids) override;
  63. // phonehub::TetherController::Observer:
  64. void OnAttemptConnectionScanFailed() override;
  65. void OnTetherStatusChanged() override {}
  66. // phonehub::CameraRollManager::Observer:
  67. void OnCameraRollDownloadError(
  68. DownloadErrorType error_type,
  69. const phonehub::proto::CameraRollItemMetadata& metadata) override;
  70. // Helper functions for creating Camera Roll notifications
  71. std::unique_ptr<message_center::Notification>
  72. CreateCameraRollGenericNotification(
  73. const phonehub::proto::CameraRollItemMetadata& metadata);
  74. std::unique_ptr<message_center::Notification>
  75. CreateCameraRollStorageNotification(
  76. const phonehub::proto::CameraRollItemMetadata& metadata);
  77. std::unique_ptr<message_center::Notification>
  78. CreateCameraRollNetworkNotification(
  79. const phonehub::proto::CameraRollItemMetadata& metadata);
  80. // Callbacks for user interactions.
  81. void OpenSettings();
  82. void DismissNotification(int64_t notification_id);
  83. void HandleNotificationBodyClick(
  84. int64_t notification_id,
  85. const phonehub::Notification::AppMetadata& app_metadata);
  86. void SendInlineReply(int64_t notification_id,
  87. const std::u16string& inline_reply_text);
  88. // Logs the number of PhoneHub notifications.
  89. void LogNotificationCount();
  90. // Shows a Chrome OS notification for the provided phonehub::Notification.
  91. // If |is_update| is true, this function updates an existing notification;
  92. // otherwise, a new notification is created.
  93. void SetNotification(const phonehub::Notification* notification,
  94. bool is_update);
  95. // Creates a message_center::Notification from the PhoneHub notification data.
  96. std::unique_ptr<message_center::Notification> CreateNotification(
  97. const phonehub::Notification* notification,
  98. const std::string& cros_id,
  99. NotificationDelegate* delegate,
  100. bool is_update);
  101. int GetSystemPriorityForNotification(
  102. const phonehub::Notification* notification,
  103. bool is_update);
  104. static std::unique_ptr<message_center::MessageView>
  105. CreateCustomNotificationView(
  106. base::WeakPtr<PhoneHubNotificationController> notification_controller,
  107. const message_center::Notification& notification,
  108. bool shown_in_popup);
  109. static std::unique_ptr<message_center::MessageView>
  110. CreateCustomActionNotificationView(
  111. base::WeakPtr<PhoneHubNotificationController> notification_controller,
  112. const message_center::Notification& notification,
  113. bool shown_in_popup);
  114. phonehub::NotificationInteractionHandler* notification_interaction_handler_ =
  115. nullptr;
  116. phonehub::NotificationManager* manager_ = nullptr;
  117. phonehub::TetherController* tether_controller_ = nullptr;
  118. phonehub::CameraRollManager* camera_roll_manager_ = nullptr;
  119. phonehub::PhoneModel* phone_model_ = nullptr;
  120. std::unordered_map<int64_t, std::unique_ptr<NotificationDelegate>>
  121. notification_map_;
  122. base::WeakPtrFactory<PhoneHubNotificationController> weak_ptr_factory_{this};
  123. };
  124. } // namespace ash
  125. #endif // ASH_SYSTEM_PHONEHUB_PHONE_HUB_NOTIFICATION_CONTROLLER_H_