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 | |
| 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. |
| 41 | struct 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. |
| 57 | struct 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. |
| 76 | class ASH_PUBLIC_EXPORT AmbientBackendController { |
| 77 | public: |
| 78 | using OnScreenUpdateInfoFetchedCallback = |
| 79 | base::OnceCallback<void(const ScreenUpdate&)>; |
wutao | 2592026 | 2020-06-20 21:11:10 | [diff] [blame] | 80 | using GetSettingsCallback = |
| 81 | base::OnceCallback<void(const base::Optional<AmbientSettings>& settings)>; |
wutao | a88fcc5 | 2020-04-28 02:10:35 | [diff] [blame] | 82 | using UpdateSettingsCallback = base::OnceCallback<void(bool success)>; |
wutao | 03be4cb | 2020-07-17 00:13:00 | [diff] [blame^] | 83 | using OnSettingPreviewFetchedCallback = |
| 84 | base::OnceCallback<void(const std::vector<std::string>& preview_urls)>; |
wutao | f4afba18 | 2020-06-21 23:36:28 | [diff] [blame] | 85 | using OnPersonalAlbumsFetchedCallback = |
wutao | df261d5 | 2020-06-30 08:19:54 | [diff] [blame] | 86 | base::OnceCallback<void(PersonalAlbums)>; |
wutao | a88fcc5 | 2020-04-28 02:10:35 | [diff] [blame] | 87 | |
| 88 | static AmbientBackendController* Get(); |
| 89 | |
| 90 | AmbientBackendController(); |
| 91 | AmbientBackendController(const AmbientBackendController&) = delete; |
| 92 | AmbientBackendController& operator=(const AmbientBackendController&) = delete; |
| 93 | virtual ~AmbientBackendController(); |
| 94 | |
wutao | 7820f093 | 2020-05-21 19:26:36 | [diff] [blame] | 95 | // Sends request to retrieve |num_topics| of |ScreenUpdate| from the backdrop |
| 96 | // server. |
wutao | a88fcc5 | 2020-04-28 02:10:35 | [diff] [blame] | 97 | // 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( |
wutao | 7820f093 | 2020-05-21 19:26:36 | [diff] [blame] | 101 | int num_topics, |
wutao | a88fcc5 | 2020-04-28 02:10:35 | [diff] [blame] | 102 | OnScreenUpdateInfoFetchedCallback callback) = 0; |
| 103 | |
| 104 | // Get ambient mode Settings from server. |
wutao | a88fcc5 | 2020-04-28 02:10:35 | [diff] [blame] | 105 | virtual void GetSettings(GetSettingsCallback callback) = 0; |
| 106 | |
| 107 | // Update ambient mode Settings to server. |
wutao | 2592026 | 2020-06-20 21:11:10 | [diff] [blame] | 108 | virtual void UpdateSettings(const AmbientSettings& settings, |
wutao | a88fcc5 | 2020-04-28 02:10:35 | [diff] [blame] | 109 | UpdateSettingsCallback callback) = 0; |
wutao | 41ddbe83 | 2020-05-01 17:07:03 | [diff] [blame] | 110 | |
wutao | 03be4cb | 2020-07-17 00:13:00 | [diff] [blame^] | 111 | // Fetch preview images for live album. |
| 112 | virtual void FetchSettingPreview(int preview_width, |
| 113 | int preview_height, |
| 114 | OnSettingPreviewFetchedCallback) = 0; |
| 115 | |
wutao | f4afba18 | 2020-06-21 23:36:28 | [diff] [blame] | 116 | virtual void FetchPersonalAlbums(int banner_width, |
| 117 | int banner_height, |
| 118 | int num_albums, |
| 119 | const std::string& resume_token, |
| 120 | OnPersonalAlbumsFetchedCallback) = 0; |
| 121 | |
wutao | 41ddbe83 | 2020-05-01 17:07:03 | [diff] [blame] | 122 | // Set the photo refresh interval in ambient mode. |
| 123 | virtual void SetPhotoRefreshInterval(base::TimeDelta interval) = 0; |
wutao | a88fcc5 | 2020-04-28 02:10:35 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | } // namespace ash |
| 127 | |
| 128 | #endif // ASH_PUBLIC_CPP_AMBIENT_AMBIENT_BACKEND_CONTROLLER_H_ |