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

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

Issue 1133463005: Update all bookmarks which use an icon URL when a favicon's bitmap is updated (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@startup_do_not_unexpire
Patch Set: Created 5 years, 6 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 1581 matching lines...) Expand 10 before | Expand all | Expand 10 after
1592 const GURL& icon_url, 1592 const GURL& icon_url,
1593 favicon_base::IconType icon_type, 1593 favicon_base::IconType icon_type,
1594 scoped_refptr<base::RefCountedMemory> bitmap_data, 1594 scoped_refptr<base::RefCountedMemory> bitmap_data,
1595 const gfx::Size& pixel_size) { 1595 const gfx::Size& pixel_size) {
1596 if (!thumbnail_db_ || !db_) 1596 if (!thumbnail_db_ || !db_)
1597 return; 1597 return;
1598 1598
1599 favicon_base::FaviconID favicon_id = 1599 favicon_base::FaviconID favicon_id =
1600 thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, icon_type, nullptr); 1600 thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, icon_type, nullptr);
1601 1601
1602 bool favicon_created = false;
1602 if (!favicon_id) { 1603 if (!favicon_id) {
1603 // There is no favicon at |icon_url|, create it. 1604 // There is no favicon at |icon_url|, create it.
1604 favicon_id = thumbnail_db_->AddFavicon(icon_url, icon_type); 1605 favicon_id = thumbnail_db_->AddFavicon(icon_url, icon_type);
1606 favicon_created = true;
1605 } 1607 }
1606 1608
1607 std::vector<FaviconBitmapIDSize> bitmap_id_sizes; 1609 std::vector<FaviconBitmapIDSize> bitmap_id_sizes;
1608 thumbnail_db_->GetFaviconBitmapIDSizes(favicon_id, &bitmap_id_sizes); 1610 thumbnail_db_->GetFaviconBitmapIDSizes(favicon_id, &bitmap_id_sizes);
1609 1611
1610 // If there is already a favicon bitmap of |pixel_size| at |icon_url|, 1612 // If there is already a favicon bitmap of |pixel_size| at |icon_url|,
1611 // replace it. 1613 // replace it.
1612 bool bitmap_identical = false; 1614 bool bitmap_identical = false;
1613 bool replaced_bitmap = false; 1615 bool replaced_bitmap = false;
1614 for (size_t i = 0; i < bitmap_id_sizes.size(); ++i) { 1616 for (size_t i = 0; i < bitmap_id_sizes.size(); ++i) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1682 // Difficulty 1: All but news.google.com/news_specific.ico are unmapped from 1684 // Difficulty 1: All but news.google.com/news_specific.ico are unmapped from
1683 // news.google.com 1685 // news.google.com
1684 // Difficulty 2: The favicon bitmaps for www.google.com/favicon.ico are not 1686 // Difficulty 2: The favicon bitmaps for www.google.com/favicon.ico are not
1685 // modified. 1687 // modified.
1686 1688
1687 std::vector<IconMapping> icon_mappings; 1689 std::vector<IconMapping> icon_mappings;
1688 thumbnail_db_->GetIconMappingsForPageURL(page_url, icon_type, &icon_mappings); 1690 thumbnail_db_->GetIconMappingsForPageURL(page_url, icon_type, &icon_mappings);
1689 1691
1690 // Copy the favicon bitmaps mapped to |page_url| to the favicon at |icon_url| 1692 // Copy the favicon bitmaps mapped to |page_url| to the favicon at |icon_url|
1691 // till the limit of |kMaxFaviconBitmapsPerIconURL| is reached. 1693 // till the limit of |kMaxFaviconBitmapsPerIconURL| is reached.
1694 bool favicon_bitmaps_copied = false;
1692 for (size_t i = 0; i < icon_mappings.size(); ++i) { 1695 for (size_t i = 0; i < icon_mappings.size(); ++i) {
1693 if (favicon_sizes.size() >= kMaxFaviconBitmapsPerIconURL) 1696 if (favicon_sizes.size() >= kMaxFaviconBitmapsPerIconURL)
1694 break; 1697 break;
1695 1698
1696 if (icon_mappings[i].icon_url == icon_url) 1699 if (icon_mappings[i].icon_url == icon_url)
1697 continue; 1700 continue;
1698 1701
1699 std::vector<FaviconBitmap> bitmaps_to_copy; 1702 std::vector<FaviconBitmap> bitmaps_to_copy;
1700 thumbnail_db_->GetFaviconBitmaps(icon_mappings[i].icon_id, 1703 thumbnail_db_->GetFaviconBitmaps(icon_mappings[i].icon_id,
1701 &bitmaps_to_copy); 1704 &bitmaps_to_copy);
1702 for (size_t j = 0; j < bitmaps_to_copy.size(); ++j) { 1705 for (size_t j = 0; j < bitmaps_to_copy.size(); ++j) {
1703 // Do not add a favicon bitmap at a pixel size for which there is already 1706 // Do not add a favicon bitmap at a pixel size for which there is already
1704 // a favicon bitmap mapped to |icon_url|. The one there is more correct 1707 // a favicon bitmap mapped to |icon_url|. The one there is more correct
1705 // and having multiple equally sized favicon bitmaps for |page_url| is 1708 // and having multiple equally sized favicon bitmaps for |page_url| is
1706 // ambiguous in terms of GetFaviconsForURL(). 1709 // ambiguous in terms of GetFaviconsForURL().
1707 std::vector<gfx::Size>::iterator it = 1710 std::vector<gfx::Size>::iterator it =
1708 std::find(favicon_sizes.begin(), favicon_sizes.end(), 1711 std::find(favicon_sizes.begin(), favicon_sizes.end(),
1709 bitmaps_to_copy[j].pixel_size); 1712 bitmaps_to_copy[j].pixel_size);
1710 if (it != favicon_sizes.end()) 1713 if (it != favicon_sizes.end())
1711 continue; 1714 continue;
1712 1715
1713 // Add the favicon bitmap as expired as it is not consistent with the 1716 // Add the favicon bitmap as expired as it is not consistent with the
1714 // merged in data. 1717 // merged in data.
1715 thumbnail_db_->AddFaviconBitmap( 1718 thumbnail_db_->AddFaviconBitmap(
1716 favicon_id, bitmaps_to_copy[j].bitmap_data, base::Time(), 1719 favicon_id, bitmaps_to_copy[j].bitmap_data, base::Time(),
1717 bitmaps_to_copy[j].pixel_size); 1720 bitmaps_to_copy[j].pixel_size);
1718 favicon_sizes.push_back(bitmaps_to_copy[j].pixel_size); 1721 favicon_sizes.push_back(bitmaps_to_copy[j].pixel_size);
1722 favicon_bitmaps_copied = true;
1719 1723
1720 if (favicon_sizes.size() >= kMaxFaviconBitmapsPerIconURL) 1724 if (favicon_sizes.size() >= kMaxFaviconBitmapsPerIconURL)
1721 break; 1725 break;
1722 } 1726 }
1723 } 1727 }
1724 1728
1725 // Update the favicon mappings such that only |icon_url| is mapped to 1729 // Update the favicon mappings such that only |icon_url| is mapped to
1726 // |page_url|. 1730 // |page_url|.
1727 bool mapping_changed = false; 1731 bool mapping_changed = false;
1728 if (icon_mappings.size() != 1 || icon_mappings[0].icon_url != icon_url) { 1732 if (icon_mappings.size() != 1 || icon_mappings[0].icon_url != icon_url) {
1729 std::vector<favicon_base::FaviconID> favicon_ids; 1733 std::vector<favicon_base::FaviconID> favicon_ids;
1730 favicon_ids.push_back(favicon_id); 1734 favicon_ids.push_back(favicon_id);
1731 SetFaviconMappingsForPageAndRedirects(page_url, icon_type, favicon_ids); 1735 SetFaviconMappingsForPageAndRedirects(page_url, icon_type, favicon_ids);
1732 mapping_changed = true; 1736 mapping_changed = true;
1733 } 1737 }
1734 1738
1735 if (mapping_changed || !bitmap_identical) 1739 if (mapping_changed)
1736 SendFaviconChangedNotificationForPageAndRedirects(page_url); 1740 SendFaviconChangedNotificationForPageAndRedirects(page_url);
1741
1742 if (!favicon_created && (!bitmap_identical || favicon_bitmaps_copied)) {
1743 // If there was a favicon at |icon_url| prior to MergeFavicon() being
1744 // called, there may be page URLs which also use the favicon at |icon_url|.
1745 // Notify the UI that the favicon has changed for |icon_url|.
1746 SendFaviconChangedNotificationForIconURL(icon_url);
1747 }
1748
1737 ScheduleCommit(); 1749 ScheduleCommit();
1738 } 1750 }
1739 1751
1740 void HistoryBackend::SetFavicons(const GURL& page_url, 1752 void HistoryBackend::SetFavicons(const GURL& page_url,
1741 favicon_base::IconType icon_type, 1753 favicon_base::IconType icon_type,
1742 const GURL& icon_url, 1754 const GURL& icon_url,
1743 const std::vector<SkBitmap>& bitmaps) { 1755 const std::vector<SkBitmap>& bitmaps) {
1744 if (!thumbnail_db_ || !db_) 1756 if (!thumbnail_db_ || !db_)
1745 return; 1757 return;
1746 1758
1747 DCHECK_GE(kMaxFaviconBitmapsPerIconURL, bitmaps.size()); 1759 DCHECK_GE(kMaxFaviconBitmapsPerIconURL, bitmaps.size());
1748 1760
1749 // Track whether the method modifies or creates any favicon bitmaps, favicons
1750 // or icon mappings.
1751 bool data_modified = false;
1752
1753 favicon_base::FaviconID icon_id = 1761 favicon_base::FaviconID icon_id =
1754 thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, icon_type, nullptr); 1762 thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, icon_type, nullptr);
1755 1763
1764 bool favicon_created = false;
1756 if (!icon_id) { 1765 if (!icon_id) {
1757 icon_id = thumbnail_db_->AddFavicon(icon_url, icon_type); 1766 icon_id = thumbnail_db_->AddFavicon(icon_url, icon_type);
1758 data_modified = true; 1767 favicon_created = true;
1759 } 1768 }
1760 1769
1761 data_modified |= SetFaviconBitmaps(icon_id, bitmaps); 1770 bool favicon_data_modified = SetFaviconBitmaps(icon_id, bitmaps);
1762 1771
1763 std::vector<favicon_base::FaviconID> icon_ids(1u, icon_id); 1772 std::vector<favicon_base::FaviconID> icon_ids(1u, icon_id);
1764 data_modified |= 1773 bool mapping_changed =
1765 SetFaviconMappingsForPageAndRedirects(page_url, icon_type, icon_ids); 1774 SetFaviconMappingsForPageAndRedirects(page_url, icon_type, icon_ids);
1766 1775
1767 if (data_modified) { 1776 if (mapping_changed) {
1768 // Send notification to the UI as an icon mapping, favicon, or favicon 1777 // Notify the UI that this function changed an icon mapping.
1769 // bitmap was changed by this function.
1770 SendFaviconChangedNotificationForPageAndRedirects(page_url); 1778 SendFaviconChangedNotificationForPageAndRedirects(page_url);
1771 } 1779 }
1780
1781 if (favicon_data_modified && !favicon_created) {
1782 // If there was a favicon at |icon_url| prior to SetFavicons() being called,
1783 // there may be page URLs which also use the favicon at |icon_url|. Notify
1784 // the UI that the favicon has changed for |icon_url|.
1785 SendFaviconChangedNotificationForIconURL(icon_url);
1786 }
1772 ScheduleCommit(); 1787 ScheduleCommit();
1773 } 1788 }
1774 1789
1775 void HistoryBackend::SetFaviconsOutOfDateForPage(const GURL& page_url) { 1790 void HistoryBackend::SetFaviconsOutOfDateForPage(const GURL& page_url) {
1776 std::vector<IconMapping> icon_mappings; 1791 std::vector<IconMapping> icon_mappings;
1777 1792
1778 if (!thumbnail_db_ || 1793 if (!thumbnail_db_ ||
1779 !thumbnail_db_->GetIconMappingsForPageURL(page_url, &icon_mappings)) 1794 !thumbnail_db_->GetIconMappingsForPageURL(page_url, &icon_mappings))
1780 return; 1795 return;
1781 1796
1782 for (std::vector<IconMapping>::iterator m = icon_mappings.begin(); 1797 for (std::vector<IconMapping>::iterator m = icon_mappings.begin();
1783 m != icon_mappings.end(); ++m) { 1798 m != icon_mappings.end(); ++m) {
1784 thumbnail_db_->SetFaviconOutOfDate(m->icon_id); 1799 thumbnail_db_->SetFaviconOutOfDate(m->icon_id);
1785 } 1800 }
1786 ScheduleCommit(); 1801 ScheduleCommit();
1787 } 1802 }
1788 1803
1789 void HistoryBackend::SetImportedFavicons( 1804 void HistoryBackend::SetImportedFavicons(
1790 const favicon_base::FaviconUsageDataList& favicon_usage) { 1805 const favicon_base::FaviconUsageDataList& favicon_usage) {
1791 if (!db_ || !thumbnail_db_) 1806 if (!db_ || !thumbnail_db_)
1792 return; 1807 return;
1793 1808
1794 Time now = Time::Now(); 1809 Time now = Time::Now();
1795 1810
1796 // Track all URLs that had their favicons set or updated. 1811 // Track all URLs that had their favicons set or updated.
1797 std::set<GURL> favicons_changed; 1812 std::vector<GURL> favicons_changed;
1798 1813
1799 for (size_t i = 0; i < favicon_usage.size(); i++) { 1814 for (size_t i = 0; i < favicon_usage.size(); i++) {
1800 favicon_base::FaviconID favicon_id = 1815 favicon_base::FaviconID favicon_id =
1801 thumbnail_db_->GetFaviconIDForFaviconURL( 1816 thumbnail_db_->GetFaviconIDForFaviconURL(
1802 favicon_usage[i].favicon_url, favicon_base::FAVICON, nullptr); 1817 favicon_usage[i].favicon_url, favicon_base::FAVICON, nullptr);
1803 if (!favicon_id) { 1818 if (!favicon_id) {
1804 // This favicon doesn't exist yet, so we create it using the given data. 1819 // This favicon doesn't exist yet, so we create it using the given data.
1805 // TODO(pkotwicz): Pass in real pixel size. 1820 // TODO(pkotwicz): Pass in real pixel size.
1806 favicon_id = thumbnail_db_->AddFavicon( 1821 favicon_id = thumbnail_db_->AddFavicon(
1807 favicon_usage[i].favicon_url, favicon_base::FAVICON, 1822 favicon_usage[i].favicon_url, favicon_base::FAVICON,
(...skipping 13 matching lines...) Expand all
1821 // cleaned, we keep an entry in the db with 0 visits as long as that 1836 // cleaned, we keep an entry in the db with 0 visits as long as that
1822 // url is bookmarked. 1837 // url is bookmarked.
1823 if (history_client && history_client->IsBookmarked(*url)) { 1838 if (history_client && history_client->IsBookmarked(*url)) {
1824 URLRow url_info(*url); 1839 URLRow url_info(*url);
1825 url_info.set_visit_count(0); 1840 url_info.set_visit_count(0);
1826 url_info.set_typed_count(0); 1841 url_info.set_typed_count(0);
1827 url_info.set_last_visit(base::Time()); 1842 url_info.set_last_visit(base::Time());
1828 url_info.set_hidden(false); 1843 url_info.set_hidden(false);
1829 db_->AddURL(url_info); 1844 db_->AddURL(url_info);
1830 thumbnail_db_->AddIconMapping(*url, favicon_id); 1845 thumbnail_db_->AddIconMapping(*url, favicon_id);
1831 favicons_changed.insert(*url); 1846 favicons_changed.push_back(*url);
1832 } 1847 }
1833 } else { 1848 } else {
1834 if (!thumbnail_db_->GetIconMappingsForPageURL( 1849 if (!thumbnail_db_->GetIconMappingsForPageURL(
1835 *url, favicon_base::FAVICON, nullptr)) { 1850 *url, favicon_base::FAVICON, nullptr)) {
1836 // URL is present in history, update the favicon *only* if it is not 1851 // URL is present in history, update the favicon *only* if it is not
1837 // set already. 1852 // set already.
1838 thumbnail_db_->AddIconMapping(*url, favicon_id); 1853 thumbnail_db_->AddIconMapping(*url, favicon_id);
1839 favicons_changed.insert(*url); 1854 favicons_changed.push_back(*url);
1840 } 1855 }
1841 } 1856 }
1842 } 1857 }
1843 } 1858 }
1844 1859
1845 if (!favicons_changed.empty()) { 1860 if (!favicons_changed.empty()) {
1846 // Send the notification about the changed favicon URLs. 1861 // Send the notification about the changed favicon URLs.
1847 NotifyFaviconChanged(favicons_changed); 1862 NotifyFaviconsChanged(favicons_changed, std::vector<GURL>());
1848 } 1863 }
1849 } 1864 }
1850 1865
1851 void HistoryBackend::UpdateFaviconMappingsAndFetchImpl( 1866 void HistoryBackend::UpdateFaviconMappingsAndFetchImpl(
1852 const GURL* page_url, 1867 const GURL* page_url,
1853 const std::vector<GURL>& icon_urls, 1868 const std::vector<GURL>& icon_urls,
1854 int icon_types, 1869 int icon_types,
1855 const std::vector<int>& desired_sizes, 1870 const std::vector<int>& desired_sizes,
1856 std::vector<favicon_base::FaviconRawBitmapResult>* bitmap_results) { 1871 std::vector<favicon_base::FaviconRawBitmapResult>* bitmap_results) {
1857 // If |page_url| is specified, |icon_types| must be either a single icon 1872 // If |page_url| is specified, |icon_types| must be either a single icon
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
2166 // No known redirects, construct mock redirect chain containing |page_url|. 2181 // No known redirects, construct mock redirect chain containing |page_url|.
2167 redirect_list->push_back(page_url); 2182 redirect_list->push_back(page_url);
2168 } 2183 }
2169 } 2184 }
2170 2185
2171 void HistoryBackend::SendFaviconChangedNotificationForPageAndRedirects( 2186 void HistoryBackend::SendFaviconChangedNotificationForPageAndRedirects(
2172 const GURL& page_url) { 2187 const GURL& page_url) {
2173 RedirectList redirect_list; 2188 RedirectList redirect_list;
2174 GetCachedRecentRedirects(page_url, &redirect_list); 2189 GetCachedRecentRedirects(page_url, &redirect_list);
2175 if (!redirect_list.empty()) { 2190 if (!redirect_list.empty()) {
2176 std::set<GURL> favicons_changed(redirect_list.begin(), redirect_list.end()); 2191 std::vector<GURL> favicons_changed(redirect_list.begin(),
2177 NotifyFaviconChanged(favicons_changed); 2192 redirect_list.end());
2193 NotifyFaviconsChanged(favicons_changed, std::vector<GURL>());
2178 } 2194 }
2179 } 2195 }
2180 2196
2197 void HistoryBackend::SendFaviconChangedNotificationForIconURL(
2198 const GURL& icon_url) {
2199 NotifyFaviconsChanged(std::vector<GURL>(),
2200 std::vector<GURL>(1u, icon_url));
2201 }
2202
2181 void HistoryBackend::Commit() { 2203 void HistoryBackend::Commit() {
2182 if (!db_) 2204 if (!db_)
2183 return; 2205 return;
2184 2206
2185 #if defined(OS_IOS) 2207 #if defined(OS_IOS)
2186 // Attempts to get the application running long enough to commit the database 2208 // Attempts to get the application running long enough to commit the database
2187 // transaction if it is currently being backgrounded. 2209 // transaction if it is currently being backgrounded.
2188 base::ios::ScopedCriticalAction scoped_critical_action; 2210 base::ios::ScopedCriticalAction scoped_critical_action;
2189 #endif 2211 #endif
2190 2212
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
2453 scoped_ptr<HistoryDBTask> task, 2475 scoped_ptr<HistoryDBTask> task,
2454 scoped_refptr<base::SingleThreadTaskRunner> origin_loop, 2476 scoped_refptr<base::SingleThreadTaskRunner> origin_loop,
2455 const base::CancelableTaskTracker::IsCanceledCallback& is_canceled) { 2477 const base::CancelableTaskTracker::IsCanceledCallback& is_canceled) {
2456 bool scheduled = !queued_history_db_tasks_.empty(); 2478 bool scheduled = !queued_history_db_tasks_.empty();
2457 queued_history_db_tasks_.push_back( 2479 queued_history_db_tasks_.push_back(
2458 new QueuedHistoryDBTask(task.Pass(), origin_loop, is_canceled)); 2480 new QueuedHistoryDBTask(task.Pass(), origin_loop, is_canceled));
2459 if (!scheduled) 2481 if (!scheduled)
2460 ProcessDBTaskImpl(); 2482 ProcessDBTaskImpl();
2461 } 2483 }
2462 2484
2463 void HistoryBackend::NotifyFaviconChanged(const std::set<GURL>& urls) { 2485 void HistoryBackend::NotifyFaviconsChanged(const std::vector<GURL>& page_urls,
2486 const std::vector<GURL>& icon_urls) {
2464 if (delegate_) 2487 if (delegate_)
2465 delegate_->NotifyFaviconChanged(urls); 2488 delegate_->NotifyFaviconsChanged(page_urls, icon_urls);
2466 } 2489 }
2467 2490
2468 void HistoryBackend::NotifyURLVisited(ui::PageTransition transition, 2491 void HistoryBackend::NotifyURLVisited(ui::PageTransition transition,
2469 const URLRow& row, 2492 const URLRow& row,
2470 const RedirectList& redirects, 2493 const RedirectList& redirects,
2471 base::Time visit_time) { 2494 base::Time visit_time) {
2472 URLRow url_info(row); 2495 URLRow url_info(row);
2473 if (typed_url_syncable_service_.get()) 2496 if (typed_url_syncable_service_.get())
2474 typed_url_syncable_service_->OnUrlVisited(transition, &url_info); 2497 typed_url_syncable_service_->OnUrlVisited(transition, &url_info);
2475 2498
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
2650 return true; 2673 return true;
2651 } 2674 }
2652 2675
2653 HistoryClient* HistoryBackend::GetHistoryClient() { 2676 HistoryClient* HistoryBackend::GetHistoryClient() {
2654 if (history_client_) 2677 if (history_client_)
2655 history_client_->BlockUntilBookmarksLoaded(); 2678 history_client_->BlockUntilBookmarksLoaded();
2656 return history_client_; 2679 return history_client_;
2657 } 2680 }
2658 2681
2659 } // namespace history 2682 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698