| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/large_icon_service.h" | 5 #include "components/favicon/core/large_icon_service.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 *bitmap = image.AsBitmap(); | 110 *bitmap = image.AsBitmap(); |
| 111 } | 111 } |
| 112 return; | 112 return; |
| 113 } | 113 } |
| 114 } | 114 } |
| 115 | 115 |
| 116 if (!fallback_icon_style) | 116 if (!fallback_icon_style) |
| 117 return; | 117 return; |
| 118 | 118 |
| 119 *fallback_icon_style = favicon_base::FallbackIconStyle(); | 119 *fallback_icon_style = favicon_base::FallbackIconStyle(); |
| 120 int fallback_icon_size = 0; |
| 120 if (db_result.is_valid()) { | 121 if (db_result.is_valid()) { |
| 121 favicon_base::SetDominantColorAsBackground(db_result.bitmap_data, | 122 favicon_base::SetDominantColorAsBackground(db_result.bitmap_data, |
| 122 fallback_icon_style); | 123 fallback_icon_style); |
| 124 // The size must be positive, we cap to 128 to avoid the sparse histogram |
| 125 // to explode (having too many different values, server-side). Size 128 |
| 126 // already indicates that there is a problem in the code, 128 px _should_ be |
| 127 // enough in all current UI surfaces. |
| 128 fallback_icon_size = db_result.pixel_size.width(); |
| 129 DCHECK_GT(fallback_icon_size, 0); |
| 130 fallback_icon_size = std::min(fallback_icon_size, 128); |
| 123 } | 131 } |
| 132 UMA_HISTOGRAM_SPARSE_SLOWLY("Favicons.LargeIconService.FallbackSize", |
| 133 fallback_icon_size); |
| 124 } | 134 } |
| 125 | 135 |
| 126 // Processes the bitmap data returned from the FaviconService as part of a | 136 // Processes the bitmap data returned from the FaviconService as part of a |
| 127 // LargeIconService request. | 137 // LargeIconService request. |
| 128 class LargeIconWorker : public base::RefCountedThreadSafe<LargeIconWorker> { | 138 class LargeIconWorker : public base::RefCountedThreadSafe<LargeIconWorker> { |
| 129 public: | 139 public: |
| 130 // Exactly one of the callbacks is expected to be non-null. | 140 // Exactly one of the callbacks is expected to be non-null. |
| 131 LargeIconWorker(int min_source_size_in_pixel, | 141 LargeIconWorker(int min_source_size_in_pixel, |
| 132 int desired_size_in_pixel, | 142 int desired_size_in_pixel, |
| 133 favicon_base::LargeIconCallback raw_bitmap_callback, | 143 favicon_base::LargeIconCallback raw_bitmap_callback, |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 // TODO(beaudoin): For now this is just a wrapper around | 354 // TODO(beaudoin): For now this is just a wrapper around |
| 345 // GetLargestRawFaviconForPageURL. Add the logic required to select the best | 355 // GetLargestRawFaviconForPageURL. Add the logic required to select the best |
| 346 // possible large icon. Also add logic to fetch-on-demand when the URL of | 356 // possible large icon. Also add logic to fetch-on-demand when the URL of |
| 347 // a large icon is known but its bitmap is not available. | 357 // a large icon is known but its bitmap is not available. |
| 348 return favicon_service_->GetLargestRawFaviconForPageURL( | 358 return favicon_service_->GetLargestRawFaviconForPageURL( |
| 349 page_url, large_icon_types_, min_source_size_in_pixel, | 359 page_url, large_icon_types_, min_source_size_in_pixel, |
| 350 base::Bind(&LargeIconWorker::OnIconLookupComplete, worker), tracker); | 360 base::Bind(&LargeIconWorker::OnIconLookupComplete, worker), tracker); |
| 351 } | 361 } |
| 352 | 362 |
| 353 } // namespace favicon | 363 } // namespace favicon |
| OLD | NEW |