recent_apps_interaction_handler_impl.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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_IMPL_H_
  5. #define ASH_COMPONENTS_PHONEHUB_RECENT_APPS_INTERACTION_HANDLER_IMPL_H_
  6. #include <stdint.h>
  7. #include <memory>
  8. #include "ash/components/phonehub/icon_decoder.h"
  9. #include "ash/components/phonehub/icon_decoder_impl.h"
  10. #include "ash/components/phonehub/multidevice_feature_access_manager.h"
  11. #include "ash/components/phonehub/notification.h"
  12. #include "ash/components/phonehub/proto/phonehub_api.pb.h"
  13. #include "ash/components/phonehub/recent_app_click_observer.h"
  14. #include "ash/components/phonehub/recent_apps_interaction_handler.h"
  15. #include "ash/services/multidevice_setup/public/cpp/multidevice_setup_client.h"
  16. #include "base/gtest_prod_util.h"
  17. #include "base/observer_list.h"
  18. #include "base/observer_list_types.h"
  19. #include "base/time/time.h"
  20. class PrefRegistrySimple;
  21. class PrefService;
  22. namespace ash {
  23. namespace phonehub {
  24. // The handler that exposes APIs to interact with Phone Hub Recent Apps.
  25. class RecentAppsInteractionHandlerImpl
  26. : public RecentAppsInteractionHandler,
  27. public multidevice_setup::MultiDeviceSetupClient::Observer,
  28. public MultideviceFeatureAccessManager::Observer {
  29. public:
  30. static void RegisterPrefs(PrefRegistrySimple* registry);
  31. explicit RecentAppsInteractionHandlerImpl(
  32. PrefService* pref_service,
  33. multidevice_setup::MultiDeviceSetupClient* multidevice_setup_client,
  34. MultideviceFeatureAccessManager* multidevice_feature_access_manager,
  35. std::unique_ptr<IconDecoder> icon_decoder);
  36. ~RecentAppsInteractionHandlerImpl() override;
  37. // RecentAppsInteractionHandler:
  38. void NotifyRecentAppClicked(
  39. const Notification::AppMetadata& app_metadata) override;
  40. void AddRecentAppClickObserver(RecentAppClickObserver* observer) override;
  41. void RemoveRecentAppClickObserver(RecentAppClickObserver* observer) override;
  42. void NotifyRecentAppAddedOrUpdated(
  43. const Notification::AppMetadata& app_metadata,
  44. base::Time last_accessed_timestamp) override;
  45. std::vector<Notification::AppMetadata> FetchRecentAppMetadataList() override;
  46. // MultiDeviceSetupClient::Observer:
  47. void OnFeatureStatesChanged(
  48. const multidevice_setup::MultiDeviceSetupClient::FeatureStatesMap&
  49. feature_states_map) override;
  50. void OnHostStatusChanged(
  51. const multidevice_setup::MultiDeviceSetupClient::HostStatusWithDevice&
  52. host_device_with_status) override;
  53. // MultideviceFeatureAccessManager::Observer:
  54. void OnNotificationAccessChanged() override;
  55. void OnAppsAccessChanged() override;
  56. void SetStreamableApps(const proto::StreamableApps& streamable_apps) override;
  57. void IconsDecoded(std::unique_ptr<std::vector<IconDecoder::DecodingData>>
  58. decoding_data_list);
  59. std::vector<std::pair<Notification::AppMetadata, base::Time>>*
  60. recent_app_metadata_list_for_testing() {
  61. return &recent_app_metadata_list_;
  62. }
  63. private:
  64. friend class RecentAppsInteractionHandlerTest;
  65. void LoadRecentAppMetadataListFromPrefIfNeed();
  66. void SaveRecentAppMetadataListToPref();
  67. void ComputeAndUpdateUiState();
  68. void ClearRecentAppMetadataListAndPref();
  69. base::flat_set<int64_t> GetUserIdsWithDisplayRecentApps();
  70. // Whether this class has finished loading |recent_app_metadata_list_| from
  71. // pref.
  72. bool has_loaded_prefs_ = false;
  73. base::ObserverList<RecentAppClickObserver> observer_list_;
  74. std::vector<std::pair<Notification::AppMetadata, base::Time>>
  75. recent_app_metadata_list_;
  76. PrefService* pref_service_;
  77. multidevice_setup::MultiDeviceSetupClient* multidevice_setup_client_;
  78. MultideviceFeatureAccessManager* multidevice_feature_access_manager_;
  79. std::unique_ptr<IconDecoder> icon_decoder_;
  80. base::WeakPtrFactory<RecentAppsInteractionHandlerImpl> weak_ptr_factory_{
  81. this};
  82. };
  83. } // namespace phonehub
  84. } // namespace ash
  85. #endif // ASH_COMPONENTS_PHONEHUB_RECENT_APPS_INTERACTION_HANDLER_IMPL_H_