OLD | NEW |
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 Loading... |
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 // TODO(sfiera): finalize interface. | 81 // TODO(sfiera): finalize interface. |
80 class MostVisitedSites : public history::TopSitesObserver, | 82 class MostVisitedSites : public history::TopSitesObserver, |
81 public MostVisitedSitesSupervisor::Observer { | 83 public MostVisitedSitesSupervisor::Observer { |
82 public: | 84 public: |
83 using PopularSitesVector = std::vector<PopularSites::Site>; | 85 using PopularSitesVector = std::vector<PopularSites::Site>; |
84 | 86 |
85 // The observer to be notified when the list of most visited sites changes. | 87 // The observer to be notified when the list of most visited sites changes. |
86 class Observer { | 88 class Observer { |
87 public: | 89 public: |
88 virtual void OnMostVisitedURLsAvailable(const NTPTilesVector& tiles) = 0; | 90 virtual void OnMostVisitedURLsAvailable(const NTPTilesVector& tiles) = 0; |
89 virtual void OnPopularURLsAvailable(const PopularSitesVector& sites) {} | 91 // TODO(sfiera): make this method required after iOS implements it: |
| 92 virtual void OnIconMadeAvailable(const GURL& site_url) {} |
90 | 93 |
91 protected: | 94 protected: |
92 virtual ~Observer() {} | 95 virtual ~Observer() {} |
93 }; | 96 }; |
94 | 97 |
95 // Construct a MostVisitedSites instance. | 98 // Construct a MostVisitedSites instance. |
96 // | 99 // |
97 // |prefs| and |suggestions| are required and may not be null. |top_sites|, | 100 // |prefs| and |suggestions| are required and may not be null. |top_sites|, |
98 // |popular_sites|, and |supervisor| are optional and if null the associated | 101 // |popular_sites|, and |supervisor| are optional and if null the associated |
99 // features will be disabled. | 102 // features will be disabled. |
100 MostVisitedSites(PrefService* prefs, | 103 MostVisitedSites(PrefService* prefs, |
101 scoped_refptr<history::TopSites> top_sites, | 104 scoped_refptr<history::TopSites> top_sites, |
102 suggestions::SuggestionsService* suggestions, | 105 suggestions::SuggestionsService* suggestions, |
103 std::unique_ptr<PopularSites> popular_sites, | 106 std::unique_ptr<PopularSites> popular_sites, |
| 107 std::unique_ptr<IconCacher> icon_cacher, |
104 MostVisitedSitesSupervisor* supervisor); | 108 MostVisitedSitesSupervisor* supervisor); |
105 | 109 |
106 ~MostVisitedSites() override; | 110 ~MostVisitedSites() override; |
107 | 111 |
108 // Does not take ownership of |observer|, which must outlive this object and | 112 // Does not take ownership of |observer|, which must outlive this object and |
109 // must not be null. | 113 // must not be null. |
110 void SetMostVisitedURLsObserver(Observer* observer, int num_sites); | 114 void SetMostVisitedURLsObserver(Observer* observer, int num_sites); |
111 | 115 |
112 void AddOrRemoveBlacklistedUrl(const GURL& url, bool add_url); | 116 void AddOrRemoveBlacklistedUrl(const GURL& url, bool add_url); |
113 | 117 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 static NTPTilesVector MergeTiles(NTPTilesVector personal_tiles, | 159 static NTPTilesVector MergeTiles(NTPTilesVector personal_tiles, |
156 NTPTilesVector whitelist_tiles, | 160 NTPTilesVector whitelist_tiles, |
157 NTPTilesVector popular_tiles); | 161 NTPTilesVector popular_tiles); |
158 | 162 |
159 // Notifies the observer about the availability of tiles. | 163 // Notifies the observer about the availability of tiles. |
160 // Also records impressions UMA if not done already. | 164 // Also records impressions UMA if not done already. |
161 void NotifyMostVisitedURLsObserver(); | 165 void NotifyMostVisitedURLsObserver(); |
162 | 166 |
163 void OnPopularSitesAvailable(bool success); | 167 void OnPopularSitesAvailable(bool success); |
164 | 168 |
| 169 void OnIconMadeAvailable(const GURL& site_url, bool newly_available); |
| 170 |
165 // history::TopSitesObserver implementation. | 171 // history::TopSitesObserver implementation. |
166 void TopSitesLoaded(history::TopSites* top_sites) override; | 172 void TopSitesLoaded(history::TopSites* top_sites) override; |
167 void TopSitesChanged(history::TopSites* top_sites, | 173 void TopSitesChanged(history::TopSites* top_sites, |
168 ChangeReason change_reason) override; | 174 ChangeReason change_reason) override; |
169 | 175 |
170 PrefService* prefs_; | 176 PrefService* prefs_; |
171 scoped_refptr<history::TopSites> top_sites_; | 177 scoped_refptr<history::TopSites> top_sites_; |
172 suggestions::SuggestionsService* suggestions_service_; | 178 suggestions::SuggestionsService* suggestions_service_; |
173 std::unique_ptr<PopularSites> const popular_sites_; | 179 std::unique_ptr<PopularSites> const popular_sites_; |
| 180 std::unique_ptr<IconCacher> const icon_cacher_; |
174 MostVisitedSitesSupervisor* supervisor_; | 181 MostVisitedSitesSupervisor* supervisor_; |
175 | 182 |
176 Observer* observer_; | 183 Observer* observer_; |
177 | 184 |
178 // The maximum number of most visited sites to return. | 185 // The maximum number of most visited sites to return. |
179 int num_sites_; | 186 int num_sites_; |
180 | 187 |
181 // True if we are still waiting for an initial set of most visited sites (from | 188 // True if we are still waiting for an initial set of most visited sites (from |
182 // either TopSites or the SuggestionsService). | 189 // either TopSites or the SuggestionsService). |
183 bool waiting_for_most_visited_sites_; | 190 bool waiting_for_most_visited_sites_; |
(...skipping 20 matching lines...) Expand all Loading... |
204 | 211 |
205 // For callbacks may be run after destruction. | 212 // For callbacks may be run after destruction. |
206 base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_; | 213 base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_; |
207 | 214 |
208 DISALLOW_COPY_AND_ASSIGN(MostVisitedSites); | 215 DISALLOW_COPY_AND_ASSIGN(MostVisitedSites); |
209 }; | 216 }; |
210 | 217 |
211 } // namespace ntp_tiles | 218 } // namespace ntp_tiles |
212 | 219 |
213 #endif // COMPONENTS_NTP_TILES_MOST_VISITED_SITES_H_ | 220 #endif // COMPONENTS_NTP_TILES_MOST_VISITED_SITES_H_ |
OLD | NEW |