Chromium Code Reviews| Index: chrome/browser/manifest/manifest_icon_downloader.cc |
| diff --git a/chrome/browser/manifest/manifest_icon_downloader.cc b/chrome/browser/manifest/manifest_icon_downloader.cc |
| index 34ff954d39e64fe15fe901ff85c973b2b19ba0da..7b07025e68a5c2f040311c0ac7e53ce50077873e 100644 |
| --- a/chrome/browser/manifest/manifest_icon_downloader.cc |
| +++ b/chrome/browser/manifest/manifest_icon_downloader.cc |
| @@ -126,5 +126,28 @@ int ManifestIconDownloader::FindClosestBitmapIndex( |
| best_delta = delta; |
| } |
| } |
| + |
| + if (best_index != -1) |
| + return best_index; |
| + |
| + // There was no square icon of a correct size found. Try to find the most |
| + // square-like icon which has both dimensions greater than the minimum size. |
| + float best_ratio_difference = std::numeric_limits<float>::infinity(); |
| + for (size_t i = 0; i < bitmaps.size(); ++i) { |
| + if (bitmaps[i].height() < minimum_icon_size_in_px || |
| + bitmaps[i].width() < minimum_icon_size_in_px) { |
| + continue; |
| + } |
| + |
| + float height = static_cast<float>(bitmaps[i].height()); |
| + float width = static_cast<float>(bitmaps[i].width()); |
| + float ratio = height / width; |
|
mlamouri (slow - plz ping)
2015/09/23 13:45:21
nit: you could inline the static_cast<float> in th
Lalit Maganti
2015/09/23 13:50:02
With the inlining this line became way too long. D
|
| + float ratio_difference = fabs(ratio - 1); |
| + if (ratio_difference < best_ratio_difference) { |
| + best_index = i; |
| + best_ratio_difference = ratio_difference; |
| + } |
| + } |
| + |
| return best_index; |
| } |