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 1690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1701 SendFaviconChangedNotificationForIconURL(icon_url); | 1701 SendFaviconChangedNotificationForIconURL(icon_url); |
1702 } | 1702 } |
1703 | 1703 |
1704 ScheduleCommit(); | 1704 ScheduleCommit(); |
1705 } | 1705 } |
1706 | 1706 |
1707 void HistoryBackend::SetFavicons(const GURL& page_url, | 1707 void HistoryBackend::SetFavicons(const GURL& page_url, |
1708 favicon_base::IconType icon_type, | 1708 favicon_base::IconType icon_type, |
1709 const GURL& icon_url, | 1709 const GURL& icon_url, |
1710 const std::vector<SkBitmap>& bitmaps) { | 1710 const std::vector<SkBitmap>& bitmaps) { |
| 1711 SetFaviconsImpl(page_url, icon_type, icon_url, bitmaps, |
| 1712 /*bitmaps_are_expired=*/false); |
| 1713 } |
| 1714 |
| 1715 bool HistoryBackend::SetLastResortFavicons( |
| 1716 const GURL& page_url, |
| 1717 favicon_base::IconType icon_type, |
| 1718 const GURL& icon_url, |
| 1719 const std::vector<SkBitmap>& bitmaps) { |
1711 if (!thumbnail_db_ || !db_) | 1720 if (!thumbnail_db_ || !db_) |
1712 return; | 1721 return false; |
1713 | 1722 |
1714 DCHECK_GE(kMaxFaviconBitmapsPerIconURL, bitmaps.size()); | 1723 // Verify there's no known data for the page URL. |
1715 | 1724 if (thumbnail_db_->GetIconMappingsForPageURL(page_url, |
1716 favicon_base::FaviconID icon_id = | 1725 /*mapping_data=*/nullptr)) { |
1717 thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, icon_type, nullptr); | 1726 return false; |
1718 | |
1719 bool favicon_created = false; | |
1720 if (!icon_id) { | |
1721 icon_id = thumbnail_db_->AddFavicon(icon_url, icon_type); | |
1722 favicon_created = true; | |
1723 } | 1727 } |
1724 | 1728 |
1725 bool favicon_data_modified = SetFaviconBitmaps(icon_id, bitmaps); | 1729 return SetFaviconsImpl(page_url, icon_type, icon_url, bitmaps, |
1726 | 1730 /*bitmaps_are_expired=*/true); |
1727 std::vector<favicon_base::FaviconID> icon_ids(1u, icon_id); | |
1728 bool mapping_changed = | |
1729 SetFaviconMappingsForPageAndRedirects(page_url, icon_type, icon_ids); | |
1730 | |
1731 if (mapping_changed) { | |
1732 // Notify the UI that this function changed an icon mapping. | |
1733 SendFaviconChangedNotificationForPageAndRedirects(page_url); | |
1734 } | |
1735 | |
1736 if (favicon_data_modified && !favicon_created) { | |
1737 // If there was a favicon at |icon_url| prior to SetFavicons() being called, | |
1738 // there may be page URLs which also use the favicon at |icon_url|. Notify | |
1739 // the UI that the favicon has changed for |icon_url|. | |
1740 SendFaviconChangedNotificationForIconURL(icon_url); | |
1741 } | |
1742 ScheduleCommit(); | |
1743 } | 1731 } |
1744 | 1732 |
1745 void HistoryBackend::SetFaviconsOutOfDateForPage(const GURL& page_url) { | 1733 void HistoryBackend::SetFaviconsOutOfDateForPage(const GURL& page_url) { |
1746 std::vector<IconMapping> icon_mappings; | 1734 std::vector<IconMapping> icon_mappings; |
1747 | 1735 |
1748 if (!thumbnail_db_ || | 1736 if (!thumbnail_db_ || |
1749 !thumbnail_db_->GetIconMappingsForPageURL(page_url, &icon_mappings)) | 1737 !thumbnail_db_->GetIconMappingsForPageURL(page_url, &icon_mappings)) |
1750 return; | 1738 return; |
1751 | 1739 |
1752 for (std::vector<IconMapping>::iterator m = icon_mappings.begin(); | 1740 for (std::vector<IconMapping>::iterator m = icon_mappings.begin(); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1810 } | 1798 } |
1811 } | 1799 } |
1812 } | 1800 } |
1813 | 1801 |
1814 if (!favicons_changed.empty()) { | 1802 if (!favicons_changed.empty()) { |
1815 // Send the notification about the changed favicon URLs. | 1803 // Send the notification about the changed favicon URLs. |
1816 NotifyFaviconsChanged(favicons_changed, GURL()); | 1804 NotifyFaviconsChanged(favicons_changed, GURL()); |
1817 } | 1805 } |
1818 } | 1806 } |
1819 | 1807 |
| 1808 bool HistoryBackend::SetFaviconsImpl(const GURL& page_url, |
| 1809 favicon_base::IconType icon_type, |
| 1810 const GURL& icon_url, |
| 1811 const std::vector<SkBitmap>& bitmaps, |
| 1812 bool bitmaps_are_expired) { |
| 1813 if (!thumbnail_db_ || !db_) |
| 1814 return false; |
| 1815 |
| 1816 DCHECK_GE(kMaxFaviconBitmapsPerIconURL, bitmaps.size()); |
| 1817 |
| 1818 favicon_base::FaviconID icon_id = |
| 1819 thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, icon_type, nullptr); |
| 1820 |
| 1821 bool favicon_created = false; |
| 1822 if (!icon_id) { |
| 1823 icon_id = thumbnail_db_->AddFavicon(icon_url, icon_type); |
| 1824 favicon_created = true; |
| 1825 } |
| 1826 |
| 1827 bool favicon_data_modified = false; |
| 1828 if (favicon_created || !bitmaps_are_expired) |
| 1829 favicon_data_modified = SetFaviconBitmaps(icon_id, bitmaps); |
| 1830 |
| 1831 if (favicon_created && bitmaps_are_expired) |
| 1832 thumbnail_db_->SetFaviconOutOfDate(icon_id); |
| 1833 |
| 1834 std::vector<favicon_base::FaviconID> icon_ids(1u, icon_id); |
| 1835 bool mapping_changed = |
| 1836 SetFaviconMappingsForPageAndRedirects(page_url, icon_type, icon_ids); |
| 1837 |
| 1838 if (mapping_changed) { |
| 1839 // Notify the UI that this function changed an icon mapping. |
| 1840 SendFaviconChangedNotificationForPageAndRedirects(page_url); |
| 1841 } |
| 1842 |
| 1843 if (favicon_data_modified && !favicon_created) { |
| 1844 // If there was a favicon at |icon_url| prior to SetFavicons() being called, |
| 1845 // there may be page URLs which also use the favicon at |icon_url|. Notify |
| 1846 // the UI that the favicon has changed for |icon_url|. |
| 1847 SendFaviconChangedNotificationForIconURL(icon_url); |
| 1848 } |
| 1849 ScheduleCommit(); |
| 1850 return favicon_data_modified; |
| 1851 } |
| 1852 |
1820 void HistoryBackend::UpdateFaviconMappingsAndFetchImpl( | 1853 void HistoryBackend::UpdateFaviconMappingsAndFetchImpl( |
1821 const GURL* page_url, | 1854 const GURL* page_url, |
1822 const std::vector<GURL>& icon_urls, | 1855 const std::vector<GURL>& icon_urls, |
1823 int icon_types, | 1856 int icon_types, |
1824 const std::vector<int>& desired_sizes, | 1857 const std::vector<int>& desired_sizes, |
1825 std::vector<favicon_base::FaviconRawBitmapResult>* bitmap_results) { | 1858 std::vector<favicon_base::FaviconRawBitmapResult>* bitmap_results) { |
1826 // If |page_url| is specified, |icon_types| must be either a single icon | 1859 // If |page_url| is specified, |icon_types| must be either a single icon |
1827 // type or icon types which are equivalent. | 1860 // type or icon types which are equivalent. |
1828 DCHECK(!page_url || icon_types == favicon_base::FAVICON || | 1861 DCHECK(!page_url || icon_types == favicon_base::FAVICON || |
1829 icon_types == favicon_base::TOUCH_ICON || | 1862 icon_types == favicon_base::TOUCH_ICON || |
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2606 // transaction is currently open. | 2639 // transaction is currently open. |
2607 db_->CommitTransaction(); | 2640 db_->CommitTransaction(); |
2608 db_->Vacuum(); | 2641 db_->Vacuum(); |
2609 db_->BeginTransaction(); | 2642 db_->BeginTransaction(); |
2610 db_->GetStartDate(&first_recorded_time_); | 2643 db_->GetStartDate(&first_recorded_time_); |
2611 | 2644 |
2612 return true; | 2645 return true; |
2613 } | 2646 } |
2614 | 2647 |
2615 } // namespace history | 2648 } // namespace history |
OLD | NEW |