blob: e8f79defbc51535f6bb63ab2d49ff206ae9d0101 [file] [log] [blame]
Avi Drissman8ba1bad2022-09-13 19:22:361// Copyright 2015 The Chromium Authors
sfiera3ff01c0d2016-06-13 15:33:382// 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 Horschigf48183742017-08-08 16:53:138#include <map>
mastizfd2c7ab2017-01-27 19:35:009#include <string>
sfiera3ff01c0d2016-06-13 15:33:3810#include <vector>
11
Avi Drissman12be0312023-01-11 09:16:0912#include "base/functional/callback.h"
Roland Bockb60178a2022-08-31 20:26:0913#include "base/values.h"
Friedrich Horschigf48183742017-08-08 16:53:1314#include "components/ntp_tiles/section_type.h"
Friedrich Horschigefec0812017-09-28 18:50:1715#include "components/ntp_tiles/tile_title_source.h"
sfiera3ff01c0d2016-06-13 15:33:3816#include "url/gurl.h"
17
sfiera08009fe2016-06-15 17:07:2618namespace ntp_tiles {
19
mastiz78efbde2016-12-14 17:07:0720// Interface to provide a list of suggested popular sites, for display on the
21// NTP when there are not enough personalized tiles.
22class PopularSites {
sfiera3ff01c0d2016-06-13 15:33:3823 public:
24 struct Site {
Jan Wilken Dörriefa241ba2021-03-11 17:57:0125 Site(const std::u16string& title,
sfiera3ff01c0d2016-06-13 15:33:3826 const GURL& url,
27 const GURL& favicon_url,
28 const GURL& large_icon_url,
Friedrich Horschigefec0812017-09-28 18:50:1729 TileTitleSource title_source);
sfiera3ff01c0d2016-06-13 15:33:3830 Site(const Site& other);
31 ~Site();
32
Jan Wilken Dörriefa241ba2021-03-11 17:57:0133 std::u16string title;
sfiera3ff01c0d2016-06-13 15:33:3834 GURL url;
35 GURL favicon_url;
36 GURL large_icon_url;
Friedrich Horschigefec0812017-09-28 18:50:1737
38 TileTitleSource title_source;
Friedrich Horschig7706ef62017-08-25 08:20:0039 bool baked_in;
fhorschigfed34be2017-03-02 23:16:0940 int default_icon_resource; // < 0 if there is none. Used for popular sites.
sfiera3ff01c0d2016-06-13 15:33:3841 };
42
mastiz78efbde2016-12-14 17:07:0743 using SitesVector = std::vector<Site>;
Ken Rockotc24303b2019-12-20 17:59:3244 using FinishedCallback = base::OnceCallback<void(bool /* success */)>;
sfiera3ff01c0d2016-06-13 15:33:3845
mastiz78efbde2016-12-14 17:07:0746 virtual ~PopularSites() = default;
sfiera00a58ab2016-07-28 10:20:4947
mastizfd2c7ab2017-01-27 19:35:0048 // 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.
sfiera00a58ab2016-07-28 10:20:4955 //
mastiz5c82ff82017-01-23 17:00:4356 // Set |force_download| to enforce re-downloading the popular sites JSON, even
57 // if it already exists in cache.
sfiera00a58ab2016-07-28 10:20:4958 //
59 // Must be called at most once on a given PopularSites object.
mastizfd2c7ab2017-01-27 19:35:0060 virtual bool MaybeStartFetch(bool force_download,
Ken Rockotc24303b2019-12-20 17:59:3261 FinishedCallback callback) = 0;
sfiera3ff01c0d2016-06-13 15:33:3862
Friedrich Horschigf48183742017-08-08 16:53:1363 // Returns the cached list of available sections and their sites.
64 virtual const std::map<SectionType, SitesVector>& sections() const = 0;
sfiera3ff01c0d2016-06-13 15:33:3865
mastiz78efbde2016-12-14 17:07:0766 // Various internals exposed publicly for diagnostic pages only.
mastiz78efbde2016-12-14 17:07:0767 virtual GURL GetURLToFetch() = 0;
mastiz7df710a2017-04-26 11:09:1068 virtual std::string GetDirectoryToFetch() = 0;
mastiz78efbde2016-12-14 17:07:0769 virtual std::string GetCountryToFetch() = 0;
70 virtual std::string GetVersionToFetch() = 0;
Roland Bockb60178a2022-08-31 20:26:0971 virtual const base::Value::List& GetCachedJson() = 0;
mastiz78efbde2016-12-14 17:07:0772};
sfiera3ff01c0d2016-06-13 15:33:3873
sfiera08009fe2016-06-15 17:07:2674} // namespace ntp_tiles
75
sfiera3ff01c0d2016-06-13 15:33:3876#endif // COMPONENTS_NTP_TILES_POPULAR_SITES_H_