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

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

Issue 1850673002: Android NTP: only query TopSites if SuggestionsService has nothing in the cache (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/android/ntp/most_visited_sites.cc
diff --git a/chrome/browser/android/ntp/most_visited_sites.cc b/chrome/browser/android/ntp/most_visited_sites.cc
index 03a8f841318f8526ab08e6f41f77701e792dce39..27debe96e9a1e69886e16b272ff52a386cfc1a05 100644
--- a/chrome/browser/android/ntp/most_visited_sites.cc
+++ b/chrome/browser/android/ntp/most_visited_sites.cc
@@ -237,11 +237,14 @@ void MostVisitedSites::SetMostVisitedURLsObserver(
received_popular_sites_ = true;
}
+ SuggestionsService* suggestions_service =
+ SuggestionsServiceFactory::GetForProfile(profile_);
+ // Immediately get the current suggestions from the cache. If the cache is
+ // empty, this will fall back to TopSites.
OnSuggestionsProfileAvailable(
- SuggestionsServiceFactory::GetForProfile(profile_)
- ->GetSuggestionsDataFromCache());
-
- QueryMostVisitedURLs();
+ suggestions_service->GetSuggestionsDataFromCache());
+ // Also start a request for fresh suggestions.
+ suggestions_service->FetchSuggestionsData();
scoped_refptr<TopSites> top_sites = TopSitesFactory::GetForProfile(profile_);
if (top_sites) {
@@ -418,8 +421,16 @@ void MostVisitedSites::RegisterProfilePrefs(
void MostVisitedSites::QueryMostVisitedURLs() {
SuggestionsService* suggestions_service =
SuggestionsServiceFactory::GetForProfile(profile_);
- if (!suggestions_service->FetchSuggestionsData())
Marc Treib 2016/03/31 12:26:03 What happened before is: This got called from SetM
- InitiateTopSitesQuery();
+ if (suggestions_service->FetchSuggestionsData()) {
+ // A suggestions network request is on its way. We'll be called back via
+ // OnSuggestionsProfileAvailable.
+ return;
+ }
+ // If no network request could be sent, try to get suggestions from the
+ // cache. If that also returns nothing, OnSuggestionsProfileAvailable will
+ // call InitiateTopSitesQuery.
+ OnSuggestionsProfileAvailable(
+ suggestions_service->GetSuggestionsDataFromCache());
}
void MostVisitedSites::InitiateTopSitesQuery() {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698