1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_AMBIENT_BACKDROP_AMBIENT_BACKEND_CONTROLLER_IMPL_H_
#define ASH_AMBIENT_BACKDROP_AMBIENT_BACKEND_CONTROLLER_IMPL_H_
#include <array>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include "ash/public/cpp/ambient/ambient_backend_controller.h"
#include "ash/public/cpp/ambient/ambient_client.h"
#include "ash/public/cpp/ambient/common/ambient_settings.h"
#include "base/memory/weak_ptr.h"
#include "chromeos/assistant/internal/ambient/backdrop_client_config.h"
namespace ash {
class BackdropURLLoader;
// The Backdrop client implementation of AmbientBackendController.
class AmbientBackendControllerImpl : public AmbientBackendController {
public:
AmbientBackendControllerImpl();
~AmbientBackendControllerImpl() override;
// AmbientBackendController:
void FetchScreenUpdateInfo(
int num_topics,
bool show_pair_personal_portraits,
const gfx::Size& screen_size,
OnScreenUpdateInfoFetchedCallback callback) override;
void FetchPreviewImages(const gfx::Size& preview_size,
OnPreviewImagesFetchedCallback callback) override;
void UpdateSettings(const AmbientSettings settings,
UpdateSettingsCallback callback) override;
void FetchSettingsAndAlbums(
int banner_width,
int banner_height,
int num_albums,
OnSettingsAndAlbumsFetchedCallback callback) override;
void FetchWeather(std::optional<std::string> weather_client_id,
FetchWeatherCallback callback) override;
const std::array<const char*, 2>& GetBackupPhotoUrls() const override;
std::array<const char*, 2> GetTimeOfDayVideoPreviewImageUrls(
AmbientVideo video) const override;
const char* GetPromoBannerUrl() const override;
const char* GetTimeOfDayProductName() const override;
private:
using BackdropClientConfig = chromeos::ambient::BackdropClientConfig;
using GetSettingsCallback =
base::OnceCallback<void(const std::optional<AmbientSettings>& settings)>;
using OnPersonalAlbumsFetchedCallback =
base::OnceCallback<void(PersonalAlbums)>;
void RequestAccessToken(AmbientClient::GetAccessTokenCallback callback);
void FetchScreenUpdateInfoInternal(int num_topics,
bool show_pair_personal_portraits,
const gfx::Size& screen_size,
OnScreenUpdateInfoFetchedCallback callback,
const GaiaId& gaia_id,
const std::string& access_token);
void OnScreenUpdateInfoFetched(
OnScreenUpdateInfoFetchedCallback callback,
std::unique_ptr<BackdropURLLoader> backdrop_url_loader,
std::unique_ptr<std::string> response);
void GetSettings(GetSettingsCallback callback);
void StartToGetSettings(GetSettingsCallback callback,
const GaiaId& gaia_id,
const std::string& access_token);
void OnGetSettings(GetSettingsCallback callback,
std::unique_ptr<BackdropURLLoader> backdrop_url_loader,
std::unique_ptr<std::string> response);
void StartToUpdateSettings(const AmbientSettings& settings,
UpdateSettingsCallback callback,
const GaiaId& gaia_id,
const std::string& access_token);
void OnUpdateSettings(UpdateSettingsCallback callback,
const AmbientSettings& settings,
std::unique_ptr<BackdropURLLoader> backdrop_url_loader,
std::unique_ptr<std::string> response);
void FetchPersonalAlbums(int banner_width,
int banner_height,
int num_albums,
const std::string& resume_token,
OnPersonalAlbumsFetchedCallback callback);
void FetchPersonalAlbumsInternal(int banner_width,
int banner_height,
int num_albums,
const std::string& resume_token,
OnPersonalAlbumsFetchedCallback callback,
const GaiaId& gaia_id,
const std::string& access_token);
void OnPersonalAlbumsFetched(
OnPersonalAlbumsFetchedCallback callback,
std::unique_ptr<BackdropURLLoader> backdrop_url_loader,
std::unique_ptr<std::string> response);
void OnSettingsFetched(base::RepeatingClosure on_done,
const std::optional<ash::AmbientSettings>& settings);
void OnAlbumsFetched(base::RepeatingClosure on_done,
ash::PersonalAlbums personal_albums);
void OnSettingsAndAlbumsFetched(OnSettingsAndAlbumsFetchedCallback callback);
// Temporary store for FetchSettingsAndAlbums() when |GetSettingsCallback|
// called. |settings_| will be std::nullopt if server returns with error.
std::optional<ash::AmbientSettings> settings_;
// Temporary store for FetchSettingsAndAlbums() when
// |OnPersonalAlbumsFetchedCallback| called. |personal_albums_| will contains
// empty values if server returns with error.
ash::PersonalAlbums personal_albums_;
BackdropClientConfig backdrop_client_config_;
base::WeakPtrFactory<AmbientBackendControllerImpl> weak_factory_{this};
};
} // namespace ash
#endif // ASH_AMBIENT_BACKDROP_AMBIENT_BACKEND_CONTROLLER_IMPL_H_
|