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

Side by Side Diff: ios/chrome/browser/suggestions/ios_image_decoder_impl.mm

Issue 2715153006: Set desired_image_size when decoding images for NTP Tile icons. (Closed)
Patch Set: comment formatting Created 3 years, 9 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ios/chrome/browser/suggestions/ios_image_decoder_impl.h" 5 #include "ios/chrome/browser/suggestions/ios_image_decoder_impl.h"
6 6
7 #import <UIKit/UIKit.h> 7 #import <UIKit/UIKit.h>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #import "base/mac/bind_objc_block.h" 10 #import "base/mac/bind_objc_block.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #import "components/image_fetcher/ios/webp_decoder.h" 14 #import "components/image_fetcher/ios/webp_decoder.h"
15 #include "ios/web/public/web_thread.h" 15 #include "ios/web/public/web_thread.h"
16 #include "ui/gfx/geometry/size.h"
16 #include "ui/gfx/image/image.h" 17 #include "ui/gfx/image/image.h"
17 18
18 #if !defined(__has_feature) || !__has_feature(objc_arc) 19 #if !defined(__has_feature) || !__has_feature(objc_arc)
19 #error "This file requires ARC support." 20 #error "This file requires ARC support."
20 #endif 21 #endif
21 22
22 namespace suggestions { 23 namespace suggestions {
23 24
24 class IOSImageDecoderImpl : public image_fetcher::ImageDecoder { 25 class IOSImageDecoderImpl : public image_fetcher::ImageDecoder {
25 public: 26 public:
26 explicit IOSImageDecoderImpl(scoped_refptr<base::TaskRunner> task_runner); 27 explicit IOSImageDecoderImpl(scoped_refptr<base::TaskRunner> task_runner);
27 ~IOSImageDecoderImpl() override; 28 ~IOSImageDecoderImpl() override;
28 29
30 // Note, that |desired_image_frame_size| is not supported
31 // (http://crbug/697596).
29 void DecodeImage( 32 void DecodeImage(
30 const std::string& image_data, 33 const std::string& image_data,
34 const gfx::Size& desired_image_frame_size,
31 const image_fetcher::ImageDecodedCallback& callback) override; 35 const image_fetcher::ImageDecodedCallback& callback) override;
32 36
33 private: 37 private:
34 void CreateUIImageAndRunCallback( 38 void CreateUIImageAndRunCallback(
35 const image_fetcher::ImageDecodedCallback& callback, 39 const image_fetcher::ImageDecodedCallback& callback,
36 NSData* image_data); 40 NSData* image_data);
37 41
38 // The task runner used to decode images if necessary. 42 // The task runner used to decode images if necessary.
39 const scoped_refptr<base::TaskRunner> task_runner_; 43 const scoped_refptr<base::TaskRunner> task_runner_;
40 44
41 // The WeakPtrFactory is used to cancel callbacks if ImageFetcher is 45 // The WeakPtrFactory is used to cancel callbacks if ImageFetcher is
42 // destroyed during WebP decoding. 46 // destroyed during WebP decoding.
43 base::WeakPtrFactory<IOSImageDecoderImpl> weak_factory_; 47 base::WeakPtrFactory<IOSImageDecoderImpl> weak_factory_;
44 48
45 DISALLOW_COPY_AND_ASSIGN(IOSImageDecoderImpl); 49 DISALLOW_COPY_AND_ASSIGN(IOSImageDecoderImpl);
46 }; 50 };
47 51
48 IOSImageDecoderImpl::IOSImageDecoderImpl( 52 IOSImageDecoderImpl::IOSImageDecoderImpl(
49 scoped_refptr<base::TaskRunner> task_runner) 53 scoped_refptr<base::TaskRunner> task_runner)
50 : task_runner_(std::move(task_runner)), weak_factory_(this) { 54 : task_runner_(std::move(task_runner)), weak_factory_(this) {
51 DCHECK(task_runner_.get()); 55 DCHECK(task_runner_.get());
52 } 56 }
53 57
54 IOSImageDecoderImpl::~IOSImageDecoderImpl() {} 58 IOSImageDecoderImpl::~IOSImageDecoderImpl() {}
55 59
56 void IOSImageDecoderImpl::DecodeImage( 60 void IOSImageDecoderImpl::DecodeImage(
57 const std::string& image_data, 61 const std::string& image_data,
62 const gfx::Size& desired_image_frame_size,
58 const image_fetcher::ImageDecodedCallback& callback) { 63 const image_fetcher::ImageDecodedCallback& callback) {
59 // Convert the |image_data| std::string to an NSData buffer. 64 // Convert the |image_data| std::string to an NSData buffer.
60 // The data is copied as it may have to outlive the caller in 65 // The data is copied as it may have to outlive the caller in
61 // PostTaskAndReplyWithResult. 66 // PostTaskAndReplyWithResult.
62 NSData* data = 67 NSData* data =
63 [NSData dataWithBytes:image_data.data() length:image_data.size()]; 68 [NSData dataWithBytes:image_data.data() length:image_data.size()];
64 69
65 // The WebP image format is not supported by iOS natively. Therefore WebP 70 // The WebP image format is not supported by iOS natively. Therefore WebP
66 // images need to be decoded explicitly, 71 // images need to be decoded explicitly,
67 if (webp_transcode::WebpDecoder::IsWebpImage(image_data)) { 72 if (webp_transcode::WebpDecoder::IsWebpImage(image_data)) {
(...skipping 27 matching lines...) Expand all
95 gfx::Image empty_image; 100 gfx::Image empty_image;
96 callback.Run(empty_image); 101 callback.Run(empty_image);
97 } 102 }
98 103
99 std::unique_ptr<image_fetcher::ImageDecoder> CreateIOSImageDecoder( 104 std::unique_ptr<image_fetcher::ImageDecoder> CreateIOSImageDecoder(
100 scoped_refptr<base::TaskRunner> task_runner) { 105 scoped_refptr<base::TaskRunner> task_runner) {
101 return base::MakeUnique<IOSImageDecoderImpl>(std::move(task_runner)); 106 return base::MakeUnique<IOSImageDecoderImpl>(std::move(task_runner));
102 } 107 }
103 108
104 } // namespace suggestions 109 } // namespace suggestions
OLDNEW
« no previous file with comments | « components/suggestions/image_manager_unittest.cc ('k') | ios/chrome/browser/suggestions/ios_image_decoder_impl_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698