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

Side by Side Diff: chrome/browser/search/suggestions/image_decoder_impl.cc

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 <algorithm> 5 #include <algorithm>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "chrome/browser/search/suggestions/image_decoder_impl.h" 9 #include "chrome/browser/search/suggestions/image_decoder_impl.h"
10 #include "ui/gfx/geometry/size.h"
10 #include "ui/gfx/image/image.h" 11 #include "ui/gfx/image/image.h"
11 12
12 namespace suggestions { 13 namespace suggestions {
13 14
14 // A request for decoding an image. 15 // A request for decoding an image.
15 class ImageDecoderImpl::DecodeImageRequest 16 class ImageDecoderImpl::DecodeImageRequest
16 : public ::ImageDecoder::ImageRequest { 17 : public ::ImageDecoder::ImageRequest {
17 public: 18 public:
18 DecodeImageRequest(ImageDecoderImpl* decoder, 19 DecodeImageRequest(ImageDecoderImpl* decoder,
19 const image_fetcher::ImageDecodedCallback& callback) 20 const image_fetcher::ImageDecodedCallback& callback)
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 // This must be the last line in the method body. 59 // This must be the last line in the method body.
59 decoder_->RemoveDecodeImageRequest(this); 60 decoder_->RemoveDecodeImageRequest(this);
60 } 61 }
61 62
62 ImageDecoderImpl::ImageDecoderImpl() {} 63 ImageDecoderImpl::ImageDecoderImpl() {}
63 64
64 ImageDecoderImpl::~ImageDecoderImpl() {} 65 ImageDecoderImpl::~ImageDecoderImpl() {}
65 66
66 void ImageDecoderImpl::DecodeImage( 67 void ImageDecoderImpl::DecodeImage(
67 const std::string& image_data, 68 const std::string& image_data,
69 const gfx::Size& desired_image_frame_size,
68 const image_fetcher::ImageDecodedCallback& callback) { 70 const image_fetcher::ImageDecodedCallback& callback) {
69 std::unique_ptr<DecodeImageRequest> decode_image_request( 71 std::unique_ptr<DecodeImageRequest> decode_image_request(
70 new DecodeImageRequest(this, callback)); 72 new DecodeImageRequest(this, callback));
71 73
72 ::ImageDecoder::Start(decode_image_request.get(), image_data); 74 ::ImageDecoder::StartWithOptions(
75 decode_image_request.get(),
76 std::vector<uint8_t>(image_data.begin(), image_data.end()),
77 ::ImageDecoder::DEFAULT_CODEC,
78 /*shrink_to_fit=*/false, desired_image_frame_size);
73 79
74 decode_image_requests_.push_back(std::move(decode_image_request)); 80 decode_image_requests_.push_back(std::move(decode_image_request));
75 } 81 }
76 82
77 void ImageDecoderImpl::RemoveDecodeImageRequest(DecodeImageRequest* request) { 83 void ImageDecoderImpl::RemoveDecodeImageRequest(DecodeImageRequest* request) {
78 // Remove the finished request from the request queue. 84 // Remove the finished request from the request queue.
79 auto request_it = 85 auto request_it =
80 std::find_if(decode_image_requests_.begin(), 86 std::find_if(decode_image_requests_.begin(),
81 decode_image_requests_.end(), 87 decode_image_requests_.end(),
82 [request](const std::unique_ptr<DecodeImageRequest>& r) { 88 [request](const std::unique_ptr<DecodeImageRequest>& r) {
83 return r.get() == request; 89 return r.get() == request;
84 }); 90 });
85 DCHECK(request_it != decode_image_requests_.end()); 91 DCHECK(request_it != decode_image_requests_.end());
86 decode_image_requests_.erase(request_it); 92 decode_image_requests_.erase(request_it);
87 } 93 }
88 94
89 } // namespace suggestions 95 } // namespace suggestions
OLDNEW
« no previous file with comments | « chrome/browser/search/suggestions/image_decoder_impl.h ('k') | components/image_fetcher/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698