ambient_backend_controller_impl.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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_AMBIENT_BACKDROP_AMBIENT_BACKEND_CONTROLLER_IMPL_H_
  5. #define ASH_AMBIENT_BACKDROP_AMBIENT_BACKEND_CONTROLLER_IMPL_H_
  6. #include <array>
  7. #include <memory>
  8. #include <string>
  9. #include <utility>
  10. #include "ash/public/cpp/ambient/ambient_backend_controller.h"
  11. #include "ash/public/cpp/ambient/ambient_client.h"
  12. #include "ash/public/cpp/ambient/common/ambient_settings.h"
  13. #include "base/memory/weak_ptr.h"
  14. #include "chromeos/assistant/internal/ambient/backdrop_client_config.h"
  15. #include "third_party/abseil-cpp/absl/types/optional.h"
  16. namespace ash {
  17. class BackdropURLLoader;
  18. // The Backdrop client implementation of AmbientBackendController.
  19. class AmbientBackendControllerImpl : public AmbientBackendController {
  20. public:
  21. AmbientBackendControllerImpl();
  22. ~AmbientBackendControllerImpl() override;
  23. // AmbientBackendController:
  24. void FetchScreenUpdateInfo(
  25. int num_topics,
  26. bool show_pair_personal_portraits,
  27. const gfx::Size& screen_size,
  28. OnScreenUpdateInfoFetchedCallback callback) override;
  29. void GetSettings(GetSettingsCallback callback) override;
  30. void UpdateSettings(const AmbientSettings& settings,
  31. UpdateSettingsCallback callback) override;
  32. void FetchPersonalAlbums(int banner_width,
  33. int banner_height,
  34. int num_albums,
  35. const std::string& resume_token,
  36. OnPersonalAlbumsFetchedCallback callback) override;
  37. void FetchSettingsAndAlbums(
  38. int banner_width,
  39. int banner_height,
  40. int num_albums,
  41. OnSettingsAndAlbumsFetchedCallback callback) override;
  42. void FetchWeather(FetchWeatherCallback callback) override;
  43. const std::array<const char*, 2>& GetBackupPhotoUrls() const override;
  44. void GetGooglePhotosAlbumsPreview(
  45. const std::vector<std::string>& album_ids,
  46. int preview_width,
  47. int preview_height,
  48. int num_previews,
  49. GetGooglePhotosAlbumsPreviewCallback callback) override;
  50. private:
  51. using BackdropClientConfig = chromeos::ambient::BackdropClientConfig;
  52. void RequestAccessToken(AmbientClient::GetAccessTokenCallback callback);
  53. void FetchScreenUpdateInfoInternal(int num_topics,
  54. bool show_pair_personal_portraits,
  55. const gfx::Size& screen_size,
  56. OnScreenUpdateInfoFetchedCallback callback,
  57. const std::string& gaia_id,
  58. const std::string& access_token);
  59. void OnScreenUpdateInfoFetched(
  60. OnScreenUpdateInfoFetchedCallback callback,
  61. std::unique_ptr<BackdropURLLoader> backdrop_url_loader,
  62. std::unique_ptr<std::string> response);
  63. void StartToGetSettings(GetSettingsCallback callback,
  64. const std::string& gaia_id,
  65. const std::string& access_token);
  66. void OnGetSettings(GetSettingsCallback callback,
  67. std::unique_ptr<BackdropURLLoader> backdrop_url_loader,
  68. std::unique_ptr<std::string> response);
  69. void StartToUpdateSettings(const AmbientSettings& settings,
  70. UpdateSettingsCallback callback,
  71. const std::string& gaia_id,
  72. const std::string& access_token);
  73. void OnUpdateSettings(UpdateSettingsCallback callback,
  74. const AmbientSettings& settings,
  75. std::unique_ptr<BackdropURLLoader> backdrop_url_loader,
  76. std::unique_ptr<std::string> response);
  77. void FetchPersonalAlbumsInternal(int banner_width,
  78. int banner_height,
  79. int num_albums,
  80. const std::string& resume_token,
  81. OnPersonalAlbumsFetchedCallback callback,
  82. const std::string& gaia_id,
  83. const std::string& access_token);
  84. void OnPersonalAlbumsFetched(
  85. OnPersonalAlbumsFetchedCallback callback,
  86. std::unique_ptr<BackdropURLLoader> backdrop_url_loader,
  87. std::unique_ptr<std::string> response);
  88. void OnSettingsFetched(base::RepeatingClosure on_done,
  89. const absl::optional<ash::AmbientSettings>& settings);
  90. void OnAlbumsFetched(base::RepeatingClosure on_done,
  91. ash::PersonalAlbums personal_albums);
  92. void OnSettingsAndAlbumsFetched(OnSettingsAndAlbumsFetchedCallback callback);
  93. void StartToGetGooglePhotosAlbumsPreview(
  94. const std::vector<std::string>& album_ids,
  95. int preview_width,
  96. int preview_height,
  97. int num_previews,
  98. GetGooglePhotosAlbumsPreviewCallback callback,
  99. const std::string& gaia_id,
  100. const std::string& access_token);
  101. void OnGetGooglePhotosAlbumsPreview(
  102. GetGooglePhotosAlbumsPreviewCallback callback,
  103. std::unique_ptr<BackdropURLLoader> backdrop_url_loader,
  104. std::unique_ptr<std::string> response);
  105. // Temporary store for FetchSettingsAndAlbums() when |GetSettingsCallback|
  106. // called. |settings_| will be absl::nullopt if server returns with error.
  107. absl::optional<ash::AmbientSettings> settings_;
  108. // Temporary store for FetchSettingsAndAlbums() when
  109. // |OnPersonalAlbumsFetchedCallback| called. |personal_albums_| will contains
  110. // empty values if server returns with error.
  111. ash::PersonalAlbums personal_albums_;
  112. BackdropClientConfig backdrop_client_config_;
  113. base::WeakPtrFactory<AmbientBackendControllerImpl> weak_factory_{this};
  114. };
  115. } // namespace ash
  116. #endif // ASH_AMBIENT_BACKDROP_AMBIENT_BACKEND_CONTROLLER_IMPL_H_