| 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 1554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1565 } | 1565 } |
| 1566 UMA_HISTOGRAM_COUNTS("History.DeleteFTSIndexDatabases", | 1566 UMA_HISTOGRAM_COUNTS("History.DeleteFTSIndexDatabases", |
| 1567 num_databases_deleted); | 1567 num_databases_deleted); |
| 1568 } | 1568 } |
| 1569 | 1569 |
| 1570 void HistoryBackend::GetFavicons( | 1570 void HistoryBackend::GetFavicons( |
| 1571 const std::vector<GURL>& icon_urls, | 1571 const std::vector<GURL>& icon_urls, |
| 1572 int icon_types, | 1572 int icon_types, |
| 1573 int desired_size_in_dip, | 1573 int desired_size_in_dip, |
| 1574 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 1574 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
| 1575 std::vector<favicon_base::FaviconBitmapResult>* bitmap_results) { | 1575 std::vector<favicon_base::FaviconRawBitmapResult>* bitmap_results) { |
| 1576 UpdateFaviconMappingsAndFetchImpl(NULL, icon_urls, icon_types, | 1576 UpdateFaviconMappingsAndFetchImpl(NULL, icon_urls, icon_types, |
| 1577 desired_size_in_dip, desired_scale_factors, | 1577 desired_size_in_dip, desired_scale_factors, |
| 1578 bitmap_results); | 1578 bitmap_results); |
| 1579 } | 1579 } |
| 1580 | 1580 |
| 1581 void HistoryBackend::GetLargestFaviconForURL( | 1581 void HistoryBackend::GetLargestFaviconForURL( |
| 1582 const GURL& page_url, | 1582 const GURL& page_url, |
| 1583 const std::vector<int>& icon_types, | 1583 const std::vector<int>& icon_types, |
| 1584 int minimum_size_in_pixels, | 1584 int minimum_size_in_pixels, |
| 1585 favicon_base::FaviconBitmapResult* favicon_bitmap_result) { | 1585 favicon_base::FaviconRawBitmapResult* favicon_bitmap_result) { |
| 1586 DCHECK(favicon_bitmap_result); | 1586 DCHECK(favicon_bitmap_result); |
| 1587 | 1587 |
| 1588 if (!db_ || !thumbnail_db_) | 1588 if (!db_ || !thumbnail_db_) |
| 1589 return; | 1589 return; |
| 1590 | 1590 |
| 1591 TimeTicks beginning_time = TimeTicks::Now(); | 1591 TimeTicks beginning_time = TimeTicks::Now(); |
| 1592 | 1592 |
| 1593 std::vector<IconMapping> icon_mappings; | 1593 std::vector<IconMapping> icon_mappings; |
| 1594 if (!thumbnail_db_->GetIconMappingsForPageURL(page_url, &icon_mappings) || | 1594 if (!thumbnail_db_->GetIconMappingsForPageURL(page_url, &icon_mappings) || |
| 1595 icon_mappings.empty()) | 1595 icon_mappings.empty()) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1647 } | 1647 } |
| 1648 | 1648 |
| 1649 GURL icon_url; | 1649 GURL icon_url; |
| 1650 favicon_base::IconType icon_type; | 1650 favicon_base::IconType icon_type; |
| 1651 if (!thumbnail_db_->GetFaviconHeader(largest_icon.icon_id, &icon_url, | 1651 if (!thumbnail_db_->GetFaviconHeader(largest_icon.icon_id, &icon_url, |
| 1652 &icon_type)) { | 1652 &icon_type)) { |
| 1653 return; | 1653 return; |
| 1654 } | 1654 } |
| 1655 | 1655 |
| 1656 base::Time last_updated; | 1656 base::Time last_updated; |
| 1657 favicon_base::FaviconBitmapResult bitmap_result; | 1657 favicon_base::FaviconRawBitmapResult bitmap_result; |
| 1658 bitmap_result.icon_url = icon_url; | 1658 bitmap_result.icon_url = icon_url; |
| 1659 bitmap_result.icon_type = icon_type; | 1659 bitmap_result.icon_type = icon_type; |
| 1660 if (!thumbnail_db_->GetFaviconBitmap(largest_icon.bitmap_id, | 1660 if (!thumbnail_db_->GetFaviconBitmap(largest_icon.bitmap_id, |
| 1661 &last_updated, | 1661 &last_updated, |
| 1662 &bitmap_result.bitmap_data, | 1662 &bitmap_result.bitmap_data, |
| 1663 &bitmap_result.pixel_size)) { | 1663 &bitmap_result.pixel_size)) { |
| 1664 return; | 1664 return; |
| 1665 } | 1665 } |
| 1666 | 1666 |
| 1667 bitmap_result.expired = (Time::Now() - last_updated) > | 1667 bitmap_result.expired = (Time::Now() - last_updated) > |
| 1668 TimeDelta::FromDays(kFaviconRefetchDays); | 1668 TimeDelta::FromDays(kFaviconRefetchDays); |
| 1669 if (bitmap_result.is_valid()) | 1669 if (bitmap_result.is_valid()) |
| 1670 *favicon_bitmap_result = bitmap_result; | 1670 *favicon_bitmap_result = bitmap_result; |
| 1671 | 1671 |
| 1672 HISTOGRAM_TIMES("History.GetLargestFaviconForURL", | 1672 HISTOGRAM_TIMES("History.GetLargestFaviconForURL", |
| 1673 TimeTicks::Now() - beginning_time); | 1673 TimeTicks::Now() - beginning_time); |
| 1674 } | 1674 } |
| 1675 | 1675 |
| 1676 void HistoryBackend::GetFaviconsForURL( | 1676 void HistoryBackend::GetFaviconsForURL( |
| 1677 const GURL& page_url, | 1677 const GURL& page_url, |
| 1678 int icon_types, | 1678 int icon_types, |
| 1679 int desired_size_in_dip, | 1679 int desired_size_in_dip, |
| 1680 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 1680 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
| 1681 std::vector<favicon_base::FaviconBitmapResult>* bitmap_results) { | 1681 std::vector<favicon_base::FaviconRawBitmapResult>* bitmap_results) { |
| 1682 DCHECK(bitmap_results); | 1682 DCHECK(bitmap_results); |
| 1683 GetFaviconsFromDB(page_url, icon_types, desired_size_in_dip, | 1683 GetFaviconsFromDB(page_url, icon_types, desired_size_in_dip, |
| 1684 desired_scale_factors, bitmap_results); | 1684 desired_scale_factors, bitmap_results); |
| 1685 } | 1685 } |
| 1686 | 1686 |
| 1687 void HistoryBackend::GetFaviconForID( | 1687 void HistoryBackend::GetFaviconForID( |
| 1688 favicon_base::FaviconID favicon_id, | 1688 favicon_base::FaviconID favicon_id, |
| 1689 int desired_size_in_dip, | 1689 int desired_size_in_dip, |
| 1690 ui::ScaleFactor desired_scale_factor, | 1690 ui::ScaleFactor desired_scale_factor, |
| 1691 std::vector<favicon_base::FaviconBitmapResult>* bitmap_results) { | 1691 std::vector<favicon_base::FaviconRawBitmapResult>* bitmap_results) { |
| 1692 std::vector<favicon_base::FaviconID> favicon_ids; | 1692 std::vector<favicon_base::FaviconID> favicon_ids; |
| 1693 favicon_ids.push_back(favicon_id); | 1693 favicon_ids.push_back(favicon_id); |
| 1694 std::vector<ui::ScaleFactor> desired_scale_factors; | 1694 std::vector<ui::ScaleFactor> desired_scale_factors; |
| 1695 desired_scale_factors.push_back(desired_scale_factor); | 1695 desired_scale_factors.push_back(desired_scale_factor); |
| 1696 | 1696 |
| 1697 // Get results from DB. | 1697 // Get results from DB. |
| 1698 GetFaviconBitmapResultsForBestMatch(favicon_ids, | 1698 GetFaviconBitmapResultsForBestMatch(favicon_ids, |
| 1699 desired_size_in_dip, | 1699 desired_size_in_dip, |
| 1700 desired_scale_factors, | 1700 desired_scale_factors, |
| 1701 bitmap_results); | 1701 bitmap_results); |
| 1702 } | 1702 } |
| 1703 | 1703 |
| 1704 void HistoryBackend::UpdateFaviconMappingsAndFetch( | 1704 void HistoryBackend::UpdateFaviconMappingsAndFetch( |
| 1705 const GURL& page_url, | 1705 const GURL& page_url, |
| 1706 const std::vector<GURL>& icon_urls, | 1706 const std::vector<GURL>& icon_urls, |
| 1707 int icon_types, | 1707 int icon_types, |
| 1708 int desired_size_in_dip, | 1708 int desired_size_in_dip, |
| 1709 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 1709 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
| 1710 std::vector<favicon_base::FaviconBitmapResult>* bitmap_results) { | 1710 std::vector<favicon_base::FaviconRawBitmapResult>* bitmap_results) { |
| 1711 UpdateFaviconMappingsAndFetchImpl(&page_url, icon_urls, icon_types, | 1711 UpdateFaviconMappingsAndFetchImpl(&page_url, icon_urls, icon_types, |
| 1712 desired_size_in_dip, desired_scale_factors, | 1712 desired_size_in_dip, desired_scale_factors, |
| 1713 bitmap_results); | 1713 bitmap_results); |
| 1714 } | 1714 } |
| 1715 | 1715 |
| 1716 void HistoryBackend::MergeFavicon( | 1716 void HistoryBackend::MergeFavicon( |
| 1717 const GURL& page_url, | 1717 const GURL& page_url, |
| 1718 const GURL& icon_url, | 1718 const GURL& icon_url, |
| 1719 favicon_base::IconType icon_type, | 1719 favicon_base::IconType icon_type, |
| 1720 scoped_refptr<base::RefCountedMemory> bitmap_data, | 1720 scoped_refptr<base::RefCountedMemory> bitmap_data, |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1850 } | 1850 } |
| 1851 | 1851 |
| 1852 if (mapping_changed || !bitmap_identical) | 1852 if (mapping_changed || !bitmap_identical) |
| 1853 SendFaviconChangedNotificationForPageAndRedirects(page_url); | 1853 SendFaviconChangedNotificationForPageAndRedirects(page_url); |
| 1854 ScheduleCommit(); | 1854 ScheduleCommit(); |
| 1855 } | 1855 } |
| 1856 | 1856 |
| 1857 void HistoryBackend::SetFavicons( | 1857 void HistoryBackend::SetFavicons( |
| 1858 const GURL& page_url, | 1858 const GURL& page_url, |
| 1859 favicon_base::IconType icon_type, | 1859 favicon_base::IconType icon_type, |
| 1860 const std::vector<favicon_base::FaviconBitmapData>& favicon_bitmap_data) { | 1860 const std::vector<favicon_base::FaviconRawBitmapData>& |
| 1861 favicon_bitmap_data) { |
| 1861 if (!thumbnail_db_ || !db_) | 1862 if (!thumbnail_db_ || !db_) |
| 1862 return; | 1863 return; |
| 1863 | 1864 |
| 1864 DCHECK(ValidateSetFaviconsParams(favicon_bitmap_data)); | 1865 DCHECK(ValidateSetFaviconsParams(favicon_bitmap_data)); |
| 1865 | 1866 |
| 1866 // Build map of FaviconBitmapData for each icon url. | 1867 // Build map of FaviconRawBitmapData for each icon url. |
| 1867 typedef std::map<GURL, std::vector<favicon_base::FaviconBitmapData> > | 1868 typedef std::map<GURL, std::vector<favicon_base::FaviconRawBitmapData> > |
| 1868 BitmapDataByIconURL; | 1869 BitmapDataByIconURL; |
| 1869 BitmapDataByIconURL grouped_by_icon_url; | 1870 BitmapDataByIconURL grouped_by_icon_url; |
| 1870 for (size_t i = 0; i < favicon_bitmap_data.size(); ++i) { | 1871 for (size_t i = 0; i < favicon_bitmap_data.size(); ++i) { |
| 1871 const GURL& icon_url = favicon_bitmap_data[i].icon_url; | 1872 const GURL& icon_url = favicon_bitmap_data[i].icon_url; |
| 1872 grouped_by_icon_url[icon_url].push_back(favicon_bitmap_data[i]); | 1873 grouped_by_icon_url[icon_url].push_back(favicon_bitmap_data[i]); |
| 1873 } | 1874 } |
| 1874 | 1875 |
| 1875 // Track whether the method modifies or creates any favicon bitmaps, favicons | 1876 // Track whether the method modifies or creates any favicon bitmaps, favicons |
| 1876 // or icon mappings. | 1877 // or icon mappings. |
| 1877 bool data_modified = false; | 1878 bool data_modified = false; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2003 changed_details.PassAs<HistoryDetails>()); | 2004 changed_details.PassAs<HistoryDetails>()); |
| 2004 } | 2005 } |
| 2005 } | 2006 } |
| 2006 | 2007 |
| 2007 void HistoryBackend::UpdateFaviconMappingsAndFetchImpl( | 2008 void HistoryBackend::UpdateFaviconMappingsAndFetchImpl( |
| 2008 const GURL* page_url, | 2009 const GURL* page_url, |
| 2009 const std::vector<GURL>& icon_urls, | 2010 const std::vector<GURL>& icon_urls, |
| 2010 int icon_types, | 2011 int icon_types, |
| 2011 int desired_size_in_dip, | 2012 int desired_size_in_dip, |
| 2012 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 2013 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
| 2013 std::vector<favicon_base::FaviconBitmapResult>* bitmap_results) { | 2014 std::vector<favicon_base::FaviconRawBitmapResult>* bitmap_results) { |
| 2014 // If |page_url| is specified, |icon_types| must be either a single icon | 2015 // If |page_url| is specified, |icon_types| must be either a single icon |
| 2015 // type or icon types which are equivalent. | 2016 // type or icon types which are equivalent. |
| 2016 DCHECK(!page_url || icon_types == favicon_base::FAVICON || | 2017 DCHECK(!page_url || icon_types == favicon_base::FAVICON || |
| 2017 icon_types == favicon_base::TOUCH_ICON || | 2018 icon_types == favicon_base::TOUCH_ICON || |
| 2018 icon_types == favicon_base::TOUCH_PRECOMPOSED_ICON || | 2019 icon_types == favicon_base::TOUCH_PRECOMPOSED_ICON || |
| 2019 icon_types == | 2020 icon_types == |
| 2020 (favicon_base::TOUCH_ICON | favicon_base::TOUCH_PRECOMPOSED_ICON)); | 2021 (favicon_base::TOUCH_ICON | favicon_base::TOUCH_PRECOMPOSED_ICON)); |
| 2021 bitmap_results->clear(); | 2022 bitmap_results->clear(); |
| 2022 | 2023 |
| 2023 if (!thumbnail_db_) { | 2024 if (!thumbnail_db_) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2059 ScheduleCommit(); | 2060 ScheduleCommit(); |
| 2060 } | 2061 } |
| 2061 } | 2062 } |
| 2062 | 2063 |
| 2063 GetFaviconBitmapResultsForBestMatch(favicon_ids, desired_size_in_dip, | 2064 GetFaviconBitmapResultsForBestMatch(favicon_ids, desired_size_in_dip, |
| 2064 desired_scale_factors, bitmap_results); | 2065 desired_scale_factors, bitmap_results); |
| 2065 } | 2066 } |
| 2066 | 2067 |
| 2067 void HistoryBackend::SetFaviconBitmaps( | 2068 void HistoryBackend::SetFaviconBitmaps( |
| 2068 favicon_base::FaviconID icon_id, | 2069 favicon_base::FaviconID icon_id, |
| 2069 const std::vector<favicon_base::FaviconBitmapData>& favicon_bitmap_data, | 2070 const std::vector<favicon_base::FaviconRawBitmapData>& favicon_bitmap_data, |
| 2070 bool* favicon_bitmaps_changed) { | 2071 bool* favicon_bitmaps_changed) { |
| 2071 if (favicon_bitmaps_changed) | 2072 if (favicon_bitmaps_changed) |
| 2072 *favicon_bitmaps_changed = false; | 2073 *favicon_bitmaps_changed = false; |
| 2073 | 2074 |
| 2074 std::vector<FaviconBitmapIDSize> bitmap_id_sizes; | 2075 std::vector<FaviconBitmapIDSize> bitmap_id_sizes; |
| 2075 thumbnail_db_->GetFaviconBitmapIDSizes(icon_id, &bitmap_id_sizes); | 2076 thumbnail_db_->GetFaviconBitmapIDSizes(icon_id, &bitmap_id_sizes); |
| 2076 | 2077 |
| 2077 std::vector<favicon_base::FaviconBitmapData> to_add = favicon_bitmap_data; | 2078 std::vector<favicon_base::FaviconRawBitmapData> to_add = favicon_bitmap_data; |
| 2078 | 2079 |
| 2079 for (size_t i = 0; i < bitmap_id_sizes.size(); ++i) { | 2080 for (size_t i = 0; i < bitmap_id_sizes.size(); ++i) { |
| 2080 const gfx::Size& pixel_size = bitmap_id_sizes[i].pixel_size; | 2081 const gfx::Size& pixel_size = bitmap_id_sizes[i].pixel_size; |
| 2081 std::vector<favicon_base::FaviconBitmapData>::iterator match_it = | 2082 std::vector<favicon_base::FaviconRawBitmapData>::iterator match_it = |
| 2082 to_add.end(); | 2083 to_add.end(); |
| 2083 for (std::vector<favicon_base::FaviconBitmapData>::iterator it = | 2084 for (std::vector<favicon_base::FaviconRawBitmapData>::iterator it = |
| 2084 to_add.begin(); | 2085 to_add.begin(); |
| 2085 it != to_add.end(); | 2086 it != to_add.end(); |
| 2086 ++it) { | 2087 ++it) { |
| 2087 if (it->pixel_size == pixel_size) { | 2088 if (it->pixel_size == pixel_size) { |
| 2088 match_it = it; | 2089 match_it = it; |
| 2089 break; | 2090 break; |
| 2090 } | 2091 } |
| 2091 } | 2092 } |
| 2092 | 2093 |
| 2093 FaviconBitmapID bitmap_id = bitmap_id_sizes[i].bitmap_id; | 2094 FaviconBitmapID bitmap_id = bitmap_id_sizes[i].bitmap_id; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 2116 for (size_t i = 0; i < to_add.size(); ++i) { | 2117 for (size_t i = 0; i < to_add.size(); ++i) { |
| 2117 thumbnail_db_->AddFaviconBitmap(icon_id, to_add[i].bitmap_data, | 2118 thumbnail_db_->AddFaviconBitmap(icon_id, to_add[i].bitmap_data, |
| 2118 base::Time::Now(), to_add[i].pixel_size); | 2119 base::Time::Now(), to_add[i].pixel_size); |
| 2119 | 2120 |
| 2120 if (favicon_bitmaps_changed) | 2121 if (favicon_bitmaps_changed) |
| 2121 *favicon_bitmaps_changed = true; | 2122 *favicon_bitmaps_changed = true; |
| 2122 } | 2123 } |
| 2123 } | 2124 } |
| 2124 | 2125 |
| 2125 bool HistoryBackend::ValidateSetFaviconsParams(const std::vector< | 2126 bool HistoryBackend::ValidateSetFaviconsParams(const std::vector< |
| 2126 favicon_base::FaviconBitmapData>& favicon_bitmap_data) const { | 2127 favicon_base::FaviconRawBitmapData>& favicon_bitmap_data) const { |
| 2127 typedef std::map<GURL, size_t> BitmapsPerIconURL; | 2128 typedef std::map<GURL, size_t> BitmapsPerIconURL; |
| 2128 BitmapsPerIconURL num_bitmaps_per_icon_url; | 2129 BitmapsPerIconURL num_bitmaps_per_icon_url; |
| 2129 for (size_t i = 0; i < favicon_bitmap_data.size(); ++i) { | 2130 for (size_t i = 0; i < favicon_bitmap_data.size(); ++i) { |
| 2130 if (!favicon_bitmap_data[i].bitmap_data.get()) | 2131 if (!favicon_bitmap_data[i].bitmap_data.get()) |
| 2131 return false; | 2132 return false; |
| 2132 | 2133 |
| 2133 const GURL& icon_url = favicon_bitmap_data[i].icon_url; | 2134 const GURL& icon_url = favicon_bitmap_data[i].icon_url; |
| 2134 if (!num_bitmaps_per_icon_url.count(icon_url)) | 2135 if (!num_bitmaps_per_icon_url.count(icon_url)) |
| 2135 num_bitmaps_per_icon_url[icon_url] = 1u; | 2136 num_bitmaps_per_icon_url[icon_url] = 1u; |
| 2136 else | 2137 else |
| (...skipping 23 matching lines...) Expand all Loading... |
| 2160 &original_bitmap_data, | 2161 &original_bitmap_data, |
| 2161 NULL); | 2162 NULL); |
| 2162 return new_bitmap_data->Equals(original_bitmap_data); | 2163 return new_bitmap_data->Equals(original_bitmap_data); |
| 2163 } | 2164 } |
| 2164 | 2165 |
| 2165 bool HistoryBackend::GetFaviconsFromDB( | 2166 bool HistoryBackend::GetFaviconsFromDB( |
| 2166 const GURL& page_url, | 2167 const GURL& page_url, |
| 2167 int icon_types, | 2168 int icon_types, |
| 2168 int desired_size_in_dip, | 2169 int desired_size_in_dip, |
| 2169 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 2170 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
| 2170 std::vector<favicon_base::FaviconBitmapResult>* favicon_bitmap_results) { | 2171 std::vector<favicon_base::FaviconRawBitmapResult>* favicon_bitmap_results) { |
| 2171 DCHECK(favicon_bitmap_results); | 2172 DCHECK(favicon_bitmap_results); |
| 2172 favicon_bitmap_results->clear(); | 2173 favicon_bitmap_results->clear(); |
| 2173 | 2174 |
| 2174 if (!db_ || !thumbnail_db_) | 2175 if (!db_ || !thumbnail_db_) |
| 2175 return false; | 2176 return false; |
| 2176 | 2177 |
| 2177 // Time the query. | 2178 // Time the query. |
| 2178 TimeTicks beginning_time = TimeTicks::Now(); | 2179 TimeTicks beginning_time = TimeTicks::Now(); |
| 2179 | 2180 |
| 2180 // Get FaviconIDs for |page_url| and one of |icon_types|. | 2181 // Get FaviconIDs for |page_url| and one of |icon_types|. |
| 2181 std::vector<IconMapping> icon_mappings; | 2182 std::vector<IconMapping> icon_mappings; |
| 2182 thumbnail_db_->GetIconMappingsForPageURL(page_url, icon_types, | 2183 thumbnail_db_->GetIconMappingsForPageURL(page_url, icon_types, |
| 2183 &icon_mappings); | 2184 &icon_mappings); |
| 2184 std::vector<favicon_base::FaviconID> favicon_ids; | 2185 std::vector<favicon_base::FaviconID> favicon_ids; |
| 2185 for (size_t i = 0; i < icon_mappings.size(); ++i) | 2186 for (size_t i = 0; i < icon_mappings.size(); ++i) |
| 2186 favicon_ids.push_back(icon_mappings[i].icon_id); | 2187 favicon_ids.push_back(icon_mappings[i].icon_id); |
| 2187 | 2188 |
| 2188 // Populate |favicon_bitmap_results| and |icon_url_sizes|. | 2189 // Populate |favicon_bitmap_results| and |icon_url_sizes|. |
| 2189 bool success = GetFaviconBitmapResultsForBestMatch(favicon_ids, | 2190 bool success = GetFaviconBitmapResultsForBestMatch(favicon_ids, |
| 2190 desired_size_in_dip, desired_scale_factors, favicon_bitmap_results); | 2191 desired_size_in_dip, desired_scale_factors, favicon_bitmap_results); |
| 2191 UMA_HISTOGRAM_TIMES("History.GetFavIconFromDB", // historical name | 2192 UMA_HISTOGRAM_TIMES("History.GetFavIconFromDB", // historical name |
| 2192 TimeTicks::Now() - beginning_time); | 2193 TimeTicks::Now() - beginning_time); |
| 2193 return success && !favicon_bitmap_results->empty(); | 2194 return success && !favicon_bitmap_results->empty(); |
| 2194 } | 2195 } |
| 2195 | 2196 |
| 2196 bool HistoryBackend::GetFaviconBitmapResultsForBestMatch( | 2197 bool HistoryBackend::GetFaviconBitmapResultsForBestMatch( |
| 2197 const std::vector<favicon_base::FaviconID>& candidate_favicon_ids, | 2198 const std::vector<favicon_base::FaviconID>& candidate_favicon_ids, |
| 2198 int desired_size_in_dip, | 2199 int desired_size_in_dip, |
| 2199 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 2200 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
| 2200 std::vector<favicon_base::FaviconBitmapResult>* favicon_bitmap_results) { | 2201 std::vector<favicon_base::FaviconRawBitmapResult>* favicon_bitmap_results) { |
| 2201 favicon_bitmap_results->clear(); | 2202 favicon_bitmap_results->clear(); |
| 2202 | 2203 |
| 2203 if (candidate_favicon_ids.empty()) | 2204 if (candidate_favicon_ids.empty()) |
| 2204 return true; | 2205 return true; |
| 2205 | 2206 |
| 2206 // Find the FaviconID and the FaviconBitmapIDs which best match | 2207 // Find the FaviconID and the FaviconBitmapIDs which best match |
| 2207 // |desired_size_in_dip| and |desired_scale_factors|. | 2208 // |desired_size_in_dip| and |desired_scale_factors|. |
| 2208 // TODO(pkotwicz): Select bitmap results from multiple favicons once | 2209 // TODO(pkotwicz): Select bitmap results from multiple favicons once |
| 2209 // content::FaviconStatus supports multiple icon URLs. | 2210 // content::FaviconStatus supports multiple icon URLs. |
| 2210 favicon_base::FaviconID best_favicon_id = 0; | 2211 favicon_base::FaviconID best_favicon_id = 0; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2232 best_favicon_id = candidate_favicon_ids[i], | 2233 best_favicon_id = candidate_favicon_ids[i], |
| 2233 best_bitmap_ids.clear(); | 2234 best_bitmap_ids.clear(); |
| 2234 for (size_t j = 0; j < candidate_bitmap_indices.size(); ++j) { | 2235 for (size_t j = 0; j < candidate_bitmap_indices.size(); ++j) { |
| 2235 size_t candidate_index = candidate_bitmap_indices[j]; | 2236 size_t candidate_index = candidate_bitmap_indices[j]; |
| 2236 best_bitmap_ids.push_back( | 2237 best_bitmap_ids.push_back( |
| 2237 bitmap_id_sizes[candidate_index].bitmap_id); | 2238 bitmap_id_sizes[candidate_index].bitmap_id); |
| 2238 } | 2239 } |
| 2239 } | 2240 } |
| 2240 } | 2241 } |
| 2241 | 2242 |
| 2242 // Construct FaviconBitmapResults from |best_favicon_id| and | 2243 // Construct FaviconRawBitmapResults from |best_favicon_id| and |
| 2243 // |best_bitmap_ids|. | 2244 // |best_bitmap_ids|. |
| 2244 GURL icon_url; | 2245 GURL icon_url; |
| 2245 favicon_base::IconType icon_type; | 2246 favicon_base::IconType icon_type; |
| 2246 if (!thumbnail_db_->GetFaviconHeader(best_favicon_id, &icon_url, | 2247 if (!thumbnail_db_->GetFaviconHeader(best_favicon_id, &icon_url, |
| 2247 &icon_type)) { | 2248 &icon_type)) { |
| 2248 return false; | 2249 return false; |
| 2249 } | 2250 } |
| 2250 | 2251 |
| 2251 for (size_t i = 0; i < best_bitmap_ids.size(); ++i) { | 2252 for (size_t i = 0; i < best_bitmap_ids.size(); ++i) { |
| 2252 base::Time last_updated; | 2253 base::Time last_updated; |
| 2253 favicon_base::FaviconBitmapResult bitmap_result; | 2254 favicon_base::FaviconRawBitmapResult bitmap_result; |
| 2254 bitmap_result.icon_url = icon_url; | 2255 bitmap_result.icon_url = icon_url; |
| 2255 bitmap_result.icon_type = icon_type; | 2256 bitmap_result.icon_type = icon_type; |
| 2256 if (!thumbnail_db_->GetFaviconBitmap(best_bitmap_ids[i], | 2257 if (!thumbnail_db_->GetFaviconBitmap(best_bitmap_ids[i], |
| 2257 &last_updated, | 2258 &last_updated, |
| 2258 &bitmap_result.bitmap_data, | 2259 &bitmap_result.bitmap_data, |
| 2259 &bitmap_result.pixel_size)) { | 2260 &bitmap_result.pixel_size)) { |
| 2260 return false; | 2261 return false; |
| 2261 } | 2262 } |
| 2262 | 2263 |
| 2263 bitmap_result.expired = (Time::Now() - last_updated) > | 2264 bitmap_result.expired = (Time::Now() - last_updated) > |
| (...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2846 int rank = kPageVisitStatsMaxTopSites; | 2847 int rank = kPageVisitStatsMaxTopSites; |
| 2847 std::map<GURL, int>::const_iterator it = most_visited_urls_map_.find(url); | 2848 std::map<GURL, int>::const_iterator it = most_visited_urls_map_.find(url); |
| 2848 if (it != most_visited_urls_map_.end()) | 2849 if (it != most_visited_urls_map_.end()) |
| 2849 rank = (*it).second; | 2850 rank = (*it).second; |
| 2850 UMA_HISTOGRAM_ENUMERATION("History.TopSitesVisitsByRank", | 2851 UMA_HISTOGRAM_ENUMERATION("History.TopSitesVisitsByRank", |
| 2851 rank, kPageVisitStatsMaxTopSites + 1); | 2852 rank, kPageVisitStatsMaxTopSites + 1); |
| 2852 } | 2853 } |
| 2853 #endif | 2854 #endif |
| 2854 | 2855 |
| 2855 } // namespace history | 2856 } // namespace history |
| OLD | NEW |