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 "components/history/core/browser/history_backend.h" | 5 #include "components/history/core/browser/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 1615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1626 // Set the preexisting favicon bitmaps as expired as the preexisting favicon | 1626 // Set the preexisting favicon bitmaps as expired as the preexisting favicon |
| 1627 // bitmaps are not consistent with the merged in data. | 1627 // bitmaps are not consistent with the merged in data. |
| 1628 thumbnail_db_->SetFaviconOutOfDate(favicon_id); | 1628 thumbnail_db_->SetFaviconOutOfDate(favicon_id); |
| 1629 | 1629 |
| 1630 // Delete an arbitrary favicon bitmap to avoid going over the limit of | 1630 // Delete an arbitrary favicon bitmap to avoid going over the limit of |
| 1631 // |kMaxFaviconBitmapsPerIconURL|. | 1631 // |kMaxFaviconBitmapsPerIconURL|. |
| 1632 if (bitmap_id_sizes.size() >= kMaxFaviconBitmapsPerIconURL) { | 1632 if (bitmap_id_sizes.size() >= kMaxFaviconBitmapsPerIconURL) { |
| 1633 thumbnail_db_->DeleteFaviconBitmap(bitmap_id_sizes[0].bitmap_id); | 1633 thumbnail_db_->DeleteFaviconBitmap(bitmap_id_sizes[0].bitmap_id); |
| 1634 favicon_sizes.erase(favicon_sizes.begin()); | 1634 favicon_sizes.erase(favicon_sizes.begin()); |
| 1635 } | 1635 } |
| 1636 thumbnail_db_->AddFaviconBitmap(favicon_id, bitmap_data, base::Time::Now(), | 1636 thumbnail_db_->AddFaviconBitmap(favicon_id, bitmap_data, |
| 1637 pixel_size); | 1637 FaviconBitmapType::ON_VISIT, |
| 1638 base::Time::Now(), pixel_size); | |
| 1638 favicon_sizes.push_back(pixel_size); | 1639 favicon_sizes.push_back(pixel_size); |
| 1639 } | 1640 } |
| 1640 | 1641 |
| 1641 // A site may have changed the favicons that it uses for |page_url|. | 1642 // A site may have changed the favicons that it uses for |page_url|. |
| 1642 // Example Scenario: | 1643 // Example Scenario: |
| 1643 // page_url = news.google.com | 1644 // page_url = news.google.com |
| 1644 // Initial State: www.google.com/favicon.ico 16x16, 32x32 | 1645 // Initial State: www.google.com/favicon.ico 16x16, 32x32 |
| 1645 // MergeFavicon(news.google.com, news.google.com/news_specific.ico, ..., | 1646 // MergeFavicon(news.google.com, news.google.com/news_specific.ico, ..., |
| 1646 // ..., 16x16) | 1647 // ..., 16x16) |
| 1647 // | 1648 // |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1688 // and having multiple equally sized favicon bitmaps for |page_url| is | 1689 // and having multiple equally sized favicon bitmaps for |page_url| is |
| 1689 // ambiguous in terms of GetFaviconsForURL(). | 1690 // ambiguous in terms of GetFaviconsForURL(). |
| 1690 std::vector<gfx::Size>::iterator it = | 1691 std::vector<gfx::Size>::iterator it = |
| 1691 std::find(favicon_sizes.begin(), favicon_sizes.end(), | 1692 std::find(favicon_sizes.begin(), favicon_sizes.end(), |
| 1692 bitmaps_to_copy[j].pixel_size); | 1693 bitmaps_to_copy[j].pixel_size); |
| 1693 if (it != favicon_sizes.end()) | 1694 if (it != favicon_sizes.end()) |
| 1694 continue; | 1695 continue; |
| 1695 | 1696 |
| 1696 // Add the favicon bitmap as expired as it is not consistent with the | 1697 // Add the favicon bitmap as expired as it is not consistent with the |
| 1697 // merged in data. | 1698 // merged in data. |
| 1698 thumbnail_db_->AddFaviconBitmap( | 1699 thumbnail_db_->AddFaviconBitmap(favicon_id, |
| 1699 favicon_id, bitmaps_to_copy[j].bitmap_data, base::Time(), | 1700 bitmaps_to_copy[j].bitmap_data, |
| 1700 bitmaps_to_copy[j].pixel_size); | 1701 FaviconBitmapType::ON_VISIT, base::Time(), |
| 1702 bitmaps_to_copy[j].pixel_size); | |
| 1701 favicon_sizes.push_back(bitmaps_to_copy[j].pixel_size); | 1703 favicon_sizes.push_back(bitmaps_to_copy[j].pixel_size); |
| 1702 favicon_bitmaps_copied = true; | 1704 favicon_bitmaps_copied = true; |
| 1703 | 1705 |
| 1704 if (favicon_sizes.size() >= kMaxFaviconBitmapsPerIconURL) | 1706 if (favicon_sizes.size() >= kMaxFaviconBitmapsPerIconURL) |
| 1705 break; | 1707 break; |
| 1706 } | 1708 } |
| 1707 } | 1709 } |
| 1708 | 1710 |
| 1709 // Update the favicon mappings such that only |icon_url| is mapped to | 1711 // Update the favicon mappings such that only |icon_url| is mapped to |
| 1710 // |page_url|. | 1712 // |page_url|. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1723 } | 1725 } |
| 1724 | 1726 |
| 1725 ScheduleCommit(); | 1727 ScheduleCommit(); |
| 1726 } | 1728 } |
| 1727 | 1729 |
| 1728 void HistoryBackend::SetFavicons(const GURL& page_url, | 1730 void HistoryBackend::SetFavicons(const GURL& page_url, |
| 1729 favicon_base::IconType icon_type, | 1731 favicon_base::IconType icon_type, |
| 1730 const GURL& icon_url, | 1732 const GURL& icon_url, |
| 1731 const std::vector<SkBitmap>& bitmaps) { | 1733 const std::vector<SkBitmap>& bitmaps) { |
| 1732 SetFaviconsImpl(page_url, icon_type, icon_url, bitmaps, | 1734 SetFaviconsImpl(page_url, icon_type, icon_url, bitmaps, |
| 1733 /*bitmaps_are_expired=*/false); | 1735 FaviconBitmapType::ON_VISIT); |
| 1734 } | 1736 } |
| 1735 | 1737 |
| 1736 bool HistoryBackend::SetLastResortFavicons( | 1738 bool HistoryBackend::SetOnDemandFavicons(const GURL& page_url, |
| 1737 const GURL& page_url, | 1739 favicon_base::IconType icon_type, |
| 1738 favicon_base::IconType icon_type, | 1740 const GURL& icon_url, |
| 1739 const GURL& icon_url, | 1741 const std::vector<SkBitmap>& bitmaps) { |
| 1740 const std::vector<SkBitmap>& bitmaps) { | |
| 1741 if (!thumbnail_db_ || !db_) | 1742 if (!thumbnail_db_ || !db_) |
| 1742 return false; | 1743 return false; |
| 1743 | 1744 |
| 1744 // Verify there's no known data for the page URL. | 1745 // Verify there's no known data for the page URL. |
| 1745 if (thumbnail_db_->GetIconMappingsForPageURL(page_url, | 1746 if (thumbnail_db_->GetIconMappingsForPageURL(page_url, |
| 1746 /*mapping_data=*/nullptr)) { | 1747 /*mapping_data=*/nullptr)) { |
| 1747 return false; | 1748 return false; |
| 1748 } | 1749 } |
| 1749 | 1750 |
| 1750 return SetFaviconsImpl(page_url, icon_type, icon_url, bitmaps, | 1751 return SetFaviconsImpl(page_url, icon_type, icon_url, bitmaps, |
| 1751 /*bitmaps_are_expired=*/true); | 1752 FaviconBitmapType::ON_DEMAND); |
| 1752 } | 1753 } |
| 1753 | 1754 |
| 1754 void HistoryBackend::SetFaviconsOutOfDateForPage(const GURL& page_url) { | 1755 void HistoryBackend::SetFaviconsOutOfDateForPage(const GURL& page_url) { |
| 1755 std::vector<IconMapping> icon_mappings; | 1756 std::vector<IconMapping> icon_mappings; |
| 1756 | 1757 |
| 1757 if (!thumbnail_db_ || | 1758 if (!thumbnail_db_ || |
| 1758 !thumbnail_db_->GetIconMappingsForPageURL(page_url, &icon_mappings)) | 1759 !thumbnail_db_->GetIconMappingsForPageURL(page_url, &icon_mappings)) |
| 1759 return; | 1760 return; |
| 1760 | 1761 |
| 1761 for (std::vector<IconMapping>::iterator m = icon_mappings.begin(); | 1762 for (std::vector<IconMapping>::iterator m = icon_mappings.begin(); |
| 1762 m != icon_mappings.end(); ++m) { | 1763 m != icon_mappings.end(); ++m) { |
| 1763 thumbnail_db_->SetFaviconOutOfDate(m->icon_id); | 1764 thumbnail_db_->SetFaviconOutOfDate(m->icon_id); |
| 1764 } | 1765 } |
| 1765 ScheduleCommit(); | 1766 ScheduleCommit(); |
| 1766 } | 1767 } |
| 1767 | 1768 |
| 1769 void HistoryBackend::TouchOnDemandFavicon(const GURL& icon_url) { | |
| 1770 if (!thumbnail_db_) | |
| 1771 return; | |
| 1772 | |
| 1773 thumbnail_db_->TouchOnDemandFavicon(icon_url, Time::Now()); | |
| 1774 ScheduleCommit(); | |
| 1775 } | |
| 1776 | |
| 1768 void HistoryBackend::SetImportedFavicons( | 1777 void HistoryBackend::SetImportedFavicons( |
| 1769 const favicon_base::FaviconUsageDataList& favicon_usage) { | 1778 const favicon_base::FaviconUsageDataList& favicon_usage) { |
| 1770 if (!db_ || !thumbnail_db_) | 1779 if (!db_ || !thumbnail_db_) |
| 1771 return; | 1780 return; |
| 1772 | 1781 |
| 1773 Time now = Time::Now(); | 1782 Time now = Time::Now(); |
| 1774 | 1783 |
| 1775 // Track all URLs that had their favicons set or updated. | 1784 // Track all URLs that had their favicons set or updated. |
| 1776 std::set<GURL> favicons_changed; | 1785 std::set<GURL> favicons_changed; |
| 1777 | 1786 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1823 if (!favicons_changed.empty()) { | 1832 if (!favicons_changed.empty()) { |
| 1824 // Send the notification about the changed favicon URLs. | 1833 // Send the notification about the changed favicon URLs. |
| 1825 NotifyFaviconsChanged(favicons_changed, GURL()); | 1834 NotifyFaviconsChanged(favicons_changed, GURL()); |
| 1826 } | 1835 } |
| 1827 } | 1836 } |
| 1828 | 1837 |
| 1829 bool HistoryBackend::SetFaviconsImpl(const GURL& page_url, | 1838 bool HistoryBackend::SetFaviconsImpl(const GURL& page_url, |
| 1830 favicon_base::IconType icon_type, | 1839 favicon_base::IconType icon_type, |
| 1831 const GURL& icon_url, | 1840 const GURL& icon_url, |
| 1832 const std::vector<SkBitmap>& bitmaps, | 1841 const std::vector<SkBitmap>& bitmaps, |
| 1833 bool bitmaps_are_expired) { | 1842 FaviconBitmapType type) { |
| 1834 if (!thumbnail_db_ || !db_) | 1843 if (!thumbnail_db_ || !db_) |
| 1835 return false; | 1844 return false; |
| 1836 | 1845 |
| 1837 DCHECK_GE(kMaxFaviconBitmapsPerIconURL, bitmaps.size()); | 1846 DCHECK_GE(kMaxFaviconBitmapsPerIconURL, bitmaps.size()); |
| 1838 | 1847 |
| 1839 favicon_base::FaviconID icon_id = | 1848 favicon_base::FaviconID icon_id = |
| 1840 thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, icon_type); | 1849 thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, icon_type); |
| 1841 | 1850 |
| 1842 bool favicon_created = false; | 1851 bool favicon_created = false; |
| 1843 if (!icon_id) { | 1852 if (!icon_id) { |
| 1844 icon_id = thumbnail_db_->AddFavicon(icon_url, icon_type); | 1853 icon_id = thumbnail_db_->AddFavicon(icon_url, icon_type); |
| 1845 favicon_created = true; | 1854 favicon_created = true; |
| 1846 } | 1855 } |
| 1847 | 1856 |
| 1848 bool favicon_data_modified = false; | 1857 bool favicon_data_modified = false; |
| 1849 if (favicon_created || !bitmaps_are_expired) | 1858 if (favicon_created || type == FaviconBitmapType::ON_VISIT) { |
| 1850 favicon_data_modified = SetFaviconBitmaps(icon_id, bitmaps); | 1859 favicon_data_modified = SetFaviconBitmaps(icon_id, bitmaps, type); |
| 1851 | 1860 } |
| 1852 if (favicon_created && bitmaps_are_expired) | |
| 1853 thumbnail_db_->SetFaviconOutOfDate(icon_id); | |
| 1854 | 1861 |
| 1855 std::vector<favicon_base::FaviconID> icon_ids(1u, icon_id); | 1862 std::vector<favicon_base::FaviconID> icon_ids(1u, icon_id); |
| 1856 bool mapping_changed = | 1863 bool mapping_changed = |
| 1857 SetFaviconMappingsForPageAndRedirects(page_url, icon_type, icon_ids); | 1864 SetFaviconMappingsForPageAndRedirects(page_url, icon_type, icon_ids); |
| 1858 | 1865 |
| 1859 if (mapping_changed) { | 1866 if (mapping_changed) { |
| 1860 // Notify the UI that this function changed an icon mapping. | 1867 // Notify the UI that this function changed an icon mapping. |
| 1861 SendFaviconChangedNotificationForPageAndRedirects(page_url); | 1868 SendFaviconChangedNotificationForPageAndRedirects(page_url); |
| 1862 } | 1869 } |
| 1863 | 1870 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1897 SendFaviconChangedNotificationForPageAndRedirects(*page_url); | 1904 SendFaviconChangedNotificationForPageAndRedirects(*page_url); |
| 1898 ScheduleCommit(); | 1905 ScheduleCommit(); |
| 1899 } | 1906 } |
| 1900 } | 1907 } |
| 1901 | 1908 |
| 1902 GetFaviconBitmapResultsForBestMatch(favicon_ids, desired_sizes, | 1909 GetFaviconBitmapResultsForBestMatch(favicon_ids, desired_sizes, |
| 1903 bitmap_results); | 1910 bitmap_results); |
| 1904 } | 1911 } |
| 1905 | 1912 |
| 1906 bool HistoryBackend::SetFaviconBitmaps(favicon_base::FaviconID icon_id, | 1913 bool HistoryBackend::SetFaviconBitmaps(favicon_base::FaviconID icon_id, |
| 1907 const std::vector<SkBitmap>& bitmaps) { | 1914 const std::vector<SkBitmap>& bitmaps, |
| 1915 FaviconBitmapType type) { | |
|
pkotwicz
2017/06/07 17:40:52
Please add a comment saying that the this function
jkrcal
2017/06/09 16:38:37
Done (in the header).
| |
| 1908 std::vector<FaviconBitmapIDSize> bitmap_id_sizes; | 1916 std::vector<FaviconBitmapIDSize> bitmap_id_sizes; |
| 1909 thumbnail_db_->GetFaviconBitmapIDSizes(icon_id, &bitmap_id_sizes); | 1917 thumbnail_db_->GetFaviconBitmapIDSizes(icon_id, &bitmap_id_sizes); |
| 1910 | 1918 |
| 1911 typedef std::pair<scoped_refptr<base::RefCountedBytes>, gfx::Size> | 1919 typedef std::pair<scoped_refptr<base::RefCountedBytes>, gfx::Size> |
| 1912 PNGEncodedBitmap; | 1920 PNGEncodedBitmap; |
| 1913 std::vector<PNGEncodedBitmap> to_add; | 1921 std::vector<PNGEncodedBitmap> to_add; |
| 1914 for (size_t i = 0; i < bitmaps.size(); ++i) { | 1922 for (size_t i = 0; i < bitmaps.size(); ++i) { |
| 1915 scoped_refptr<base::RefCountedBytes> bitmap_data(new base::RefCountedBytes); | 1923 scoped_refptr<base::RefCountedBytes> bitmap_data(new base::RefCountedBytes); |
| 1916 if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmaps[i], false, | 1924 if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmaps[i], false, |
| 1917 &bitmap_data->data())) { | 1925 &bitmap_data->data())) { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 1934 } | 1942 } |
| 1935 | 1943 |
| 1936 FaviconBitmapID bitmap_id = bitmap_id_sizes[i].bitmap_id; | 1944 FaviconBitmapID bitmap_id = bitmap_id_sizes[i].bitmap_id; |
| 1937 if (match_it == to_add.end()) { | 1945 if (match_it == to_add.end()) { |
| 1938 thumbnail_db_->DeleteFaviconBitmap(bitmap_id); | 1946 thumbnail_db_->DeleteFaviconBitmap(bitmap_id); |
| 1939 | 1947 |
| 1940 favicon_bitmaps_changed = true; | 1948 favicon_bitmaps_changed = true; |
| 1941 } else { | 1949 } else { |
| 1942 if (!favicon_bitmaps_changed && | 1950 if (!favicon_bitmaps_changed && |
| 1943 IsFaviconBitmapDataEqual(bitmap_id, match_it->first)) { | 1951 IsFaviconBitmapDataEqual(bitmap_id, match_it->first)) { |
| 1944 thumbnail_db_->SetFaviconBitmapLastUpdateTime(bitmap_id, | 1952 thumbnail_db_->SetFaviconBitmapLastUpdateTime( |
| 1945 base::Time::Now()); | 1953 bitmap_id, base::Time::Now() /* new last updated time */); |
| 1946 } else { | 1954 } else { |
| 1947 thumbnail_db_->SetFaviconBitmap(bitmap_id, match_it->first, | 1955 thumbnail_db_->SetFaviconBitmap( |
| 1948 base::Time::Now()); | 1956 bitmap_id, match_it->first, |
| 1957 base::Time::Now() /* new last updated time */); | |
| 1949 favicon_bitmaps_changed = true; | 1958 favicon_bitmaps_changed = true; |
| 1950 } | 1959 } |
| 1951 to_add.erase(match_it); | 1960 to_add.erase(match_it); |
| 1952 } | 1961 } |
| 1953 } | 1962 } |
| 1954 | 1963 |
| 1955 for (size_t i = 0; i < to_add.size(); ++i) { | 1964 for (size_t i = 0; i < to_add.size(); ++i) { |
| 1956 thumbnail_db_->AddFaviconBitmap(icon_id, to_add[i].first, base::Time::Now(), | 1965 thumbnail_db_->AddFaviconBitmap( |
| 1957 to_add[i].second); | 1966 icon_id, to_add[i].first, type, |
| 1967 base::Time::Now() /* new last updated / last requested time */, | |
| 1968 to_add[i].second); | |
| 1958 | 1969 |
| 1959 favicon_bitmaps_changed = true; | 1970 favicon_bitmaps_changed = true; |
| 1960 } | 1971 } |
| 1961 return favicon_bitmaps_changed; | 1972 return favicon_bitmaps_changed; |
| 1962 } | 1973 } |
| 1963 | 1974 |
| 1964 bool HistoryBackend::IsFaviconBitmapDataEqual( | 1975 bool HistoryBackend::IsFaviconBitmapDataEqual( |
| 1965 FaviconBitmapID bitmap_id, | 1976 FaviconBitmapID bitmap_id, |
| 1966 const scoped_refptr<base::RefCountedMemory>& new_bitmap_data) { | 1977 const scoped_refptr<base::RefCountedMemory>& new_bitmap_data) { |
| 1967 if (!new_bitmap_data) | 1978 if (!new_bitmap_data) |
| (...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2636 // transaction is currently open. | 2647 // transaction is currently open. |
| 2637 db_->CommitTransaction(); | 2648 db_->CommitTransaction(); |
| 2638 db_->Vacuum(); | 2649 db_->Vacuum(); |
| 2639 db_->BeginTransaction(); | 2650 db_->BeginTransaction(); |
| 2640 db_->GetStartDate(&first_recorded_time_); | 2651 db_->GetStartDate(&first_recorded_time_); |
| 2641 | 2652 |
| 2642 return true; | 2653 return true; |
| 2643 } | 2654 } |
| 2644 | 2655 |
| 2645 } // namespace history | 2656 } // namespace history |
| OLD | NEW |