blob: 4c61f3df36776c2f12b47e9bca96c2f91d6c77d4 [file] [log] [blame]
sfiera3ff01c0d2016-06-13 15:33:381// 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 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
12#include "base/callback.h"
sfiera3ff01c0d2016-06-13 15:33:3813#include "base/macros.h"
sfiera3ff01c0d2016-06-13 15:33:3814#include "base/strings/string16.h"
Friedrich Horschigf48183742017-08-08 16:53:1315#include "components/ntp_tiles/section_type.h"
Friedrich Horschigefec0812017-09-28 18:50:1716#include "components/ntp_tiles/tile_title_source.h"
sfiera3ff01c0d2016-06-13 15:33:3817#include "url/gurl.h"
18
mastiz5c82ff82017-01-23 17:00:4319namespace base {
20class ListValue;
21}
22
sfiera08009fe2016-06-15 17:07:2623namespace ntp_tiles {
24
mastiz78efbde2016-12-14 17:07:0725// Interface to provide a list of suggested popular sites, for display on the
26// NTP when there are not enough personalized tiles.
27class PopularSites {
sfiera3ff01c0d2016-06-13 15:33:3828 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 Horschigefec0812017-09-28 18:50:1734 const GURL& thumbnail_url,
35 TileTitleSource title_source);
sfiera3ff01c0d2016-06-13 15:33:3836 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 Horschigefec0812017-09-28 18:50:1744
45 TileTitleSource title_source;
Friedrich Horschig7706ef62017-08-25 08:20:0046 bool baked_in;
fhorschigfed34be2017-03-02 23:16:0947 int default_icon_resource; // < 0 if there is none. Used for popular sites.
sfiera3ff01c0d2016-06-13 15:33:3848 };
49
mastiz78efbde2016-12-14 17:07:0750 using SitesVector = std::vector<Site>;
sfiera3ff01c0d2016-06-13 15:33:3851 using FinishedCallback = base::Callback<void(bool /* success */)>;
52
mastiz78efbde2016-12-14 17:07:0753 virtual ~PopularSites() = default;
sfiera00a58ab2016-07-28 10:20:4954
mastizfd2c7ab2017-01-27 19:35:0055 // 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.
sfiera00a58ab2016-07-28 10:20:4962 //
mastiz5c82ff82017-01-23 17:00:4363 // Set |force_download| to enforce re-downloading the popular sites JSON, even
64 // if it already exists in cache.
sfiera00a58ab2016-07-28 10:20:4965 //
66 // Must be called at most once on a given PopularSites object.
mastizfd2c7ab2017-01-27 19:35:0067 virtual bool MaybeStartFetch(bool force_download,
68 const FinishedCallback& callback) = 0;
sfiera3ff01c0d2016-06-13 15:33:3869
Friedrich Horschigf48183742017-08-08 16:53:1370 // Returns the cached list of available sections and their sites.
71 virtual const std::map<SectionType, SitesVector>& sections() const = 0;
sfiera3ff01c0d2016-06-13 15:33:3872
mastiz78efbde2016-12-14 17:07:0773 // Various internals exposed publicly for diagnostic pages only.
74 virtual GURL GetLastURLFetched() const = 0;
mastiz78efbde2016-12-14 17:07:0775 virtual GURL GetURLToFetch() = 0;
mastiz7df710a2017-04-26 11:09:1076 virtual std::string GetDirectoryToFetch() = 0;
mastiz78efbde2016-12-14 17:07:0777 virtual std::string GetCountryToFetch() = 0;
78 virtual std::string GetVersionToFetch() = 0;
mastiz5c82ff82017-01-23 17:00:4379 virtual const base::ListValue* GetCachedJson() = 0;
mastiz78efbde2016-12-14 17:07:0780};
sfiera3ff01c0d2016-06-13 15:33:3881
sfiera08009fe2016-06-15 17:07:2682} // namespace ntp_tiles
83
sfiera3ff01c0d2016-06-13 15:33:3884#endif // COMPONENTS_NTP_TILES_POPULAR_SITES_H_