| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/favicon/core/favicon_service_impl.h" | 5 #include "components/favicon/core/favicon_service_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 // favicon_base::GetFaviconScales(). | 29 // favicon_base::GetFaviconScales(). |
| 30 std::vector<int> GetPixelSizesForFaviconScales(int size_in_dip) { | 30 std::vector<int> GetPixelSizesForFaviconScales(int size_in_dip) { |
| 31 std::vector<float> scales = favicon_base::GetFaviconScales(); | 31 std::vector<float> scales = favicon_base::GetFaviconScales(); |
| 32 std::vector<int> sizes_in_pixel; | 32 std::vector<int> sizes_in_pixel; |
| 33 for (size_t i = 0; i < scales.size(); ++i) { | 33 for (size_t i = 0; i < scales.size(); ++i) { |
| 34 sizes_in_pixel.push_back(std::ceil(size_in_dip * scales[i])); | 34 sizes_in_pixel.push_back(std::ceil(size_in_dip * scales[i])); |
| 35 } | 35 } |
| 36 return sizes_in_pixel; | 36 return sizes_in_pixel; |
| 37 } | 37 } |
| 38 | 38 |
| 39 std::vector<SkBitmap> ExtractSkBitmapsToStore(const gfx::Image& image) { |
| 40 gfx::ImageSkia image_skia = image.AsImageSkia(); |
| 41 image_skia.EnsureRepsForSupportedScales(); |
| 42 const std::vector<gfx::ImageSkiaRep>& image_reps = image_skia.image_reps(); |
| 43 std::vector<SkBitmap> bitmaps; |
| 44 const std::vector<float> favicon_scales = favicon_base::GetFaviconScales(); |
| 45 for (size_t i = 0; i < image_reps.size(); ++i) { |
| 46 // Don't save if the scale isn't one of supported favicon scales. |
| 47 if (std::find(favicon_scales.begin(), favicon_scales.end(), |
| 48 image_reps[i].scale()) == favicon_scales.end()) { |
| 49 continue; |
| 50 } |
| 51 bitmaps.push_back(image_reps[i].sk_bitmap()); |
| 52 } |
| 53 return bitmaps; |
| 54 } |
| 55 |
| 39 } // namespace | 56 } // namespace |
| 40 | 57 |
| 41 FaviconServiceImpl::FaviconServiceImpl( | 58 FaviconServiceImpl::FaviconServiceImpl( |
| 42 std::unique_ptr<FaviconClient> favicon_client, | 59 std::unique_ptr<FaviconClient> favicon_client, |
| 43 history::HistoryService* history_service) | 60 history::HistoryService* history_service) |
| 44 : favicon_client_(std::move(favicon_client)), | 61 : favicon_client_(std::move(favicon_client)), |
| 45 history_service_(history_service) { | 62 history_service_(history_service) { |
| 46 DCHECK(history_service_); | 63 DCHECK(history_service_); |
| 47 } | 64 } |
| 48 | 65 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 scoped_refptr<base::RefCountedMemory> bitmap_data, | 225 scoped_refptr<base::RefCountedMemory> bitmap_data, |
| 209 const gfx::Size& pixel_size) { | 226 const gfx::Size& pixel_size) { |
| 210 history_service_->MergeFavicon(page_url, icon_url, icon_type, bitmap_data, | 227 history_service_->MergeFavicon(page_url, icon_url, icon_type, bitmap_data, |
| 211 pixel_size); | 228 pixel_size); |
| 212 } | 229 } |
| 213 | 230 |
| 214 void FaviconServiceImpl::SetFavicons(const GURL& page_url, | 231 void FaviconServiceImpl::SetFavicons(const GURL& page_url, |
| 215 const GURL& icon_url, | 232 const GURL& icon_url, |
| 216 favicon_base::IconType icon_type, | 233 favicon_base::IconType icon_type, |
| 217 const gfx::Image& image) { | 234 const gfx::Image& image) { |
| 218 gfx::ImageSkia image_skia = image.AsImageSkia(); | 235 history_service_->SetFavicons(page_url, icon_type, icon_url, |
| 219 image_skia.EnsureRepsForSupportedScales(); | 236 ExtractSkBitmapsToStore(image)); |
| 220 const std::vector<gfx::ImageSkiaRep>& image_reps = image_skia.image_reps(); | 237 } |
| 221 std::vector<SkBitmap> bitmaps; | 238 |
| 222 const std::vector<float> favicon_scales = favicon_base::GetFaviconScales(); | 239 void FaviconServiceImpl::SetLastResortFavicons( |
| 223 for (size_t i = 0; i < image_reps.size(); ++i) { | 240 const GURL& page_url, |
| 224 // Don't save if the scale isn't one of supported favicon scales. | 241 const GURL& icon_url, |
| 225 if (std::find(favicon_scales.begin(), favicon_scales.end(), | 242 favicon_base::IconType icon_type, |
| 226 image_reps[i].scale()) == favicon_scales.end()) { | 243 const gfx::Image& image, |
| 227 continue; | 244 base::Callback<void(bool)> callback) { |
| 228 } | 245 history_service_->SetLastResortFavicons( |
| 229 bitmaps.push_back(image_reps[i].sk_bitmap()); | 246 page_url, icon_type, icon_url, ExtractSkBitmapsToStore(image), callback); |
| 230 } | |
| 231 history_service_->SetFavicons(page_url, icon_type, icon_url, bitmaps); | |
| 232 } | 247 } |
| 233 | 248 |
| 234 void FaviconServiceImpl::UnableToDownloadFavicon(const GURL& icon_url) { | 249 void FaviconServiceImpl::UnableToDownloadFavicon(const GURL& icon_url) { |
| 235 MissingFaviconURLHash url_hash = base::Hash(icon_url.spec()); | 250 MissingFaviconURLHash url_hash = base::Hash(icon_url.spec()); |
| 236 missing_favicon_urls_.insert(url_hash); | 251 missing_favicon_urls_.insert(url_hash); |
| 237 } | 252 } |
| 238 | 253 |
| 239 bool FaviconServiceImpl::WasUnableToDownloadFavicon( | 254 bool FaviconServiceImpl::WasUnableToDownloadFavicon( |
| 240 const GURL& icon_url) const { | 255 const GURL& icon_url) const { |
| 241 MissingFaviconURLHash url_hash = base::Hash(icon_url.spec()); | 256 MissingFaviconURLHash url_hash = base::Hash(icon_url.spec()); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 const std::vector<favicon_base::FaviconRawBitmapResult>& | 301 const std::vector<favicon_base::FaviconRawBitmapResult>& |
| 287 favicon_bitmap_results) { | 302 favicon_bitmap_results) { |
| 288 TRACE_EVENT0( | 303 TRACE_EVENT0( |
| 289 "browser", | 304 "browser", |
| 290 "FaviconServiceImpl::RunFaviconRawBitmapCallbackWithBitmapResults"); | 305 "FaviconServiceImpl::RunFaviconRawBitmapCallbackWithBitmapResults"); |
| 291 callback.Run( | 306 callback.Run( |
| 292 ResizeFaviconBitmapResult(favicon_bitmap_results, desired_size_in_pixel)); | 307 ResizeFaviconBitmapResult(favicon_bitmap_results, desired_size_in_pixel)); |
| 293 } | 308 } |
| 294 | 309 |
| 295 } // namespace favicon | 310 } // namespace favicon |
| OLD | NEW |