Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: chrome/browser/favicon/favicon_handler.cc

Issue 335233003: Convert ui::ScaleFactor -> float in favicon/history code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/browser/favicon/favicon_handler.h" 5 #include "chrome/browser/favicon/favicon_handler.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <cmath>
10 #include <vector> 11 #include <vector>
11 12
12 #include "base/bind.h" 13 #include "base/bind.h"
13 #include "base/bind_helpers.h" 14 #include "base/bind_helpers.h"
14 #include "base/memory/ref_counted_memory.h" 15 #include "base/memory/ref_counted_memory.h"
15 #include "chrome/browser/favicon/favicon_service.h" 16 #include "chrome/browser/favicon/favicon_service.h"
16 #include "chrome/browser/favicon/favicon_service_factory.h" 17 #include "chrome/browser/favicon/favicon_service_factory.h"
17 #include "components/favicon_base/favicon_util.h" 18 #include "components/favicon_base/favicon_util.h"
18 #include "components/favicon_base/select_favicon_frames.h" 19 #include "components/favicon_base/select_favicon_frames.h"
19 #include "skia/ext/image_operations.h" 20 #include "skia/ext/image_operations.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 // Any favicon size is good if the desired size is 0. 112 // Any favicon size is good if the desired size is 0.
112 if (desired_size_in_dip == 0) 113 if (desired_size_in_dip == 0)
113 return false; 114 return false;
114 115
115 // Check if the favicon for at least one of the scale factors is missing. 116 // Check if the favicon for at least one of the scale factors is missing.
116 // |bitmap_results| should always be complete for data inserted by 117 // |bitmap_results| should always be complete for data inserted by
117 // FaviconHandler as the FaviconHandler stores favicons resized to all 118 // FaviconHandler as the FaviconHandler stores favicons resized to all
118 // of favicon_base::GetFaviconScaleFactors() into the history backend. 119 // of favicon_base::GetFaviconScaleFactors() into the history backend.
119 // Examples of when |bitmap_results| can be incomplete: 120 // Examples of when |bitmap_results| can be incomplete:
120 // - Favicons inserted into the history backend by sync. 121 // - Favicons inserted into the history backend by sync.
121 // - Favicons for imported bookmarks. 122 // - Favicons for imported bookmarks.
pkotwicz 2014/06/20 00:35:41 Can you update this comment? Can you please also g
oshima 2014/06/20 04:16:33 Done.
122 std::vector<gfx::Size> favicon_sizes; 123 std::vector<gfx::Size> favicon_sizes;
123 for (size_t i = 0; i < bitmap_results.size(); ++i) 124 for (size_t i = 0; i < bitmap_results.size(); ++i)
124 favicon_sizes.push_back(bitmap_results[i].pixel_size); 125 favicon_sizes.push_back(bitmap_results[i].pixel_size);
125 126
126 std::vector<ui::ScaleFactor> scale_factors = 127 std::vector<float> favicon_scales = favicon_base::GetFaviconScales();
127 favicon_base::GetFaviconScaleFactors(); 128 for (size_t i = 0; i < favicon_scales.size(); ++i) {
128 for (size_t i = 0; i < scale_factors.size(); ++i) { 129 int edge_size_in_pixel = std::ceil(desired_size_in_dip * favicon_scales[i]);
129 int edge_size_in_pixel = floor(
130 desired_size_in_dip * ui::GetScaleForScaleFactor(scale_factors[i]));
131 std::vector<gfx::Size>::iterator it = std::find(favicon_sizes.begin(), 130 std::vector<gfx::Size>::iterator it = std::find(favicon_sizes.begin(),
132 favicon_sizes.end(), gfx::Size(edge_size_in_pixel, edge_size_in_pixel)); 131 favicon_sizes.end(), gfx::Size(edge_size_in_pixel, edge_size_in_pixel));
133 if (it == favicon_sizes.end()) 132 if (it == favicon_sizes.end())
134 return true; 133 return true;
135 } 134 }
136 return false; 135 return false;
137 } 136 }
138 137
139 // Returns true if at least one of |bitmap_results| is valid. 138 // Returns true if at least one of |bitmap_results| is valid.
140 bool HasValidResult( 139 bool HasValidResult(
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 if (UrlMatches(url, url_) && icon_type == favicon_base::FAVICON) { 309 if (UrlMatches(url, url_) && icon_type == favicon_base::FAVICON) {
311 if (!PageChangedSinceFaviconWasRequested()) 310 if (!PageChangedSinceFaviconWasRequested())
312 SetFaviconOnActivePage(icon_url, image); 311 SetFaviconOnActivePage(icon_url, image);
313 } 312 }
314 } 313 }
315 314
316 void FaviconHandler::SetFaviconOnActivePage(const std::vector< 315 void FaviconHandler::SetFaviconOnActivePage(const std::vector<
317 favicon_base::FaviconRawBitmapResult>& favicon_bitmap_results) { 316 favicon_base::FaviconRawBitmapResult>& favicon_bitmap_results) {
318 gfx::Image resized_image = favicon_base::SelectFaviconFramesFromPNGs( 317 gfx::Image resized_image = favicon_base::SelectFaviconFramesFromPNGs(
319 favicon_bitmap_results, 318 favicon_bitmap_results,
320 favicon_base::GetFaviconScaleFactors(), 319 favicon_base::GetFaviconScales(),
321 preferred_icon_size()); 320 preferred_icon_size());
322 // The history service sends back results for a single icon URL, so it does 321 // The history service sends back results for a single icon URL, so it does
323 // not matter which result we get the |icon_url| from. 322 // not matter which result we get the |icon_url| from.
324 const GURL icon_url = favicon_bitmap_results.empty() ? 323 const GURL icon_url = favicon_bitmap_results.empty() ?
325 GURL() : favicon_bitmap_results[0].icon_url; 324 GURL() : favicon_bitmap_results[0].icon_url;
326 SetFaviconOnActivePage(icon_url, resized_image); 325 SetFaviconOnActivePage(icon_url, resized_image);
327 } 326 }
328 327
329 void FaviconHandler::SetFaviconOnActivePage(const GURL& icon_url, 328 void FaviconHandler::SetFaviconOnActivePage(const GURL& icon_url,
330 const gfx::Image& image) { 329 const gfx::Image& image) {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 current_candidate()->icon_sizes[0]); 420 current_candidate()->icon_sizes[0]);
422 // Find largest bitmap if there is no one exactly matched. 421 // Find largest bitmap if there is no one exactly matched.
423 if (index == -1) { 422 if (index == -1) {
424 index = GetLargestSizeIndex(original_bitmap_sizes, 423 index = GetLargestSizeIndex(original_bitmap_sizes,
425 max_size * max_size); 424 max_size * max_size);
426 } 425 }
427 } 426 }
428 if (index != -1) 427 if (index != -1)
429 image_skia = gfx::ImageSkia(gfx::ImageSkiaRep(bitmaps[index], 1)); 428 image_skia = gfx::ImageSkia(gfx::ImageSkiaRep(bitmaps[index], 1));
430 } else { 429 } else {
431 std::vector<ui::ScaleFactor> scale_factors =
432 favicon_base::GetFaviconScaleFactors();
433 image_skia = SelectFaviconFrames(bitmaps, 430 image_skia = SelectFaviconFrames(bitmaps,
434 original_bitmap_sizes, 431 original_bitmap_sizes,
435 scale_factors, 432 favicon_base::GetFaviconScales(),
436 preferred_icon_size(), 433 preferred_icon_size(),
437 &score); 434 &score);
438 } 435 }
439 436
440 if (!image_skia.isNull()) { 437 if (!image_skia.isNull()) {
441 gfx::Image image(image_skia); 438 gfx::Image image(image_skia);
442 // The downloaded icon is still valid when there is no FaviconURL update 439 // The downloaded icon is still valid when there is no FaviconURL update
443 // during the downloading. 440 // during the downloading.
444 if (!bitmaps.empty()) { 441 if (!bitmaps.empty()) {
445 request_next_icon = !UpdateFaviconCandidate( 442 request_next_icon = !UpdateFaviconCandidate(
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 } else { 681 } else {
685 gfx::Size largest = i->icon_sizes[index]; 682 gfx::Size largest = i->icon_sizes[index];
686 i->icon_sizes.clear(); 683 i->icon_sizes.clear();
687 i->icon_sizes.push_back(largest); 684 i->icon_sizes.push_back(largest);
688 ++i; 685 ++i;
689 } 686 }
690 } 687 }
691 std::stable_sort(image_urls_.begin(), image_urls_.end(), 688 std::stable_sort(image_urls_.begin(), image_urls_.end(),
692 CompareIconSize); 689 CompareIconSize);
693 } 690 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698