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

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

Issue 1272883004: Popular sites on the NTP: Favicons! (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@enable_popular_sites
Patch Set: . Created 5 years, 4 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 #include "chrome/browser/android/most_visited_sites.h" 5 #include "chrome/browser/android/most_visited_sites.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_array.h" 8 #include "base/android/jni_array.h"
9 #include "base/android/jni_string.h" 9 #include "base/android/jni_string.h"
10 #include "base/android/scoped_java_ref.h" 10 #include "base/android/scoped_java_ref.h"
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 DCHECK_EQ(titles.size(), urls.size()); 439 DCHECK_EQ(titles.size(), urls.size());
440 if (!initial_load_done_) 440 if (!initial_load_done_)
441 UMA_HISTOGRAM_SPARSE_SLOWLY(kNumTilesHistogramName, titles.size()); 441 UMA_HISTOGRAM_SPARSE_SLOWLY(kNumTilesHistogramName, titles.size());
442 initial_load_done_ = true; 442 initial_load_done_ = true;
443 JNIEnv* env = AttachCurrentThread(); 443 JNIEnv* env = AttachCurrentThread();
444 Java_MostVisitedURLsObserver_onMostVisitedURLsAvailable( 444 Java_MostVisitedURLsObserver_onMostVisitedURLsAvailable(
445 env, observer_.obj(), ToJavaArrayOfStrings(env, titles).obj(), 445 env, observer_.obj(), ToJavaArrayOfStrings(env, titles).obj(),
446 ToJavaArrayOfStrings(env, urls).obj()); 446 ToJavaArrayOfStrings(env, urls).obj());
447 } 447 }
448 448
449 void MostVisitedSites::NotifyPopularURLsObserver(
450 const std::vector<std::string>& urls,
451 const std::vector<std::string>& favicon_urls) {
452 DCHECK_EQ(urls.size(), favicon_urls.size());
453 JNIEnv* env = AttachCurrentThread();
454 Java_MostVisitedURLsObserver_onPopularURLsAvailable(
455 env, observer_.obj(), ToJavaArrayOfStrings(env, urls).obj(),
456 ToJavaArrayOfStrings(env, favicon_urls).obj());
457 }
458
449 void MostVisitedSites::OnPopularSitesAvailable(bool success) { 459 void MostVisitedSites::OnPopularSitesAvailable(bool success) {
450 if (!success) { 460 if (!success) {
451 LOG(WARNING) << "Download of popular sites failed"; 461 LOG(WARNING) << "Download of popular sites failed";
452 return; 462 return;
453 } 463 }
454 464
455 if (!observer_.is_null()) 465 if (!observer_.is_null()) {
Bernhard Bauer 2015/08/11 09:37:25 Early-return if the observer is null?
Marc Treib 2015/08/11 10:23:33 Done.
466 std::vector<std::string> urls;
467 std::vector<std::string> favicon_urls;
468 for (const PopularSites::Site& popular_site : popular_sites_->sites()) {
469 urls.push_back(popular_site.url.spec());
470 favicon_urls.push_back(popular_site.favicon_url.spec());
471 }
472 NotifyPopularURLsObserver(urls, favicon_urls);
Bernhard Bauer 2015/08/11 09:37:25 I think you could inline this method.
Marc Treib 2015/08/11 10:23:33 Done.
473
456 QueryMostVisitedURLs(); 474 QueryMostVisitedURLs();
475 }
457 } 476 }
458 477
459 void MostVisitedSites::RecordUMAMetrics() { 478 void MostVisitedSites::RecordUMAMetrics() {
460 UMA_HISTOGRAM_SPARSE_SLOWLY(kNumLocalThumbnailTilesHistogramName, 479 UMA_HISTOGRAM_SPARSE_SLOWLY(kNumLocalThumbnailTilesHistogramName,
461 num_local_thumbs_); 480 num_local_thumbs_);
462 num_local_thumbs_ = 0; 481 num_local_thumbs_ = 0;
463 UMA_HISTOGRAM_SPARSE_SLOWLY(kNumEmptyTilesHistogramName, num_empty_thumbs_); 482 UMA_HISTOGRAM_SPARSE_SLOWLY(kNumEmptyTilesHistogramName, num_empty_thumbs_);
464 num_empty_thumbs_ = 0; 483 num_empty_thumbs_ = 0;
465 UMA_HISTOGRAM_SPARSE_SLOWLY(kNumServerTilesHistogramName, num_server_thumbs_); 484 UMA_HISTOGRAM_SPARSE_SLOWLY(kNumServerTilesHistogramName, num_server_thumbs_);
466 num_server_thumbs_ = 0; 485 num_server_thumbs_ = 0;
467 } 486 }
468 487
469 void MostVisitedSites::TopSitesLoaded(history::TopSites* top_sites) { 488 void MostVisitedSites::TopSitesLoaded(history::TopSites* top_sites) {
470 } 489 }
471 490
472 void MostVisitedSites::TopSitesChanged(history::TopSites* top_sites, 491 void MostVisitedSites::TopSitesChanged(history::TopSites* top_sites,
473 ChangeReason change_reason) { 492 ChangeReason change_reason) {
474 if (mv_source_ == TOP_SITES) { 493 if (mv_source_ == TOP_SITES) {
475 // The displayed suggestions are invalidated. 494 // The displayed suggestions are invalidated.
476 QueryMostVisitedURLs(); 495 QueryMostVisitedURLs();
477 } 496 }
478 } 497 }
479 498
480 static jlong Init(JNIEnv* env, jobject obj, jobject jprofile) { 499 static jlong Init(JNIEnv* env, jobject obj, jobject jprofile) {
481 MostVisitedSites* most_visited_sites = 500 MostVisitedSites* most_visited_sites =
482 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile)); 501 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile));
483 return reinterpret_cast<intptr_t>(most_visited_sites); 502 return reinterpret_cast<intptr_t>(most_visited_sites);
484 } 503 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698