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

Side by Side Diff: chrome/browser/android/ntp/most_visited_sites.h

Issue 1899683003: NTP tiles: Split C++ and Java MostVisitedSites classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 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 <jni.h> 8 #include <jni.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 10
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 virtual void OnMostVisitedURLsAvailable( 45 virtual void OnMostVisitedURLsAvailable(
46 const std::vector<base::string16>& titles, 46 const std::vector<base::string16>& titles,
47 const std::vector<std::string>& urls, 47 const std::vector<std::string>& urls,
48 const std::vector<std::string>& whitelist_icon_paths) = 0; 48 const std::vector<std::string>& whitelist_icon_paths) = 0;
49 virtual void OnPopularURLsAvailable( 49 virtual void OnPopularURLsAvailable(
50 const std::vector<std::string>& urls, 50 const std::vector<std::string>& urls,
51 const std::vector<std::string>& favicon_urls, 51 const std::vector<std::string>& favicon_urls,
52 const std::vector<std::string>& large_icon_urls) = 0; 52 const std::vector<std::string>& large_icon_urls) = 0;
53 }; 53 };
54 54
55 // Provides the list of most visited sites and their thumbnails to Java. 55 // Tracks the list of most visited sites and their thumbnails.
56 class MostVisitedSites : public history::TopSitesObserver, 56 class MostVisitedSites : public history::TopSitesObserver,
57 public SupervisedUserServiceObserver { 57 public SupervisedUserServiceObserver {
58 public: 58 public:
59 explicit MostVisitedSites(Profile* profile); 59 explicit MostVisitedSites(Profile* profile);
60 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj);
61 60
62 // Java methods 61 ~MostVisitedSites() override;
63 62
64 void SetMostVisitedURLsObserver( 63 void SetMostVisitedURLsObserver(
65 JNIEnv* env, 64 MostVisitedSitesObserver* observer, int num_sites);
66 const base::android::JavaParamRef<jobject>& obj,
67 const base::android::JavaParamRef<jobject>& j_observer,
68 jint num_sites);
69
70 void GetURLThumbnail(
71 JNIEnv* env,
72 const base::android::JavaParamRef<jobject>& obj,
73 const base::android::JavaParamRef<jstring>& url,
74 const base::android::JavaParamRef<jobject>& j_callback);
75 void AddOrRemoveBlacklistedUrl(
76 JNIEnv* env,
77 const base::android::JavaParamRef<jobject>& obj,
78 const base::android::JavaParamRef<jstring>& j_url,
79 jboolean add_url);
80 void RecordTileTypeMetrics(
81 JNIEnv* env,
82 const base::android::JavaParamRef<jobject>& obj,
83 const base::android::JavaParamRef<jintArray>& jtile_types);
84 void RecordOpenedMostVisitedItem(
85 JNIEnv* env,
86 const base::android::JavaParamRef<jobject>& obj,
87 jint index,
88 jint tile_type);
89
90 // C++ methods
91
92 void SetMostVisitedURLsObserver(
93 std::unique_ptr<MostVisitedSitesObserver> observer, int num_sites);
94 65
95 using ThumbnailCallback = base::Callback< 66 using ThumbnailCallback = base::Callback<
96 void(bool /* is_local_thumbnail */, const SkBitmap* /* bitmap */)>; 67 void(bool /* is_local_thumbnail */, const SkBitmap* /* bitmap */)>;
97 void GetURLThumbnail(const GURL& url, const ThumbnailCallback& callback); 68 void GetURLThumbnail(const GURL& url, const ThumbnailCallback& callback);
98 void AddOrRemoveBlacklistedUrl(const GURL& url, bool add_url); 69 void AddOrRemoveBlacklistedUrl(const GURL& url, bool add_url);
99 void RecordTileTypeMetrics(const std::vector<int>& tile_types); 70 void RecordTileTypeMetrics(const std::vector<int>& tile_types);
100 void RecordOpenedMostVisitedItem(int index, int tile_type); 71 void RecordOpenedMostVisitedItem(int index, int tile_type);
101 72
102 // SupervisedUserServiceObserver implementation. 73 // SupervisedUserServiceObserver implementation.
103 void OnURLFilterChanged() override; 74 void OnURLFilterChanged() override;
104 75
105 // Registers JNI methods.
106 static bool Register(JNIEnv* env);
107
108 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 76 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
109 77
110 private: 78 private:
111 friend class MostVisitedSitesTest; 79 friend class MostVisitedSitesTest;
112 80
113 // The source of the Most Visited sites. 81 // The source of the Most Visited sites.
114 enum MostVisitedSource { TOP_SITES, SUGGESTIONS_SERVICE, POPULAR, WHITELIST }; 82 enum MostVisitedSource { TOP_SITES, SUGGESTIONS_SERVICE, POPULAR, WHITELIST };
115 83
116 struct Suggestion { 84 struct Suggestion {
117 base::string16 title; 85 base::string16 title;
(...skipping 11 matching lines...) Expand all
129 97
130 // Get the Histogram name associated with the source. 98 // Get the Histogram name associated with the source.
131 std::string GetSourceHistogramName() const; 99 std::string GetSourceHistogramName() const;
132 100
133 private: 101 private:
134 DISALLOW_COPY_AND_ASSIGN(Suggestion); 102 DISALLOW_COPY_AND_ASSIGN(Suggestion);
135 }; 103 };
136 104
137 using SuggestionsVector = std::vector<std::unique_ptr<Suggestion>>; 105 using SuggestionsVector = std::vector<std::unique_ptr<Suggestion>>;
138 106
139 ~MostVisitedSites() override;
140 void QueryMostVisitedURLs(); 107 void QueryMostVisitedURLs();
141 108
142 // Initialize the query to Top Sites. Called if the SuggestionsService is not 109 // Initialize the query to Top Sites. Called if the SuggestionsService is not
143 // enabled, or if it returns no data. 110 // enabled, or if it returns no data.
144 void InitiateTopSitesQuery(); 111 void InitiateTopSitesQuery();
145 112
146 // If there's a whitelist entry point for the URL, return the large icon path. 113 // If there's a whitelist entry point for the URL, return the large icon path.
147 base::FilePath GetWhitelistLargeIconPath(const GURL& url); 114 base::FilePath GetWhitelistLargeIconPath(const GURL& url);
148 115
149 // Callback for when data is available from TopSites. 116 // Callback for when data is available from TopSites.
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 void RecordImpressionUMAMetrics(); 198 void RecordImpressionUMAMetrics();
232 199
233 // history::TopSitesObserver implementation. 200 // history::TopSitesObserver implementation.
234 void TopSitesLoaded(history::TopSites* top_sites) override; 201 void TopSitesLoaded(history::TopSites* top_sites) override;
235 void TopSitesChanged(history::TopSites* top_sites, 202 void TopSitesChanged(history::TopSites* top_sites,
236 ChangeReason change_reason) override; 203 ChangeReason change_reason) override;
237 204
238 // The profile whose most visited sites will be queried. 205 // The profile whose most visited sites will be queried.
239 Profile* profile_; 206 Profile* profile_;
240 207
241 std::unique_ptr<MostVisitedSitesObserver> observer_; 208 MostVisitedSitesObserver* observer_;
242 209
243 // The maximum number of most visited sites to return. 210 // The maximum number of most visited sites to return.
244 int num_sites_; 211 int num_sites_;
245 212
246 // Whether we have received an initial set of most visited sites (from either 213 // Whether we have received an initial set of most visited sites (from either
247 // TopSites or the SuggestionsService). 214 // TopSites or the SuggestionsService).
248 bool received_most_visited_sites_; 215 bool received_most_visited_sites_;
249 216
250 // Whether we have received the set of popular sites. Immediately set to true 217 // Whether we have received the set of popular sites. Immediately set to true
251 // if popular sites are disabled. 218 // if popular sites are disabled.
(...skipping 14 matching lines...) Expand all
266 std::unique_ptr<PopularSites> popular_sites_; 233 std::unique_ptr<PopularSites> popular_sites_;
267 234
268 SuggestionsVector current_suggestions_; 235 SuggestionsVector current_suggestions_;
269 236
270 // For callbacks may be run after destruction. 237 // For callbacks may be run after destruction.
271 base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_; 238 base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_;
272 239
273 DISALLOW_COPY_AND_ASSIGN(MostVisitedSites); 240 DISALLOW_COPY_AND_ASSIGN(MostVisitedSites);
274 }; 241 };
275 242
243 // Provides the list of most visited sites and their thumbnails to Java.
244 class MostVisitedSitesJavaBridge {
Marc Treib 2016/04/19 08:14:47 Also here: just "MostVisitedSitesBridge" will do.
sfiera 2016/04/19 12:15:13 Renamed. What's the end goal? Do we want "android
Marc Treib 2016/04/19 13:20:54 Yes, that would be my preference.
sfiera 2016/04/19 16:53:43 OK. If the bridge class is going to end up in a di
245 public:
246 explicit MostVisitedSitesJavaBridge(Profile* profile);
247
248 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj);
249
250 void SetMostVisitedURLsObserver(
251 JNIEnv* env,
252 const base::android::JavaParamRef<jobject>& obj,
253 const base::android::JavaParamRef<jobject>& j_observer,
254 jint num_sites);
255
256 void GetURLThumbnail(
257 JNIEnv* env,
258 const base::android::JavaParamRef<jobject>& obj,
259 const base::android::JavaParamRef<jstring>& url,
260 const base::android::JavaParamRef<jobject>& j_callback);
261 void AddOrRemoveBlacklistedUrl(
262 JNIEnv* env,
263 const base::android::JavaParamRef<jobject>& obj,
264 const base::android::JavaParamRef<jstring>& j_url,
265 jboolean add_url);
266 void RecordTileTypeMetrics(
267 JNIEnv* env,
268 const base::android::JavaParamRef<jobject>& obj,
269 const base::android::JavaParamRef<jintArray>& jtile_types);
270 void RecordOpenedMostVisitedItem(
271 JNIEnv* env,
272 const base::android::JavaParamRef<jobject>& obj,
273 jint index,
274 jint tile_type);
275
276 // Registers JNI methods.
277 static bool Register(JNIEnv* env);
278
279 private:
280 ~MostVisitedSitesJavaBridge();
281
282 class Observer : public MostVisitedSitesObserver {
283 public:
284 Observer(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj);
285
286 void OnMostVisitedURLsAvailable(
287 const std::vector<base::string16>& titles,
288 const std::vector<std::string>& urls,
289 const std::vector<std::string>& whitelist_icon_paths) override;
290
291 void OnPopularURLsAvailable(
292 const std::vector<std::string>& urls,
293 const std::vector<std::string>& favicon_urls,
294 const std::vector<std::string>& large_icon_urls) override;
295
296 private:
297 base::android::ScopedJavaGlobalRef<jobject> observer_;
298
299 DISALLOW_COPY_AND_ASSIGN(Observer);
300 };
301 std::unique_ptr<Observer> observer_;
302
303 MostVisitedSites mv_;
Marc Treib 2016/04/19 08:14:47 nit: most_visited_?
sfiera 2016/04/19 12:15:13 OK.
304
305 DISALLOW_COPY_AND_ASSIGN(MostVisitedSitesJavaBridge);
306 };
307
276 #endif // CHROME_BROWSER_ANDROID_NTP_MOST_VISITED_SITES_H_ 308 #endif // CHROME_BROWSER_ANDROID_NTP_MOST_VISITED_SITES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698