| 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 1549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1560 num_databases_deleted++; | 1560 num_databases_deleted++; |
| 1561 } | 1561 } |
| 1562 UMA_HISTOGRAM_COUNTS("History.DeleteFTSIndexDatabases", | 1562 UMA_HISTOGRAM_COUNTS("History.DeleteFTSIndexDatabases", |
| 1563 num_databases_deleted); | 1563 num_databases_deleted); |
| 1564 } | 1564 } |
| 1565 | 1565 |
| 1566 void HistoryBackend::GetFavicons( | 1566 void HistoryBackend::GetFavicons( |
| 1567 const std::vector<GURL>& icon_urls, | 1567 const std::vector<GURL>& icon_urls, |
| 1568 int icon_types, | 1568 int icon_types, |
| 1569 int desired_size_in_dip, | 1569 int desired_size_in_dip, |
| 1570 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 1570 const std::vector<float>& desired_favicon_scales, |
| 1571 std::vector<favicon_base::FaviconRawBitmapResult>* bitmap_results) { | 1571 std::vector<favicon_base::FaviconRawBitmapResult>* bitmap_results) { |
| 1572 UpdateFaviconMappingsAndFetchImpl(NULL, icon_urls, icon_types, | 1572 UpdateFaviconMappingsAndFetchImpl(NULL, icon_urls, icon_types, |
| 1573 desired_size_in_dip, desired_scale_factors, | 1573 desired_size_in_dip, desired_favicon_scales, |
| 1574 bitmap_results); | 1574 bitmap_results); |
| 1575 } | 1575 } |
| 1576 | 1576 |
| 1577 void HistoryBackend::GetLargestFaviconForURL( | 1577 void HistoryBackend::GetLargestFaviconForURL( |
| 1578 const GURL& page_url, | 1578 const GURL& page_url, |
| 1579 const std::vector<int>& icon_types, | 1579 const std::vector<int>& icon_types, |
| 1580 int minimum_size_in_pixels, | 1580 int minimum_size_in_pixels, |
| 1581 favicon_base::FaviconRawBitmapResult* favicon_bitmap_result) { | 1581 favicon_base::FaviconRawBitmapResult* favicon_bitmap_result) { |
| 1582 DCHECK(favicon_bitmap_result); | 1582 DCHECK(favicon_bitmap_result); |
| 1583 | 1583 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1666 *favicon_bitmap_result = bitmap_result; | 1666 *favicon_bitmap_result = bitmap_result; |
| 1667 | 1667 |
| 1668 HISTOGRAM_TIMES("History.GetLargestFaviconForURL", | 1668 HISTOGRAM_TIMES("History.GetLargestFaviconForURL", |
| 1669 TimeTicks::Now() - beginning_time); | 1669 TimeTicks::Now() - beginning_time); |
| 1670 } | 1670 } |
| 1671 | 1671 |
| 1672 void HistoryBackend::GetFaviconsForURL( | 1672 void HistoryBackend::GetFaviconsForURL( |
| 1673 const GURL& page_url, | 1673 const GURL& page_url, |
| 1674 int icon_types, | 1674 int icon_types, |
| 1675 int desired_size_in_dip, | 1675 int desired_size_in_dip, |
| 1676 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 1676 const std::vector<float>& desired_favicon_scales, |
| 1677 std::vector<favicon_base::FaviconRawBitmapResult>* bitmap_results) { | 1677 std::vector<favicon_base::FaviconRawBitmapResult>* bitmap_results) { |
| 1678 DCHECK(bitmap_results); | 1678 DCHECK(bitmap_results); |
| 1679 GetFaviconsFromDB(page_url, icon_types, desired_size_in_dip, | 1679 GetFaviconsFromDB(page_url, icon_types, desired_size_in_dip, |
| 1680 desired_scale_factors, bitmap_results); | 1680 desired_favicon_scales, bitmap_results); |
| 1681 } | 1681 } |
| 1682 | 1682 |
| 1683 void HistoryBackend::GetFaviconForID( | 1683 void HistoryBackend::GetFaviconForID( |
| 1684 favicon_base::FaviconID favicon_id, | 1684 favicon_base::FaviconID favicon_id, |
| 1685 int desired_size_in_dip, | 1685 int desired_size_in_dip, |
| 1686 ui::ScaleFactor desired_scale_factor, | 1686 float desired_favicon_scale, |
| 1687 std::vector<favicon_base::FaviconRawBitmapResult>* bitmap_results) { | 1687 std::vector<favicon_base::FaviconRawBitmapResult>* bitmap_results) { |
| 1688 std::vector<favicon_base::FaviconID> favicon_ids; | 1688 std::vector<favicon_base::FaviconID> favicon_ids; |
| 1689 favicon_ids.push_back(favicon_id); | 1689 favicon_ids.push_back(favicon_id); |
| 1690 std::vector<ui::ScaleFactor> desired_scale_factors; | 1690 std::vector<float> desired_favicon_scales; |
| 1691 desired_scale_factors.push_back(desired_scale_factor); | 1691 desired_favicon_scales.push_back(desired_favicon_scale); |
| 1692 | 1692 |
| 1693 // Get results from DB. | 1693 // Get results from DB. |
| 1694 GetFaviconBitmapResultsForBestMatch(favicon_ids, | 1694 GetFaviconBitmapResultsForBestMatch(favicon_ids, |
| 1695 desired_size_in_dip, | 1695 desired_size_in_dip, |
| 1696 desired_scale_factors, | 1696 desired_favicon_scales, |
| 1697 bitmap_results); | 1697 bitmap_results); |
| 1698 } | 1698 } |
| 1699 | 1699 |
| 1700 void HistoryBackend::UpdateFaviconMappingsAndFetch( | 1700 void HistoryBackend::UpdateFaviconMappingsAndFetch( |
| 1701 const GURL& page_url, | 1701 const GURL& page_url, |
| 1702 const std::vector<GURL>& icon_urls, | 1702 const std::vector<GURL>& icon_urls, |
| 1703 int icon_types, | 1703 int icon_types, |
| 1704 int desired_size_in_dip, | 1704 int desired_size_in_dip, |
| 1705 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 1705 const std::vector<float>& desired_favicon_scales, |
| 1706 std::vector<favicon_base::FaviconRawBitmapResult>* bitmap_results) { | 1706 std::vector<favicon_base::FaviconRawBitmapResult>* bitmap_results) { |
| 1707 UpdateFaviconMappingsAndFetchImpl(&page_url, icon_urls, icon_types, | 1707 UpdateFaviconMappingsAndFetchImpl(&page_url, icon_urls, icon_types, |
| 1708 desired_size_in_dip, desired_scale_factors, | 1708 desired_size_in_dip, desired_favicon_scales, |
| 1709 bitmap_results); | 1709 bitmap_results); |
| 1710 } | 1710 } |
| 1711 | 1711 |
| 1712 void HistoryBackend::MergeFavicon( | 1712 void HistoryBackend::MergeFavicon( |
| 1713 const GURL& page_url, | 1713 const GURL& page_url, |
| 1714 const GURL& icon_url, | 1714 const GURL& icon_url, |
| 1715 favicon_base::IconType icon_type, | 1715 favicon_base::IconType icon_type, |
| 1716 scoped_refptr<base::RefCountedMemory> bitmap_data, | 1716 scoped_refptr<base::RefCountedMemory> bitmap_data, |
| 1717 const gfx::Size& pixel_size) { | 1717 const gfx::Size& pixel_size) { |
| 1718 if (!thumbnail_db_ || !db_) | 1718 if (!thumbnail_db_ || !db_) |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1999 BroadcastNotifications(chrome::NOTIFICATION_FAVICON_CHANGED, | 1999 BroadcastNotifications(chrome::NOTIFICATION_FAVICON_CHANGED, |
| 2000 changed_details.PassAs<HistoryDetails>()); | 2000 changed_details.PassAs<HistoryDetails>()); |
| 2001 } | 2001 } |
| 2002 } | 2002 } |
| 2003 | 2003 |
| 2004 void HistoryBackend::UpdateFaviconMappingsAndFetchImpl( | 2004 void HistoryBackend::UpdateFaviconMappingsAndFetchImpl( |
| 2005 const GURL* page_url, | 2005 const GURL* page_url, |
| 2006 const std::vector<GURL>& icon_urls, | 2006 const std::vector<GURL>& icon_urls, |
| 2007 int icon_types, | 2007 int icon_types, |
| 2008 int desired_size_in_dip, | 2008 int desired_size_in_dip, |
| 2009 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 2009 const std::vector<float>& desired_favicon_scales, |
| 2010 std::vector<favicon_base::FaviconRawBitmapResult>* bitmap_results) { | 2010 std::vector<favicon_base::FaviconRawBitmapResult>* bitmap_results) { |
| 2011 // If |page_url| is specified, |icon_types| must be either a single icon | 2011 // If |page_url| is specified, |icon_types| must be either a single icon |
| 2012 // type or icon types which are equivalent. | 2012 // type or icon types which are equivalent. |
| 2013 DCHECK(!page_url || icon_types == favicon_base::FAVICON || | 2013 DCHECK(!page_url || icon_types == favicon_base::FAVICON || |
| 2014 icon_types == favicon_base::TOUCH_ICON || | 2014 icon_types == favicon_base::TOUCH_ICON || |
| 2015 icon_types == favicon_base::TOUCH_PRECOMPOSED_ICON || | 2015 icon_types == favicon_base::TOUCH_PRECOMPOSED_ICON || |
| 2016 icon_types == | 2016 icon_types == |
| 2017 (favicon_base::TOUCH_ICON | favicon_base::TOUCH_PRECOMPOSED_ICON)); | 2017 (favicon_base::TOUCH_ICON | favicon_base::TOUCH_PRECOMPOSED_ICON)); |
| 2018 bitmap_results->clear(); | 2018 bitmap_results->clear(); |
| 2019 | 2019 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2051 bool mappings_updated = | 2051 bool mappings_updated = |
| 2052 SetFaviconMappingsForPageAndRedirects(*page_url, selected_icon_type, | 2052 SetFaviconMappingsForPageAndRedirects(*page_url, selected_icon_type, |
| 2053 favicon_ids); | 2053 favicon_ids); |
| 2054 if (mappings_updated) { | 2054 if (mappings_updated) { |
| 2055 SendFaviconChangedNotificationForPageAndRedirects(*page_url); | 2055 SendFaviconChangedNotificationForPageAndRedirects(*page_url); |
| 2056 ScheduleCommit(); | 2056 ScheduleCommit(); |
| 2057 } | 2057 } |
| 2058 } | 2058 } |
| 2059 | 2059 |
| 2060 GetFaviconBitmapResultsForBestMatch(favicon_ids, desired_size_in_dip, | 2060 GetFaviconBitmapResultsForBestMatch(favicon_ids, desired_size_in_dip, |
| 2061 desired_scale_factors, bitmap_results); | 2061 desired_favicon_scales, bitmap_results); |
| 2062 } | 2062 } |
| 2063 | 2063 |
| 2064 void HistoryBackend::SetFaviconBitmaps( | 2064 void HistoryBackend::SetFaviconBitmaps( |
| 2065 favicon_base::FaviconID icon_id, | 2065 favicon_base::FaviconID icon_id, |
| 2066 const std::vector<favicon_base::FaviconRawBitmapData>& favicon_bitmap_data, | 2066 const std::vector<favicon_base::FaviconRawBitmapData>& favicon_bitmap_data, |
| 2067 bool* favicon_bitmaps_changed) { | 2067 bool* favicon_bitmaps_changed) { |
| 2068 if (favicon_bitmaps_changed) | 2068 if (favicon_bitmaps_changed) |
| 2069 *favicon_bitmaps_changed = false; | 2069 *favicon_bitmaps_changed = false; |
| 2070 | 2070 |
| 2071 std::vector<FaviconBitmapIDSize> bitmap_id_sizes; | 2071 std::vector<FaviconBitmapIDSize> bitmap_id_sizes; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2156 NULL, | 2156 NULL, |
| 2157 &original_bitmap_data, | 2157 &original_bitmap_data, |
| 2158 NULL); | 2158 NULL); |
| 2159 return new_bitmap_data->Equals(original_bitmap_data); | 2159 return new_bitmap_data->Equals(original_bitmap_data); |
| 2160 } | 2160 } |
| 2161 | 2161 |
| 2162 bool HistoryBackend::GetFaviconsFromDB( | 2162 bool HistoryBackend::GetFaviconsFromDB( |
| 2163 const GURL& page_url, | 2163 const GURL& page_url, |
| 2164 int icon_types, | 2164 int icon_types, |
| 2165 int desired_size_in_dip, | 2165 int desired_size_in_dip, |
| 2166 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 2166 const std::vector<float>& desired_favicon_scales, |
| 2167 std::vector<favicon_base::FaviconRawBitmapResult>* favicon_bitmap_results) { | 2167 std::vector<favicon_base::FaviconRawBitmapResult>* favicon_bitmap_results) { |
| 2168 DCHECK(favicon_bitmap_results); | 2168 DCHECK(favicon_bitmap_results); |
| 2169 favicon_bitmap_results->clear(); | 2169 favicon_bitmap_results->clear(); |
| 2170 | 2170 |
| 2171 if (!db_ || !thumbnail_db_) | 2171 if (!db_ || !thumbnail_db_) |
| 2172 return false; | 2172 return false; |
| 2173 | 2173 |
| 2174 // Time the query. | 2174 // Time the query. |
| 2175 TimeTicks beginning_time = TimeTicks::Now(); | 2175 TimeTicks beginning_time = TimeTicks::Now(); |
| 2176 | 2176 |
| 2177 // Get FaviconIDs for |page_url| and one of |icon_types|. | 2177 // Get FaviconIDs for |page_url| and one of |icon_types|. |
| 2178 std::vector<IconMapping> icon_mappings; | 2178 std::vector<IconMapping> icon_mappings; |
| 2179 thumbnail_db_->GetIconMappingsForPageURL(page_url, icon_types, | 2179 thumbnail_db_->GetIconMappingsForPageURL(page_url, icon_types, |
| 2180 &icon_mappings); | 2180 &icon_mappings); |
| 2181 std::vector<favicon_base::FaviconID> favicon_ids; | 2181 std::vector<favicon_base::FaviconID> favicon_ids; |
| 2182 for (size_t i = 0; i < icon_mappings.size(); ++i) | 2182 for (size_t i = 0; i < icon_mappings.size(); ++i) |
| 2183 favicon_ids.push_back(icon_mappings[i].icon_id); | 2183 favicon_ids.push_back(icon_mappings[i].icon_id); |
| 2184 | 2184 |
| 2185 // Populate |favicon_bitmap_results| and |icon_url_sizes|. | 2185 // Populate |favicon_bitmap_results| and |icon_url_sizes|. |
| 2186 bool success = GetFaviconBitmapResultsForBestMatch(favicon_ids, | 2186 bool success = GetFaviconBitmapResultsForBestMatch(favicon_ids, |
| 2187 desired_size_in_dip, desired_scale_factors, favicon_bitmap_results); | 2187 desired_size_in_dip, desired_favicon_scales, favicon_bitmap_results); |
| 2188 UMA_HISTOGRAM_TIMES("History.GetFavIconFromDB", // historical name | 2188 UMA_HISTOGRAM_TIMES("History.GetFavIconFromDB", // historical name |
| 2189 TimeTicks::Now() - beginning_time); | 2189 TimeTicks::Now() - beginning_time); |
| 2190 return success && !favicon_bitmap_results->empty(); | 2190 return success && !favicon_bitmap_results->empty(); |
| 2191 } | 2191 } |
| 2192 | 2192 |
| 2193 bool HistoryBackend::GetFaviconBitmapResultsForBestMatch( | 2193 bool HistoryBackend::GetFaviconBitmapResultsForBestMatch( |
| 2194 const std::vector<favicon_base::FaviconID>& candidate_favicon_ids, | 2194 const std::vector<favicon_base::FaviconID>& candidate_favicon_ids, |
| 2195 int desired_size_in_dip, | 2195 int desired_size_in_dip, |
| 2196 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 2196 const std::vector<float>& desired_favicon_scales, |
| 2197 std::vector<favicon_base::FaviconRawBitmapResult>* favicon_bitmap_results) { | 2197 std::vector<favicon_base::FaviconRawBitmapResult>* favicon_bitmap_results) { |
| 2198 favicon_bitmap_results->clear(); | 2198 favicon_bitmap_results->clear(); |
| 2199 | 2199 |
| 2200 if (candidate_favicon_ids.empty()) | 2200 if (candidate_favicon_ids.empty()) |
| 2201 return true; | 2201 return true; |
| 2202 | 2202 |
| 2203 // Find the FaviconID and the FaviconBitmapIDs which best match | 2203 // Find the FaviconID and the FaviconBitmapIDs which best match |
| 2204 // |desired_size_in_dip| and |desired_scale_factors|. | 2204 // |desired_size_in_dip| and |desired_favicon_scales|. |
| 2205 // TODO(pkotwicz): Select bitmap results from multiple favicons once | 2205 // TODO(pkotwicz): Select bitmap results from multiple favicons once |
| 2206 // content::FaviconStatus supports multiple icon URLs. | 2206 // content::FaviconStatus supports multiple icon URLs. |
| 2207 favicon_base::FaviconID best_favicon_id = 0; | 2207 favicon_base::FaviconID best_favicon_id = 0; |
| 2208 std::vector<FaviconBitmapID> best_bitmap_ids; | 2208 std::vector<FaviconBitmapID> best_bitmap_ids; |
| 2209 float highest_score = kSelectFaviconFramesInvalidScore; | 2209 float highest_score = kSelectFaviconFramesInvalidScore; |
| 2210 for (size_t i = 0; i < candidate_favicon_ids.size(); ++i) { | 2210 for (size_t i = 0; i < candidate_favicon_ids.size(); ++i) { |
| 2211 std::vector<FaviconBitmapIDSize> bitmap_id_sizes; | 2211 std::vector<FaviconBitmapIDSize> bitmap_id_sizes; |
| 2212 thumbnail_db_->GetFaviconBitmapIDSizes(candidate_favicon_ids[i], | 2212 thumbnail_db_->GetFaviconBitmapIDSizes(candidate_favicon_ids[i], |
| 2213 &bitmap_id_sizes); | 2213 &bitmap_id_sizes); |
| 2214 | 2214 |
| 2215 // Build vector of gfx::Size from |bitmap_id_sizes|. | 2215 // Build vector of gfx::Size from |bitmap_id_sizes|. |
| 2216 std::vector<gfx::Size> sizes; | 2216 std::vector<gfx::Size> sizes; |
| 2217 for (size_t j = 0; j < bitmap_id_sizes.size(); ++j) | 2217 for (size_t j = 0; j < bitmap_id_sizes.size(); ++j) |
| 2218 sizes.push_back(bitmap_id_sizes[j].pixel_size); | 2218 sizes.push_back(bitmap_id_sizes[j].pixel_size); |
| 2219 | 2219 |
| 2220 std::vector<size_t> candidate_bitmap_indices; | 2220 std::vector<size_t> candidate_bitmap_indices; |
| 2221 float score = 0; | 2221 float score = 0; |
| 2222 SelectFaviconFrameIndices(sizes, | 2222 SelectFaviconFrameIndices(sizes, |
| 2223 desired_scale_factors, | 2223 desired_favicon_scales, |
| 2224 desired_size_in_dip, | 2224 desired_size_in_dip, |
| 2225 &candidate_bitmap_indices, | 2225 &candidate_bitmap_indices, |
| 2226 &score); | 2226 &score); |
| 2227 if (score > highest_score) { | 2227 if (score > highest_score) { |
| 2228 highest_score = score; | 2228 highest_score = score; |
| 2229 best_favicon_id = candidate_favicon_ids[i], | 2229 best_favicon_id = candidate_favicon_ids[i], |
| 2230 best_bitmap_ids.clear(); | 2230 best_bitmap_ids.clear(); |
| 2231 for (size_t j = 0; j < candidate_bitmap_indices.size(); ++j) { | 2231 for (size_t j = 0; j < candidate_bitmap_indices.size(); ++j) { |
| 2232 size_t candidate_index = candidate_bitmap_indices[j]; | 2232 size_t candidate_index = candidate_bitmap_indices[j]; |
| 2233 best_bitmap_ids.push_back( | 2233 best_bitmap_ids.push_back( |
| (...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2843 int rank = kPageVisitStatsMaxTopSites; | 2843 int rank = kPageVisitStatsMaxTopSites; |
| 2844 std::map<GURL, int>::const_iterator it = most_visited_urls_map_.find(url); | 2844 std::map<GURL, int>::const_iterator it = most_visited_urls_map_.find(url); |
| 2845 if (it != most_visited_urls_map_.end()) | 2845 if (it != most_visited_urls_map_.end()) |
| 2846 rank = (*it).second; | 2846 rank = (*it).second; |
| 2847 UMA_HISTOGRAM_ENUMERATION("History.TopSitesVisitsByRank", | 2847 UMA_HISTOGRAM_ENUMERATION("History.TopSitesVisitsByRank", |
| 2848 rank, kPageVisitStatsMaxTopSites + 1); | 2848 rank, kPageVisitStatsMaxTopSites + 1); |
| 2849 } | 2849 } |
| 2850 #endif | 2850 #endif |
| 2851 | 2851 |
| 2852 } // namespace history | 2852 } // namespace history |
| OLD | NEW |