Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 minimum_size_in_pixels, | |
| 1703 chrome::FaviconBitmapResult* favicon_bitmap_result) { | |
| 1704 DCHECK(favicon_bitmap_result); | |
| 1705 | |
| 1706 if (!db_ || !thumbnail_db_) | |
| 1707 return; | |
| 1708 | |
| 1709 TimeTicks beginning_time = TimeTicks::Now(); | |
| 1710 | |
| 1711 std::vector<IconMapping> icon_mappings; | |
| 1712 if (!thumbnail_db_->GetIconMappingsForPageURL(page_url, &icon_mappings) || | |
| 1713 icon_mappings.empty()) | |
| 1714 return; | |
| 1715 | |
| 1716 int required_icon_types = 0; | |
| 1717 for (std::vector<int>::const_iterator i = icon_types.begin(); | |
| 1718 i != icon_types.end(); ++i) { | |
| 1719 required_icon_types |= *i; | |
| 1720 } | |
| 1721 | |
| 1722 // Find the largest bitmap for each IconType placing in | |
| 1723 // |largest_favicon_bitmaps|. | |
| 1724 std::map<chrome::IconType, FaviconBitmap> largest_favicon_bitmaps; | |
| 1725 for (std::vector<IconMapping>::const_iterator i = icon_mappings.begin(); | |
| 1726 i != icon_mappings.end(); ++i) { | |
| 1727 if (!(i->icon_type & required_icon_types)) | |
| 1728 continue; | |
| 1729 std::vector<FaviconBitmapIDSize> bitmap_id_sizes; | |
| 1730 thumbnail_db_->GetFaviconBitmapIDSizes(i->icon_id, &bitmap_id_sizes); | |
| 1731 FaviconBitmap& largest = largest_favicon_bitmaps[i->icon_type]; | |
| 1732 for (std::vector<FaviconBitmapIDSize>::const_iterator j = | |
| 1733 bitmap_id_sizes.begin(); j != bitmap_id_sizes.end(); ++j) { | |
| 1734 if ((largest.icon_id == 0 && largest.bitmap_id == 0) || | |
|
pkotwicz
2013/10/17 22:54:17
Nit: Checking largest.bitmap_id == 0 should be suf
| |
| 1735 (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 } | |
| 1743 if (largest_favicon_bitmaps.empty()) | |
| 1744 return; | |
| 1745 | |
| 1746 // Find an icon which is larger than minimal_size_in_pixels in the order of | |
| 1747 // icon_types. | |
| 1748 FaviconBitmap largest_icon; | |
| 1749 for (std::vector<int>::const_iterator t = icon_types.begin(); | |
| 1750 t != icon_types.end(); ++t) { | |
| 1751 for (std::map<chrome::IconType, FaviconBitmap>::const_iterator f = | |
| 1752 largest_favicon_bitmaps.begin(); f != largest_favicon_bitmaps.end(); | |
| 1753 ++f) { | |
| 1754 if (f->first & *t && | |
|
pkotwicz
2013/10/17 22:54:17
Shouldn't you be checking largest_icon.bitmap_id =
michaelbai
2013/10/18 00:27:06
Correct, thanks
| |
| 1755 largest_icon.pixel_size.width() < f->second.pixel_size.width() && | |
| 1756 largest_icon.pixel_size.height() < f->second.pixel_size.height()) { | |
| 1757 largest_icon = f->second; | |
| 1758 } | |
| 1759 } | |
| 1760 if (largest_icon.pixel_size.width() > minimum_size_in_pixels && | |
| 1761 largest_icon.pixel_size.height() > minimum_size_in_pixels) | |
| 1762 break; | |
| 1763 } | |
| 1764 | |
| 1765 GURL icon_url; | |
| 1766 chrome::IconType icon_type; | |
| 1767 if (!thumbnail_db_->GetFaviconHeader(largest_icon.icon_id, &icon_url, | |
| 1768 &icon_type)) { | |
| 1769 return; | |
| 1770 } | |
| 1771 | |
| 1772 base::Time last_updated; | |
| 1773 chrome::FaviconBitmapResult bitmap_result; | |
| 1774 bitmap_result.icon_url = icon_url; | |
| 1775 bitmap_result.icon_type = icon_type; | |
| 1776 if (!thumbnail_db_->GetFaviconBitmap(largest_icon.bitmap_id, | |
| 1777 &last_updated, | |
| 1778 &bitmap_result.bitmap_data, | |
| 1779 &bitmap_result.pixel_size)) { | |
| 1780 return; | |
| 1781 } | |
| 1782 | |
| 1783 bitmap_result.expired = (Time::Now() - last_updated) > | |
| 1784 TimeDelta::FromDays(kFaviconRefetchDays); | |
| 1785 if (bitmap_result.is_valid()) | |
| 1786 *favicon_bitmap_result = bitmap_result; | |
| 1787 | |
| 1788 HISTOGRAM_TIMES("History.GetLargestFaviconForURL", | |
| 1789 TimeTicks::Now() - beginning_time); | |
| 1790 } | |
| 1791 | |
| 1699 void HistoryBackend::GetFaviconsForURL( | 1792 void HistoryBackend::GetFaviconsForURL( |
| 1700 const GURL& page_url, | 1793 const GURL& page_url, |
| 1701 int icon_types, | 1794 int icon_types, |
| 1702 int desired_size_in_dip, | 1795 int desired_size_in_dip, |
| 1703 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 1796 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
| 1704 std::vector<chrome::FaviconBitmapResult>* bitmap_results) { | 1797 std::vector<chrome::FaviconBitmapResult>* bitmap_results) { |
| 1705 DCHECK(bitmap_results); | 1798 DCHECK(bitmap_results); |
| 1706 GetFaviconsFromDB(page_url, icon_types, desired_size_in_dip, | 1799 GetFaviconsFromDB(page_url, icon_types, desired_size_in_dip, |
| 1707 desired_scale_factors, bitmap_results); | 1800 desired_scale_factors, bitmap_results); |
| 1708 } | 1801 } |
| (...skipping 1173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2882 int rank = kPageVisitStatsMaxTopSites; | 2975 int rank = kPageVisitStatsMaxTopSites; |
| 2883 std::map<GURL, int>::const_iterator it = most_visited_urls_map_.find(url); | 2976 std::map<GURL, int>::const_iterator it = most_visited_urls_map_.find(url); |
| 2884 if (it != most_visited_urls_map_.end()) | 2977 if (it != most_visited_urls_map_.end()) |
| 2885 rank = (*it).second; | 2978 rank = (*it).second; |
| 2886 UMA_HISTOGRAM_ENUMERATION("History.TopSitesVisitsByRank", | 2979 UMA_HISTOGRAM_ENUMERATION("History.TopSitesVisitsByRank", |
| 2887 rank, kPageVisitStatsMaxTopSites + 1); | 2980 rank, kPageVisitStatsMaxTopSites + 1); |
| 2888 } | 2981 } |
| 2889 #endif | 2982 #endif |
| 2890 | 2983 |
| 2891 } // namespace history | 2984 } // namespace history |
| OLD | NEW |