blob: d45bff244c7009f484806afe30440ac07873ef5e [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
30 // Image url.
31 std::string url;
32
33 // Optional for non-cropped portrait style images. The same image as in
34 // |url| but it is not cropped and is better for portrait displaying.
35 base::Optional<std::string> portrait_image_url;
36};
37
38// WeatherInfo contains the weather information we need for rendering a
39// glanceable weather content on Ambient Mode. Corresponding to the
40// |backdrop::WeatherInfo| proto.
41struct ASH_PUBLIC_EXPORT WeatherInfo {
42 WeatherInfo();
43 WeatherInfo(const WeatherInfo&);
44 WeatherInfo& operator=(const WeatherInfo&);
45 ~WeatherInfo();
46
47 // The url of the weather condition icon image.
48 base::Optional<std::string> condition_icon_url;
49
50 // Weather temperature in Fahrenheit.
51 base::Optional<float> temp_f;
52};
53
54// Trimmed-down version of |backdrop::ScreenUpdate| proto from the backdrop
55// server. It contains necessary information we need to render photo frame and
56// glancible weather card in Ambient Mode.
57struct ASH_PUBLIC_EXPORT ScreenUpdate {
58 ScreenUpdate();
59 ScreenUpdate(const ScreenUpdate&);
60 ScreenUpdate& operator=(const ScreenUpdate&);
61 ~ScreenUpdate();
62
63 // A list of |Topic| (size >= 0).
64 std::vector<AmbientModeTopic> next_topics;
65
66 // Weather information with weather condition icon and temperature in
67 // Fahrenheit. Will be a null-opt if:
68 // 1. The weather setting was disabled in the request, or
69 // 2. Fatal errors, such as response parsing failure, happened during the
70 // process, and a dummy |ScreenUpdate| instance was returned to indicate
71 // the error.
72 base::Optional<WeatherInfo> weather_info;
73};
74
75// Interface to manage ambient mode backend.
76class ASH_PUBLIC_EXPORT AmbientBackendController {
77 public:
78 using OnScreenUpdateInfoFetchedCallback =
79 base::OnceCallback<void(const ScreenUpdate&)>;
wutao25920262020-06-20 21:11:1080 using GetSettingsCallback =
81 base::OnceCallback<void(const base::Optional<AmbientSettings>& settings)>;
wutaoa88fcc52020-04-28 02:10:3582 using UpdateSettingsCallback = base::OnceCallback<void(bool success)>;
wutao03be4cb2020-07-17 00:13:0083 using OnSettingPreviewFetchedCallback =
84 base::OnceCallback<void(const std::vector<std::string>& preview_urls)>;
wutaof4afba182020-06-21 23:36:2885 using OnPersonalAlbumsFetchedCallback =
wutaodf261d52020-06-30 08:19:5486 base::OnceCallback<void(PersonalAlbums)>;
wutaoa88fcc52020-04-28 02:10:3587
88 static AmbientBackendController* Get();
89
90 AmbientBackendController();
91 AmbientBackendController(const AmbientBackendController&) = delete;
92 AmbientBackendController& operator=(const AmbientBackendController&) = delete;
93 virtual ~AmbientBackendController();
94
wutao7820f0932020-05-21 19:26:3695 // Sends request to retrieve |num_topics| of |ScreenUpdate| from the backdrop
96 // server.
wutaoa88fcc52020-04-28 02:10:3597 // Upon completion, |callback| is run with the parsed |ScreenUpdate|. If any
98 // errors happened during the process, e.g. failed to fetch access token, a
99 // dummy instance will be returned.
100 virtual void FetchScreenUpdateInfo(
wutao7820f0932020-05-21 19:26:36101 int num_topics,
wutaoa88fcc52020-04-28 02:10:35102 OnScreenUpdateInfoFetchedCallback callback) = 0;
103
104 // Get ambient mode Settings from server.
wutaoa88fcc52020-04-28 02:10:35105 virtual void GetSettings(GetSettingsCallback callback) = 0;
106
107 // Update ambient mode Settings to server.
wutao25920262020-06-20 21:11:10108 virtual void UpdateSettings(const AmbientSettings& settings,
wutaoa88fcc52020-04-28 02:10:35109 UpdateSettingsCallback callback) = 0;
wutao41ddbe832020-05-01 17:07:03110
wutao03be4cb2020-07-17 00:13:00111 // Fetch preview images for live album.
112 virtual void FetchSettingPreview(int preview_width,
113 int preview_height,
114 OnSettingPreviewFetchedCallback) = 0;
115
wutaof4afba182020-06-21 23:36:28116 virtual void FetchPersonalAlbums(int banner_width,
117 int banner_height,
118 int num_albums,
119 const std::string& resume_token,
120 OnPersonalAlbumsFetchedCallback) = 0;
121
wutao41ddbe832020-05-01 17:07:03122 // Set the photo refresh interval in ambient mode.
123 virtual void SetPhotoRefreshInterval(base::TimeDelta interval) = 0;
wutaoa88fcc52020-04-28 02:10:35124};
125
126} // namespace ash
127
128#endif // ASH_PUBLIC_CPP_AMBIENT_AMBIENT_BACKEND_CONTROLLER_H_