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

Side by Side 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, 5 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ios/chrome/browser/suggestions/ios_image_decoder_impl.h"
6
7 #include <UIKit/UIKit.h>
8
9 #include "base/callback.h"
10 #include "ui/gfx/image/image.h"
11
12 namespace suggestions {
13
14 IOSImageDecoderImpl::IOSImageDecoderImpl() {}
15
16 IOSImageDecoderImpl::~IOSImageDecoderImpl() {}
17
18 void IOSImageDecoderImpl::DecodeImage(
19 const std::string& image_data,
20 const image_fetcher::ImageDecodedCallback& callback) {
21 // Convert the |image_data| std::string to a NSData buffer.
22 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.
23 [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
24
25 // Decode the Image using UIImage.
26 if (nsData) {
27 // Most likely always returns 1x images.
28 UIImage* ui_image = [UIImage imageWithData:nsData scale:1];
29 if (ui_image) {
30 gfx::Image gfx_image(ui_image);
31 callback.Run(gfx_image);
32 return;
33 }
34 }
35 gfx::Image empty_image;
36 callback.Run(empty_image);
37 }
38
39 } // namespace suggestions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698