recent_apps_interaction_handler.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Copyright 2021 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_COMPONENTS_PHONEHUB_RECENT_APPS_INTERACTION_HANDLER_H_
  5. #define ASH_COMPONENTS_PHONEHUB_RECENT_APPS_INTERACTION_HANDLER_H_
  6. #include <stdint.h>
  7. #include "ash/components/phonehub/notification.h"
  8. #include "ash/components/phonehub/proto/phonehub_api.pb.h"
  9. #include "ash/components/phonehub/recent_app_click_observer.h"
  10. #include "base/gtest_prod_util.h"
  11. #include "base/observer_list.h"
  12. #include "base/observer_list_types.h"
  13. namespace ash {
  14. namespace phonehub {
  15. // The handler that exposes APIs to interact with Phone Hub Recent Apps.
  16. // TODO(paulzchen): Implement Eche's RecentAppClickObserver and add/remove
  17. // observer via this handler.
  18. class RecentAppsInteractionHandler {
  19. public:
  20. class Observer : public base::CheckedObserver {
  21. public:
  22. ~Observer() override = default;
  23. // Notifies observers that recent apps view needs be refreshed, the access
  24. // state of recent apps feature is updated or current recent apps list has
  25. // changed.
  26. virtual void OnRecentAppsUiStateUpdated() = 0;
  27. };
  28. enum class RecentAppsUiState {
  29. // Feature is either not supported, or supported but disabled by user.
  30. HIDDEN,
  31. // Feature is supported and enabled but no recent app has been added yet.
  32. PLACEHOLDER_VIEW,
  33. // We have recent app that can be displayed.
  34. ITEMS_VISIBLE,
  35. };
  36. // Records each users' quiet mode to decide showing recent apps or not.
  37. struct UserState {
  38. int64_t user_id;
  39. // The state when user turn on/off work apps/notification.
  40. bool is_enabled;
  41. };
  42. RecentAppsInteractionHandler(const RecentAppsInteractionHandler&) = delete;
  43. RecentAppsInteractionHandler& operator=(const RecentAppsInteractionHandler&) =
  44. delete;
  45. virtual ~RecentAppsInteractionHandler();
  46. void AddObserver(Observer* observer);
  47. void RemoveObserver(Observer* observer);
  48. RecentAppsUiState ui_state() { return ui_state_; }
  49. std::vector<UserState> user_states() { return user_states_; }
  50. void set_user_states(const std::vector<UserState>& user_states) {
  51. user_states_ = user_states;
  52. }
  53. virtual void AddRecentAppClickObserver(RecentAppClickObserver* observer);
  54. virtual void RemoveRecentAppClickObserver(RecentAppClickObserver* observer);
  55. virtual void NotifyRecentAppClicked(
  56. const Notification::AppMetadata& app_metadata) = 0;
  57. virtual void NotifyRecentAppAddedOrUpdated(
  58. const Notification::AppMetadata& app_metadata,
  59. base::Time last_accessed_timestamp) = 0;
  60. virtual std::vector<Notification::AppMetadata>
  61. FetchRecentAppMetadataList() = 0;
  62. virtual void SetStreamableApps(
  63. const proto::StreamableApps& streamable_apps) = 0;
  64. protected:
  65. RecentAppsInteractionHandler();
  66. RecentAppsUiState ui_state_ = RecentAppsUiState::HIDDEN;
  67. void NotifyRecentAppsViewUiStateUpdated();
  68. private:
  69. base::ObserverList<RecentAppClickObserver> recent_app_click_observer_list_;
  70. base::ObserverList<Observer> observer_list_;
  71. std::vector<UserState> user_states_;
  72. };
  73. } // namespace phonehub
  74. } // namespace ash
  75. #endif // ASH_COMPONENTS_PHONEHUB_RECENT_APPS_INTERACTION_HANDLER_H_