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