wutao | a88fcc5 | 2020-04-28 02:10:35 | [diff] [blame] | 1 | // 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> |
wutao | 41ddbe83 | 2020-05-01 17:07:03 | [diff] [blame] | 9 | #include <vector> |
wutao | a88fcc5 | 2020-04-28 02:10:35 | [diff] [blame] | 10 | |
wutao | 2592026 | 2020-06-20 21:11:10 | [diff] [blame] | 11 | #include "ash/public/cpp/ambient/common/ambient_settings.h" |
wutao | a88fcc5 | 2020-04-28 02:10:35 | [diff] [blame] | 12 | #include "ash/public/cpp/ash_public_export.h" |
| 13 | #include "base/callback_forward.h" |
| 14 | #include "base/optional.h" |
| 15 | |
wutao | 41ddbe83 | 2020-05-01 17:07:03 | [diff] [blame] | 16 | namespace base { |
| 17 | class TimeDelta; |
| 18 | } // namespace base |
| 19 | |
wutao | a88fcc5 | 2020-04-28 02:10:35 | [diff] [blame] | 20 | namespace ash { |
| 21 | |
wutao | a88fcc5 | 2020-04-28 02:10:35 | [diff] [blame] | 22 | // AmbientModeTopic contains the information we need for rendering photo frame |
| 23 | // for Ambient Mode. Corresponding to the |backdrop::ScreenUpdate::Topic| proto. |
| 24 | struct ASH_PUBLIC_EXPORT AmbientModeTopic { |
| 25 | AmbientModeTopic(); |
| 26 | AmbientModeTopic(const AmbientModeTopic&); |
| 27 | AmbientModeTopic& operator=(const AmbientModeTopic&); |
| 28 | ~AmbientModeTopic(); |
| 29 | |
Meilin Wang | 3195342d | 2020-08-12 06:28:40 | [diff] [blame] | 30 | // Details, i.e. the attribution, to be displayed for the current photo on |
| 31 | // ambient. |
| 32 | std::string details; |
| 33 | |
wutao | a88fcc5 | 2020-04-28 02:10:35 | [diff] [blame] | 34 | // Image url. |
| 35 | std::string url; |
| 36 | |
wutao | e8d5890 | 2020-09-23 06:33:55 | [diff] [blame^] | 37 | // Only support portrait image tiling in landscape orientation. |
| 38 | base::Optional<std::string> related_image_url; |
wutao | a88fcc5 | 2020-04-28 02:10:35 | [diff] [blame] | 39 | }; |
| 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. |
| 44 | struct 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 Young | e441bfc | 2020-08-10 16:41:09 | [diff] [blame] | 55 | |
| 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; |
wutao | a88fcc5 | 2020-04-28 02:10:35 | [diff] [blame] | 59 | }; |
| 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. |
| 64 | struct 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 Dhollander | f277b5f | 2020-08-04 00:57:20 | [diff] [blame] | 77 | // process, and a default |ScreenUpdate| instance was returned to indicate |
wutao | a88fcc5 | 2020-04-28 02:10:35 | [diff] [blame] | 78 | // the error. |
| 79 | base::Optional<WeatherInfo> weather_info; |
| 80 | }; |
| 81 | |
| 82 | // Interface to manage ambient mode backend. |
| 83 | class ASH_PUBLIC_EXPORT AmbientBackendController { |
| 84 | public: |
| 85 | using OnScreenUpdateInfoFetchedCallback = |
| 86 | base::OnceCallback<void(const ScreenUpdate&)>; |
wutao | 2592026 | 2020-06-20 21:11:10 | [diff] [blame] | 87 | using GetSettingsCallback = |
| 88 | base::OnceCallback<void(const base::Optional<AmbientSettings>& settings)>; |
wutao | a88fcc5 | 2020-04-28 02:10:35 | [diff] [blame] | 89 | using UpdateSettingsCallback = base::OnceCallback<void(bool success)>; |
wutao | 03be4cb | 2020-07-17 00:13:00 | [diff] [blame] | 90 | using OnSettingPreviewFetchedCallback = |
| 91 | base::OnceCallback<void(const std::vector<std::string>& preview_urls)>; |
wutao | f4afba18 | 2020-06-21 23:36:28 | [diff] [blame] | 92 | using OnPersonalAlbumsFetchedCallback = |
wutao | df261d5 | 2020-06-30 08:19:54 | [diff] [blame] | 93 | base::OnceCallback<void(PersonalAlbums)>; |
wutao | 046f252 | 2020-08-06 00:11:28 | [diff] [blame] | 94 | // TODO(wutao): Make |settings| move only. |
| 95 | using OnSettingsAndAlbumsFetchedCallback = |
| 96 | base::OnceCallback<void(const base::Optional<AmbientSettings>& settings, |
| 97 | PersonalAlbums personal_albums)>; |
wutao | a88fcc5 | 2020-04-28 02:10:35 | [diff] [blame] | 98 | |
| 99 | static AmbientBackendController* Get(); |
| 100 | |
| 101 | AmbientBackendController(); |
| 102 | AmbientBackendController(const AmbientBackendController&) = delete; |
| 103 | AmbientBackendController& operator=(const AmbientBackendController&) = delete; |
| 104 | virtual ~AmbientBackendController(); |
| 105 | |
wutao | 7820f093 | 2020-05-21 19:26:36 | [diff] [blame] | 106 | // Sends request to retrieve |num_topics| of |ScreenUpdate| from the backdrop |
| 107 | // server. |
wutao | a88fcc5 | 2020-04-28 02:10:35 | [diff] [blame] | 108 | // 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 Dhollander | f277b5f | 2020-08-04 00:57:20 | [diff] [blame] | 110 | // default instance will be returned. |
wutao | a88fcc5 | 2020-04-28 02:10:35 | [diff] [blame] | 111 | virtual void FetchScreenUpdateInfo( |
wutao | 7820f093 | 2020-05-21 19:26:36 | [diff] [blame] | 112 | int num_topics, |
wutao | a88fcc5 | 2020-04-28 02:10:35 | [diff] [blame] | 113 | OnScreenUpdateInfoFetchedCallback callback) = 0; |
| 114 | |
Meilin Wang | abbeb57 | 2020-08-28 17:37:20 | [diff] [blame] | 115 | // Sets the initial settings to the backdrop server. |
| 116 | virtual void InitSettings(UpdateSettingsCallback callback) = 0; |
| 117 | |
wutao | a88fcc5 | 2020-04-28 02:10:35 | [diff] [blame] | 118 | // Get ambient mode Settings from server. |
wutao | a88fcc5 | 2020-04-28 02:10:35 | [diff] [blame] | 119 | virtual void GetSettings(GetSettingsCallback callback) = 0; |
| 120 | |
| 121 | // Update ambient mode Settings to server. |
wutao | 2592026 | 2020-06-20 21:11:10 | [diff] [blame] | 122 | virtual void UpdateSettings(const AmbientSettings& settings, |
wutao | a88fcc5 | 2020-04-28 02:10:35 | [diff] [blame] | 123 | UpdateSettingsCallback callback) = 0; |
wutao | 41ddbe83 | 2020-05-01 17:07:03 | [diff] [blame] | 124 | |
wutao | 03be4cb | 2020-07-17 00:13:00 | [diff] [blame] | 125 | // Fetch preview images for live album. |
| 126 | virtual void FetchSettingPreview(int preview_width, |
| 127 | int preview_height, |
| 128 | OnSettingPreviewFetchedCallback) = 0; |
| 129 | |
wutao | f4afba18 | 2020-06-21 23:36:28 | [diff] [blame] | 130 | virtual void FetchPersonalAlbums(int banner_width, |
| 131 | int banner_height, |
| 132 | int num_albums, |
| 133 | const std::string& resume_token, |
| 134 | OnPersonalAlbumsFetchedCallback) = 0; |
| 135 | |
wutao | 046f252 | 2020-08-06 00:11:28 | [diff] [blame] | 136 | // 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 | |
wutao | 41ddbe83 | 2020-05-01 17:07:03 | [diff] [blame] | 142 | // Set the photo refresh interval in ambient mode. |
| 143 | virtual void SetPhotoRefreshInterval(base::TimeDelta interval) = 0; |
wutao | a88fcc5 | 2020-04-28 02:10:35 | [diff] [blame] | 144 | }; |
| 145 | |
| 146 | } // namespace ash |
| 147 | |
| 148 | #endif // ASH_PUBLIC_CPP_AMBIENT_AMBIENT_BACKEND_CONTROLLER_H_ |