Commit 03be4cb1 authored by wutao's avatar wutao Committed by Commit Bot

ambient: Add API to fetch preview images of live album

Bug: b/160753530
Test: manual
Change-Id: I4edae4b329f17919ad25aca3800adf79861e6f1e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2287273Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Commit-Queue: Tao Wu <wutao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#789276}
parent 214f0dd0
......@@ -199,6 +199,16 @@ void AmbientBackendControllerImpl::UpdateSettings(
weak_factory_.GetWeakPtr(), settings, std::move(callback)));
}
void AmbientBackendControllerImpl::FetchSettingPreview(
int preview_width,
int preview_height,
OnSettingPreviewFetchedCallback callback) {
Shell::Get()->ambient_controller()->RequestAccessToken(
base::BindOnce(&AmbientBackendControllerImpl::FetchSettingPreviewInternal,
weak_factory_.GetWeakPtr(), preview_width, preview_height,
std::move(callback)));
}
void AmbientBackendControllerImpl::FetchPersonalAlbums(
int banner_width,
int banner_height,
......@@ -337,6 +347,47 @@ void AmbientBackendControllerImpl::OnUpdateSettings(
std::move(callback).Run(success);
}
void AmbientBackendControllerImpl::FetchSettingPreviewInternal(
int preview_width,
int preview_height,
OnSettingPreviewFetchedCallback callback,
const std::string& gaia_id,
const std::string& access_token) {
if (gaia_id.empty() || access_token.empty()) {
LOG(ERROR) << "Failed to fetch access token";
// Returns a dummy instance to indicate the failure.
std::move(callback).Run(/*preview_urls=*/{});
return;
}
BackdropClientConfig::Request request =
backdrop_client_config_.CreateFetchSettingPreviewRequest(
preview_width, preview_height, gaia_id, access_token);
std::unique_ptr<network::ResourceRequest> resource_request =
CreateResourceRequest(request);
auto backdrop_url_loader = std::make_unique<BackdropURLLoader>();
auto* loader_ptr = backdrop_url_loader.get();
loader_ptr->Start(
std::move(resource_request), /*request_body=*/base::nullopt,
NO_TRAFFIC_ANNOTATION_YET,
base::BindOnce(&AmbientBackendControllerImpl::OnSettingPreviewFetched,
weak_factory_.GetWeakPtr(), std::move(callback),
std::move(backdrop_url_loader)));
}
void AmbientBackendControllerImpl::OnSettingPreviewFetched(
OnSettingPreviewFetchedCallback callback,
std::unique_ptr<BackdropURLLoader> backdrop_url_loader,
std::unique_ptr<std::string> response) {
DCHECK(backdrop_url_loader);
// Parse the |SettingPreviewResponse| out from the response string.
// Note that the |preview_urls| can be empty if the parsing has failed.
std::vector<std::string> preview_urls =
BackdropClientConfig::ParseSettingPreviewResponse(*response);
std::move(callback).Run(std::move(preview_urls));
}
void AmbientBackendControllerImpl::FetchPersonalAlbumsInternal(
int banner_width,
int banner_height,
......
......@@ -31,6 +31,9 @@ class AmbientBackendControllerImpl : public AmbientBackendController {
void GetSettings(GetSettingsCallback callback) override;
void UpdateSettings(const AmbientSettings& settings,
UpdateSettingsCallback callback) override;
void FetchSettingPreview(int preview_width,
int preview_height,
OnSettingPreviewFetchedCallback callback) override;
void FetchPersonalAlbums(int banner_width,
int banner_height,
int num_albums,
......@@ -69,6 +72,17 @@ class AmbientBackendControllerImpl : public AmbientBackendController {
std::unique_ptr<BackdropURLLoader> backdrop_url_loader,
std::unique_ptr<std::string> response);
void FetchSettingPreviewInternal(int preview_width,
int preview_height,
OnSettingPreviewFetchedCallback callback,
const std::string& gaia_id,
const std::string& access_token);
void OnSettingPreviewFetched(
OnSettingPreviewFetchedCallback callback,
std::unique_ptr<BackdropURLLoader> backdrop_url_loader,
std::unique_ptr<std::string> response);
void FetchPersonalAlbumsInternal(int banner_width,
int banner_height,
int num_albums,
......
......@@ -60,6 +60,16 @@ void FakeAmbientBackendControllerImpl::UpdateSettings(
FROM_HERE, base::BindOnce(std::move(callback), /*success=*/true));
}
void FakeAmbientBackendControllerImpl::FetchSettingPreview(
int preview_width,
int preview_height,
OnSettingPreviewFetchedCallback callback) {
std::vector<std::string> urls = {kFakeUrl};
// Pretend to respond asynchronously.
base::SequencedTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(std::move(callback), urls));
}
void FakeAmbientBackendControllerImpl::FetchPersonalAlbums(
int banner_width,
int banner_height,
......
......@@ -25,6 +25,9 @@ class ASH_EXPORT FakeAmbientBackendControllerImpl
void GetSettings(GetSettingsCallback callback) override;
void UpdateSettings(const AmbientSettings& settings,
UpdateSettingsCallback callback) override;
void FetchSettingPreview(int preview_width,
int preview_height,
OnSettingPreviewFetchedCallback) override;
void FetchPersonalAlbums(int banner_width,
int banner_height,
int num_albums,
......
......@@ -80,6 +80,8 @@ class ASH_PUBLIC_EXPORT AmbientBackendController {
using GetSettingsCallback =
base::OnceCallback<void(const base::Optional<AmbientSettings>& settings)>;
using UpdateSettingsCallback = base::OnceCallback<void(bool success)>;
using OnSettingPreviewFetchedCallback =
base::OnceCallback<void(const std::vector<std::string>& preview_urls)>;
using OnPersonalAlbumsFetchedCallback =
base::OnceCallback<void(PersonalAlbums)>;
......@@ -106,6 +108,11 @@ class ASH_PUBLIC_EXPORT AmbientBackendController {
virtual void UpdateSettings(const AmbientSettings& settings,
UpdateSettingsCallback callback) = 0;
// Fetch preview images for live album.
virtual void FetchSettingPreview(int preview_width,
int preview_height,
OnSettingPreviewFetchedCallback) = 0;
virtual void FetchPersonalAlbums(int banner_width,
int banner_height,
int num_albums,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment