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 minimal_size_in_pixels, | |
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 TimeTicks beginning_time = TimeTicks::Now(); | |
1711 | |
1712 std::vector<IconMapping> icon_mappings; | |
1713 if (!thumbnail_db_->GetIconMappingsForPageURL(page_url, &icon_mappings)) | |
1714 return; | |
1715 | |
1716 if (icon_mappings.empty()) return; | |
1717 | |
1718 int required_icon_types = 0; | |
1719 for (std::vector<int>::const_iterator i = icon_types.begin(); | |
1720 i != icon_types.end(); ++i) { | |
1721 required_icon_types |= *i; | |
1722 } | |
1723 | |
1724 // Find the largest bitmap for in each icon_types. | |
sky
2013/10/16 13:27:16
Find the largest bitmap for each IconType placing
michaelbai
2013/10/16 18:17:05
Done.
| |
1725 std::map<chrome::IconType, FaviconBitmap> largest_favicon_bitmaps; | |
1726 for (std::vector<IconMapping>::const_iterator i = icon_mappings.begin(); | |
1727 i != icon_mappings.end(); ++i) { | |
1728 if (!(i->icon_type & required_icon_types)) continue; | |
sky
2013/10/16 13:27:16
no single line if.
michaelbai
2013/10/16 18:17:05
Done.
| |
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) || | |
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()) return; | |
sky
2013/10/16 13:27:16
no single line if.
michaelbai
2013/10/16 18:17:05
Done.
| |
1744 | |
1745 // Find an icon which is larger than minimal_size_in_pixels in the order of | |
1746 // icon_types. | |
1747 FaviconBitmap largest_icon; | |
1748 for (std::vector<int>::const_iterator t = icon_types.begin(); | |
1749 t != icon_types.end(); ++t) { | |
1750 for (std::map<chrome::IconType, FaviconBitmap>::const_iterator f = | |
1751 largest_favicon_bitmaps.begin(); f != largest_favicon_bitmaps.end(); | |
1752 ++f) { | |
1753 if (f->first & *t && | |
1754 largest_icon.pixel_size.width() < f->second.pixel_size.width() && | |
1755 largest_icon.pixel_size.height() < f->second.pixel_size.height()) | |
1756 largest_icon = f->second; | |
1757 } | |
1758 if (largest_icon.pixel_size.width() > minimal_size_in_pixels && | |
1759 largest_icon.pixel_size.height() > minimal_size_in_pixels) | |
1760 break; | |
1761 } | |
1762 | |
1763 GURL icon_url; | |
1764 chrome::IconType icon_type; | |
1765 if (!thumbnail_db_->GetFaviconHeader(largest_icon.icon_id, &icon_url, | |
1766 &icon_type)) { | |
1767 return; | |
1768 } | |
1769 | |
1770 base::Time last_updated; | |
1771 chrome::FaviconBitmapResult bitmap_result; | |
1772 bitmap_result.icon_url = icon_url; | |
1773 bitmap_result.icon_type = icon_type; | |
1774 if (!thumbnail_db_->GetFaviconBitmap(largest_icon.bitmap_id, | |
1775 &last_updated, | |
1776 &bitmap_result.bitmap_data, | |
1777 &bitmap_result.pixel_size)) { | |
1778 return; | |
1779 } | |
1780 | |
1781 bitmap_result.expired = (Time::Now() - last_updated) > | |
1782 TimeDelta::FromDays(kFaviconRefetchDays); | |
1783 if (bitmap_result.is_valid()) | |
1784 favicon_bitmap_results->push_back(bitmap_result); | |
sky
2013/10/16 13:27:16
As this only ever returns a single value, why the
michaelbai
2013/10/16 18:17:05
It because ChromeWebUIControllerFactory::GetInstan
| |
1785 | |
1786 HISTOGRAM_TIMES("History.GetLargestFaviconForURL", | |
1787 TimeTicks::Now() - beginning_time); | |
1788 } | |
1789 | |
1699 void HistoryBackend::GetFaviconsForURL( | 1790 void HistoryBackend::GetFaviconsForURL( |
1700 const GURL& page_url, | 1791 const GURL& page_url, |
1701 int icon_types, | 1792 int icon_types, |
1702 int desired_size_in_dip, | 1793 int desired_size_in_dip, |
1703 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 1794 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
1704 std::vector<chrome::FaviconBitmapResult>* bitmap_results) { | 1795 std::vector<chrome::FaviconBitmapResult>* bitmap_results) { |
1705 DCHECK(bitmap_results); | 1796 DCHECK(bitmap_results); |
1706 GetFaviconsFromDB(page_url, icon_types, desired_size_in_dip, | 1797 GetFaviconsFromDB(page_url, icon_types, desired_size_in_dip, |
1707 desired_scale_factors, bitmap_results); | 1798 desired_scale_factors, bitmap_results); |
1708 } | 1799 } |
(...skipping 1173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2882 int rank = kPageVisitStatsMaxTopSites; | 2973 int rank = kPageVisitStatsMaxTopSites; |
2883 std::map<GURL, int>::const_iterator it = most_visited_urls_map_.find(url); | 2974 std::map<GURL, int>::const_iterator it = most_visited_urls_map_.find(url); |
2884 if (it != most_visited_urls_map_.end()) | 2975 if (it != most_visited_urls_map_.end()) |
2885 rank = (*it).second; | 2976 rank = (*it).second; |
2886 UMA_HISTOGRAM_ENUMERATION("History.TopSitesVisitsByRank", | 2977 UMA_HISTOGRAM_ENUMERATION("History.TopSitesVisitsByRank", |
2887 rank, kPageVisitStatsMaxTopSites + 1); | 2978 rank, kPageVisitStatsMaxTopSites + 1); |
2888 } | 2979 } |
2889 #endif | 2980 #endif |
2890 | 2981 |
2891 } // namespace history | 2982 } // namespace history |
OLD | NEW |