Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 profile_, | 230 profile_, |
| 231 GetPopularSitesCountry(), | 231 GetPopularSitesCountry(), |
| 232 GetPopularSitesVersion(), | 232 GetPopularSitesVersion(), |
| 233 false, | 233 false, |
| 234 base::Bind(&MostVisitedSites::OnPopularSitesAvailable, | 234 base::Bind(&MostVisitedSites::OnPopularSitesAvailable, |
| 235 base::Unretained(this)))); | 235 base::Unretained(this)))); |
| 236 } else { | 236 } else { |
| 237 received_popular_sites_ = true; | 237 received_popular_sites_ = true; |
| 238 } | 238 } |
| 239 | 239 |
| 240 SuggestionsService* suggestions_service = | |
| 241 SuggestionsServiceFactory::GetForProfile(profile_); | |
| 242 // Immediately get the current suggestions from the cache. If the cache is | |
| 243 // empty, this will fall back to TopSites. | |
| 240 OnSuggestionsProfileAvailable( | 244 OnSuggestionsProfileAvailable( |
| 241 SuggestionsServiceFactory::GetForProfile(profile_) | 245 suggestions_service->GetSuggestionsDataFromCache()); |
| 242 ->GetSuggestionsDataFromCache()); | 246 // Also start a request for fresh suggestions. |
| 243 | 247 suggestions_service->FetchSuggestionsData(); |
| 244 QueryMostVisitedURLs(); | |
| 245 | 248 |
| 246 scoped_refptr<TopSites> top_sites = TopSitesFactory::GetForProfile(profile_); | 249 scoped_refptr<TopSites> top_sites = TopSitesFactory::GetForProfile(profile_); |
| 247 if (top_sites) { | 250 if (top_sites) { |
| 248 // TopSites updates itself after a delay. To ensure up-to-date results, | 251 // TopSites updates itself after a delay. To ensure up-to-date results, |
| 249 // force an update now. | 252 // force an update now. |
| 250 top_sites->SyncWithHistory(); | 253 top_sites->SyncWithHistory(); |
| 251 | 254 |
| 252 // Register as TopSitesObserver so that we can update ourselves when the | 255 // Register as TopSitesObserver so that we can update ourselves when the |
| 253 // TopSites changes. | 256 // TopSites changes. |
| 254 scoped_observer_.Add(top_sites.get()); | 257 scoped_observer_.Add(top_sites.get()); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 411 // static | 414 // static |
| 412 void MostVisitedSites::RegisterProfilePrefs( | 415 void MostVisitedSites::RegisterProfilePrefs( |
| 413 user_prefs::PrefRegistrySyncable* registry) { | 416 user_prefs::PrefRegistrySyncable* registry) { |
| 414 registry->RegisterListPref(prefs::kNTPSuggestionsURL); | 417 registry->RegisterListPref(prefs::kNTPSuggestionsURL); |
| 415 registry->RegisterListPref(prefs::kNTPSuggestionsIsPersonal); | 418 registry->RegisterListPref(prefs::kNTPSuggestionsIsPersonal); |
| 416 } | 419 } |
| 417 | 420 |
| 418 void MostVisitedSites::QueryMostVisitedURLs() { | 421 void MostVisitedSites::QueryMostVisitedURLs() { |
| 419 SuggestionsService* suggestions_service = | 422 SuggestionsService* suggestions_service = |
| 420 SuggestionsServiceFactory::GetForProfile(profile_); | 423 SuggestionsServiceFactory::GetForProfile(profile_); |
| 421 if (!suggestions_service->FetchSuggestionsData()) | 424 if (suggestions_service->FetchSuggestionsData()) { |
|
Marc Treib
2016/03/31 12:26:03
What happened before is:
This got called from SetM
| |
| 422 InitiateTopSitesQuery(); | 425 // A suggestions network request is on its way. We'll be called back via |
| 426 // OnSuggestionsProfileAvailable. | |
| 427 return; | |
| 428 } | |
| 429 // If no network request could be sent, try to get suggestions from the | |
| 430 // cache. If that also returns nothing, OnSuggestionsProfileAvailable will | |
| 431 // call InitiateTopSitesQuery. | |
| 432 OnSuggestionsProfileAvailable( | |
| 433 suggestions_service->GetSuggestionsDataFromCache()); | |
| 423 } | 434 } |
| 424 | 435 |
| 425 void MostVisitedSites::InitiateTopSitesQuery() { | 436 void MostVisitedSites::InitiateTopSitesQuery() { |
| 426 scoped_refptr<TopSites> top_sites = TopSitesFactory::GetForProfile(profile_); | 437 scoped_refptr<TopSites> top_sites = TopSitesFactory::GetForProfile(profile_); |
| 427 if (!top_sites) | 438 if (!top_sites) |
| 428 return; | 439 return; |
| 429 | 440 |
| 430 top_sites->GetMostVisitedURLs( | 441 top_sites->GetMostVisitedURLs( |
| 431 base::Bind(&MostVisitedSites::OnMostVisitedURLsAvailable, | 442 base::Bind(&MostVisitedSites::OnMostVisitedURLsAvailable, |
| 432 weak_ptr_factory_.GetWeakPtr()), | 443 weak_ptr_factory_.GetWeakPtr()), |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 859 } | 870 } |
| 860 } | 871 } |
| 861 | 872 |
| 862 static jlong Init(JNIEnv* env, | 873 static jlong Init(JNIEnv* env, |
| 863 const JavaParamRef<jobject>& obj, | 874 const JavaParamRef<jobject>& obj, |
| 864 const JavaParamRef<jobject>& jprofile) { | 875 const JavaParamRef<jobject>& jprofile) { |
| 865 MostVisitedSites* most_visited_sites = | 876 MostVisitedSites* most_visited_sites = |
| 866 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile)); | 877 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile)); |
| 867 return reinterpret_cast<intptr_t>(most_visited_sites); | 878 return reinterpret_cast<intptr_t>(most_visited_sites); |
| 868 } | 879 } |
| OLD | NEW |