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

Side by Side Diff: chrome/browser/history/history_backend.cc

Issue 26563004: Find Favicon in priority of icon_type. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add a new method Created 7 years, 2 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
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/history/history_backend.h" 5 #include "chrome/browser/history/history_backend.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <list> 9 #include <list>
10 #include <map> 10 #include <map>
(...skipping 1678 matching lines...) Expand 10 before | Expand all | Expand 10 after
1689 const std::vector<GURL>& icon_urls, 1689 const std::vector<GURL>& icon_urls,
1690 int icon_types, 1690 int icon_types,
1691 int desired_size_in_dip, 1691 int desired_size_in_dip,
1692 const std::vector<ui::ScaleFactor>& desired_scale_factors, 1692 const std::vector<ui::ScaleFactor>& desired_scale_factors,
1693 std::vector<chrome::FaviconBitmapResult>* bitmap_results) { 1693 std::vector<chrome::FaviconBitmapResult>* bitmap_results) {
1694 UpdateFaviconMappingsAndFetchImpl(NULL, icon_urls, icon_types, 1694 UpdateFaviconMappingsAndFetchImpl(NULL, icon_urls, icon_types,
1695 desired_size_in_dip, desired_scale_factors, 1695 desired_size_in_dip, desired_scale_factors,
1696 bitmap_results); 1696 bitmap_results);
1697 } 1697 }
1698 1698
1699 void HistoryBackend::GetLargestFaviconForURL(
1700 const GURL& page_url,
1701 const std::vector<int>& icon_types,
1702 int minimal_size_in_pixel,
1703 std::vector<chrome::FaviconBitmapResult>* favicon_bitmap_results) {
1704 DCHECK(favicon_bitmap_results);
1705 favicon_bitmap_results->clear();
1706
1707 if (!db_ || !thumbnail_db_)
1708 return;
1709
1710 // Time the query.
sky 2013/10/15 15:03:47 nit: remove comment, just describes what the code
michaelbai 2013/10/15 19:36:31 Done.
1711 TimeTicks beginning_time = TimeTicks::Now();
1712
1713 int required_icon_types = 0;
1714 for (std::vector<int>::const_iterator i = icon_types.begin();
1715 i != icon_types.end(); ++i) {
1716 required_icon_types |= *i;
1717 }
1718
1719 std::vector<IconMapping> icon_mappings;
1720 if (!thumbnail_db_->GetAllIconMappingsForPageURL(page_url,
1721 required_icon_types, &icon_mappings)) {
1722 return;
1723 }
1724 if (icon_mappings.empty())
sky 2013/10/15 15:03:47 nit: merge with if on 1721.
michaelbai 2013/10/15 19:36:31 Done.
1725 return;
1726
1727 std::map<chrome::IconType, FaviconBitmap> largest_favicon_bitmaps;
sky 2013/10/15 15:03:47 nit: add comments describing what you're doing her
michaelbai 2013/10/15 19:36:31 Done.
1728 for (std::vector<IconMapping>::const_iterator i = icon_mappings.begin();
1729 i != icon_mappings.end(); ++i) {
1730 std::vector<FaviconBitmapIDSize> bitmap_id_sizes;
1731 thumbnail_db_->GetFaviconBitmapIDSizes(i->icon_id, &bitmap_id_sizes);
1732 FaviconBitmap largest = largest_favicon_bitmaps[i->icon_type];
sky 2013/10/15 15:03:47 This should be a ref. That way you don't need 1742
michaelbai 2013/10/15 19:36:31 Done.
1733 for (std::vector<FaviconBitmapIDSize>::const_iterator j =
pkotwicz 2013/10/15 16:44:33 largest will not be populated if all of the pixel
michaelbai 2013/10/15 19:36:31 added if (largest_icon.pixel_size.width() == 0 ..
1734 bitmap_id_sizes.begin(); j != bitmap_id_sizes.end(); ++j) {
1735 if (largest.pixel_size.width() < j->pixel_size.width() &&
1736 largest.pixel_size.height() < j->pixel_size.height()) {
1737 largest.icon_id = i->icon_id;
1738 largest.bitmap_id = j->bitmap_id;
1739 largest.pixel_size = j->pixel_size;
1740 }
1741 }
1742 largest_favicon_bitmaps[i->icon_type] = largest;
1743 }
1744
1745 FaviconBitmap largest_icon;
1746 for (std::vector<int>::const_iterator t = icon_types.begin();
1747 t != icon_types.end(); ++t) {
1748 for (std::map<chrome::IconType, FaviconBitmap>::const_iterator f =
1749 largest_favicon_bitmaps.begin(); f != largest_favicon_bitmaps.end();
1750 ++f) {
1751 if (f->first & *t &&
1752 largest_icon.pixel_size.width() < f->second.pixel_size.width() &&
1753 largest_icon.pixel_size.height() < f->second.pixel_size.height())
1754 largest_icon = f->second;
1755 }
1756 if (largest_icon.pixel_size.width() > minimal_size_in_pixel &&
1757 largest_icon.pixel_size.height() > minimal_size_in_pixel)
1758 break;
1759 }
1760
1761 // Construct FaviconBitmapResults.
sky 2013/10/15 15:03:47 nit: this comment isn't helpful, especially when b
michaelbai 2013/10/15 19:36:31 Done.
1762 GURL icon_url;
1763 chrome::IconType icon_type;
1764 if (!thumbnail_db_->GetFaviconHeader(largest_icon.icon_id, &icon_url,
sky 2013/10/15 15:03:47 Might it be possible that you've never set largest
michaelbai 2013/10/15 19:36:31 added if (largest_icon.pixel_size.width() == 0 .
1765 &icon_type)) {
1766 return;
1767 }
1768
1769 base::Time last_updated;
1770 chrome::FaviconBitmapResult bitmap_result;
1771 bitmap_result.icon_url = icon_url;
1772 bitmap_result.icon_type = icon_type;
1773 if (!thumbnail_db_->GetFaviconBitmap(largest_icon.bitmap_id,
1774 &last_updated,
1775 &bitmap_result.bitmap_data,
1776 &bitmap_result.pixel_size)) {
1777 return;
1778 }
1779
1780 bitmap_result.expired = (Time::Now() - last_updated) >
1781 TimeDelta::FromDays(kFaviconRefetchDays);
1782 if (bitmap_result.is_valid())
1783 favicon_bitmap_results->push_back(bitmap_result);
1784
1785 HISTOGRAM_TIMES("History.GetLargestFaviconForURL",
1786 TimeTicks::Now() - beginning_time);
1787 }
1788
1699 void HistoryBackend::GetFaviconsForURL( 1789 void HistoryBackend::GetFaviconsForURL(
1700 const GURL& page_url, 1790 const GURL& page_url,
1701 int icon_types, 1791 int icon_types,
1702 int desired_size_in_dip, 1792 int desired_size_in_dip,
1703 const std::vector<ui::ScaleFactor>& desired_scale_factors, 1793 const std::vector<ui::ScaleFactor>& desired_scale_factors,
1704 std::vector<chrome::FaviconBitmapResult>* bitmap_results) { 1794 std::vector<chrome::FaviconBitmapResult>* bitmap_results) {
1705 DCHECK(bitmap_results); 1795 DCHECK(bitmap_results);
1706 GetFaviconsFromDB(page_url, icon_types, desired_size_in_dip, 1796 GetFaviconsFromDB(page_url, icon_types, desired_size_in_dip,
1707 desired_scale_factors, bitmap_results); 1797 desired_scale_factors, bitmap_results);
1708 } 1798 }
(...skipping 1173 matching lines...) Expand 10 before | Expand all | Expand 10 after
2882 int rank = kPageVisitStatsMaxTopSites; 2972 int rank = kPageVisitStatsMaxTopSites;
2883 std::map<GURL, int>::const_iterator it = most_visited_urls_map_.find(url); 2973 std::map<GURL, int>::const_iterator it = most_visited_urls_map_.find(url);
2884 if (it != most_visited_urls_map_.end()) 2974 if (it != most_visited_urls_map_.end())
2885 rank = (*it).second; 2975 rank = (*it).second;
2886 UMA_HISTOGRAM_ENUMERATION("History.TopSitesVisitsByRank", 2976 UMA_HISTOGRAM_ENUMERATION("History.TopSitesVisitsByRank",
2887 rank, kPageVisitStatsMaxTopSites + 1); 2977 rank, kPageVisitStatsMaxTopSites + 1);
2888 } 2978 }
2889 #endif 2979 #endif
2890 2980
2891 } // namespace history 2981 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698