Commit 7820f093 authored by wutao's avatar wutao Committed by Commit Bot

ambient: Pass the topic batch size to server

Bug: b/157099464
Test: pass current tests.
Change-Id: Ie364f743da23dc73b136c77416a630db3ba6e840
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2209891Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Commit-Queue: Tao Wu <wutao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771145}
parent dbff1601
...@@ -22,6 +22,8 @@ namespace ash { ...@@ -22,6 +22,8 @@ namespace ash {
namespace { namespace {
constexpr int kNumberTopics = 100;
using DownloadCallback = base::OnceCallback<void(const gfx::ImageSkia&)>; using DownloadCallback = base::OnceCallback<void(const gfx::ImageSkia&)>;
void DownloadImageFromUrl(const std::string& url, DownloadCallback callback) { void DownloadImageFromUrl(const std::string& url, DownloadCallback callback) {
...@@ -44,6 +46,7 @@ void AmbientPhotoController::StartScreenUpdate() { ...@@ -44,6 +46,7 @@ void AmbientPhotoController::StartScreenUpdate() {
->ambient_controller() ->ambient_controller()
->ambient_backend_controller() ->ambient_backend_controller()
->FetchScreenUpdateInfo( ->FetchScreenUpdateInfo(
kNumberTopics,
base::BindOnce(&AmbientPhotoController::OnScreenUpdateInfoFetched, base::BindOnce(&AmbientPhotoController::OnScreenUpdateInfoFetched,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
} }
......
...@@ -176,12 +176,13 @@ AmbientBackendControllerImpl::AmbientBackendControllerImpl() = default; ...@@ -176,12 +176,13 @@ AmbientBackendControllerImpl::AmbientBackendControllerImpl() = default;
AmbientBackendControllerImpl::~AmbientBackendControllerImpl() = default; AmbientBackendControllerImpl::~AmbientBackendControllerImpl() = default;
void AmbientBackendControllerImpl::FetchScreenUpdateInfo( void AmbientBackendControllerImpl::FetchScreenUpdateInfo(
int num_topics,
OnScreenUpdateInfoFetchedCallback callback) { OnScreenUpdateInfoFetchedCallback callback) {
// Consolidate the functions of FetchScreenUpdateInfoInternal, // Consolidate the functions of FetchScreenUpdateInfoInternal,
// StartToGetSettings, and StartToUpdateSettings after this is done. // StartToGetSettings, and StartToUpdateSettings after this is done.
Shell::Get()->ambient_controller()->RequestAccessToken(base::BindOnce( Shell::Get()->ambient_controller()->RequestAccessToken(base::BindOnce(
&AmbientBackendControllerImpl::FetchScreenUpdateInfoInternal, &AmbientBackendControllerImpl::FetchScreenUpdateInfoInternal,
weak_factory_.GetWeakPtr(), std::move(callback))); weak_factory_.GetWeakPtr(), num_topics, std::move(callback)));
} }
void AmbientBackendControllerImpl::GetSettings(GetSettingsCallback callback) { void AmbientBackendControllerImpl::GetSettings(GetSettingsCallback callback) {
...@@ -207,6 +208,7 @@ void AmbientBackendControllerImpl::SetPhotoRefreshInterval( ...@@ -207,6 +208,7 @@ void AmbientBackendControllerImpl::SetPhotoRefreshInterval(
} }
void AmbientBackendControllerImpl::FetchScreenUpdateInfoInternal( void AmbientBackendControllerImpl::FetchScreenUpdateInfoInternal(
int num_topics,
OnScreenUpdateInfoFetchedCallback callback, OnScreenUpdateInfoFetchedCallback callback,
const std::string& gaia_id, const std::string& gaia_id,
const std::string& access_token) { const std::string& access_token) {
...@@ -220,7 +222,7 @@ void AmbientBackendControllerImpl::FetchScreenUpdateInfoInternal( ...@@ -220,7 +222,7 @@ void AmbientBackendControllerImpl::FetchScreenUpdateInfoInternal(
std::string client_id = GetClientId(); std::string client_id = GetClientId();
BackdropClientConfig::Request request = BackdropClientConfig::Request request =
backdrop_client_config_.CreateFetchScreenUpdateRequest( backdrop_client_config_.CreateFetchScreenUpdateRequest(
gaia_id, access_token, client_id); num_topics, gaia_id, access_token, client_id);
auto resource_request = CreateResourceRequest(request); auto resource_request = CreateResourceRequest(request);
auto backdrop_url_loader = std::make_unique<BackdropURLLoader>(); auto backdrop_url_loader = std::make_unique<BackdropURLLoader>();
......
...@@ -26,6 +26,7 @@ class AmbientBackendControllerImpl : public AmbientBackendController { ...@@ -26,6 +26,7 @@ class AmbientBackendControllerImpl : public AmbientBackendController {
// AmbientBackendController: // AmbientBackendController:
void FetchScreenUpdateInfo( void FetchScreenUpdateInfo(
int num_topics,
OnScreenUpdateInfoFetchedCallback callback) override; OnScreenUpdateInfoFetchedCallback callback) override;
void GetSettings(GetSettingsCallback callback) override; void GetSettings(GetSettingsCallback callback) override;
void UpdateSettings(AmbientModeTopicSource topic_source, void UpdateSettings(AmbientModeTopicSource topic_source,
...@@ -36,7 +37,8 @@ class AmbientBackendControllerImpl : public AmbientBackendController { ...@@ -36,7 +37,8 @@ class AmbientBackendControllerImpl : public AmbientBackendController {
using BackdropClientConfig = chromeos::ambient::BackdropClientConfig; using BackdropClientConfig = chromeos::ambient::BackdropClientConfig;
void RequestAccessToken(AmbientClient::GetAccessTokenCallback callback); void RequestAccessToken(AmbientClient::GetAccessTokenCallback callback);
void FetchScreenUpdateInfoInternal(OnScreenUpdateInfoFetchedCallback callback, void FetchScreenUpdateInfoInternal(int num_topics,
OnScreenUpdateInfoFetchedCallback callback,
const std::string& gaia_id, const std::string& gaia_id,
const std::string& access_token); const std::string& access_token);
......
...@@ -25,6 +25,7 @@ FakeAmbientBackendControllerImpl::FakeAmbientBackendControllerImpl() = default; ...@@ -25,6 +25,7 @@ FakeAmbientBackendControllerImpl::FakeAmbientBackendControllerImpl() = default;
FakeAmbientBackendControllerImpl::~FakeAmbientBackendControllerImpl() = default; FakeAmbientBackendControllerImpl::~FakeAmbientBackendControllerImpl() = default;
void FakeAmbientBackendControllerImpl::FetchScreenUpdateInfo( void FakeAmbientBackendControllerImpl::FetchScreenUpdateInfo(
int num_topics,
OnScreenUpdateInfoFetchedCallback callback) { OnScreenUpdateInfoFetchedCallback callback) {
ash::AmbientModeTopic topic; ash::AmbientModeTopic topic;
topic.url = kFakeUrl; topic.url = kFakeUrl;
......
...@@ -20,6 +20,7 @@ class ASH_EXPORT FakeAmbientBackendControllerImpl ...@@ -20,6 +20,7 @@ class ASH_EXPORT FakeAmbientBackendControllerImpl
// AmbientBackendController: // AmbientBackendController:
void FetchScreenUpdateInfo( void FetchScreenUpdateInfo(
int num_topics,
OnScreenUpdateInfoFetchedCallback callback) override; OnScreenUpdateInfoFetchedCallback callback) override;
void GetSettings(GetSettingsCallback callback) override; void GetSettings(GetSettingsCallback callback) override;
void UpdateSettings(AmbientModeTopicSource topic_source, void UpdateSettings(AmbientModeTopicSource topic_source,
......
...@@ -97,11 +97,13 @@ class ASH_PUBLIC_EXPORT AmbientBackendController { ...@@ -97,11 +97,13 @@ class ASH_PUBLIC_EXPORT AmbientBackendController {
AmbientBackendController& operator=(const AmbientBackendController&) = delete; AmbientBackendController& operator=(const AmbientBackendController&) = delete;
virtual ~AmbientBackendController(); virtual ~AmbientBackendController();
// Sends request to retrieve |ScreenUpdate| from the backdrop server. // Sends request to retrieve |num_topics| of |ScreenUpdate| from the backdrop
// server.
// Upon completion, |callback| is run with the parsed |ScreenUpdate|. If any // Upon completion, |callback| is run with the parsed |ScreenUpdate|. If any
// errors happened during the process, e.g. failed to fetch access token, a // errors happened during the process, e.g. failed to fetch access token, a
// dummy instance will be returned. // dummy instance will be returned.
virtual void FetchScreenUpdateInfo( virtual void FetchScreenUpdateInfo(
int num_topics,
OnScreenUpdateInfoFetchedCallback callback) = 0; OnScreenUpdateInfoFetchedCallback callback) = 0;
// Get ambient mode Settings from server. // Get ambient mode Settings from server.
......
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