Don't crash when SimpleCache index is corrupt.
[chromium-blink-merge.git] / ui / gfx / favicon_size.cc
blobd0ba48a4ccdd597f0f3e12bd77f124c276f3c425
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/gfx/favicon_size.h"
7 namespace gfx {
9 const int kFaviconSize = 16;
11 void CalculateFaviconTargetSize(int* width, int* height) {
12 if (*width > kFaviconSize || *height > kFaviconSize) {
13 // Too big, resize it maintaining the aspect ratio.
14 float aspect_ratio = static_cast<float>(*width) /
15 static_cast<float>(*height);
16 *height = kFaviconSize;
17 *width = static_cast<int>(aspect_ratio * *height);
18 if (*width > kFaviconSize) {
19 *width = kFaviconSize;
20 *height = static_cast<int>(*width / aspect_ratio);
25 } // namespace gfx