blob: 9edbc4c5fd5e66679f06947d063d9b260f636862 [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
8#include <string>
wutao41ddbe832020-05-01 17:07:039#include <vector>
wutaoa88fcc52020-04-28 02:10:3510
wutao25920262020-06-20 21:11:1011#include "ash/public/cpp/ambient/common/ambient_settings.h"
wutaoa88fcc52020-04-28 02:10:3512#include "ash/public/cpp/ash_public_export.h"
13#include "base/callback_forward.h"
14#include "base/optional.h"
15
wutao41ddbe832020-05-01 17:07:0316namespace base {
17class TimeDelta;
18} // namespace base
19
wutaoa88fcc52020-04-28 02:10:3520namespace ash {
21
wutaoa88fcc52020-04-28 02:10:3522// AmbientModeTopic contains the information we need for rendering photo frame
23// for Ambient Mode. Corresponding to the |backdrop::ScreenUpdate::Topic| proto.
24struct ASH_PUBLIC_EXPORT AmbientModeTopic {
25 AmbientModeTopic();
26 AmbientModeTopic(const AmbientModeTopic&);
27 AmbientModeTopic& operator=(const AmbientModeTopic&);
28 ~AmbientModeTopic();
29
Meilin Wang3195342d2020-08-12 06:28:4030 // Details, i.e. the attribution, to be displayed for the current photo on
31 // ambient.
32 std::string details;
33
wutaoa88fcc52020-04-28 02:10:3534 // Image url.
35 std::string url;
36
wutaoe8d58902020-09-23 06:33:5537 // Only support portrait image tiling in landscape orientation.
38 base::Optional<std::string> related_image_url;
wutaoa88fcc52020-04-28 02:10:3539};
40
41// WeatherInfo contains the weather information we need for rendering a
42// glanceable weather content on Ambient Mode. Corresponding to the
43// |backdrop::WeatherInfo| proto.
44struct ASH_PUBLIC_EXPORT WeatherInfo {
45 WeatherInfo();
46 WeatherInfo(const WeatherInfo&);
47 WeatherInfo& operator=(const WeatherInfo&);
48 ~WeatherInfo();
49
50 // The url of the weather condition icon image.
51 base::Optional<std::string> condition_icon_url;
52
53 // Weather temperature in Fahrenheit.
54 base::Optional<float> temp_f;
Jeffrey Younge441bfc2020-08-10 16:41:0955
56 // If the temperature should be displayed in celsius. Conversion must happen
57 // before the value in temp_f is displayed.
58 bool show_celsius = false;
wutaoa88fcc52020-04-28 02:10:3559};
60
61// Trimmed-down version of |backdrop::ScreenUpdate| proto from the backdrop
62// server. It contains necessary information we need to render photo frame and
63// glancible weather card in Ambient Mode.
64struct ASH_PUBLIC_EXPORT ScreenUpdate {
65 ScreenUpdate();
66 ScreenUpdate(const ScreenUpdate&);
67 ScreenUpdate& operator=(const ScreenUpdate&);
68 ~ScreenUpdate();
69
70 // A list of |Topic| (size >= 0).
71 std::vector<AmbientModeTopic> next_topics;
72
73 // Weather information with weather condition icon and temperature in
74 // Fahrenheit. Will be a null-opt if:
75 // 1. The weather setting was disabled in the request, or
76 // 2. Fatal errors, such as response parsing failure, happened during the
Jeroen Dhollanderf277b5f2020-08-04 00:57:2077 // process, and a default |ScreenUpdate| instance was returned to indicate
wutaoa88fcc52020-04-28 02:10:3578 // the error.
79 base::Optional<WeatherInfo> weather_info;
80};
81
82// Interface to manage ambient mode backend.
83class ASH_PUBLIC_EXPORT AmbientBackendController {
84 public:
85 using OnScreenUpdateInfoFetchedCallback =
86 base::OnceCallback<void(const ScreenUpdate&)>;
wutao25920262020-06-20 21:11:1087 using GetSettingsCallback =
88 base::OnceCallback<void(const base::Optional<AmbientSettings>& settings)>;
wutaoa88fcc52020-04-28 02:10:3589 using UpdateSettingsCallback = base::OnceCallback<void(bool success)>;
wutao03be4cb2020-07-17 00:13:0090 using OnSettingPreviewFetchedCallback =
91 base::OnceCallback<void(const std::vector<std::string>& preview_urls)>;
wutaof4afba182020-06-21 23:36:2892 using OnPersonalAlbumsFetchedCallback =
wutaodf261d52020-06-30 08:19:5493 base::OnceCallback<void(PersonalAlbums)>;
wutao046f2522020-08-06 00:11:2894 // TODO(wutao): Make |settings| move only.
95 using OnSettingsAndAlbumsFetchedCallback =
96 base::OnceCallback<void(const base::Optional<AmbientSettings>& settings,
97 PersonalAlbums personal_albums)>;
wutaoa88fcc52020-04-28 02:10:3598
99 static AmbientBackendController* Get();
100
101 AmbientBackendController();
102 AmbientBackendController(const AmbientBackendController&) = delete;
103 AmbientBackendController& operator=(const AmbientBackendController&) = delete;
104 virtual ~AmbientBackendController();
105
wutao7820f0932020-05-21 19:26:36106 // Sends request to retrieve |num_topics| of |ScreenUpdate| from the backdrop
107 // server.
wutaoa88fcc52020-04-28 02:10:35108 // Upon completion, |callback| is run with the parsed |ScreenUpdate|. If any
109 // errors happened during the process, e.g. failed to fetch access token, a
Jeroen Dhollanderf277b5f2020-08-04 00:57:20110 // default instance will be returned.
wutaoa88fcc52020-04-28 02:10:35111 virtual void FetchScreenUpdateInfo(
wutao7820f0932020-05-21 19:26:36112 int num_topics,
wutaoa88fcc52020-04-28 02:10:35113 OnScreenUpdateInfoFetchedCallback callback) = 0;
114
Meilin Wangabbeb572020-08-28 17:37:20115 // Sets the initial settings to the backdrop server.
116 virtual void InitSettings(UpdateSettingsCallback callback) = 0;
117
wutaoa88fcc52020-04-28 02:10:35118 // Get ambient mode Settings from server.
wutaoa88fcc52020-04-28 02:10:35119 virtual void GetSettings(GetSettingsCallback callback) = 0;
120
121 // Update ambient mode Settings to server.
wutao25920262020-06-20 21:11:10122 virtual void UpdateSettings(const AmbientSettings& settings,
wutaoa88fcc52020-04-28 02:10:35123 UpdateSettingsCallback callback) = 0;
wutao41ddbe832020-05-01 17:07:03124
wutao03be4cb2020-07-17 00:13:00125 // Fetch preview images for live album.
126 virtual void FetchSettingPreview(int preview_width,
127 int preview_height,
128 OnSettingPreviewFetchedCallback) = 0;
129
wutaof4afba182020-06-21 23:36:28130 virtual void FetchPersonalAlbums(int banner_width,
131 int banner_height,
132 int num_albums,
133 const std::string& resume_token,
134 OnPersonalAlbumsFetchedCallback) = 0;
135
wutao046f2522020-08-06 00:11:28136 // Fetch the Settings and albums as one API.
137 virtual void FetchSettingsAndAlbums(int banner_width,
138 int banner_height,
139 int num_albums,
140 OnSettingsAndAlbumsFetchedCallback) = 0;
141
wutao41ddbe832020-05-01 17:07:03142 // Set the photo refresh interval in ambient mode.
143 virtual void SetPhotoRefreshInterval(base::TimeDelta interval) = 0;
wutaoa88fcc52020-04-28 02:10:35144};
145
146} // namespace ash
147
148#endif // ASH_PUBLIC_CPP_AMBIENT_AMBIENT_BACKEND_CONTROLLER_H_