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

Unified Diff: components/suggestions/image_manager.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 side-by-side diff with in-line comments
Download patch
Index: components/suggestions/image_manager.cc
diff --git a/components/suggestions/image_manager.cc b/components/suggestions/image_manager.cc
index 46618f44cbcf012a20bc8641a347d27fff80ba5c..713338f5b6cea8864aa5f3e8a5b5fadc6a62340e 100644
--- a/components/suggestions/image_manager.cc
+++ b/components/suggestions/image_manager.cc
@@ -30,19 +30,6 @@ std::unique_ptr<SkBitmap> DecodeImage(
encoded_data->size());
}
-// Wraps an ImageManager callback so that it can be used with the ImageFetcher.
-// ImageManager callbacks expect SkBitmaps while ImageFetcher callbacks expect
-// gfx::Images. The image can be empty. In this case it is mapped to nullptr.
-void WrapImageManagerCallback(
- const base::Callback<void(const GURL&, const SkBitmap*)>& wrapped_callback,
- const GURL& url,
- const gfx::Image& image) {
- const SkBitmap* bitmap = nullptr;
- if (!image.IsEmpty())
- bitmap = image.ToSkBitmap();
- wrapped_callback.Run(url, bitmap);
-}
-
} // namespace
namespace suggestions {
@@ -91,13 +78,14 @@ void ImageManager::AddImageURL(const GURL& url, const GURL& image_url) {
void ImageManager::GetImageForURL(
const GURL& url,
- base::Callback<void(const GURL&, const SkBitmap*)> callback) {
+ base::Callback<void(const GURL&, const gfx::Image&)> callback) {
DCHECK(thread_checker_.CalledOnValidThread());
// If |url| is not found in |image_url_map_|, then invoke |callback| with
// NULL since there is no associated image for this |url|.
GURL image_url;
if (!GetImageURL(url, &image_url)) {
- callback.Run(url, nullptr);
+ const gfx::Image empty_image;
+ callback.Run(url, empty_image);
Marc Treib 2016/05/20 14:40:04 Any reason for declaring an empty_image variable,
markusheintz_ 2016/05/23 13:20:46 Done.
return;
}
@@ -128,7 +116,7 @@ bool ImageManager::GetImageURL(const GURL& url, GURL* image_url) {
void ImageManager::QueueCacheRequest(
const GURL& url, const GURL& image_url,
- base::Callback<void(const GURL&, const SkBitmap*)> callback) {
+ base::Callback<void(const GURL&, const gfx::Image&)> callback) {
// To be served when the database has loaded.
ImageCacheRequestMap::iterator it = pending_cache_requests_.find(url);
if (it == pending_cache_requests_.end()) {
@@ -146,13 +134,14 @@ void ImageManager::QueueCacheRequest(
void ImageManager::OnCacheImageDecoded(
const GURL& url,
const GURL& image_url,
- base::Callback<void(const GURL&, const SkBitmap*)> callback,
+ const base::Callback<void(const GURL&, const gfx::Image&)>& callback,
std::unique_ptr<SkBitmap> bitmap) {
if (bitmap.get()) {
- callback.Run(url, bitmap.get());
+ const gfx::Image image(gfx::Image::CreateFrom1xBitmap(*bitmap.get()));
Marc Treib 2016/05/20 14:40:04 I think the .get() isn't needed, you can directly
markusheintz_ 2016/05/23 13:20:46 Uups sorry forgot to remove done.
+ callback.Run(url, image);
Marc Treib 2016/05/20 14:40:03 Also here: I'd just inline the gfx::Image::CreateF
markusheintz_ 2016/05/23 13:20:46 Done.
} else {
image_fetcher_->StartOrQueueNetworkRequest(
- url, image_url, base::Bind(&WrapImageManagerCallback, callback));
+ url, image_url, callback);
}
}
@@ -168,7 +157,7 @@ scoped_refptr<base::RefCountedMemory> ImageManager::GetEncodedImageFromCache(
void ImageManager::ServeFromCacheOrNetwork(
const GURL& url,
const GURL& image_url,
- base::Callback<void(const GURL&, const SkBitmap*)> callback) {
+ base::Callback<void(const GURL&, const gfx::Image&)> callback) {
scoped_refptr<base::RefCountedMemory> encoded_data =
GetEncodedImageFromCache(url);
if (encoded_data.get()) {
@@ -179,7 +168,7 @@ void ImageManager::ServeFromCacheOrNetwork(
weak_ptr_factory_.GetWeakPtr(), url, image_url, callback));
} else {
image_fetcher_->StartOrQueueNetworkRequest(
- url, image_url, base::Bind(&WrapImageManagerCallback, callback));
+ url, image_url, callback);
Marc Treib 2016/05/20 14:40:03 This should fit on the previous line now :)
markusheintz_ 2016/05/23 13:20:46 Done.
}
}

Powered by Google App Engine
This is Rietveld 408576698