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

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

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
« no previous file with comments | « chrome/browser/android/ntp/most_visited_sites.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "chrome/browser/android/ntp/most_visited_sites.h" 5 #include "chrome/browser/android/ntp/most_visited_sites.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_array.h" 10 #include "base/android/jni_array.h"
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 } 155 }
156 // The whole grid is already filled with personal suggestions, no point in 156 // The whole grid is already filled with personal suggestions, no point in
157 // bothering with popular ones. 157 // bothering with popular ones.
158 return false; 158 return false;
159 } 159 }
160 160
161 bool AreURLsEquivalent(const GURL& url1, const GURL& url2) { 161 bool AreURLsEquivalent(const GURL& url1, const GURL& url2) {
162 return url1.host() == url2.host() && url1.path() == url2.path(); 162 return url1.host() == url2.host() && url1.path() == url2.path();
163 } 163 }
164 164
165 class JavaObserverBridge : public MostVisitedSitesObserver { 165 void CallJavaWithBitmap(
166 public: 166 std::unique_ptr<ScopedJavaGlobalRef<jobject>> j_callback,
167 JavaObserverBridge(JNIEnv* env, const JavaParamRef<jobject>& obj) 167 bool is_local_thumbnail,
168 : observer_(env, obj) {} 168 const SkBitmap* bitmap) {
169 169 JNIEnv* env = AttachCurrentThread();
170 void OnMostVisitedURLsAvailable( 170 ScopedJavaLocalRef<jobject> j_bitmap;
171 const std::vector<base::string16>& titles, 171 if (bitmap)
172 const std::vector<std::string>& urls, 172 j_bitmap = gfx::ConvertToJavaBitmap(bitmap);
173 const std::vector<std::string>& whitelist_icon_paths) override { 173 Java_ThumbnailCallback_onMostVisitedURLsThumbnailAvailable(
174 JNIEnv* env = AttachCurrentThread(); 174 env, j_callback->obj(), j_bitmap.obj(), is_local_thumbnail);
175 DCHECK_EQ(titles.size(), urls.size()); 175 }
176 Java_MostVisitedURLsObserver_onMostVisitedURLsAvailable(
177 env, observer_.obj(), ToJavaArrayOfStrings(env, titles).obj(),
178 ToJavaArrayOfStrings(env, urls).obj(),
179 ToJavaArrayOfStrings(env, whitelist_icon_paths).obj());
180 }
181
182 void OnPopularURLsAvailable(
183 const std::vector<std::string>& urls,
184 const std::vector<std::string>& favicon_urls,
185 const std::vector<std::string>& large_icon_urls) override {
186 JNIEnv* env = AttachCurrentThread();
187 Java_MostVisitedURLsObserver_onPopularURLsAvailable(
188 env, observer_.obj(), ToJavaArrayOfStrings(env, urls).obj(),
189 ToJavaArrayOfStrings(env, favicon_urls).obj(),
190 ToJavaArrayOfStrings(env, large_icon_urls).obj());
191 }
192
193 private:
194 ScopedJavaGlobalRef<jobject> observer_;
195
196 DISALLOW_COPY_AND_ASSIGN(JavaObserverBridge);
197 };
198 176
199 } // namespace 177 } // namespace
200 178
201 MostVisitedSites::Suggestion::Suggestion() : provider_index(-1) {} 179 MostVisitedSites::Suggestion::Suggestion() : provider_index(-1) {}
202 180
203 MostVisitedSites::Suggestion::~Suggestion() {} 181 MostVisitedSites::Suggestion::~Suggestion() {}
204 182
205 std::string MostVisitedSites::Suggestion::GetSourceHistogramName() const { 183 std::string MostVisitedSites::Suggestion::GetSourceHistogramName() const {
206 switch (source) { 184 switch (source) {
207 case MostVisitedSites::TOP_SITES: 185 case MostVisitedSites::TOP_SITES:
208 return kHistogramClientName; 186 return kHistogramClientName;
209 case MostVisitedSites::POPULAR: 187 case MostVisitedSites::POPULAR:
210 return kHistogramPopularName; 188 return kHistogramPopularName;
211 case MostVisitedSites::WHITELIST: 189 case MostVisitedSites::WHITELIST:
212 return kHistogramWhitelistName; 190 return kHistogramWhitelistName;
213 case MostVisitedSites::SUGGESTIONS_SERVICE: 191 case MostVisitedSites::SUGGESTIONS_SERVICE:
214 return provider_index >= 0 192 return provider_index >= 0
215 ? base::StringPrintf(kHistogramServerFormat, provider_index) 193 ? base::StringPrintf(kHistogramServerFormat, provider_index)
216 : kHistogramServerName; 194 : kHistogramServerName;
217 } 195 }
218 NOTREACHED(); 196 NOTREACHED();
219 return std::string(); 197 return std::string();
220 } 198 }
221 199
222 MostVisitedSites::MostVisitedSites(Profile* profile) 200 MostVisitedSites::MostVisitedSites(Profile* profile)
223 : profile_(profile), num_sites_(0), received_most_visited_sites_(false), 201 : profile_(profile), observer_(nullptr), num_sites_(0),
224 received_popular_sites_(false), recorded_uma_(false), 202 received_most_visited_sites_(false), received_popular_sites_(false),
225 scoped_observer_(this), weak_ptr_factory_(this) { 203 recorded_uma_(false), scoped_observer_(this), weak_ptr_factory_(this) {
226 // Register the debugging page for the Suggestions Service and the thumbnails 204 // Register the debugging page for the Suggestions Service and the thumbnails
227 // debugging page. 205 // debugging page.
228 content::URLDataSource::Add(profile_, 206 content::URLDataSource::Add(profile_,
229 new suggestions::SuggestionsSource(profile_)); 207 new suggestions::SuggestionsSource(profile_));
230 content::URLDataSource::Add(profile_, new ThumbnailListSource(profile_)); 208 content::URLDataSource::Add(profile_, new ThumbnailListSource(profile_));
231 209
232 SupervisedUserService* supervised_user_service = 210 SupervisedUserService* supervised_user_service =
233 SupervisedUserServiceFactory::GetForProfile(profile_); 211 SupervisedUserServiceFactory::GetForProfile(profile_);
234 supervised_user_service->AddObserver(this); 212 supervised_user_service->AddObserver(this);
235 } 213 }
236 214
237 MostVisitedSites::~MostVisitedSites() { 215 MostVisitedSites::~MostVisitedSites() {
238 SupervisedUserService* supervised_user_service = 216 SupervisedUserService* supervised_user_service =
239 SupervisedUserServiceFactory::GetForProfile(profile_); 217 SupervisedUserServiceFactory::GetForProfile(profile_);
240 supervised_user_service->RemoveObserver(this); 218 supervised_user_service->RemoveObserver(this);
241 } 219 }
242 220
243 void MostVisitedSites::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) {
244 delete this;
245 }
246
247 void MostVisitedSites::SetMostVisitedURLsObserver( 221 void MostVisitedSites::SetMostVisitedURLsObserver(
248 JNIEnv* env, 222 MostVisitedSitesObserver* observer, int num_sites) {
249 const JavaParamRef<jobject>& obj, 223 DCHECK(observer_ == nullptr);
Marc Treib 2016/04/19 13:20:54 nit: The common way to do this is "DCHECK(!observe
250 const JavaParamRef<jobject>& j_observer, 224 observer_ = observer;
251 jint num_sites) {
252 SetMostVisitedURLsObserver(
253 std::unique_ptr<MostVisitedSitesObserver>(
254 new JavaObserverBridge(env, j_observer)),
255 num_sites);
256 }
257
258 void MostVisitedSites::SetMostVisitedURLsObserver(
259 std::unique_ptr<MostVisitedSitesObserver> observer, int num_sites) {
260 observer_ = std::move(observer);
261 num_sites_ = num_sites; 225 num_sites_ = num_sites;
262 226
263 if (ShouldShowPopularSites() && 227 if (ShouldShowPopularSites() &&
264 NeedPopularSites(profile_->GetPrefs(), num_sites_)) { 228 NeedPopularSites(profile_->GetPrefs(), num_sites_)) {
265 popular_sites_.reset(new PopularSites( 229 popular_sites_.reset(new PopularSites(
266 profile_, 230 profile_,
267 GetPopularSitesCountry(), 231 GetPopularSitesCountry(),
268 GetPopularSitesVersion(), 232 GetPopularSitesVersion(),
269 false, 233 false,
270 base::Bind(&MostVisitedSites::OnPopularSitesAvailable, 234 base::Bind(&MostVisitedSites::OnPopularSitesAvailable,
(...skipping 20 matching lines...) Expand all
291 base::Unretained(this))); 255 base::Unretained(this)));
292 256
293 // Immediately get the current suggestions from the cache. If the cache is 257 // Immediately get the current suggestions from the cache. If the cache is
294 // empty, this will fall back to TopSites. 258 // empty, this will fall back to TopSites.
295 OnSuggestionsProfileAvailable( 259 OnSuggestionsProfileAvailable(
296 suggestions_service->GetSuggestionsDataFromCache()); 260 suggestions_service->GetSuggestionsDataFromCache());
297 // Also start a request for fresh suggestions. 261 // Also start a request for fresh suggestions.
298 suggestions_service->FetchSuggestionsData(); 262 suggestions_service->FetchSuggestionsData();
299 } 263 }
300 264
301 static void CallJavaWithBitmap(
302 std::unique_ptr<ScopedJavaGlobalRef<jobject>> j_callback,
303 bool is_local_thumbnail,
304 const SkBitmap* bitmap);
305
306 void MostVisitedSites::GetURLThumbnail(
307 JNIEnv* env,
308 const JavaParamRef<jobject>& obj,
309 const JavaParamRef<jstring>& j_url,
310 const JavaParamRef<jobject>& j_callback_obj) {
311 std::unique_ptr<ScopedJavaGlobalRef<jobject>> j_callback(
312 new ScopedJavaGlobalRef<jobject>(env, j_callback_obj));
313 auto callback = base::Bind(&CallJavaWithBitmap, base::Passed(&j_callback));
314 GURL url(ConvertJavaStringToUTF8(env, j_url));
315 GetURLThumbnail(url, callback);
316 }
317
318 void MostVisitedSites::GetURLThumbnail( 265 void MostVisitedSites::GetURLThumbnail(
319 const GURL& url, 266 const GURL& url,
320 const ThumbnailCallback& callback) { 267 const ThumbnailCallback& callback) {
321 DCHECK_CURRENTLY_ON(BrowserThread::UI); 268 DCHECK_CURRENTLY_ON(BrowserThread::UI);
322 scoped_refptr<TopSites> top_sites(TopSitesFactory::GetForProfile(profile_)); 269 scoped_refptr<TopSites> top_sites(TopSitesFactory::GetForProfile(profile_));
323 270
324 BrowserThread::PostTaskAndReplyWithResult( 271 BrowserThread::PostTaskAndReplyWithResult(
325 BrowserThread::DB, FROM_HERE, 272 BrowserThread::DB, FROM_HERE,
326 base::Bind(&MaybeFetchLocalThumbnail, url, top_sites), 273 base::Bind(&MaybeFetchLocalThumbnail, url, top_sites),
327 base::Bind(&MostVisitedSites::OnLocalThumbnailFetched, 274 base::Bind(&MostVisitedSites::OnLocalThumbnailFetched,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 313
367 void MostVisitedSites::OnObtainedThumbnail( 314 void MostVisitedSites::OnObtainedThumbnail(
368 bool is_local_thumbnail, 315 bool is_local_thumbnail,
369 const ThumbnailCallback& callback, 316 const ThumbnailCallback& callback,
370 const GURL& url, 317 const GURL& url,
371 const SkBitmap* bitmap) { 318 const SkBitmap* bitmap) {
372 DCHECK_CURRENTLY_ON(BrowserThread::UI); 319 DCHECK_CURRENTLY_ON(BrowserThread::UI);
373 callback.Run(is_local_thumbnail, bitmap); 320 callback.Run(is_local_thumbnail, bitmap);
374 } 321 }
375 322
376 static void CallJavaWithBitmap(
377 std::unique_ptr<ScopedJavaGlobalRef<jobject>> j_callback,
378 bool is_local_thumbnail,
379 const SkBitmap* bitmap) {
380 JNIEnv* env = AttachCurrentThread();
381 ScopedJavaLocalRef<jobject> j_bitmap;
382 if (bitmap)
383 j_bitmap = gfx::ConvertToJavaBitmap(bitmap);
384 Java_ThumbnailCallback_onMostVisitedURLsThumbnailAvailable(
385 env, j_callback->obj(), j_bitmap.obj(), is_local_thumbnail);
386 }
387
388 void MostVisitedSites::AddOrRemoveBlacklistedUrl(
389 JNIEnv* env,
390 const JavaParamRef<jobject>& obj,
391 const JavaParamRef<jstring>& j_url,
392 jboolean add_url) {
393 GURL url(ConvertJavaStringToUTF8(env, j_url));
394 AddOrRemoveBlacklistedUrl(url, add_url);
395 }
396
397 void MostVisitedSites::AddOrRemoveBlacklistedUrl( 323 void MostVisitedSites::AddOrRemoveBlacklistedUrl(
398 const GURL& url, bool add_url) { 324 const GURL& url, bool add_url) {
399 // Always blacklist in the local TopSites. 325 // Always blacklist in the local TopSites.
400 scoped_refptr<TopSites> top_sites = TopSitesFactory::GetForProfile(profile_); 326 scoped_refptr<TopSites> top_sites = TopSitesFactory::GetForProfile(profile_);
401 if (top_sites) { 327 if (top_sites) {
402 if (add_url) 328 if (add_url)
403 top_sites->AddBlacklistedURL(url); 329 top_sites->AddBlacklistedURL(url);
404 else 330 else
405 top_sites->RemoveBlacklistedURL(url); 331 top_sites->RemoveBlacklistedURL(url);
406 } 332 }
407 333
408 // Only blacklist in the server-side suggestions service if it's active. 334 // Only blacklist in the server-side suggestions service if it's active.
409 if (mv_source_ == SUGGESTIONS_SERVICE) { 335 if (mv_source_ == SUGGESTIONS_SERVICE) {
410 SuggestionsService* suggestions_service = 336 SuggestionsService* suggestions_service =
411 SuggestionsServiceFactory::GetForProfile(profile_); 337 SuggestionsServiceFactory::GetForProfile(profile_);
412 if (add_url) 338 if (add_url)
413 suggestions_service->BlacklistURL(url); 339 suggestions_service->BlacklistURL(url);
414 else 340 else
415 suggestions_service->UndoBlacklistURL(url); 341 suggestions_service->UndoBlacklistURL(url);
416 } 342 }
417 } 343 }
418 344
419 void MostVisitedSites::RecordTileTypeMetrics( 345 void MostVisitedSites::RecordTileTypeMetrics(
420 JNIEnv* env,
421 const JavaParamRef<jobject>& obj,
422 const JavaParamRef<jintArray>& jtile_types) {
423 std::vector<int> tile_types;
424 base::android::JavaIntArrayToIntVector(env, jtile_types, &tile_types);
425 DCHECK_EQ(current_suggestions_.size(), tile_types.size());
426 RecordTileTypeMetrics(tile_types);
427 }
428
429 void MostVisitedSites::RecordTileTypeMetrics(
430 const std::vector<int>& tile_types) { 346 const std::vector<int>& tile_types) {
347 DCHECK_EQ(current_suggestions_.size(), tile_types.size());
431 int counts_per_type[NUM_TILE_TYPES] = {0}; 348 int counts_per_type[NUM_TILE_TYPES] = {0};
432 for (size_t i = 0; i < tile_types.size(); ++i) { 349 for (size_t i = 0; i < tile_types.size(); ++i) {
433 int tile_type = tile_types[i]; 350 int tile_type = tile_types[i];
434 ++counts_per_type[tile_type]; 351 ++counts_per_type[tile_type];
435 std::string histogram = base::StringPrintf( 352 std::string histogram = base::StringPrintf(
436 "NewTabPage.TileType.%s", 353 "NewTabPage.TileType.%s",
437 current_suggestions_[i]->GetSourceHistogramName().c_str()); 354 current_suggestions_[i]->GetSourceHistogramName().c_str());
438 LogHistogramEvent(histogram, tile_type, NUM_TILE_TYPES); 355 LogHistogramEvent(histogram, tile_type, NUM_TILE_TYPES);
439 } 356 }
440 357
441 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsReal", 358 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsReal",
442 counts_per_type[ICON_REAL]); 359 counts_per_type[ICON_REAL]);
443 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsColor", 360 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsColor",
444 counts_per_type[ICON_COLOR]); 361 counts_per_type[ICON_COLOR]);
445 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsGray", 362 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsGray",
446 counts_per_type[ICON_DEFAULT]); 363 counts_per_type[ICON_DEFAULT]);
447 } 364 }
448 365
449 void MostVisitedSites::RecordOpenedMostVisitedItem(
450 JNIEnv* env,
451 const JavaParamRef<jobject>& obj,
452 jint index,
453 jint tile_type) {
454 RecordOpenedMostVisitedItem(index, tile_type);
455 }
456
457 void MostVisitedSites::RecordOpenedMostVisitedItem(int index, int tile_type) { 366 void MostVisitedSites::RecordOpenedMostVisitedItem(int index, int tile_type) {
458 DCHECK_GE(index, 0); 367 DCHECK_GE(index, 0);
459 DCHECK_LT(index, static_cast<int>(current_suggestions_.size())); 368 DCHECK_LT(index, static_cast<int>(current_suggestions_.size()));
460 std::string histogram = base::StringPrintf( 369 std::string histogram = base::StringPrintf(
461 "NewTabPage.MostVisited.%s", 370 "NewTabPage.MostVisited.%s",
462 current_suggestions_[index]->GetSourceHistogramName().c_str()); 371 current_suggestions_[index]->GetSourceHistogramName().c_str());
463 LogHistogramEvent(histogram, index, num_sites_); 372 LogHistogramEvent(histogram, index, num_sites_);
464 373
465 histogram = base::StringPrintf( 374 histogram = base::StringPrintf(
466 "NewTabPage.TileTypeClicked.%s", 375 "NewTabPage.TileTypeClicked.%s",
467 current_suggestions_[index]->GetSourceHistogramName().c_str()); 376 current_suggestions_[index]->GetSourceHistogramName().c_str());
468 LogHistogramEvent(histogram, tile_type, NUM_TILE_TYPES); 377 LogHistogramEvent(histogram, tile_type, NUM_TILE_TYPES);
469 } 378 }
470 379
471 void MostVisitedSites::OnURLFilterChanged() { 380 void MostVisitedSites::OnURLFilterChanged() {
472 QueryMostVisitedURLs(); 381 QueryMostVisitedURLs();
473 } 382 }
474 383
475 // static 384 // static
476 bool MostVisitedSites::Register(JNIEnv* env) {
477 return RegisterNativesImpl(env);
478 }
479
480 // static
481 void MostVisitedSites::RegisterProfilePrefs( 385 void MostVisitedSites::RegisterProfilePrefs(
482 user_prefs::PrefRegistrySyncable* registry) { 386 user_prefs::PrefRegistrySyncable* registry) {
483 registry->RegisterListPref(prefs::kNTPSuggestionsURL); 387 registry->RegisterListPref(prefs::kNTPSuggestionsURL);
484 registry->RegisterListPref(prefs::kNTPSuggestionsIsPersonal); 388 registry->RegisterListPref(prefs::kNTPSuggestionsIsPersonal);
485 } 389 }
486 390
487 void MostVisitedSites::QueryMostVisitedURLs() { 391 void MostVisitedSites::QueryMostVisitedURLs() {
488 SuggestionsService* suggestions_service = 392 SuggestionsService* suggestions_service =
489 SuggestionsServiceFactory::GetForProfile(profile_); 393 SuggestionsServiceFactory::GetForProfile(profile_);
490 if (suggestions_service->FetchSuggestionsData()) { 394 if (suggestions_service->FetchSuggestionsData()) {
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 void MostVisitedSites::TopSitesLoaded(TopSites* top_sites) {} 828 void MostVisitedSites::TopSitesLoaded(TopSites* top_sites) {}
925 829
926 void MostVisitedSites::TopSitesChanged(TopSites* top_sites, 830 void MostVisitedSites::TopSitesChanged(TopSites* top_sites,
927 ChangeReason change_reason) { 831 ChangeReason change_reason) {
928 if (mv_source_ == TOP_SITES) { 832 if (mv_source_ == TOP_SITES) {
929 // The displayed suggestions are invalidated. 833 // The displayed suggestions are invalidated.
930 InitiateTopSitesQuery(); 834 InitiateTopSitesQuery();
931 } 835 }
932 } 836 }
933 837
838 // static
839 bool MostVisitedSitesBridge::Register(JNIEnv* env) {
840 return RegisterNativesImpl(env);
841 }
842
843 MostVisitedSitesBridge::MostVisitedSitesBridge(Profile* profile)
844 : most_visited_(profile) { }
845
846 MostVisitedSitesBridge::~MostVisitedSitesBridge() { }
847
848 void MostVisitedSitesBridge::Destroy(
849 JNIEnv* env, const JavaParamRef<jobject>& obj) {
850 delete this;
851 }
852
853 void MostVisitedSitesBridge::SetMostVisitedURLsObserver(
854 JNIEnv* env,
855 const JavaParamRef<jobject>& obj,
856 const JavaParamRef<jobject>& j_observer,
857 jint num_sites) {
858 observer_.reset(new Observer(env, j_observer));
859 most_visited_.SetMostVisitedURLsObserver(observer_.get(), num_sites);
860 }
861
862 void MostVisitedSitesBridge::GetURLThumbnail(
863 JNIEnv* env,
864 const JavaParamRef<jobject>& obj,
865 const JavaParamRef<jstring>& j_url,
866 const JavaParamRef<jobject>& j_callback_obj) {
867 std::unique_ptr<ScopedJavaGlobalRef<jobject>> j_callback(
868 new ScopedJavaGlobalRef<jobject>(env, j_callback_obj));
869 auto callback = base::Bind(&CallJavaWithBitmap, base::Passed(&j_callback));
870 GURL url(ConvertJavaStringToUTF8(env, j_url));
871 most_visited_.GetURLThumbnail(url, callback);
872 }
873
874 void MostVisitedSitesBridge::AddOrRemoveBlacklistedUrl(
875 JNIEnv* env,
876 const JavaParamRef<jobject>& obj,
877 const JavaParamRef<jstring>& j_url,
878 jboolean add_url) {
879 GURL url(ConvertJavaStringToUTF8(env, j_url));
880 most_visited_.AddOrRemoveBlacklistedUrl(url, add_url);
881 }
882
883 void MostVisitedSitesBridge::RecordTileTypeMetrics(
884 JNIEnv* env,
885 const JavaParamRef<jobject>& obj,
886 const JavaParamRef<jintArray>& jtile_types) {
887 std::vector<int> tile_types;
888 base::android::JavaIntArrayToIntVector(env, jtile_types, &tile_types);
889 most_visited_.RecordTileTypeMetrics(tile_types);
890 }
891
892 void MostVisitedSitesBridge::RecordOpenedMostVisitedItem(
893 JNIEnv* env,
894 const JavaParamRef<jobject>& obj,
895 jint index,
896 jint tile_type) {
897 most_visited_.RecordOpenedMostVisitedItem(index, tile_type);
898 }
899
900 MostVisitedSitesBridge::Observer::Observer(
901 JNIEnv* env, const JavaParamRef<jobject>& obj)
902 : observer_(env, obj) {}
903
904 void MostVisitedSitesBridge::Observer::OnMostVisitedURLsAvailable(
905 const std::vector<base::string16>& titles,
906 const std::vector<std::string>& urls,
907 const std::vector<std::string>& whitelist_icon_paths) {
908 JNIEnv* env = AttachCurrentThread();
909 DCHECK_EQ(titles.size(), urls.size());
910 DCHECK_EQ(titles.size(), whitelist_icon_paths.size());
911 Java_MostVisitedURLsObserver_onMostVisitedURLsAvailable(
912 env, observer_.obj(), ToJavaArrayOfStrings(env, titles).obj(),
913 ToJavaArrayOfStrings(env, urls).obj(),
914 ToJavaArrayOfStrings(env, whitelist_icon_paths).obj());
915 }
916
917 void MostVisitedSitesBridge::Observer::OnPopularURLsAvailable(
918 const std::vector<std::string>& urls,
919 const std::vector<std::string>& favicon_urls,
920 const std::vector<std::string>& large_icon_urls) {
921 JNIEnv* env = AttachCurrentThread();
922 Java_MostVisitedURLsObserver_onPopularURLsAvailable(
923 env, observer_.obj(), ToJavaArrayOfStrings(env, urls).obj(),
924 ToJavaArrayOfStrings(env, favicon_urls).obj(),
925 ToJavaArrayOfStrings(env, large_icon_urls).obj());
926 }
927
934 static jlong Init(JNIEnv* env, 928 static jlong Init(JNIEnv* env,
935 const JavaParamRef<jobject>& obj, 929 const JavaParamRef<jobject>& obj,
936 const JavaParamRef<jobject>& jprofile) { 930 const JavaParamRef<jobject>& jprofile) {
937 MostVisitedSites* most_visited_sites = 931 MostVisitedSitesBridge* most_visited_sites =
938 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile)); 932 new MostVisitedSitesBridge(
933 ProfileAndroid::FromProfileAndroid(jprofile));
939 return reinterpret_cast<intptr_t>(most_visited_sites); 934 return reinterpret_cast<intptr_t>(most_visited_sites);
940 } 935 }
OLDNEW
« no previous file with comments | « chrome/browser/android/ntp/most_visited_sites.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698