Chromium Code Reviews| 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() { |