OLD | NEW |
---|---|
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" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 // For images with multiple frames, prefer one of size 128x128px. | 42 // For images with multiple frames, prefer one of size 128x128px. |
43 image_fetcher_->SetDesiredImageFrameSize(gfx::Size(128, 128)); | 43 image_fetcher_->SetDesiredImageFrameSize(gfx::Size(128, 128)); |
44 } | 44 } |
45 | 45 |
46 IconCacherImpl::~IconCacherImpl() = default; | 46 IconCacherImpl::~IconCacherImpl() = default; |
47 | 47 |
48 void IconCacherImpl::StartFetch( | 48 void IconCacherImpl::StartFetch( |
49 PopularSites::Site site, | 49 PopularSites::Site site, |
50 const base::Closure& icon_available, | 50 const base::Closure& icon_available, |
51 const base::Closure& preliminary_icon_available) { | 51 const base::Closure& preliminary_icon_available) { |
52 DCHECK(!icon_available.is_null()); | |
53 favicon::GetFaviconImageForPageURL( | 52 favicon::GetFaviconImageForPageURL( |
54 favicon_service_, site.url, IconType(site), | 53 favicon_service_, site.url, IconType(site), |
55 base::Bind(&IconCacherImpl::OnGetFaviconImageForPageURLFinished, | 54 base::Bind(&IconCacherImpl::OnGetFaviconImageForPageURLFinished, |
56 base::Unretained(this), std::move(site), icon_available, | 55 base::Unretained(this), std::move(site), icon_available, |
57 preliminary_icon_available), | 56 preliminary_icon_available), |
58 &tracker_); | 57 &tracker_); |
59 } | 58 } |
60 | 59 |
61 void IconCacherImpl::OnGetFaviconImageForPageURLFinished( | 60 void IconCacherImpl::OnGetFaviconImageForPageURLFinished( |
62 PopularSites::Site site, | 61 PopularSites::Site site, |
(...skipping 15 matching lines...) Expand all Loading... | |
78 | 77 |
79 void IconCacherImpl::OnFaviconDownloaded(PopularSites::Site site, | 78 void IconCacherImpl::OnFaviconDownloaded(PopularSites::Site site, |
80 const base::Closure& icon_available, | 79 const base::Closure& icon_available, |
81 const std::string& id, | 80 const std::string& id, |
82 const gfx::Image& fetched_image) { | 81 const gfx::Image& fetched_image) { |
83 if (fetched_image.IsEmpty()) { | 82 if (fetched_image.IsEmpty()) { |
84 return; | 83 return; |
85 } | 84 } |
86 | 85 |
87 SaveIconForSite(site, fetched_image); | 86 SaveIconForSite(site, fetched_image); |
88 icon_available.Run(); | 87 if (!icon_available.is_null()) { |
Marc Treib
2017/03/03 10:29:42
optional: I think you can just write "if (icon_ava
fhorschig
2017/03/03 10:35:26
Done.
| |
88 icon_available.Run(); | |
89 } | |
89 } | 90 } |
90 | 91 |
91 void IconCacherImpl::SaveIconForSite(const PopularSites::Site& site, | 92 void IconCacherImpl::SaveIconForSite(const PopularSites::Site& site, |
92 gfx::Image image) { | 93 gfx::Image image) { |
93 favicon_base::SetFaviconColorSpace(&image); | 94 favicon_base::SetFaviconColorSpace(&image); |
94 favicon_service_->SetFavicons(site.url, IconURL(site), IconType(site), image); | 95 favicon_service_->SetFavicons(site.url, IconURL(site), IconType(site), image); |
95 } | 96 } |
96 | 97 |
97 bool IconCacherImpl::ProvideDefaultIcon(const PopularSites::Site& site) { | 98 bool IconCacherImpl::ProvideDefaultIcon(const PopularSites::Site& site) { |
98 if (site.default_icon_resource < 0) { | 99 if (site.default_icon_resource < 0) { |
99 return false; | 100 return false; |
100 } | 101 } |
101 SaveIconForSite(site, ResourceBundle::GetSharedInstance().GetNativeImageNamed( | 102 SaveIconForSite(site, ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
102 site.default_icon_resource)); | 103 site.default_icon_resource)); |
103 return true; | 104 return true; |
104 } | 105 } |
105 | 106 |
106 } // namespace ntp_tiles | 107 } // namespace ntp_tiles |
OLD | NEW |