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

Unified Diff: components/suggestions/image_manager.cc

Issue 1974013002: Replace SkBitmap with gfx::Image in the ImageFetcher API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix more iOS build errors. 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 440813c92965f098dae6821c06ba6493548ce92c..d97de224fef0fd2e46183a6ab1136cf17b2dd60c 100644
--- a/components/suggestions/image_manager.cc
+++ b/components/suggestions/image_manager.cc
@@ -12,6 +12,7 @@
#include "base/task_runner_util.h"
#include "components/image_fetcher/image_fetcher.h"
#include "components/suggestions/image_encoder.h"
+#include "ui/gfx/image/image.h"
using leveldb_proto::ProtoDatabase;
@@ -29,6 +30,21 @@ 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 expecte
+// gfx::Images. The ImageFetcher used to return NULL when the image could not be
+// loaded. Now an empty image is returned which is mapped to NULL.
+void WrapImageManagerCallback(
+ base::Callback<void(const GURL&, const SkBitmap*)> wrapped_callback,
noyau (Ping after 24h) 2016/05/13 16:10:09 Same here. The rule of thumb is: If you are in co
markusheintz_ 2016/05/17 13:08:23 Same as the other. This will be changed. Just in a
+ const GURL& url,
+ const gfx::Image& image) {
+ const SkBitmap* bitmap = NULL;
+ if (!image.IsEmpty()) {
+ bitmap = image.ToSkBitmap();
+ }
+ wrapped_callback.Run(url, bitmap);
+}
+
} // namespace
namespace suggestions {
@@ -98,9 +114,10 @@ void ImageManager::GetImageForURL(
ServeFromCacheOrNetwork(url, image_url, callback);
}
-void ImageManager::OnImageFetched(const GURL& url, const SkBitmap* bitmap) {
- if (bitmap) // |bitmap| can be nullptr if image fetch was unsuccessful.
- SaveImage(url, *bitmap);
+void ImageManager::OnImageFetched(const GURL& url, const gfx::Image& image) {
+ // |image| can be empty if image fetch was unsuccessful.
+ if (!image.IsEmpty())
+ SaveImage(url, *(image.ToSkBitmap()));
}
bool ImageManager::GetImageURL(const GURL& url, GURL* image_url) {
@@ -136,7 +153,8 @@ void ImageManager::OnCacheImageDecoded(
if (bitmap.get()) {
callback.Run(url, bitmap.get());
} else {
- image_fetcher_->StartOrQueueNetworkRequest(url, image_url, callback);
+ image_fetcher_->StartOrQueueNetworkRequest(
+ url, image_url, base::Bind(&WrapImageManagerCallback, callback));
}
}
@@ -162,7 +180,8 @@ void ImageManager::ServeFromCacheOrNetwork(
base::Bind(&ImageManager::OnCacheImageDecoded,
weak_ptr_factory_.GetWeakPtr(), url, image_url, callback));
} else {
- image_fetcher_->StartOrQueueNetworkRequest(url, image_url, callback);
+ image_fetcher_->StartOrQueueNetworkRequest(
+ url, image_url, base::Bind(&WrapImageManagerCallback, callback));
}
}

Powered by Google App Engine
This is Rietveld 408576698