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

Side by Side Diff: components/image_fetcher/image_fetcher_impl.cc

Issue 2715153006: Set desired_image_size when decoding images for NTP Tile icons. (Closed)
Patch Set: ax 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/image_fetcher/image_fetcher_impl.h" 5 #include "components/image_fetcher/image_fetcher_impl.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "net/base/load_flags.h" 10 #include "net/base/load_flags.h"
(...skipping 21 matching lines...) Expand all
32 void ImageFetcherImpl::SetImageFetcherDelegate(ImageFetcherDelegate* delegate) { 32 void ImageFetcherImpl::SetImageFetcherDelegate(ImageFetcherDelegate* delegate) {
33 DCHECK(delegate); 33 DCHECK(delegate);
34 delegate_ = delegate; 34 delegate_ = delegate;
35 } 35 }
36 36
37 void ImageFetcherImpl::SetDataUseServiceName( 37 void ImageFetcherImpl::SetDataUseServiceName(
38 DataUseServiceName data_use_service_name) { 38 DataUseServiceName data_use_service_name) {
39 image_data_fetcher_->SetDataUseServiceName(data_use_service_name); 39 image_data_fetcher_->SetDataUseServiceName(data_use_service_name);
40 } 40 }
41 41
42 void ImageFetcherImpl::SetDesiredImageFrameSize(const gfx::Size& size) {
43 desired_image_frame_size_ = size;
44 }
42 void ImageFetcherImpl::StartOrQueueNetworkRequest( 45 void ImageFetcherImpl::StartOrQueueNetworkRequest(
Marc Treib 2017/03/01 09:17:26 nit: empty line before
tschumann 2017/03/01 09:37:43 Done.
43 const std::string& id, 46 const std::string& id,
44 const GURL& image_url, 47 const GURL& image_url,
45 base::Callback<void(const std::string&, const gfx::Image&)> callback) { 48 base::Callback<void(const std::string&, const gfx::Image&)> callback) {
46 // Before starting to fetch the image. Look for a request in progress for 49 // Before starting to fetch the image. Look for a request in progress for
47 // |image_url|, and queue if appropriate. 50 // |image_url|, and queue if appropriate.
48 ImageRequestMap::iterator it = pending_net_requests_.find(image_url); 51 ImageRequestMap::iterator it = pending_net_requests_.find(image_url);
49 if (it == pending_net_requests_.end()) { 52 if (it == pending_net_requests_.end()) {
50 ImageRequest request; 53 ImageRequest request;
51 request.id = id; 54 request.id = id;
52 request.callbacks.push_back(callback); 55 request.callbacks.push_back(callback);
(...skipping 12 matching lines...) Expand all
65 void ImageFetcherImpl::OnImageURLFetched(const GURL& image_url, 68 void ImageFetcherImpl::OnImageURLFetched(const GURL& image_url,
66 const std::string& image_data) { 69 const std::string& image_data) {
67 // Inform the ImageFetcherDelegate. 70 // Inform the ImageFetcherDelegate.
68 if (delegate_) { 71 if (delegate_) {
69 auto it = pending_net_requests_.find(image_url); 72 auto it = pending_net_requests_.find(image_url);
70 DCHECK(it != pending_net_requests_.end()); 73 DCHECK(it != pending_net_requests_.end());
71 delegate_->OnImageDataFetched(it->second.id, image_data); 74 delegate_->OnImageDataFetched(it->second.id, image_data);
72 } 75 }
73 76
74 image_decoder_->DecodeImage( 77 image_decoder_->DecodeImage(
75 image_data, 78 image_data, desired_image_frame_size_,
76 base::Bind(&ImageFetcherImpl::OnImageDecoded, 79 base::Bind(&ImageFetcherImpl::OnImageDecoded,
77 base::Unretained(this), image_url)); 80 base::Unretained(this), image_url));
78 } 81 }
79 82
80 void ImageFetcherImpl::OnImageDecoded(const GURL& image_url, 83 void ImageFetcherImpl::OnImageDecoded(const GURL& image_url,
81 const gfx::Image& image) { 84 const gfx::Image& image) {
82 // Get request for the given image_url from the request queue. 85 // Get request for the given image_url from the request queue.
83 ImageRequestMap::iterator image_iter = pending_net_requests_.find(image_url); 86 ImageRequestMap::iterator image_iter = pending_net_requests_.find(image_url);
84 DCHECK(image_iter != pending_net_requests_.end()); 87 DCHECK(image_iter != pending_net_requests_.end());
85 ImageRequest* request = &image_iter->second; 88 ImageRequest* request = &image_iter->second;
86 89
87 // Run all callbacks 90 // Run all callbacks
88 for (const auto& callback : request->callbacks) { 91 for (const auto& callback : request->callbacks) {
89 callback.Run(request->id, image); 92 callback.Run(request->id, image);
90 } 93 }
91 94
92 // Inform the ImageFetcherDelegate. 95 // Inform the ImageFetcherDelegate.
93 if (delegate_) { 96 if (delegate_) {
94 delegate_->OnImageFetched(request->id, image); 97 delegate_->OnImageFetched(request->id, image);
95 } 98 }
96 99
97 // Erase the completed ImageRequest. 100 // Erase the completed ImageRequest.
98 pending_net_requests_.erase(image_iter); 101 pending_net_requests_.erase(image_iter);
99 } 102 }
100 103
101 } // namespace image_fetcher 104 } // namespace image_fetcher
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698