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/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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 const GURL& url, | 222 const GURL& url, |
| 223 scoped_ptr<ScopedJavaGlobalRef<jobject>> j_callback, | 223 scoped_ptr<ScopedJavaGlobalRef<jobject>> j_callback, |
| 224 scoped_ptr<SkBitmap> bitmap) { | 224 scoped_ptr<SkBitmap> bitmap) { |
| 225 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 225 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 226 if (!bitmap.get()) { | 226 if (!bitmap.get()) { |
| 227 // A thumbnail is not locally available for |url|. Make sure it is put in | 227 // A thumbnail is not locally available for |url|. Make sure it is put in |
| 228 // the list to be fetched at the next visit to this site. | 228 // the list to be fetched at the next visit to this site. |
| 229 scoped_refptr<TopSites> top_sites(TopSitesFactory::GetForProfile(profile_)); | 229 scoped_refptr<TopSites> top_sites(TopSitesFactory::GetForProfile(profile_)); |
| 230 if (top_sites) | 230 if (top_sites) |
| 231 top_sites->AddForcedURL(url, base::Time::Now()); | 231 top_sites->AddForcedURL(url, base::Time::Now()); |
| 232 // Also fetch a remote thumbnail if possible. PopularSites or the | |
| 233 // SuggestionsService can supply a thumbnail download URL. | |
| 232 SuggestionsService* suggestions_service = | 234 SuggestionsService* suggestions_service = |
| 233 (mv_source_ == SUGGESTIONS_SERVICE) | 235 SuggestionsServiceFactory::GetForProfile(profile_); |
| 234 ? SuggestionsServiceFactory::GetForProfile(profile_) | |
| 235 : nullptr; | |
| 236 if (suggestions_service) { | 236 if (suggestions_service) { |
| 237 return suggestions_service->GetPageThumbnail( | 237 if (popular_sites_) { |
| 238 url, base::Bind(&MostVisitedSites::OnObtainedThumbnail, | 238 const std::vector<PopularSites::Site>& sites = popular_sites_->sites(); |
| 239 weak_ptr_factory_.GetWeakPtr(), false, | 239 auto it = std::find_if(sites.begin(), sites.end(), |
| 240 base::Passed(&j_callback))); | 240 [&url](const PopularSites::Site& site) { |
| 241 return site.url == url; | |
| 242 }); | |
| 243 if (it != sites.end() && it->thumbnail_url.is_valid()) { | |
| 244 return suggestions_service->GetPageThumbnailWithURL( | |
|
Marc Treib
2015/09/04 13:29:12
I guess it's a bit hacky to go through the Suggest
| |
| 245 url, it->thumbnail_url, | |
| 246 base::Bind(&MostVisitedSites::OnObtainedThumbnail, | |
| 247 weak_ptr_factory_.GetWeakPtr(), false, | |
| 248 base::Passed(&j_callback))); | |
| 249 } | |
| 250 } | |
| 251 if (mv_source_ == SUGGESTIONS_SERVICE) { | |
| 252 return suggestions_service->GetPageThumbnail( | |
| 253 url, base::Bind(&MostVisitedSites::OnObtainedThumbnail, | |
| 254 weak_ptr_factory_.GetWeakPtr(), false, | |
| 255 base::Passed(&j_callback))); | |
| 256 } | |
| 241 } | 257 } |
| 242 } | 258 } |
| 243 OnObtainedThumbnail(true, j_callback.Pass(), url, bitmap.get()); | 259 OnObtainedThumbnail(true, j_callback.Pass(), url, bitmap.get()); |
| 244 } | 260 } |
| 245 | 261 |
| 246 void MostVisitedSites::OnObtainedThumbnail( | 262 void MostVisitedSites::OnObtainedThumbnail( |
| 247 bool is_local_thumbnail, | 263 bool is_local_thumbnail, |
| 248 scoped_ptr<ScopedJavaGlobalRef<jobject>> j_callback, | 264 scoped_ptr<ScopedJavaGlobalRef<jobject>> j_callback, |
| 249 const GURL& url, | 265 const GURL& url, |
| 250 const SkBitmap* bitmap) { | 266 const SkBitmap* bitmap) { |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 571 } | 587 } |
| 572 } | 588 } |
| 573 | 589 |
| 574 static jlong Init(JNIEnv* env, | 590 static jlong Init(JNIEnv* env, |
| 575 const JavaParamRef<jobject>& obj, | 591 const JavaParamRef<jobject>& obj, |
| 576 const JavaParamRef<jobject>& jprofile) { | 592 const JavaParamRef<jobject>& jprofile) { |
| 577 MostVisitedSites* most_visited_sites = | 593 MostVisitedSites* most_visited_sites = |
| 578 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile)); | 594 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile)); |
| 579 return reinterpret_cast<intptr_t>(most_visited_sites); | 595 return reinterpret_cast<intptr_t>(most_visited_sites); |
| 580 } | 596 } |
| OLD | NEW |