Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: components/ntp_tiles/most_visited_sites.h

Issue 2388783004: Ensure PopularSite icon availability in ntp_tiles. (Closed)
Patch Set: Fix comments, variable names. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_NTP_TILES_MOST_VISITED_SITES_H_ 5 #ifndef COMPONENTS_NTP_TILES_MOST_VISITED_SITES_H_
6 #define COMPONENTS_NTP_TILES_MOST_VISITED_SITES_H_ 6 #define COMPONENTS_NTP_TILES_MOST_VISITED_SITES_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 16 matching lines...) Expand all
27 namespace history { 27 namespace history {
28 class TopSites; 28 class TopSites;
29 } 29 }
30 30
31 namespace user_prefs { 31 namespace user_prefs {
32 class PrefRegistrySyncable; 32 class PrefRegistrySyncable;
33 } 33 }
34 34
35 namespace ntp_tiles { 35 namespace ntp_tiles {
36 36
37 class IconCacher;
38
37 // Shim interface for SupervisedUserService. 39 // Shim interface for SupervisedUserService.
38 class MostVisitedSitesSupervisor { 40 class MostVisitedSitesSupervisor {
39 public: 41 public:
40 struct Whitelist { 42 struct Whitelist {
41 base::string16 title; 43 base::string16 title;
42 GURL entry_point; 44 GURL entry_point;
43 base::FilePath large_icon_path; 45 base::FilePath large_icon_path;
44 }; 46 };
45 47
46 class Observer { 48 class Observer {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 ICON_COLOR, 100 ICON_COLOR,
99 // The item displays a default gray box in place of an icon. 101 // The item displays a default gray box in place of an icon.
100 ICON_DEFAULT, 102 ICON_DEFAULT,
101 NUM_TILE_TYPES, 103 NUM_TILE_TYPES,
102 }; 104 };
103 105
104 // The observer to be notified when the list of most visited sites changes. 106 // The observer to be notified when the list of most visited sites changes.
105 class Observer { 107 class Observer {
106 public: 108 public:
107 virtual void OnMostVisitedURLsAvailable(const NTPTilesVector& tiles) = 0; 109 virtual void OnMostVisitedURLsAvailable(const NTPTilesVector& tiles) = 0;
108 virtual void OnPopularURLsAvailable(const PopularSitesVector& sites) {} 110 // TODO(sfiera): make this method required after iOS implements it:
111 virtual void OnIconMadeAvailable(const GURL& site_url) {}
109 112
110 protected: 113 protected:
111 virtual ~Observer() {} 114 virtual ~Observer() {}
112 }; 115 };
113 116
114 // Construct a MostVisitedSites instance. 117 // Construct a MostVisitedSites instance.
115 // 118 //
116 // |prefs| and |suggestions| are required and may not be null. |top_sites|, 119 // |prefs| and |suggestions| are required and may not be null. |top_sites|,
117 // |popular_sites|, and |supervisor| are optional and if null the associated 120 // |popular_sites|, and |supervisor| are optional and if null the associated
118 // features will be disabled. 121 // features will be disabled.
119 MostVisitedSites(PrefService* prefs, 122 MostVisitedSites(PrefService* prefs,
120 scoped_refptr<history::TopSites> top_sites, 123 scoped_refptr<history::TopSites> top_sites,
121 suggestions::SuggestionsService* suggestions, 124 suggestions::SuggestionsService* suggestions,
122 std::unique_ptr<PopularSites> popular_sites, 125 std::unique_ptr<PopularSites> popular_sites,
126 std::unique_ptr<IconCacher> icon_cacher,
123 MostVisitedSitesSupervisor* supervisor); 127 MostVisitedSitesSupervisor* supervisor);
124 128
125 ~MostVisitedSites() override; 129 ~MostVisitedSites() override;
126 130
127 // Does not take ownership of |observer|, which must outlive this object and 131 // Does not take ownership of |observer|, which must outlive this object and
128 // must not be null. 132 // must not be null.
129 void SetMostVisitedURLsObserver(Observer* observer, int num_sites); 133 void SetMostVisitedURLsObserver(Observer* observer, int num_sites);
130 134
131 void AddOrRemoveBlacklistedUrl(const GURL& url, bool add_url); 135 void AddOrRemoveBlacklistedUrl(const GURL& url, bool add_url);
132 void RecordTileTypeMetrics(const std::vector<MostVisitedTileType>& tile_types, 136 void RecordTileTypeMetrics(const std::vector<MostVisitedTileType>& tile_types,
133 const std::vector<NTPTileSource>& sources); 137 const std::vector<NTPTileSource>& sources);
134 void RecordOpenedMostVisitedItem(int index, 138 void RecordOpenedMostVisitedItem(int index,
135 MostVisitedTileType tile_type, 139 MostVisitedTileType tile_type,
136 NTPTileSource source); 140 NTPTileSource source);
137 141
138 // MostVisitedSitesSupervisor::Observer implementation. 142 // MostVisitedSitesSupervisor::Observer implementation.
139 void OnBlockedSitesChanged() override; 143 void OnBlockedSitesChanged() override;
140 144
141 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 145 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
142 146
143 private: 147 private:
144 friend class MostVisitedSitesTest; 148 friend class MostVisitedSitesTest;
145 149
150 void OnIconMadeAvailable(const GURL& site_url, bool newly_available);
Marc Treib 2016/10/12 09:11:29 nit: Maybe move this below OnPopularSitesAvailable
sfiera 2016/10/13 09:06:46 Done.
151
146 void BuildCurrentTiles(); 152 void BuildCurrentTiles();
147 153
148 // Initialize the query to Top Sites. Called if the SuggestionsService 154 // Initialize the query to Top Sites. Called if the SuggestionsService
149 // returned no data. 155 // returned no data.
150 void InitiateTopSitesQuery(); 156 void InitiateTopSitesQuery();
151 157
152 // If there's a whitelist entry point for the URL, return the large icon path. 158 // If there's a whitelist entry point for the URL, return the large icon path.
153 base::FilePath GetWhitelistLargeIconPath(const GURL& url); 159 base::FilePath GetWhitelistLargeIconPath(const GURL& url);
154 160
155 // Callback for when data is available from TopSites. 161 // Callback for when data is available from TopSites.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 197
192 // history::TopSitesObserver implementation. 198 // history::TopSitesObserver implementation.
193 void TopSitesLoaded(history::TopSites* top_sites) override; 199 void TopSitesLoaded(history::TopSites* top_sites) override;
194 void TopSitesChanged(history::TopSites* top_sites, 200 void TopSitesChanged(history::TopSites* top_sites,
195 ChangeReason change_reason) override; 201 ChangeReason change_reason) override;
196 202
197 PrefService* prefs_; 203 PrefService* prefs_;
198 scoped_refptr<history::TopSites> top_sites_; 204 scoped_refptr<history::TopSites> top_sites_;
199 suggestions::SuggestionsService* suggestions_service_; 205 suggestions::SuggestionsService* suggestions_service_;
200 std::unique_ptr<PopularSites> const popular_sites_; 206 std::unique_ptr<PopularSites> const popular_sites_;
207 std::unique_ptr<IconCacher> const icon_cacher_;
201 MostVisitedSitesSupervisor* supervisor_; 208 MostVisitedSitesSupervisor* supervisor_;
202 209
203 Observer* observer_; 210 Observer* observer_;
204 211
205 // The maximum number of most visited sites to return. 212 // The maximum number of most visited sites to return.
206 int num_sites_; 213 int num_sites_;
207 214
208 // True if we are still waiting for an initial set of most visited sites (from 215 // True if we are still waiting for an initial set of most visited sites (from
209 // either TopSites or the SuggestionsService). 216 // either TopSites or the SuggestionsService).
210 bool waiting_for_most_visited_sites_; 217 bool waiting_for_most_visited_sites_;
(...skipping 20 matching lines...) Expand all
231 238
232 // For callbacks may be run after destruction. 239 // For callbacks may be run after destruction.
233 base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_; 240 base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_;
234 241
235 DISALLOW_COPY_AND_ASSIGN(MostVisitedSites); 242 DISALLOW_COPY_AND_ASSIGN(MostVisitedSites);
236 }; 243 };
237 244
238 } // namespace ntp_tiles 245 } // namespace ntp_tiles
239 246
240 #endif // COMPONENTS_NTP_TILES_MOST_VISITED_SITES_H_ 247 #endif // COMPONENTS_NTP_TILES_MOST_VISITED_SITES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698