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

Side by Side Diff: components/ntp_tiles/icon_cacher_impl.cc

Issue 2725293002: Handle null callbacks in OnFaviconDownloaded (Closed)
Patch Set: Address comments 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
« no previous file with comments | « components/ntp_tiles/icon_cacher.h ('k') | components/ntp_tiles/icon_cacher_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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) {
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
OLDNEW
« no previous file with comments | « components/ntp_tiles/icon_cacher.h ('k') | components/ntp_tiles/icon_cacher_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698