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

Side by Side Diff: chrome/browser/android/most_visited_sites.cc

Issue 1314493013: Popular sites on the NTP: add thumbnails! (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix android_clang_dbg_recipe build 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/android/popular_sites.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 const GURL& url, 223 const GURL& url,
224 scoped_ptr<ScopedJavaGlobalRef<jobject>> j_callback, 224 scoped_ptr<ScopedJavaGlobalRef<jobject>> j_callback,
225 scoped_ptr<SkBitmap> bitmap) { 225 scoped_ptr<SkBitmap> bitmap) {
226 DCHECK_CURRENTLY_ON(BrowserThread::UI); 226 DCHECK_CURRENTLY_ON(BrowserThread::UI);
227 if (!bitmap.get()) { 227 if (!bitmap.get()) {
228 // A thumbnail is not locally available for |url|. Make sure it is put in 228 // A thumbnail is not locally available for |url|. Make sure it is put in
229 // the list to be fetched at the next visit to this site. 229 // the list to be fetched at the next visit to this site.
230 scoped_refptr<TopSites> top_sites(TopSitesFactory::GetForProfile(profile_)); 230 scoped_refptr<TopSites> top_sites(TopSitesFactory::GetForProfile(profile_));
231 if (top_sites) 231 if (top_sites)
232 top_sites->AddForcedURL(url, base::Time::Now()); 232 top_sites->AddForcedURL(url, base::Time::Now());
233 // Also fetch a remote thumbnail if possible. PopularSites or the
234 // SuggestionsService can supply a thumbnail download URL.
233 SuggestionsService* suggestions_service = 235 SuggestionsService* suggestions_service =
234 (mv_source_ == SUGGESTIONS_SERVICE) 236 SuggestionsServiceFactory::GetForProfile(profile_);
235 ? SuggestionsServiceFactory::GetForProfile(profile_)
236 : nullptr;
237 if (suggestions_service) { 237 if (suggestions_service) {
238 return suggestions_service->GetPageThumbnail( 238 if (popular_sites_) {
239 url, base::Bind(&MostVisitedSites::OnObtainedThumbnail, 239 const std::vector<PopularSites::Site>& sites = popular_sites_->sites();
240 weak_ptr_factory_.GetWeakPtr(), false, 240 auto it = std::find_if(sites.begin(), sites.end(),
241 base::Passed(&j_callback))); 241 [&url](const PopularSites::Site& site) {
242 return site.url == url;
243 });
244 if (it != sites.end() && it->thumbnail_url.is_valid()) {
245 return suggestions_service->GetPageThumbnailWithURL(
246 url, it->thumbnail_url,
247 base::Bind(&MostVisitedSites::OnObtainedThumbnail,
248 weak_ptr_factory_.GetWeakPtr(), false,
249 base::Passed(&j_callback)));
250 }
251 }
252 if (mv_source_ == SUGGESTIONS_SERVICE) {
253 return suggestions_service->GetPageThumbnail(
254 url, base::Bind(&MostVisitedSites::OnObtainedThumbnail,
255 weak_ptr_factory_.GetWeakPtr(), false,
256 base::Passed(&j_callback)));
257 }
242 } 258 }
243 } 259 }
244 OnObtainedThumbnail(true, j_callback.Pass(), url, bitmap.get()); 260 OnObtainedThumbnail(true, j_callback.Pass(), url, bitmap.get());
245 } 261 }
246 262
247 void MostVisitedSites::OnObtainedThumbnail( 263 void MostVisitedSites::OnObtainedThumbnail(
248 bool is_local_thumbnail, 264 bool is_local_thumbnail,
249 scoped_ptr<ScopedJavaGlobalRef<jobject>> j_callback, 265 scoped_ptr<ScopedJavaGlobalRef<jobject>> j_callback,
250 const GURL& url, 266 const GURL& url,
251 const SkBitmap* bitmap) { 267 const SkBitmap* bitmap) {
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 } 588 }
573 } 589 }
574 590
575 static jlong Init(JNIEnv* env, 591 static jlong Init(JNIEnv* env,
576 const JavaParamRef<jobject>& obj, 592 const JavaParamRef<jobject>& obj,
577 const JavaParamRef<jobject>& jprofile) { 593 const JavaParamRef<jobject>& jprofile) {
578 MostVisitedSites* most_visited_sites = 594 MostVisitedSites* most_visited_sites =
579 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile)); 595 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile));
580 return reinterpret_cast<intptr_t>(most_visited_sites); 596 return reinterpret_cast<intptr_t>(most_visited_sites);
581 } 597 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/android/popular_sites.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698