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: components/ntp_tiles/icon_cacher_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 "components/ntp_tiles/icon_cacher_impl.h" 5 #include "components/ntp_tiles/icon_cacher_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "components/favicon/core/favicon_service.h" 9 #include "components/favicon/core/favicon_service.h"
10 #include "components/favicon/core/favicon_util.h" 10 #include "components/favicon/core/favicon_util.h"
11 #include "components/favicon_base/favicon_types.h" 11 #include "components/favicon_base/favicon_types.h"
12 #include "components/favicon_base/favicon_util.h" 12 #include "components/favicon_base/favicon_util.h"
13 #include "components/image_fetcher/image_fetcher.h" 13 #include "components/image_fetcher/image_fetcher.h"
14 #include "ui/gfx/geometry/size.h"
14 #include "ui/gfx/image/image.h" 15 #include "ui/gfx/image/image.h"
15 #include "url/gurl.h" 16 #include "url/gurl.h"
16 17
17 namespace ntp_tiles { 18 namespace ntp_tiles {
18 19
19 namespace { 20 namespace {
20 21
21 favicon_base::IconType IconType(const PopularSites::Site& site) { 22 favicon_base::IconType IconType(const PopularSites::Site& site) {
22 return site.large_icon_url.is_valid() ? favicon_base::TOUCH_ICON 23 return site.large_icon_url.is_valid() ? favicon_base::TOUCH_ICON
23 : favicon_base::FAVICON; 24 : favicon_base::FAVICON;
24 } 25 }
25 26
26 const GURL& IconURL(const PopularSites::Site& site) { 27 const GURL& IconURL(const PopularSites::Site& site) {
27 return site.large_icon_url.is_valid() ? site.large_icon_url 28 return site.large_icon_url.is_valid() ? site.large_icon_url
28 : site.favicon_url; 29 : site.favicon_url;
29 } 30 }
30 31
31 } // namespace 32 } // namespace
32 33
33 IconCacherImpl::IconCacherImpl( 34 IconCacherImpl::IconCacherImpl(
34 favicon::FaviconService* favicon_service, 35 favicon::FaviconService* favicon_service,
35 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher) 36 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher)
36 : favicon_service_(favicon_service), 37 : favicon_service_(favicon_service),
37 image_fetcher_(std::move(image_fetcher)) { 38 image_fetcher_(std::move(image_fetcher)) {
38 image_fetcher_->SetDataUseServiceName( 39 image_fetcher_->SetDataUseServiceName(
39 data_use_measurement::DataUseUserData::NTP_TILES); 40 data_use_measurement::DataUseUserData::NTP_TILES);
41 // For images with multiple frames, prefer one of size 128x128px.
42 image_fetcher_->SetDesiredImageFrameSize(gfx::Size(128, 128));
40 } 43 }
41 44
42 IconCacherImpl::~IconCacherImpl() = default; 45 IconCacherImpl::~IconCacherImpl() = default;
43 46
44 void IconCacherImpl::StartFetch(PopularSites::Site site, 47 void IconCacherImpl::StartFetch(PopularSites::Site site,
45 const base::Callback<void(bool)>& done) { 48 const base::Callback<void(bool)>& done) {
46 favicon::GetFaviconImageForPageURL( 49 favicon::GetFaviconImageForPageURL(
47 favicon_service_, site.url, IconType(site), 50 favicon_service_, site.url, IconType(site),
48 base::Bind(&IconCacherImpl::OnGetFaviconImageForPageURLFinished, 51 base::Bind(&IconCacherImpl::OnGetFaviconImageForPageURLFinished,
49 base::Unretained(this), std::move(site), done), 52 base::Unretained(this), std::move(site), done),
(...skipping 24 matching lines...) Expand all
74 return; 77 return;
75 } 78 }
76 79
77 gfx::Image image = fetched_image; 80 gfx::Image image = fetched_image;
78 favicon_base::SetFaviconColorSpace(&image); 81 favicon_base::SetFaviconColorSpace(&image);
79 favicon_service_->SetFavicons(site.url, IconURL(site), IconType(site), image); 82 favicon_service_->SetFavicons(site.url, IconURL(site), IconType(site), image);
80 done.Run(true); 83 done.Run(true);
81 } 84 }
82 85
83 } // namespace ntp_tiles 86 } // namespace ntp_tiles
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698