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

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

Issue 2000653002: Replace the usage of SkBitmap with gfx::Image in the suggestion service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Replace SkBitmap with gfx::Image in the suggestions_service interface Created 4 years, 7 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
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/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/callback.h" 9 #include "base/callback.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 base::Bind(&MaybeFetchLocalThumbnail, url, top_sites_), 250 base::Bind(&MaybeFetchLocalThumbnail, url, top_sites_),
251 base::Bind(&MostVisitedSites::OnLocalThumbnailFetched, 251 base::Bind(&MostVisitedSites::OnLocalThumbnailFetched,
252 weak_ptr_factory_.GetWeakPtr(), url, callback)); 252 weak_ptr_factory_.GetWeakPtr(), url, callback));
253 } 253 }
254 254
255 void MostVisitedSites::OnLocalThumbnailFetched( 255 void MostVisitedSites::OnLocalThumbnailFetched(
256 const GURL& url, 256 const GURL& url,
257 const ThumbnailCallback& callback, 257 const ThumbnailCallback& callback,
258 std::unique_ptr<SkBitmap> bitmap) { 258 std::unique_ptr<SkBitmap> bitmap) {
259 DCHECK_CURRENTLY_ON(BrowserThread::UI); 259 DCHECK_CURRENTLY_ON(BrowserThread::UI);
260 if (!bitmap.get()) { 260 if (bitmap.get()) {
Marc Treib 2016/05/20 14:40:03 Wow, this was confusing. The new code is much bett
markusheintz_ 2016/05/23 13:20:46 Thanks. :-)
261 // A thumbnail is not locally available for |url|. Make sure it is put in 261 callback.Run(true /* is_local_thumbnail */, bitmap.get());
262 // the list to be fetched at the next visit to this site. 262 return;
263 if (top_sites_) 263 }
264 top_sites_->AddForcedURL(url, base::Time::Now()); 264
265 // Also fetch a remote thumbnail if possible. PopularSites or the 265 // A thumbnail is not locally available for |url|. Make sure it is put in
266 // SuggestionsService can supply a thumbnail download URL. 266 // the list to be fetched at the next visit to this site.
267 if (popular_sites_) { 267 if (top_sites_)
268 const std::vector<PopularSites::Site>& sites = popular_sites_->sites(); 268 top_sites_->AddForcedURL(url, base::Time::Now());
269 auto it = std::find_if( 269 // Also fetch a remote thumbnail if possible. PopularSites or the
270 sites.begin(), sites.end(), 270 // SuggestionsService can supply a thumbnail download URL.
271 [&url](const PopularSites::Site& site) { return site.url == url; }); 271 if (popular_sites_) {
272 if (it != sites.end() && it->thumbnail_url.is_valid()) { 272 const std::vector<PopularSites::Site>& sites = popular_sites_->sites();
273 return suggestions_service_->GetPageThumbnailWithURL( 273 auto it = std::find_if(
274 url, it->thumbnail_url, 274 sites.begin(), sites.end(),
275 base::Bind(&MostVisitedSites::OnObtainedThumbnail, 275 [&url](const PopularSites::Site& site) { return site.url == url; });
276 weak_ptr_factory_.GetWeakPtr(), false, callback)); 276 if (it != sites.end() && it->thumbnail_url.is_valid()) {
277 } 277 return suggestions_service_->GetPageThumbnailWithURL(
278 } 278 url, it->thumbnail_url,
279 if (mv_source_ == SUGGESTIONS_SERVICE) { 279 base::Bind(&MostVisitedSites::OnObtainedThumbnail,
280 return suggestions_service_->GetPageThumbnail( 280 weak_ptr_factory_.GetWeakPtr(), false, callback));
281 url, base::Bind(&MostVisitedSites::OnObtainedThumbnail,
282 weak_ptr_factory_.GetWeakPtr(), false, callback));
283 } 281 }
284 } 282 }
285 OnObtainedThumbnail(true, callback, url, bitmap.get()); 283 if (mv_source_ == SUGGESTIONS_SERVICE) {
284 return suggestions_service_->GetPageThumbnail(
285 url, base::Bind(&MostVisitedSites::OnObtainedThumbnail,
286 weak_ptr_factory_.GetWeakPtr(), false, callback));
287 }
288 // If no bitmap could be fetched and neither PopularSites nor the
289 // SuggestionsService is available then a nullptr is passed to the callback.
290 callback.Run(true /* is_local_thumbnail */, nullptr);
286 } 291 }
287 292
288 void MostVisitedSites::OnObtainedThumbnail(bool is_local_thumbnail, 293 void MostVisitedSites::OnObtainedThumbnail(bool is_local_thumbnail,
289 const ThumbnailCallback& callback, 294 const ThumbnailCallback& callback,
290 const GURL& url, 295 const GURL& url,
291 const SkBitmap* bitmap) { 296 const gfx::Image& image) {
292 DCHECK_CURRENTLY_ON(BrowserThread::UI); 297 DCHECK_CURRENTLY_ON(BrowserThread::UI);
298 const SkBitmap* bitmap = nullptr;
299 if (!image.IsEmpty())
300 bitmap = image.ToSkBitmap();
293 callback.Run(is_local_thumbnail, bitmap); 301 callback.Run(is_local_thumbnail, bitmap);
294 } 302 }
295 303
296 void MostVisitedSites::AddOrRemoveBlacklistedUrl(const GURL& url, 304 void MostVisitedSites::AddOrRemoveBlacklistedUrl(const GURL& url,
297 bool add_url) { 305 bool add_url) {
298 // Always blacklist in the local TopSites. 306 // Always blacklist in the local TopSites.
299 if (top_sites_) { 307 if (top_sites_) {
300 if (add_url) 308 if (add_url)
301 top_sites_->AddBlacklistedURL(url); 309 top_sites_->AddBlacklistedURL(url);
302 else 310 else
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 653
646 void MostVisitedSites::TopSitesLoaded(TopSites* top_sites) {} 654 void MostVisitedSites::TopSitesLoaded(TopSites* top_sites) {}
647 655
648 void MostVisitedSites::TopSitesChanged(TopSites* top_sites, 656 void MostVisitedSites::TopSitesChanged(TopSites* top_sites,
649 ChangeReason change_reason) { 657 ChangeReason change_reason) {
650 if (mv_source_ == TOP_SITES) { 658 if (mv_source_ == TOP_SITES) {
651 // The displayed suggestions are invalidated. 659 // The displayed suggestions are invalidated.
652 InitiateTopSitesQuery(); 660 InitiateTopSitesQuery();
653 } 661 }
654 } 662 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698