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

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: Modify the std::string to NSData conversion 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
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..8c34226ed9c8513961155769d8f83430d600c7bb
--- /dev/null
+++ b/ios/chrome/browser/suggestions/ios_image_decoder_impl.mm
@@ -0,0 +1,39 @@
+// 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* nsData =
noyau (Ping after 24h) 2016/06/30 08:28:53 We tend to drop the prefix for variables. s/nsData
markusheintz_ 2016/06/30 09:15:14 Done.
+ [NSData dataWithBytes:image_data.c_str() length:image_data.length()];
noyau (Ping after 24h) 2016/06/30 08:28:53 This causes a copy of the string buffer. If you u
markusheintz_ 2016/06/30 09:15:14 c_str or data are returning a const char* . But da
+
+ // Decode the Image using UIImage.
+ if (nsData) {
+ // Most likely always returns 1x images.
+ UIImage* ui_image = [UIImage imageWithData:nsData 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

Powered by Google App Engine
This is Rietveld 408576698