Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1356)

Side by Side Diff: components/history/core/browser/history_backend.cc

Issue 2856873002: [Thumbnails DB] Allow setting last_requested time when accessing favicons. (Closed)
Patch Set: Splitting off clearing Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1711 matching lines...) Expand 10 before | Expand all | Expand 10 after
1722 SendFaviconChangedNotificationForIconURL(icon_url); 1722 SendFaviconChangedNotificationForIconURL(icon_url);
1723 } 1723 }
1724 1724
1725 ScheduleCommit(); 1725 ScheduleCommit();
1726 } 1726 }
1727 1727
1728 void HistoryBackend::SetFavicons(const GURL& page_url, 1728 void HistoryBackend::SetFavicons(const GURL& page_url,
1729 favicon_base::IconType icon_type, 1729 favicon_base::IconType icon_type,
1730 const GURL& icon_url, 1730 const GURL& icon_url,
1731 const std::vector<SkBitmap>& bitmaps) { 1731 const std::vector<SkBitmap>& bitmaps) {
1732 SetFaviconsImpl(page_url, icon_type, icon_url, bitmaps, 1732 SetFaviconsImpl(page_url, icon_type, icon_url, bitmaps, /*on_demand=*/false);
1733 /*bitmaps_are_expired=*/false);
1734 } 1733 }
1735 1734
1736 bool HistoryBackend::SetLastResortFavicons( 1735 bool HistoryBackend::SetOnDemandFavicons(const GURL& page_url,
1737 const GURL& page_url, 1736 favicon_base::IconType icon_type,
1738 favicon_base::IconType icon_type, 1737 const GURL& icon_url,
1739 const GURL& icon_url, 1738 const std::vector<SkBitmap>& bitmaps) {
1740 const std::vector<SkBitmap>& bitmaps) {
1741 if (!thumbnail_db_ || !db_) 1739 if (!thumbnail_db_ || !db_)
1742 return false; 1740 return false;
1743 1741
1744 // Verify there's no known data for the page URL. 1742 // Verify there's no known data for the page URL.
1745 if (thumbnail_db_->GetIconMappingsForPageURL(page_url, 1743 if (thumbnail_db_->GetIconMappingsForPageURL(page_url,
1746 /*mapping_data=*/nullptr)) { 1744 /*mapping_data=*/nullptr)) {
1747 return false; 1745 return false;
1748 } 1746 }
1749 1747
1750 return SetFaviconsImpl(page_url, icon_type, icon_url, bitmaps, 1748 return SetFaviconsImpl(page_url, icon_type, icon_url, bitmaps,
1751 /*bitmaps_are_expired=*/true); 1749 /*on_demand=*/true);
1752 } 1750 }
1753 1751
1754 void HistoryBackend::SetFaviconsOutOfDateForPage(const GURL& page_url) { 1752 void HistoryBackend::SetFaviconsOutOfDateForPage(const GURL& page_url) {
1755 std::vector<IconMapping> icon_mappings; 1753 std::vector<IconMapping> icon_mappings;
1756 1754
1757 if (!thumbnail_db_ || 1755 if (!thumbnail_db_ ||
1758 !thumbnail_db_->GetIconMappingsForPageURL(page_url, &icon_mappings)) 1756 !thumbnail_db_->GetIconMappingsForPageURL(page_url, &icon_mappings))
1759 return; 1757 return;
1760 1758
1761 for (std::vector<IconMapping>::iterator m = icon_mappings.begin(); 1759 for (std::vector<IconMapping>::iterator m = icon_mappings.begin();
1762 m != icon_mappings.end(); ++m) { 1760 m != icon_mappings.end(); ++m) {
1763 thumbnail_db_->SetFaviconOutOfDate(m->icon_id); 1761 thumbnail_db_->SetFaviconOutOfDate(m->icon_id);
1764 } 1762 }
1765 ScheduleCommit(); 1763 ScheduleCommit();
1766 } 1764 }
1767 1765
1766 void HistoryBackend::TouchOnDemandFavicon(const GURL& icon_url) {
1767 if (!thumbnail_db_)
1768 return;
1769
1770 thumbnail_db_->TouchOnDemandFavicon(icon_url, Time::Now());
1771 ScheduleCommit();
1772 }
1773
1768 void HistoryBackend::SetImportedFavicons( 1774 void HistoryBackend::SetImportedFavicons(
1769 const favicon_base::FaviconUsageDataList& favicon_usage) { 1775 const favicon_base::FaviconUsageDataList& favicon_usage) {
1770 if (!db_ || !thumbnail_db_) 1776 if (!db_ || !thumbnail_db_)
1771 return; 1777 return;
1772 1778
1773 Time now = Time::Now(); 1779 Time now = Time::Now();
1774 1780
1775 // Track all URLs that had their favicons set or updated. 1781 // Track all URLs that had their favicons set or updated.
1776 std::set<GURL> favicons_changed; 1782 std::set<GURL> favicons_changed;
1777 1783
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1823 if (!favicons_changed.empty()) { 1829 if (!favicons_changed.empty()) {
1824 // Send the notification about the changed favicon URLs. 1830 // Send the notification about the changed favicon URLs.
1825 NotifyFaviconsChanged(favicons_changed, GURL()); 1831 NotifyFaviconsChanged(favicons_changed, GURL());
1826 } 1832 }
1827 } 1833 }
1828 1834
1829 bool HistoryBackend::SetFaviconsImpl(const GURL& page_url, 1835 bool HistoryBackend::SetFaviconsImpl(const GURL& page_url,
1830 favicon_base::IconType icon_type, 1836 favicon_base::IconType icon_type,
1831 const GURL& icon_url, 1837 const GURL& icon_url,
1832 const std::vector<SkBitmap>& bitmaps, 1838 const std::vector<SkBitmap>& bitmaps,
1833 bool bitmaps_are_expired) { 1839 bool on_demand) {
1834 if (!thumbnail_db_ || !db_) 1840 if (!thumbnail_db_ || !db_)
1835 return false; 1841 return false;
1836 1842
1837 DCHECK_GE(kMaxFaviconBitmapsPerIconURL, bitmaps.size()); 1843 DCHECK_GE(kMaxFaviconBitmapsPerIconURL, bitmaps.size());
1838 1844
1839 favicon_base::FaviconID icon_id = 1845 favicon_base::FaviconID icon_id =
1840 thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, icon_type); 1846 thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, icon_type);
1841 1847
1842 bool favicon_created = false; 1848 bool favicon_created = false;
1843 if (!icon_id) { 1849 if (!icon_id) {
1844 icon_id = thumbnail_db_->AddFavicon(icon_url, icon_type); 1850 icon_id = thumbnail_db_->AddFavicon(icon_url, icon_type);
1845 favicon_created = true; 1851 favicon_created = true;
1846 } 1852 }
1847 1853
1848 bool favicon_data_modified = false; 1854 bool favicon_data_modified = false;
1849 if (favicon_created || !bitmaps_are_expired) 1855 if (favicon_created || !on_demand) {
1850 favicon_data_modified = SetFaviconBitmaps(icon_id, bitmaps); 1856 favicon_data_modified = SetFaviconBitmaps(icon_id, bitmaps, on_demand);
1851 1857 }
1852 if (favicon_created && bitmaps_are_expired)
1853 thumbnail_db_->SetFaviconOutOfDate(icon_id);
jkrcal 2017/05/23 14:18:40 This operation is now performed implicitly in Thum
1854 1858
1855 std::vector<favicon_base::FaviconID> icon_ids(1u, icon_id); 1859 std::vector<favicon_base::FaviconID> icon_ids(1u, icon_id);
1856 bool mapping_changed = 1860 bool mapping_changed =
1857 SetFaviconMappingsForPageAndRedirects(page_url, icon_type, icon_ids); 1861 SetFaviconMappingsForPageAndRedirects(page_url, icon_type, icon_ids);
1858 1862
1859 if (mapping_changed) { 1863 if (mapping_changed) {
1860 // Notify the UI that this function changed an icon mapping. 1864 // Notify the UI that this function changed an icon mapping.
1861 SendFaviconChangedNotificationForPageAndRedirects(page_url); 1865 SendFaviconChangedNotificationForPageAndRedirects(page_url);
1862 } 1866 }
1863 1867
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1897 SendFaviconChangedNotificationForPageAndRedirects(*page_url); 1901 SendFaviconChangedNotificationForPageAndRedirects(*page_url);
1898 ScheduleCommit(); 1902 ScheduleCommit();
1899 } 1903 }
1900 } 1904 }
1901 1905
1902 GetFaviconBitmapResultsForBestMatch(favicon_ids, desired_sizes, 1906 GetFaviconBitmapResultsForBestMatch(favicon_ids, desired_sizes,
1903 bitmap_results); 1907 bitmap_results);
1904 } 1908 }
1905 1909
1906 bool HistoryBackend::SetFaviconBitmaps(favicon_base::FaviconID icon_id, 1910 bool HistoryBackend::SetFaviconBitmaps(favicon_base::FaviconID icon_id,
1907 const std::vector<SkBitmap>& bitmaps) { 1911 const std::vector<SkBitmap>& bitmaps,
1912 bool on_demand) {
pkotwicz 2017/05/24 15:43:31 Maybe it would be clearer if you passed the |new_l
jkrcal 2017/06/06 15:41:55 This does not work well after merging AddFaviconBi
1908 std::vector<FaviconBitmapIDSize> bitmap_id_sizes; 1913 std::vector<FaviconBitmapIDSize> bitmap_id_sizes;
1909 thumbnail_db_->GetFaviconBitmapIDSizes(icon_id, &bitmap_id_sizes); 1914 thumbnail_db_->GetFaviconBitmapIDSizes(icon_id, &bitmap_id_sizes);
1910 1915
1911 typedef std::pair<scoped_refptr<base::RefCountedBytes>, gfx::Size> 1916 typedef std::pair<scoped_refptr<base::RefCountedBytes>, gfx::Size>
1912 PNGEncodedBitmap; 1917 PNGEncodedBitmap;
1913 std::vector<PNGEncodedBitmap> to_add; 1918 std::vector<PNGEncodedBitmap> to_add;
1914 for (size_t i = 0; i < bitmaps.size(); ++i) { 1919 for (size_t i = 0; i < bitmaps.size(); ++i) {
1915 scoped_refptr<base::RefCountedBytes> bitmap_data(new base::RefCountedBytes); 1920 scoped_refptr<base::RefCountedBytes> bitmap_data(new base::RefCountedBytes);
1916 if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmaps[i], false, 1921 if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmaps[i], false,
1917 &bitmap_data->data())) { 1922 &bitmap_data->data())) {
(...skipping 28 matching lines...) Expand all
1946 } else { 1951 } else {
1947 thumbnail_db_->SetFaviconBitmap(bitmap_id, match_it->first, 1952 thumbnail_db_->SetFaviconBitmap(bitmap_id, match_it->first,
1948 base::Time::Now()); 1953 base::Time::Now());
1949 favicon_bitmaps_changed = true; 1954 favicon_bitmaps_changed = true;
1950 } 1955 }
1951 to_add.erase(match_it); 1956 to_add.erase(match_it);
1952 } 1957 }
1953 } 1958 }
1954 1959
1955 for (size_t i = 0; i < to_add.size(); ++i) { 1960 for (size_t i = 0; i < to_add.size(); ++i) {
1956 thumbnail_db_->AddFaviconBitmap(icon_id, to_add[i].first, base::Time::Now(), 1961 if (on_demand) {
1957 to_add[i].second); 1962 thumbnail_db_->AddOnDemandFaviconBitmap(
1963 icon_id, to_add[i].first, base::Time::Now(), to_add[i].second);
1964 } else {
1965 thumbnail_db_->AddFaviconBitmap(icon_id, to_add[i].first,
1966 base::Time::Now(), to_add[i].second);
1967 }
1958 1968
1959 favicon_bitmaps_changed = true; 1969 favicon_bitmaps_changed = true;
1960 } 1970 }
1961 return favicon_bitmaps_changed; 1971 return favicon_bitmaps_changed;
1962 } 1972 }
1963 1973
1964 bool HistoryBackend::IsFaviconBitmapDataEqual( 1974 bool HistoryBackend::IsFaviconBitmapDataEqual(
1965 FaviconBitmapID bitmap_id, 1975 FaviconBitmapID bitmap_id,
1966 const scoped_refptr<base::RefCountedMemory>& new_bitmap_data) { 1976 const scoped_refptr<base::RefCountedMemory>& new_bitmap_data) {
1967 if (!new_bitmap_data) 1977 if (!new_bitmap_data)
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after
2636 // transaction is currently open. 2646 // transaction is currently open.
2637 db_->CommitTransaction(); 2647 db_->CommitTransaction();
2638 db_->Vacuum(); 2648 db_->Vacuum();
2639 db_->BeginTransaction(); 2649 db_->BeginTransaction();
2640 db_->GetStartDate(&first_recorded_time_); 2650 db_->GetStartDate(&first_recorded_time_);
2641 2651
2642 return true; 2652 return true;
2643 } 2653 }
2644 2654
2645 } // namespace history 2655 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698