Chromium Code Reviews| Index: components/favicon/core/favicon_service_impl.cc |
| diff --git a/components/favicon/core/favicon_service_impl.cc b/components/favicon/core/favicon_service_impl.cc |
| index a57c99e9ce2f2f23032ad4049aa7653ccae49337..64ef2e3a8ab615ec620534d6862a5451abe2253a 100644 |
| --- a/components/favicon/core/favicon_service_impl.cc |
| +++ b/components/favicon/core/favicon_service_impl.cc |
| @@ -36,6 +36,23 @@ std::vector<int> GetPixelSizesForFaviconScales(int size_in_dip) { |
| return sizes_in_pixel; |
| } |
| +std::vector<SkBitmap> GetFaviconBitmapsToSave(const gfx::Image& image) { |
|
pkotwicz
2017/03/23 14:35:02
Maybe rename this method to: ExtractSkBitmapsToSto
mastiz
2017/03/23 15:28:17
Done.
|
| + gfx::ImageSkia image_skia = image.AsImageSkia(); |
| + image_skia.EnsureRepsForSupportedScales(); |
| + const std::vector<gfx::ImageSkiaRep>& image_reps = image_skia.image_reps(); |
| + std::vector<SkBitmap> bitmaps; |
| + const std::vector<float> favicon_scales = favicon_base::GetFaviconScales(); |
| + for (size_t i = 0; i < image_reps.size(); ++i) { |
| + // Don't save if the scale isn't one of supported favicon scales. |
| + if (std::find(favicon_scales.begin(), favicon_scales.end(), |
| + image_reps[i].scale()) == favicon_scales.end()) { |
| + continue; |
| + } |
| + bitmaps.push_back(image_reps[i].sk_bitmap()); |
| + } |
| + return bitmaps; |
| +} |
| + |
| } // namespace |
| FaviconServiceImpl::FaviconServiceImpl( |
| @@ -215,20 +232,18 @@ void FaviconServiceImpl::SetFavicons(const GURL& page_url, |
| const GURL& icon_url, |
| favicon_base::IconType icon_type, |
| const gfx::Image& image) { |
| - gfx::ImageSkia image_skia = image.AsImageSkia(); |
| - image_skia.EnsureRepsForSupportedScales(); |
| - const std::vector<gfx::ImageSkiaRep>& image_reps = image_skia.image_reps(); |
| - std::vector<SkBitmap> bitmaps; |
| - const std::vector<float> favicon_scales = favicon_base::GetFaviconScales(); |
| - for (size_t i = 0; i < image_reps.size(); ++i) { |
| - // Don't save if the scale isn't one of supported favicon scales. |
| - if (std::find(favicon_scales.begin(), favicon_scales.end(), |
| - image_reps[i].scale()) == favicon_scales.end()) { |
| - continue; |
| - } |
| - bitmaps.push_back(image_reps[i].sk_bitmap()); |
| - } |
| - history_service_->SetFavicons(page_url, icon_type, icon_url, bitmaps); |
| + history_service_->SetFavicons(page_url, icon_type, icon_url, |
| + GetFaviconBitmapsToSave(image)); |
| +} |
| + |
| +void FaviconServiceImpl::SetLastResortFavicons( |
| + const GURL& page_url, |
| + const GURL& icon_url, |
| + favicon_base::IconType icon_type, |
| + const gfx::Image& image, |
| + base::Callback<void(bool)> callback) { |
| + history_service_->SetLastResortFavicons( |
| + page_url, icon_type, icon_url, GetFaviconBitmapsToSave(image), callback); |
| } |
| void FaviconServiceImpl::UnableToDownloadFavicon(const GURL& icon_url) { |