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

Unified Diff: components/suggestions/image_manager.cc

Issue 641513003: [Suggestions] Introduce a different image encoder/decoder for iOS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Latest Created 6 years, 2 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 9e4338127d35e4fcce065d010f06a66a5fe01ecb..5309e0bb790d05a2ac8e903cbd8d09bba9701be9 100644
--- a/components/suggestions/image_manager.cc
+++ b/components/suggestions/image_manager.cc
@@ -6,18 +6,14 @@
#include "base/bind.h"
#include "components/suggestions/image_fetcher.h"
-#include "ui/gfx/codec/jpeg_codec.h"
-using leveldb_proto::ProtoDatabase;
-
-namespace {
-
-// From JPEG-encoded bytes to SkBitmap.
-SkBitmap* DecodeImage(const std::vector<unsigned char>& encoded_data) {
- return gfx::JPEGCodec::Decode(&encoded_data[0], encoded_data.size());
-}
+#if defined(OS_IOS)
+#include "components/suggestions/image_encoder_ios.h"
+#else
+#include "components/suggestions/image_encoder.h"
+#endif
-} // namespace
+using leveldb_proto::ProtoDatabase;
namespace suggestions {
@@ -139,7 +135,7 @@ void ImageManager::SaveImage(const GURL& url, const SkBitmap& bitmap) {
// Attempt to save a JPEG representation to the database. If not successful,
// the fetched bitmap will still be inserted in the cache, above.
std::vector<unsigned char> encoded_data;
- if (EncodeImage(bitmap, &encoded_data)) {
+ if (EncodeSkBitmapToJPEG(bitmap, &encoded_data)) {
// Save the resulting bitmap to the database.
ImageData data;
data.set_url(url.spec());
@@ -194,7 +190,7 @@ void ImageManager::LoadEntriesInCache(scoped_ptr<ImageDataVector> entries) {
std::vector<unsigned char> encoded_data(it->data().begin(),
it->data().end());
- scoped_ptr<SkBitmap> bitmap(DecodeImage(encoded_data));
+ scoped_ptr<SkBitmap> bitmap(DecodeJPEGToSkBitmap(encoded_data));
if (bitmap.get()) {
image_map_.insert(std::make_pair(it->url(), *bitmap));
}
@@ -212,17 +208,4 @@ void ImageManager::ServePendingCacheRequests() {
}
}
-// static
-bool ImageManager::EncodeImage(const SkBitmap& bitmap,
- std::vector<unsigned char>* dest) {
- SkAutoLockPixels bitmap_lock(bitmap);
- if (!bitmap.readyToDraw() || bitmap.isNull()) {
- return false;
- }
- return gfx::JPEGCodec::Encode(
- reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)),
- gfx::JPEGCodec::FORMAT_SkBitmap, bitmap.width(), bitmap.height(),
- bitmap.rowBytes(), 100, dest);
-}
-
} // namespace suggestions

Powered by Google App Engine
This is Rietveld 408576698