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

Unified Diff: chrome/browser/android/most_visited_sites.cc

Issue 1308723005: Popular sites on the NTP: re-download popular suggestions once per Chrome run (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@knn_ordering
Patch Set: rebase Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/android/popular_sites.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/android/most_visited_sites.cc
diff --git a/chrome/browser/android/most_visited_sites.cc b/chrome/browser/android/most_visited_sites.cc
index 03fb06c4781e12b829d7b0520c01d73148923153..e1c550c1349381121225216a5ecd3222008a887f 100644
--- a/chrome/browser/android/most_visited_sites.cc
+++ b/chrome/browser/android/most_visited_sites.cc
@@ -134,6 +134,27 @@ std::string GetPopularSitesFilename() {
"filename");
}
+// Determine whether we need any popular suggestions to fill up a grid of
+// |num_tiles| tiles.
+bool NeedPopularSites(const PrefService* prefs, size_t num_tiles) {
+ const base::ListValue* source_list =
+ prefs->GetList(prefs::kNTPSuggestionsIsPersonal);
+ // If there aren't enough previous suggestions to fill the grid, we need
+ // popular suggestions.
+ if (source_list->GetSize() < num_tiles)
+ return true;
+ // Otherwise, if any of the previous suggestions is not personal, then also
+ // get popular suggestions.
+ for (size_t i = 0; i < num_tiles; ++i) {
+ bool is_personal = false;
+ if (source_list->GetBoolean(i, &is_personal) && !is_personal)
+ return true;
+ }
+ // The whole grid is already filled with personal suggestions, no point in
+ // bothering with popular ones.
+ return false;
+}
+
} // namespace
MostVisitedSites::Suggestion::Suggestion(const base::string16& title,
@@ -189,17 +210,6 @@ MostVisitedSites::MostVisitedSites(Profile* profile)
ProfileSyncServiceFactory::GetForProfile(profile_);
if (profile_sync_service)
profile_sync_service->AddObserver(this);
-
- if (ShouldShowPopularSites()) {
- popular_sites_.reset(new PopularSites(
- profile,
- GetPopularSitesFilename(),
- profile_->GetRequestContext(),
- base::Bind(&MostVisitedSites::OnPopularSitesAvailable,
- base::Unretained(this))));
- } else {
- received_popular_sites_ = true;
- }
}
MostVisitedSites::~MostVisitedSites() {
@@ -224,6 +234,18 @@ void MostVisitedSites::SetMostVisitedURLsObserver(JNIEnv* env,
observer_.Reset(env, j_observer);
num_sites_ = num_sites;
+ if (ShouldShowPopularSites() &&
+ NeedPopularSites(profile_->GetPrefs(), num_sites_)) {
+ popular_sites_.reset(new PopularSites(
+ profile_,
+ GetPopularSitesFilename(),
+ profile_->GetRequestContext(),
+ base::Bind(&MostVisitedSites::OnPopularSitesAvailable,
+ base::Unretained(this))));
+ } else {
+ received_popular_sites_ = true;
+ }
+
QueryMostVisitedURLs();
scoped_refptr<history::TopSites> top_sites =
« no previous file with comments | « no previous file | chrome/browser/android/popular_sites.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698