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

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

Issue 1884203002: NTP tiles: split methods into C++ and Java parts. (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 19 matching lines...) Expand all
30 class SuggestionsService; 30 class SuggestionsService;
31 } 31 }
32 32
33 namespace user_prefs { 33 namespace user_prefs {
34 class PrefRegistrySyncable; 34 class PrefRegistrySyncable;
35 } 35 }
36 36
37 class PopularSites; 37 class PopularSites;
38 class Profile; 38 class Profile;
39 39
40 // The observer to be notified when the list of most visited sites changes.
41 class MostVisitedSitesObserver {
42 public:
43 virtual ~MostVisitedSitesObserver() {}
44
45 virtual void NotifyMostVisitedURLsObserver(
46 const std::vector<base::string16>& titles,
47 const std::vector<std::string>& urls,
48 const std::vector<std::string>& whitelist_icon_paths);
49 virtual void OnPopularSitesAvailable(
50 const std::vector<std::string>& urls,
51 const std::vector<std::string>& favicon_urls,
52 const std::vector<std::string>& large_icon_urls);
Marc Treib 2016/04/14 16:57:36 I think these should be pure virtual? (i.e. add "
sfiera 2016/04/15 13:36:00 Pure virtual; I'd forgotten.
53 };
54
40 // Provides the list of most visited sites and their thumbnails to Java. 55 // Provides the list of most visited sites and their thumbnails to Java.
41 class MostVisitedSites : public history::TopSitesObserver, 56 class MostVisitedSites : public history::TopSitesObserver,
42 public SupervisedUserServiceObserver { 57 public SupervisedUserServiceObserver {
43 public: 58 public:
44 explicit MostVisitedSites(Profile* profile); 59 explicit MostVisitedSites(Profile* profile);
45 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); 60 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj);
61
62 // Java methods
63
46 void SetMostVisitedURLsObserver( 64 void SetMostVisitedURLsObserver(
47 JNIEnv* env, 65 JNIEnv* env,
48 const base::android::JavaParamRef<jobject>& obj, 66 const base::android::JavaParamRef<jobject>& obj,
49 const base::android::JavaParamRef<jobject>& j_observer, 67 const base::android::JavaParamRef<jobject>& j_observer,
50 jint num_sites); 68 jint num_sites);
51 void GetURLThumbnail(JNIEnv* env,
52 const base::android::JavaParamRef<jobject>& obj,
53 const base::android::JavaParamRef<jstring>& url,
54 const base::android::JavaParamRef<jobject>& j_callback);
55 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);
56 void AddOrRemoveBlacklistedUrl( 75 void AddOrRemoveBlacklistedUrl(
57 JNIEnv* env, 76 JNIEnv* env,
58 const base::android::JavaParamRef<jobject>& obj, 77 const base::android::JavaParamRef<jobject>& obj,
59 const base::android::JavaParamRef<jstring>& j_url, 78 const base::android::JavaParamRef<jstring>& j_url,
60 jboolean add_url); 79 jboolean add_url);
61 void RecordTileTypeMetrics( 80 void RecordTileTypeMetrics(
62 JNIEnv* env, 81 JNIEnv* env,
63 const base::android::JavaParamRef<jobject>& obj, 82 const base::android::JavaParamRef<jobject>& obj,
64 const base::android::JavaParamRef<jintArray>& jtile_types); 83 const base::android::JavaParamRef<jintArray>& jtile_types);
65 void RecordOpenedMostVisitedItem( 84 void RecordOpenedMostVisitedItem(
66 JNIEnv* env, 85 JNIEnv* env,
67 const base::android::JavaParamRef<jobject>& obj, 86 const base::android::JavaParamRef<jobject>& obj,
68 jint index, 87 jint index,
69 jint tile_type); 88 jint tile_type);
70 89
90 // C++ methods
Marc Treib 2016/04/14 16:57:36 All these can be private for now, right?
sfiera 2016/04/15 13:36:00 Could be. If I could choose, I'd rather make the J
Marc Treib 2016/04/15 15:21:41 AFAIK JNI doesn't care about public/private, so pr
sfiera 2016/04/15 16:09:06 After digging into the generated code a little, I
Marc Treib 2016/04/15 16:30:03 Acknowledged.
91
92 void SetMostVisitedURLsObserver(
93 std::unique_ptr<MostVisitedSitesObserver> observer, int num_sites);
94
95 using ThumbnailCallback = base::Callback<
96 void(bool /* is_local_thumbnail */, const SkBitmap* /* bitmap */)>;
97 void GetURLThumbnail(const GURL& url, const ThumbnailCallback& callback);
Marc Treib 2016/04/14 16:57:36 Hm.. generally, method overloading is kinda frowne
sfiera 2016/04/15 13:36:00 I double-checked the style guide and the verdict i
Marc Treib 2016/04/15 15:21:41 Fair enough. And, again, it's a temporary state of
98 void AddOrRemoveBlacklistedUrl(const GURL& url, bool add_url);
99 void RecordTileTypeMetrics(const std::vector<int>& tile_types);
100 void RecordOpenedMostVisitedItem(int index, int tile_type);
101
71 // SupervisedUserServiceObserver implementation. 102 // SupervisedUserServiceObserver implementation.
72 void OnURLFilterChanged() override; 103 void OnURLFilterChanged() override;
73 104
74 // Registers JNI methods. 105 // Registers JNI methods.
75 static bool Register(JNIEnv* env); 106 static bool Register(JNIEnv* env);
76 107
77 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 108 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
78 109
79 private: 110 private:
80 friend class MostVisitedSitesTest; 111 friend class MostVisitedSitesTest;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 // Inserts suggestions from |src_suggestions| at positions |insert_positions| 197 // Inserts suggestions from |src_suggestions| at positions |insert_positions|
167 // into |dst_suggestions| where ever empty starting from |start_position|. 198 // into |dst_suggestions| where ever empty starting from |start_position|.
168 // Returns the last filled position so that future insertions can start from 199 // Returns the last filled position so that future insertions can start from
169 // there. 200 // there.
170 static size_t InsertAllSuggestions( 201 static size_t InsertAllSuggestions(
171 size_t start_position, 202 size_t start_position,
172 const std::vector<size_t>& insert_positions, 203 const std::vector<size_t>& insert_positions,
173 SuggestionsVector* src_suggestions, 204 SuggestionsVector* src_suggestions,
174 SuggestionsVector* dst_suggestions); 205 SuggestionsVector* dst_suggestions);
175 206
176 // Notifies the Java side observer about the availability of suggestions. 207 // Notifies the observer about the availability of suggestions.
177 // Also records impressions UMA if not done already. 208 // Also records impressions UMA if not done already.
178 void NotifyMostVisitedURLsObserver(); 209 void NotifyMostVisitedURLsObserver();
179 210
180 void OnPopularSitesAvailable(bool success); 211 void OnPopularSitesAvailable(bool success);
181 212
182 // Runs on the UI Thread. 213 // Runs on the UI Thread.
183 void OnLocalThumbnailFetched( 214 void OnLocalThumbnailFetched(
184 const GURL& url, 215 const GURL& url,
185 std::unique_ptr<base::android::ScopedJavaGlobalRef<jobject>> j_callback, 216 const base::Callback<void(bool, const SkBitmap*)>& callback,
Marc Treib 2016/04/14 16:57:36 ThumbnailCallback?
sfiera 2016/04/15 13:36:00 Done.
186 std::unique_ptr<SkBitmap> bitmap); 217 std::unique_ptr<SkBitmap> bitmap);
187 218
188 // Callback for when the thumbnail lookup is complete. 219 // Callback for when the thumbnail lookup is complete.
189 // Runs on the UI Thread. 220 // Runs on the UI Thread.
190 void OnObtainedThumbnail( 221 void OnObtainedThumbnail(
191 bool is_local_thumbnail, 222 bool is_local_thumbnail,
192 std::unique_ptr<base::android::ScopedJavaGlobalRef<jobject>> j_callback, 223 const base::Callback<void(bool, const SkBitmap*)>& callback,
Marc Treib 2016/04/14 16:57:36 Here too
sfiera 2016/04/15 13:36:00 Done. (and in the .cc file)
193 const GURL& url, 224 const GURL& url,
194 const SkBitmap* bitmap); 225 const SkBitmap* bitmap);
195 226
196 // Records thumbnail-related UMA histogram metrics. 227 // Records thumbnail-related UMA histogram metrics.
197 void RecordThumbnailUMAMetrics(); 228 void RecordThumbnailUMAMetrics();
198 229
199 // Records UMA histogram metrics related to the number of impressions. 230 // Records UMA histogram metrics related to the number of impressions.
200 void RecordImpressionUMAMetrics(); 231 void RecordImpressionUMAMetrics();
201 232
202 // history::TopSitesObserver implementation. 233 // history::TopSitesObserver implementation.
203 void TopSitesLoaded(history::TopSites* top_sites) override; 234 void TopSitesLoaded(history::TopSites* top_sites) override;
204 void TopSitesChanged(history::TopSites* top_sites, 235 void TopSitesChanged(history::TopSites* top_sites,
205 ChangeReason change_reason) override; 236 ChangeReason change_reason) override;
206 237
207 // The profile whose most visited sites will be queried. 238 // The profile whose most visited sites will be queried.
208 Profile* profile_; 239 Profile* profile_;
209 240
210 // The observer to be notified when the list of most visited sites changes. 241 std::unique_ptr<MostVisitedSitesObserver> observer_;
Marc Treib 2016/04/14 16:57:36 This is a very uncommon pattern - the observed obj
sfiera 2016/04/15 13:36:00 Again, I could do with some more knowledge about J
Marc Treib 2016/04/15 15:21:41 Java objects always have shared ownership, AFAIK t
sfiera 2016/04/15 16:09:06 I think so, roughly, though I would put the Java r
Marc Treib 2016/04/15 16:30:03 Sure, SGTM.
211 base::android::ScopedJavaGlobalRef<jobject> observer_;
212 242
213 // The maximum number of most visited sites to return. 243 // The maximum number of most visited sites to return.
214 int num_sites_; 244 int num_sites_;
215 245
216 // Whether we have received an initial set of most visited sites (from either 246 // Whether we have received an initial set of most visited sites (from either
217 // TopSites or the SuggestionsService). 247 // TopSites or the SuggestionsService).
218 bool received_most_visited_sites_; 248 bool received_most_visited_sites_;
219 249
220 // Whether we have received the set of popular sites. Immediately set to true 250 // Whether we have received the set of popular sites. Immediately set to true
221 // if popular sites are disabled. 251 // if popular sites are disabled.
(...skipping 15 matching lines...) Expand all
237 267
238 SuggestionsVector current_suggestions_; 268 SuggestionsVector current_suggestions_;
239 269
240 // For callbacks may be run after destruction. 270 // For callbacks may be run after destruction.
241 base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_; 271 base::WeakPtrFactory<MostVisitedSites> weak_ptr_factory_;
242 272
243 DISALLOW_COPY_AND_ASSIGN(MostVisitedSites); 273 DISALLOW_COPY_AND_ASSIGN(MostVisitedSites);
244 }; 274 };
245 275
246 #endif // CHROME_BROWSER_ANDROID_NTP_MOST_VISITED_SITES_H_ 276 #endif // CHROME_BROWSER_ANDROID_NTP_MOST_VISITED_SITES_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/android/ntp/most_visited_sites.cc » ('j') | chrome/browser/android/ntp/most_visited_sites.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698