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( | |
pkotwicz
2013/10/15 21:39:41
Nit: Order method in same order as in header file
michaelbai
2013/10/15 22:52:34
Changed the header file order.
On 2013/10/15 21:3
| |
1700 const GURL& page_url, | |
1701 const std::vector<int>& icon_types, | |
pkotwicz
2013/10/15 21:39:41
Given your current implementation, is there any re
michaelbai
2013/10/15 22:52:34
No, the icon_types could be
FAVICON
TOUCH_ICON |
pkotwicz
2013/10/16 16:59:41
I see your point.
In practice we only ever save on
michaelbai
2013/10/16 18:17:05
Don't like this, the TOUCH_ICON and PRECOMPOSED_TO
| |
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)) { | |
pkotwicz
2013/10/15 21:39:41
Nit: the braces are not necessary
michaelbai
2013/10/15 22:52:34
Done.
| |
1714 return; | |
1715 } | |
1716 if (icon_mappings.empty()) return; | |
pkotwicz
2013/10/15 21:39:41
Nit: Return on a new line
michaelbai
2013/10/15 22:52:34
Sky want to use this style in his previous comment
sky
2013/10/16 13:27:15
Not sure what you mean here. I do not like single
| |
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 each favicon in icon_types. | |
pkotwicz
2013/10/15 21:39:41
How about: "Find the largest favicon bitmap for ea
michaelbai
2013/10/15 22:52:34
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; | |
pkotwicz
2013/10/15 21:39:41
Nit: "continue" on a new line
michaelbai
2013/10/15 22:52:34
ditto
On 2013/10/15 21:39:41, pkotwicz wrote:
| |
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.pixel_size.width() < j->pixel_size.width() && | |
1735 largest.pixel_size.height() < j->pixel_size.height()) { | |
1736 largest.icon_id = i->icon_id; | |
1737 largest.bitmap_id = j->bitmap_id; | |
1738 largest.pixel_size = j->pixel_size; | |
1739 } | |
1740 } | |
1741 } | |
1742 if (largest_favicon_bitmaps.empty()) return; | |
pkotwicz
2013/10/15 21:39:41
Nit: return on a separate line
michaelbai
2013/10/15 22:52:34
ditto
On 2013/10/15 21:39:41, pkotwicz wrote:
| |
1743 | |
1744 // Find an icon which is larger than minimal_size_in_pixels in the order of | |
1745 // icon_types. | |
1746 FaviconBitmap largest_icon; | |
1747 for (std::vector<int>::const_iterator t = icon_types.begin(); | |
1748 t != icon_types.end(); ++t) { | |
1749 for (std::map<chrome::IconType, FaviconBitmap>::const_iterator f = | |
1750 largest_favicon_bitmaps.begin(); f != largest_favicon_bitmaps.end(); | |
1751 ++f) { | |
1752 if (f->first & *t && | |
1753 largest_icon.pixel_size.width() < f->second.pixel_size.width() && | |
1754 largest_icon.pixel_size.height() < f->second.pixel_size.height()) | |
1755 largest_icon = f->second; | |
1756 } | |
1757 if (largest_icon.pixel_size.width() > minimal_size_in_pixels && | |
1758 largest_icon.pixel_size.height() > minimal_size_in_pixels) | |
1759 break; | |
1760 } | |
1761 if (largest_icon.pixel_size.width() == 0 || | |
1762 largest_icon.pixel_size.height() == 0) { | |
pkotwicz
2013/10/15 21:39:41
This is wrong. A pixel width and height in the dat
michaelbai
2013/10/15 22:52:34
In which situation, it is unknown?
On 2013/10/15
pkotwicz
2013/10/16 16:59:41
FaviconSQLHandler::Insert() is an example.
michaelbai
2013/10/16 18:17:05
Is this the only case?
On 2013/10/16 16:59:41, pk
pkotwicz
2013/10/16 18:28:24
HistoryBackend::SetImportedFavicons() is another c
| |
1763 return; | |
1764 } | |
1765 | |
1766 GURL icon_url; | |
1767 chrome::IconType icon_type; | |
1768 if (!thumbnail_db_->GetFaviconHeader(largest_icon.icon_id, &icon_url, | |
1769 &icon_type)) { | |
1770 return; | |
1771 } | |
1772 | |
1773 base::Time last_updated; | |
1774 chrome::FaviconBitmapResult bitmap_result; | |
1775 bitmap_result.icon_url = icon_url; | |
1776 bitmap_result.icon_type = icon_type; | |
1777 if (!thumbnail_db_->GetFaviconBitmap(largest_icon.bitmap_id, | |
1778 &last_updated, | |
1779 &bitmap_result.bitmap_data, | |
1780 &bitmap_result.pixel_size)) { | |
1781 return; | |
1782 } | |
1783 | |
1784 bitmap_result.expired = (Time::Now() - last_updated) > | |
1785 TimeDelta::FromDays(kFaviconRefetchDays); | |
1786 if (bitmap_result.is_valid()) | |
1787 favicon_bitmap_results->push_back(bitmap_result); | |
1788 | |
1789 HISTOGRAM_TIMES("History.GetLargestFaviconForURL", | |
1790 TimeTicks::Now() - beginning_time); | |
1791 } | |
1792 | |
1699 void HistoryBackend::GetFaviconsForURL( | 1793 void HistoryBackend::GetFaviconsForURL( |
1700 const GURL& page_url, | 1794 const GURL& page_url, |
1701 int icon_types, | 1795 int icon_types, |
1702 int desired_size_in_dip, | 1796 int desired_size_in_dip, |
1703 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 1797 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
1704 std::vector<chrome::FaviconBitmapResult>* bitmap_results) { | 1798 std::vector<chrome::FaviconBitmapResult>* bitmap_results) { |
1705 DCHECK(bitmap_results); | 1799 DCHECK(bitmap_results); |
1706 GetFaviconsFromDB(page_url, icon_types, desired_size_in_dip, | 1800 GetFaviconsFromDB(page_url, icon_types, desired_size_in_dip, |
1707 desired_scale_factors, bitmap_results); | 1801 desired_scale_factors, bitmap_results); |
1708 } | 1802 } |
(...skipping 1173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2882 int rank = kPageVisitStatsMaxTopSites; | 2976 int rank = kPageVisitStatsMaxTopSites; |
2883 std::map<GURL, int>::const_iterator it = most_visited_urls_map_.find(url); | 2977 std::map<GURL, int>::const_iterator it = most_visited_urls_map_.find(url); |
2884 if (it != most_visited_urls_map_.end()) | 2978 if (it != most_visited_urls_map_.end()) |
2885 rank = (*it).second; | 2979 rank = (*it).second; |
2886 UMA_HISTOGRAM_ENUMERATION("History.TopSitesVisitsByRank", | 2980 UMA_HISTOGRAM_ENUMERATION("History.TopSitesVisitsByRank", |
2887 rank, kPageVisitStatsMaxTopSites + 1); | 2981 rank, kPageVisitStatsMaxTopSites + 1); |
2888 } | 2982 } |
2889 #endif | 2983 #endif |
2890 | 2984 |
2891 } // namespace history | 2985 } // namespace history |
OLD | NEW |