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