Avi Drissman | 8ba1bad | 2022-09-13 19:22:36 | [diff] [blame] | 1 | // Copyright 2015 The Chromium Authors |
sfiera | 3ff01c0d | 2016-06-13 15:33:38 | [diff] [blame] | 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 COMPONENTS_NTP_TILES_POPULAR_SITES_H_ |
| 6 | #define COMPONENTS_NTP_TILES_POPULAR_SITES_H_ |
| 7 | |
Friedrich Horschig | f4818374 | 2017-08-08 16:53:13 | [diff] [blame] | 8 | #include <map> |
mastiz | fd2c7ab | 2017-01-27 19:35:00 | [diff] [blame] | 9 | #include <string> |
sfiera | 3ff01c0d | 2016-06-13 15:33:38 | [diff] [blame] | 10 | #include <vector> |
| 11 | |
Avi Drissman | 12be031 | 2023-01-11 09:16:09 | [diff] [blame] | 12 | #include "base/functional/callback.h" |
Roland Bock | b60178a | 2022-08-31 20:26:09 | [diff] [blame] | 13 | #include "base/values.h" |
Friedrich Horschig | f4818374 | 2017-08-08 16:53:13 | [diff] [blame] | 14 | #include "components/ntp_tiles/section_type.h" |
Friedrich Horschig | efec081 | 2017-09-28 18:50:17 | [diff] [blame] | 15 | #include "components/ntp_tiles/tile_title_source.h" |
sfiera | 3ff01c0d | 2016-06-13 15:33:38 | [diff] [blame] | 16 | #include "url/gurl.h" |
| 17 | |
sfiera | 08009fe | 2016-06-15 17:07:26 | [diff] [blame] | 18 | namespace ntp_tiles { |
| 19 | |
mastiz | 78efbde | 2016-12-14 17:07:07 | [diff] [blame] | 20 | // Interface to provide a list of suggested popular sites, for display on the |
| 21 | // NTP when there are not enough personalized tiles. |
| 22 | class PopularSites { |
sfiera | 3ff01c0d | 2016-06-13 15:33:38 | [diff] [blame] | 23 | public: |
| 24 | struct Site { |
Jan Wilken Dörrie | fa241ba | 2021-03-11 17:57:01 | [diff] [blame] | 25 | Site(const std::u16string& title, |
sfiera | 3ff01c0d | 2016-06-13 15:33:38 | [diff] [blame] | 26 | const GURL& url, |
| 27 | const GURL& favicon_url, |
| 28 | const GURL& large_icon_url, |
Friedrich Horschig | efec081 | 2017-09-28 18:50:17 | [diff] [blame] | 29 | TileTitleSource title_source); |
sfiera | 3ff01c0d | 2016-06-13 15:33:38 | [diff] [blame] | 30 | Site(const Site& other); |
| 31 | ~Site(); |
| 32 | |
Jan Wilken Dörrie | fa241ba | 2021-03-11 17:57:01 | [diff] [blame] | 33 | std::u16string title; |
sfiera | 3ff01c0d | 2016-06-13 15:33:38 | [diff] [blame] | 34 | GURL url; |
| 35 | GURL favicon_url; |
| 36 | GURL large_icon_url; |
Friedrich Horschig | efec081 | 2017-09-28 18:50:17 | [diff] [blame] | 37 | |
| 38 | TileTitleSource title_source; |
Friedrich Horschig | 7706ef6 | 2017-08-25 08:20:00 | [diff] [blame] | 39 | bool baked_in; |
fhorschig | fed34be | 2017-03-02 23:16:09 | [diff] [blame] | 40 | int default_icon_resource; // < 0 if there is none. Used for popular sites. |
sfiera | 3ff01c0d | 2016-06-13 15:33:38 | [diff] [blame] | 41 | }; |
| 42 | |
mastiz | 78efbde | 2016-12-14 17:07:07 | [diff] [blame] | 43 | using SitesVector = std::vector<Site>; |
Ken Rockot | c24303b | 2019-12-20 17:59:32 | [diff] [blame] | 44 | using FinishedCallback = base::OnceCallback<void(bool /* success */)>; |
sfiera | 3ff01c0d | 2016-06-13 15:33:38 | [diff] [blame] | 45 | |
mastiz | 78efbde | 2016-12-14 17:07:07 | [diff] [blame] | 46 | virtual ~PopularSites() = default; |
sfiera | 00a58ab | 2016-07-28 10:20:49 | [diff] [blame] | 47 | |
mastiz | fd2c7ab | 2017-01-27 19:35:00 | [diff] [blame] | 48 | // May start the process of retrieving popular sites. If an actual download |
| 49 | // gets triggered, returns true and invokes |callback| with the result, on the |
| 50 | // same thread as the caller. Never invokes |callback| before returning |
| 51 | // control to the caller. |
| 52 | // |
| 53 | // If the result is immediately known and hence no download is triggered, the |
| 54 | // function returns false and the callback will never be executed. |
sfiera | 00a58ab | 2016-07-28 10:20:49 | [diff] [blame] | 55 | // |
mastiz | 5c82ff8 | 2017-01-23 17:00:43 | [diff] [blame] | 56 | // Set |force_download| to enforce re-downloading the popular sites JSON, even |
| 57 | // if it already exists in cache. |
sfiera | 00a58ab | 2016-07-28 10:20:49 | [diff] [blame] | 58 | // |
| 59 | // Must be called at most once on a given PopularSites object. |
mastiz | fd2c7ab | 2017-01-27 19:35:00 | [diff] [blame] | 60 | virtual bool MaybeStartFetch(bool force_download, |
Ken Rockot | c24303b | 2019-12-20 17:59:32 | [diff] [blame] | 61 | FinishedCallback callback) = 0; |
sfiera | 3ff01c0d | 2016-06-13 15:33:38 | [diff] [blame] | 62 | |
Friedrich Horschig | f4818374 | 2017-08-08 16:53:13 | [diff] [blame] | 63 | // Returns the cached list of available sections and their sites. |
| 64 | virtual const std::map<SectionType, SitesVector>& sections() const = 0; |
sfiera | 3ff01c0d | 2016-06-13 15:33:38 | [diff] [blame] | 65 | |
mastiz | 78efbde | 2016-12-14 17:07:07 | [diff] [blame] | 66 | // Various internals exposed publicly for diagnostic pages only. |
mastiz | 78efbde | 2016-12-14 17:07:07 | [diff] [blame] | 67 | virtual GURL GetURLToFetch() = 0; |
mastiz | 7df710a | 2017-04-26 11:09:10 | [diff] [blame] | 68 | virtual std::string GetDirectoryToFetch() = 0; |
mastiz | 78efbde | 2016-12-14 17:07:07 | [diff] [blame] | 69 | virtual std::string GetCountryToFetch() = 0; |
| 70 | virtual std::string GetVersionToFetch() = 0; |
Roland Bock | b60178a | 2022-08-31 20:26:09 | [diff] [blame] | 71 | virtual const base::Value::List& GetCachedJson() = 0; |
mastiz | 78efbde | 2016-12-14 17:07:07 | [diff] [blame] | 72 | }; |
sfiera | 3ff01c0d | 2016-06-13 15:33:38 | [diff] [blame] | 73 | |
sfiera | 08009fe | 2016-06-15 17:07:26 | [diff] [blame] | 74 | } // namespace ntp_tiles |
| 75 | |
sfiera | 3ff01c0d | 2016-06-13 15:33:38 | [diff] [blame] | 76 | #endif // COMPONENTS_NTP_TILES_POPULAR_SITES_H_ |