Chromium Code Reviews| 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 |