blob: 77f59318e1c5525756d8a753dbd7795ed93ea841 [file] [log] [blame]
wutaoa88fcc52020-04-28 02:10:351// 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
5#ifndef ASH_PUBLIC_CPP_AMBIENT_AMBIENT_BACKEND_CONTROLLER_H_
6#define ASH_PUBLIC_CPP_AMBIENT_AMBIENT_BACKEND_CONTROLLER_H_
7
Jeffrey Young57520f42020-10-07 02:13:358#include <array>
wutaoa88fcc52020-04-28 02:10:359#include <string>
wutao41ddbe832020-05-01 17:07:0310#include <vector>
wutaoa88fcc52020-04-28 02:10:3511
wutao25920262020-06-20 21:11:1012#include "ash/public/cpp/ambient/common/ambient_settings.h"
wutaoa88fcc52020-04-28 02:10:3513#include "ash/public/cpp/ash_public_export.h"
14#include "base/callback_forward.h"
15#include "base/optional.h"
16
wutao41ddbe832020-05-01 17:07:0317namespace base {
18class TimeDelta;
19} // namespace base
20
wutaoa88fcc52020-04-28 02:10:3521namespace ash {
22
Jeffrey Young4944cfe2020-09-24 03:29:5923enum class AmbientModeTopicType {
24 kCurated,
25 kPersonal,
26 kFeatured,
27 kGeo,
28 kCulturalInstitute,
29 kRss,
30 kCapturedOnPixel,
31 kOther,
32};
33
wutaoa88fcc52020-04-28 02:10:3534// AmbientModeTopic contains the information we need for rendering photo frame
35// for Ambient Mode. Corresponding to the |backdrop::ScreenUpdate::Topic| proto.
36struct ASH_PUBLIC_EXPORT AmbientModeTopic {
37 AmbientModeTopic();
38 AmbientModeTopic(const AmbientModeTopic&);
39 AmbientModeTopic& operator=(const AmbientModeTopic&);
40 ~AmbientModeTopic();
41
Meilin Wang3195342d2020-08-12 06:28:4042 // Details, i.e. the attribution, to be displayed for the current photo on
43 // ambient.
44 std::string details;
45
wutaoa88fcc52020-04-28 02:10:3546 // Image url.
47 std::string url;
48
wutaoe8d58902020-09-23 06:33:5549 // Only support portrait image tiling in landscape orientation.
50 base::Optional<std::string> related_image_url;
Jeffrey Young4944cfe2020-09-24 03:29:5951
52 AmbientModeTopicType topic_type = AmbientModeTopicType::kOther;
wutaoa88fcc52020-04-28 02:10:3553};
54
55// WeatherInfo contains the weather information we need for rendering a
56// glanceable weather content on Ambient Mode. Corresponding to the
57// |backdrop::WeatherInfo| proto.
58struct ASH_PUBLIC_EXPORT WeatherInfo {
59 WeatherInfo();
60 WeatherInfo(const WeatherInfo&);
61 WeatherInfo& operator=(const WeatherInfo&);
62 ~WeatherInfo();
63
64 // The url of the weather condition icon image.
65 base::Optional<std::string> condition_icon_url;
66
67 // Weather temperature in Fahrenheit.
68 base::Optional<float> temp_f;
Jeffrey Younge441bfc2020-08-10 16:41:0969
70 // If the temperature should be displayed in celsius. Conversion must happen
71 // before the value in temp_f is displayed.
72 bool show_celsius = false;
wutaoa88fcc52020-04-28 02:10:3573};
74
75// Trimmed-down version of |backdrop::ScreenUpdate| proto from the backdrop
76// server. It contains necessary information we need to render photo frame and
77// glancible weather card in Ambient Mode.
78struct ASH_PUBLIC_EXPORT ScreenUpdate {
79 ScreenUpdate();
80 ScreenUpdate(const ScreenUpdate&);
81 ScreenUpdate& operator=(const ScreenUpdate&);
82 ~ScreenUpdate();
83
84 // A list of |Topic| (size >= 0).
85 std::vector<AmbientModeTopic> next_topics;
86
87 // Weather information with weather condition icon and temperature in
88 // Fahrenheit. Will be a null-opt if:
89 // 1. The weather setting was disabled in the request, or
90 // 2. Fatal errors, such as response parsing failure, happened during the
Jeroen Dhollanderf277b5f2020-08-04 00:57:2091 // process, and a default |ScreenUpdate| instance was returned to indicate
wutaoa88fcc52020-04-28 02:10:3592 // the error.
93 base::Optional<WeatherInfo> weather_info;
94};
95
96// Interface to manage ambient mode backend.
97class ASH_PUBLIC_EXPORT AmbientBackendController {
98 public:
99 using OnScreenUpdateInfoFetchedCallback =
100 base::OnceCallback<void(const ScreenUpdate&)>;
wutao25920262020-06-20 21:11:10101 using GetSettingsCallback =
102 base::OnceCallback<void(const base::Optional<AmbientSettings>& settings)>;
wutaoa88fcc52020-04-28 02:10:35103 using UpdateSettingsCallback = base::OnceCallback<void(bool success)>;
wutao03be4cb2020-07-17 00:13:00104 using OnSettingPreviewFetchedCallback =
105 base::OnceCallback<void(const std::vector<std::string>& preview_urls)>;
wutaof4afba182020-06-21 23:36:28106 using OnPersonalAlbumsFetchedCallback =
wutaodf261d52020-06-30 08:19:54107 base::OnceCallback<void(PersonalAlbums)>;
wutao046f2522020-08-06 00:11:28108 // TODO(wutao): Make |settings| move only.
109 using OnSettingsAndAlbumsFetchedCallback =
110 base::OnceCallback<void(const base::Optional<AmbientSettings>& settings,
111 PersonalAlbums personal_albums)>;
Xiaohui Chen5985f532020-09-28 18:43:36112 using FetchWeatherCallback =
113 base::OnceCallback<void(const base::Optional<WeatherInfo>& weather_info)>;
wutaoa88fcc52020-04-28 02:10:35114
115 static AmbientBackendController* Get();
116
117 AmbientBackendController();
118 AmbientBackendController(const AmbientBackendController&) = delete;
119 AmbientBackendController& operator=(const AmbientBackendController&) = delete;
120 virtual ~AmbientBackendController();
121
wutao7820f0932020-05-21 19:26:36122 // Sends request to retrieve |num_topics| of |ScreenUpdate| from the backdrop
123 // server.
wutaoa88fcc52020-04-28 02:10:35124 // Upon completion, |callback| is run with the parsed |ScreenUpdate|. If any
125 // errors happened during the process, e.g. failed to fetch access token, a
Jeroen Dhollanderf277b5f2020-08-04 00:57:20126 // default instance will be returned.
wutaoa88fcc52020-04-28 02:10:35127 virtual void FetchScreenUpdateInfo(
wutao7820f0932020-05-21 19:26:36128 int num_topics,
wutaoa88fcc52020-04-28 02:10:35129 OnScreenUpdateInfoFetchedCallback callback) = 0;
130
131 // Get ambient mode Settings from server.
wutaoa88fcc52020-04-28 02:10:35132 virtual void GetSettings(GetSettingsCallback callback) = 0;
133
134 // Update ambient mode Settings to server.
wutao25920262020-06-20 21:11:10135 virtual void UpdateSettings(const AmbientSettings& settings,
wutaoa88fcc52020-04-28 02:10:35136 UpdateSettingsCallback callback) = 0;
wutao41ddbe832020-05-01 17:07:03137
wutao03be4cb2020-07-17 00:13:00138 // Fetch preview images for live album.
139 virtual void FetchSettingPreview(int preview_width,
140 int preview_height,
141 OnSettingPreviewFetchedCallback) = 0;
142
wutaof4afba182020-06-21 23:36:28143 virtual void FetchPersonalAlbums(int banner_width,
144 int banner_height,
145 int num_albums,
146 const std::string& resume_token,
147 OnPersonalAlbumsFetchedCallback) = 0;
148
wutao046f2522020-08-06 00:11:28149 // Fetch the Settings and albums as one API.
150 virtual void FetchSettingsAndAlbums(int banner_width,
151 int banner_height,
152 int num_albums,
153 OnSettingsAndAlbumsFetchedCallback) = 0;
154
wutao41ddbe832020-05-01 17:07:03155 // Set the photo refresh interval in ambient mode.
156 virtual void SetPhotoRefreshInterval(base::TimeDelta interval) = 0;
Xiaohui Chen5985f532020-09-28 18:43:36157
158 // Fetch the weather information.
159 virtual void FetchWeather(FetchWeatherCallback) = 0;
Jeffrey Young57520f42020-10-07 02:13:35160
161 // Get stock photo urls to cache in advance in case Ambient mode is started
162 // without internet access.
163 virtual const std::array<const char*, 2>& GetBackupPhotoUrls() const = 0;
wutaoa88fcc52020-04-28 02:10:35164};
165
166} // namespace ash
167
168#endif // ASH_PUBLIC_CPP_AMBIENT_AMBIENT_BACKEND_CONTROLLER_H_