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

Unified Diff: ios/chrome/browser/suggestions/ios_image_decoder_impl.mm

Issue 2111573002: Add ios_image_decoder_impl.* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix typo in ios_chrome.gyp Created 4 years, 6 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
« no previous file with comments | « ios/chrome/browser/suggestions/ios_image_decoder_impl.h ('k') | ios/chrome/ios_chrome.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/suggestions/ios_image_decoder_impl.mm
diff --git a/ios/chrome/browser/suggestions/ios_image_decoder_impl.mm b/ios/chrome/browser/suggestions/ios_image_decoder_impl.mm
new file mode 100644
index 0000000000000000000000000000000000000000..f28d382f1fb0e538bbe54b28161a81e245d5415b
--- /dev/null
+++ b/ios/chrome/browser/suggestions/ios_image_decoder_impl.mm
@@ -0,0 +1,41 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ios/chrome/browser/suggestions/ios_image_decoder_impl.h"
+
+#include <UIKit/UIKit.h>
+
+#include "base/callback.h"
+#include "ui/gfx/image/image.h"
+
+namespace suggestions {
+
+IOSImageDecoderImpl::IOSImageDecoderImpl() {}
+
+IOSImageDecoderImpl::~IOSImageDecoderImpl() {}
+
+void IOSImageDecoderImpl::DecodeImage(
+ const std::string& image_data,
+ const image_fetcher::ImageDecodedCallback& callback) {
+ // Convert the |image_data| std::string to a NSData buffer.
+ NSData* data =
+ [NSData dataWithBytesNoCopy:const_cast<char*>(image_data.c_str())
+ length:image_data.length()
+ freeWhenDone:NO];
+
+ // Decode the Image using UIImage.
+ if (data) {
+ // Most likely always returns 1x images.
+ UIImage* ui_image = [UIImage imageWithData:data scale:1];
+ if (ui_image) {
+ gfx::Image gfx_image(ui_image);
+ callback.Run(gfx_image);
+ return;
+ }
+ }
+ gfx::Image empty_image;
+ callback.Run(empty_image);
+}
+
+} // namespace suggestions
« no previous file with comments | « ios/chrome/browser/suggestions/ios_image_decoder_impl.h ('k') | ios/chrome/ios_chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698