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 CHROME_BROWSER_ANDROID_NTP_MOST_VISITED_SITES_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_NTP_MOST_VISITED_SITES_H_ |
6 #define CHROME_BROWSER_ANDROID_NTP_MOST_VISITED_SITES_H_ | 6 #define CHROME_BROWSER_ANDROID_NTP_MOST_VISITED_SITES_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 15 matching lines...) Expand all Loading... | |
26 | 26 |
27 namespace suggestions { | 27 namespace suggestions { |
28 class SuggestionsService; | 28 class SuggestionsService; |
29 } | 29 } |
30 | 30 |
31 namespace user_prefs { | 31 namespace user_prefs { |
32 class PrefRegistrySyncable; | 32 class PrefRegistrySyncable; |
33 } | 33 } |
34 | 34 |
35 class PopularSites; | 35 class PopularSites; |
36 struct PopularSites_Site; | |
36 class Profile; | 37 class Profile; |
37 | 38 |
38 // The observer to be notified when the list of most visited sites changes. | |
39 class MostVisitedSitesObserver { | |
40 public: | |
41 virtual ~MostVisitedSitesObserver() {} | |
42 | |
43 virtual void OnMostVisitedURLsAvailable( | |
44 const std::vector<base::string16>& titles, | |
45 const std::vector<std::string>& urls, | |
46 const std::vector<std::string>& whitelist_icon_paths) = 0; | |
47 virtual void OnPopularURLsAvailable( | |
48 const std::vector<std::string>& urls, | |
49 const std::vector<std::string>& favicon_urls, | |
50 const std::vector<std::string>& large_icon_urls) = 0; | |
51 }; | |
52 | |
53 // Tracks the list of most visited sites and their thumbnails. | 39 // Tracks the list of most visited sites and their thumbnails. |
54 // | 40 // |
55 // Do not use, except from MostVisitedSitesBridge. The interface is in flux | 41 // Do not use, except from MostVisitedSitesBridge. The interface is in flux |
56 // while we are extracting the functionality of the Java class to make available | 42 // while we are extracting the functionality of the Java class to make available |
57 // in C++. | 43 // in C++. |
58 // | 44 // |
59 // TODO(sfiera): finalize interface. | 45 // TODO(sfiera): finalize interface. |
60 class MostVisitedSites : public history::TopSitesObserver, | 46 class MostVisitedSites : public history::TopSitesObserver, |
61 public SupervisedUserServiceObserver { | 47 public SupervisedUserServiceObserver { |
62 public: | 48 public: |
49 class Observer; | |
50 class Suggestion; | |
Marc Treib
2016/04/25 13:58:38
Any reason for not defining these inline here? Sin
sfiera
2016/04/25 16:26:08
I find out-of-line easier, though some csearching
Marc Treib
2016/04/25 16:42:36
That's my impression as well, but I don't have num
sfiera
2016/04/26 09:18:17
My numbers say it's about 100:1 in favor of in-lin
Marc Treib
2016/04/26 09:57:55
Thanks for checking!
| |
51 | |
52 using SuggestionsVector = std::vector<std::unique_ptr<Suggestion>>; | |
53 using PopularSiteVector = std::vector<PopularSites_Site>; | |
Marc Treib
2016/04/25 13:58:38
Why is one of these a vector of pointers, the othe
sfiera
2016/04/25 16:26:08
These were the types that MostVisitedSites and Pop
Marc Treib
2016/04/25 16:42:36
Ah, I see.
Much of that merging/order-persisting c
sfiera
2016/04/26 09:18:17
Well, in that case, how about I go ahead and updat
Marc Treib
2016/04/26 09:37:28
Sure, SGTM.
I just wanted to avoid unnecessary wor
| |
54 | |
63 explicit MostVisitedSites(Profile* profile); | 55 explicit MostVisitedSites(Profile* profile); |
64 | 56 |
65 ~MostVisitedSites() override; | 57 ~MostVisitedSites() override; |
66 | 58 |
67 // Does not take ownership of |observer|, which must outlive this object. | 59 // Does not take ownership of |observer|, which must outlive this object. |
68 void SetMostVisitedURLsObserver( | 60 void SetMostVisitedURLsObserver( |
69 MostVisitedSitesObserver* observer, int num_sites); | 61 Observer* observer, int num_sites); |
70 | 62 |
71 using ThumbnailCallback = base::Callback< | 63 using ThumbnailCallback = base::Callback< |
72 void(bool /* is_local_thumbnail */, const SkBitmap* /* bitmap */)>; | 64 void(bool /* is_local_thumbnail */, const SkBitmap* /* bitmap */)>; |
73 void GetURLThumbnail(const GURL& url, const ThumbnailCallback& callback); | 65 void GetURLThumbnail(const GURL& url, const ThumbnailCallback& callback); |
74 void AddOrRemoveBlacklistedUrl(const GURL& url, bool add_url); | 66 void AddOrRemoveBlacklistedUrl(const GURL& url, bool add_url); |
75 void RecordTileTypeMetrics(const std::vector<int>& tile_types); | 67 void RecordTileTypeMetrics(const std::vector<int>& tile_types); |
76 void RecordOpenedMostVisitedItem(int index, int tile_type); | 68 void RecordOpenedMostVisitedItem(int index, int tile_type); |
77 | 69 |
78 // SupervisedUserServiceObserver implementation. | 70 // SupervisedUserServiceObserver implementation. |
79 void OnURLFilterChanged() override; | 71 void OnURLFilterChanged() override; |
80 | 72 |
81 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 73 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
82 | 74 |
83 private: | 75 private: |
84 friend class MostVisitedSitesTest; | 76 friend class MostVisitedSitesTest; |
85 | 77 |
86 // The source of the Most Visited sites. | 78 // The source of the Most Visited sites. |
87 enum MostVisitedSource { TOP_SITES, SUGGESTIONS_SERVICE, POPULAR, WHITELIST }; | 79 enum MostVisitedSource { TOP_SITES, SUGGESTIONS_SERVICE, POPULAR, WHITELIST }; |
88 | 80 |
89 struct Suggestion { | |
90 base::string16 title; | |
91 GURL url; | |
92 MostVisitedSource source; | |
93 | |
94 // Only valid for source == WHITELIST (empty otherwise). | |
95 base::FilePath whitelist_icon_path; | |
96 | |
97 // Only valid for source == SUGGESTIONS_SERVICE (-1 otherwise). | |
98 int provider_index; | |
99 | |
100 Suggestion(); | |
101 ~Suggestion(); | |
102 | |
103 // Get the Histogram name associated with the source. | |
104 std::string GetSourceHistogramName() const; | |
105 | |
106 private: | |
107 DISALLOW_COPY_AND_ASSIGN(Suggestion); | |
108 }; | |
109 | |
110 using SuggestionsVector = std::vector<std::unique_ptr<Suggestion>>; | |
111 | |
112 void QueryMostVisitedURLs(); | 81 void QueryMostVisitedURLs(); |
113 | 82 |
114 // Initialize the query to Top Sites. Called if the SuggestionsService is not | 83 // Initialize the query to Top Sites. Called if the SuggestionsService is not |
115 // enabled, or if it returns no data. | 84 // enabled, or if it returns no data. |
116 void InitiateTopSitesQuery(); | 85 void InitiateTopSitesQuery(); |
117 | 86 |
118 // If there's a whitelist entry point for the URL, return the large icon path. | 87 // If there's a whitelist entry point for the URL, return the large icon path. |
119 base::FilePath GetWhitelistLargeIconPath(const GURL& url); | 88 base::FilePath GetWhitelistLargeIconPath(const GURL& url); |
120 | 89 |
121 // Callback for when data is available from TopSites. | 90 // Callback for when data is available from TopSites. |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 void RecordImpressionUMAMetrics(); | 172 void RecordImpressionUMAMetrics(); |
204 | 173 |
205 // history::TopSitesObserver implementation. | 174 // history::TopSitesObserver implementation. |
206 void TopSitesLoaded(history::TopSites* top_sites) override; | 175 void TopSitesLoaded(history::TopSites* top_sites) override; |
207 void TopSitesChanged(history::TopSites* top_sites, | 176 void TopSitesChanged(history::TopSites* top_sites, |
208 ChangeReason change_reason) override; | 177 ChangeReason change_reason) override; |
209 | 178 |
210 // The profile whose most visited sites will be queried. | 179 // The profile whose most visited sites will be queried. |
211 Profile* profile_; | 180 Profile* profile_; |
212 | 181 |
213 MostVisitedSitesObserver* observer_; | 182 Observer* observer_; |
214 | 183 |
215 // The maximum number of most visited sites to return. | 184 // The maximum number of most visited sites to return. |
216 int num_sites_; | 185 int num_sites_; |
217 | 186 |
218 // Whether we have received an initial set of most visited sites (from either | 187 // Whether we have received an initial set of most visited sites (from either |
219 // TopSites or the SuggestionsService). | 188 // TopSites or the SuggestionsService). |
220 bool received_most_visited_sites_; | 189 bool received_most_visited_sites_; |
221 | 190 |
222 // Whether we have received the set of popular sites. Immediately set to true | 191 // Whether we have received the set of popular sites. Immediately set to true |
223 // if popular sites are disabled. | 192 // if popular sites are disabled. |
(...skipping 14 matching lines...) Expand all Loading... | |
238 std::unique_ptr<PopularSites> popular_sites_; | 207 std::unique_ptr<PopularSites> popular_sites_; |
239 | 208 |
240 SuggestionsVector current_suggestions_; | 209 SuggestionsVector current_suggestions_; |
241 | 210 |
242 // For callbacks may be run after destruction. | 211 // For callbacks may be run after destruction. |
243 base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_; | 212 base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_; |
244 | 213 |
245 DISALLOW_COPY_AND_ASSIGN(MostVisitedSites); | 214 DISALLOW_COPY_AND_ASSIGN(MostVisitedSites); |
246 }; | 215 }; |
247 | 216 |
217 // The observer to be notified when the list of most visited sites changes. | |
218 class MostVisitedSites::Observer { | |
219 public: | |
220 virtual ~Observer() {} | |
221 | |
222 virtual void OnMostVisitedURLsAvailable( | |
223 const SuggestionsVector& suggestions) = 0; | |
224 virtual void OnPopularURLsAvailable(const PopularSiteVector& sites) = 0; | |
225 }; | |
226 | |
227 class MostVisitedSites::Suggestion { | |
228 public: | |
Marc Treib
2016/04/25 13:58:38
If you want to keep the public member variables, t
sfiera
2016/04/25 16:26:08
Done.
| |
229 base::string16 title; | |
230 GURL url; | |
231 MostVisitedSource source; | |
232 | |
233 // Only valid for source == WHITELIST (empty otherwise). | |
234 base::FilePath whitelist_icon_path; | |
235 | |
236 // Only valid for source == SUGGESTIONS_SERVICE (-1 otherwise). | |
237 int provider_index; | |
238 | |
239 Suggestion(); | |
240 ~Suggestion(); | |
241 | |
242 // Get the Histogram name associated with the source. | |
243 std::string GetSourceHistogramName() const; | |
Marc Treib
2016/04/25 13:58:38
Since Suggestion is now part of the public interfa
sfiera
2016/04/26 09:18:17
I removed it from the header, since it no longer n
| |
244 | |
245 private: | |
246 DISALLOW_COPY_AND_ASSIGN(Suggestion); | |
247 }; | |
248 | |
248 #endif // CHROME_BROWSER_ANDROID_NTP_MOST_VISITED_SITES_H_ | 249 #endif // CHROME_BROWSER_ANDROID_NTP_MOST_VISITED_SITES_H_ |
OLD | NEW |