| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 if (ProvideDefaultIcon(site) && !preliminary_icon_available.is_null()) { | 71 if (ProvideDefaultIcon(site) && !preliminary_icon_available.is_null()) { |
| 72 preliminary_icon_available.Run(); | 72 preliminary_icon_available.Run(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 image_fetcher_->StartOrQueueNetworkRequest( | 75 image_fetcher_->StartOrQueueNetworkRequest( |
| 76 std::string(), IconURL(site), | 76 std::string(), IconURL(site), |
| 77 base::Bind(&IconCacherImpl::OnFaviconDownloaded, base::Unretained(this), | 77 base::Bind(&IconCacherImpl::OnFaviconDownloaded, base::Unretained(this), |
| 78 site, icon_available)); | 78 site, icon_available)); |
| 79 } | 79 } |
| 80 | 80 |
| 81 void IconCacherImpl::OnFaviconDownloaded(PopularSites::Site site, | 81 void IconCacherImpl::OnFaviconDownloaded( |
| 82 const base::Closure& icon_available, | 82 PopularSites::Site site, |
| 83 const std::string& id, | 83 const base::Closure& icon_available, |
| 84 const gfx::Image& fetched_image) { | 84 const std::string& id, |
| 85 const gfx::Image& fetched_image, |
| 86 const image_fetcher::RequestMetadata& metadata) { |
| 85 if (fetched_image.IsEmpty()) { | 87 if (fetched_image.IsEmpty()) { |
| 86 return; | 88 return; |
| 87 } | 89 } |
| 88 | 90 |
| 89 SaveIconForSite(site, fetched_image); | 91 SaveIconForSite(site, fetched_image); |
| 90 if (icon_available) { | 92 if (icon_available) { |
| 91 icon_available.Run(); | 93 icon_available.Run(); |
| 92 } | 94 } |
| 93 } | 95 } |
| 94 | 96 |
| 95 void IconCacherImpl::SaveIconForSite(const PopularSites::Site& site, | 97 void IconCacherImpl::SaveIconForSite(const PopularSites::Site& site, |
| 96 gfx::Image image) { | 98 gfx::Image image) { |
| 97 favicon_base::SetFaviconColorSpace(&image); | 99 favicon_base::SetFaviconColorSpace(&image); |
| 98 favicon_service_->SetFavicons(site.url, IconURL(site), IconType(site), image); | 100 favicon_service_->SetFavicons(site.url, IconURL(site), IconType(site), image); |
| 99 } | 101 } |
| 100 | 102 |
| 101 bool IconCacherImpl::ProvideDefaultIcon(const PopularSites::Site& site) { | 103 bool IconCacherImpl::ProvideDefaultIcon(const PopularSites::Site& site) { |
| 102 if (site.default_icon_resource < 0) { | 104 if (site.default_icon_resource < 0) { |
| 103 return false; | 105 return false; |
| 104 } | 106 } |
| 105 SaveIconForSite(site, ResourceBundle::GetSharedInstance().GetNativeImageNamed( | 107 SaveIconForSite(site, ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
| 106 site.default_icon_resource)); | 108 site.default_icon_resource)); |
| 107 return true; | 109 return true; |
| 108 } | 110 } |
| 109 | 111 |
| 110 } // namespace ntp_tiles | 112 } // namespace ntp_tiles |
| OLD | NEW |