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

Side by Side Diff: chrome/browser/history/history_backend.cc

Issue 6698031: fav icon -> favicon. Pass 7: FavIconID -> FaviconID (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/history/history_backend.h" 5 #include "chrome/browser/history/history_backend.h"
6 6
7 #include <list> 7 #include <list>
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
(...skipping 1622 matching lines...) Expand 10 before | Expand all | Expand 10 after
1633 const std::vector<ImportedFavIconUsage>& favicon_usage) { 1633 const std::vector<ImportedFavIconUsage>& favicon_usage) {
1634 if (!db_.get() || !thumbnail_db_.get()) 1634 if (!db_.get() || !thumbnail_db_.get())
1635 return; 1635 return;
1636 1636
1637 Time now = Time::Now(); 1637 Time now = Time::Now();
1638 1638
1639 // Track all URLs that had their favicons set or updated. 1639 // Track all URLs that had their favicons set or updated.
1640 std::set<GURL> favicons_changed; 1640 std::set<GURL> favicons_changed;
1641 1641
1642 for (size_t i = 0; i < favicon_usage.size(); i++) { 1642 for (size_t i = 0; i < favicon_usage.size(); i++) {
1643 FavIconID favicon_id = thumbnail_db_->GetFavIconIDForFavIconURL( 1643 FaviconID favicon_id = thumbnail_db_->GetFaviconIDForFavIconURL(
1644 favicon_usage[i].favicon_url, history::FAV_ICON, NULL); 1644 favicon_usage[i].favicon_url, history::FAV_ICON, NULL);
1645 if (!favicon_id) { 1645 if (!favicon_id) {
1646 // This favicon doesn't exist yet, so we create it using the given data. 1646 // This favicon doesn't exist yet, so we create it using the given data.
1647 favicon_id = thumbnail_db_->AddFavIcon(favicon_usage[i].favicon_url, 1647 favicon_id = thumbnail_db_->AddFavIcon(favicon_usage[i].favicon_url,
1648 history::FAV_ICON); 1648 history::FAV_ICON);
1649 if (!favicon_id) 1649 if (!favicon_id)
1650 continue; // Unable to add the favicon. 1650 continue; // Unable to add the favicon.
1651 thumbnail_db_->SetFavicon(favicon_id, 1651 thumbnail_db_->SetFavicon(favicon_id,
1652 new RefCountedBytes(favicon_usage[i].png_data), now); 1652 new RefCountedBytes(favicon_usage[i].png_data), now);
1653 } 1653 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1703 1703
1704 if (request->canceled()) 1704 if (request->canceled())
1705 return; 1705 return;
1706 1706
1707 bool know_favicon = false; 1707 bool know_favicon = false;
1708 bool expired = true; 1708 bool expired = true;
1709 scoped_refptr<RefCountedBytes> data; 1709 scoped_refptr<RefCountedBytes> data;
1710 1710
1711 if (thumbnail_db_.get()) { 1711 if (thumbnail_db_.get()) {
1712 IconType returned_icon_type; 1712 IconType returned_icon_type;
1713 const FavIconID favicon_id = 1713 const FaviconID favicon_id =
1714 thumbnail_db_->GetFavIconIDForFavIconURL( 1714 thumbnail_db_->GetFaviconIDForFavIconURL(
1715 icon_url, icon_types, &returned_icon_type); 1715 icon_url, icon_types, &returned_icon_type);
1716 if (favicon_id) { 1716 if (favicon_id) {
1717 data = new RefCountedBytes; 1717 data = new RefCountedBytes;
1718 know_favicon = true; 1718 know_favicon = true;
1719 Time last_updated; 1719 Time last_updated;
1720 if (thumbnail_db_->GetFavicon(favicon_id, &last_updated, &data->data, 1720 if (thumbnail_db_->GetFavicon(favicon_id, &last_updated, &data->data,
1721 NULL)) { 1721 NULL)) {
1722 expired = (Time::Now() - last_updated) > 1722 expired = (Time::Now() - last_updated) >
1723 TimeDelta::FromDays(kFavIconRefetchDays); 1723 TimeDelta::FromDays(kFavIconRefetchDays);
1724 } 1724 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1774 1774
1775 void HistoryBackend::SetFavicon( 1775 void HistoryBackend::SetFavicon(
1776 const GURL& page_url, 1776 const GURL& page_url,
1777 const GURL& icon_url, 1777 const GURL& icon_url,
1778 scoped_refptr<RefCountedMemory> data, 1778 scoped_refptr<RefCountedMemory> data,
1779 IconType icon_type) { 1779 IconType icon_type) {
1780 DCHECK(data.get()); 1780 DCHECK(data.get());
1781 if (!thumbnail_db_.get() || !db_.get()) 1781 if (!thumbnail_db_.get() || !db_.get())
1782 return; 1782 return;
1783 1783
1784 FavIconID id = thumbnail_db_->GetFavIconIDForFavIconURL( 1784 FaviconID id = thumbnail_db_->GetFaviconIDForFavIconURL(
1785 icon_url, icon_type, NULL); 1785 icon_url, icon_type, NULL);
1786 if (!id) 1786 if (!id)
1787 id = thumbnail_db_->AddFavIcon(icon_url, icon_type); 1787 id = thumbnail_db_->AddFavIcon(icon_url, icon_type);
1788 1788
1789 // Set the image data. 1789 // Set the image data.
1790 thumbnail_db_->SetFavicon(id, data, Time::Now()); 1790 thumbnail_db_->SetFavicon(id, data, Time::Now());
1791 1791
1792 SetFaviconMapping(page_url, id, icon_type); 1792 SetFaviconMapping(page_url, id, icon_type);
1793 } 1793 }
1794 1794
1795 void HistoryBackend::SetFaviconMapping(const GURL& page_url, 1795 void HistoryBackend::SetFaviconMapping(const GURL& page_url,
1796 FavIconID id, 1796 FaviconID id,
1797 IconType icon_type) { 1797 IconType icon_type) {
1798 if (!thumbnail_db_.get()) 1798 if (!thumbnail_db_.get())
1799 return; 1799 return;
1800 1800
1801 // Find all the pages whose favicons we should set, we want to set it for 1801 // Find all the pages whose favicons we should set, we want to set it for
1802 // all the pages in the redirect chain if it redirected. 1802 // all the pages in the redirect chain if it redirected.
1803 history::RedirectList dummy_list; 1803 history::RedirectList dummy_list;
1804 history::RedirectList* redirects; 1804 history::RedirectList* redirects;
1805 RedirectCache::iterator iter = recent_redirects_.Get(page_url); 1805 RedirectCache::iterator iter = recent_redirects_.Get(page_url);
1806 if (iter != recent_redirects_.end()) { 1806 if (iter != recent_redirects_.end()) {
1807 redirects = &iter->second; 1807 redirects = &iter->second;
1808 1808
1809 // This redirect chain should have the destination URL as the last item. 1809 // This redirect chain should have the destination URL as the last item.
1810 DCHECK(!redirects->empty()); 1810 DCHECK(!redirects->empty());
1811 DCHECK(redirects->back() == page_url); 1811 DCHECK(redirects->back() == page_url);
1812 } else { 1812 } else {
1813 // No redirect chain stored, make up one containing the URL we want to we 1813 // No redirect chain stored, make up one containing the URL we want to we
1814 // can use the same logic below. 1814 // can use the same logic below.
1815 dummy_list.push_back(page_url); 1815 dummy_list.push_back(page_url);
1816 redirects = &dummy_list; 1816 redirects = &dummy_list;
1817 } 1817 }
1818 1818
1819 std::set<GURL> favicons_changed; 1819 std::set<GURL> favicons_changed;
1820 1820
1821 // Save page <-> favicon association. 1821 // Save page <-> favicon association.
1822 for (history::RedirectList::const_iterator i(redirects->begin()); 1822 for (history::RedirectList::const_iterator i(redirects->begin());
1823 i != redirects->end(); ++i) { 1823 i != redirects->end(); ++i) {
1824 FavIconID replaced_id; 1824 FaviconID replaced_id;
1825 if (AddOrUpdateIconMapping(*i, id, icon_type, &replaced_id)) { 1825 if (AddOrUpdateIconMapping(*i, id, icon_type, &replaced_id)) {
1826 // The page's favicon ID changed. This means that the one we just 1826 // The page's favicon ID changed. This means that the one we just
1827 // changed from could have been orphaned, and we need to re-check it. 1827 // changed from could have been orphaned, and we need to re-check it.
1828 // This is not super fast, but this case will get triggered rarely, 1828 // This is not super fast, but this case will get triggered rarely,
1829 // since normally a page will always map to the same favicon ID. It 1829 // since normally a page will always map to the same favicon ID. It
1830 // will mostly happen for favicons we import. 1830 // will mostly happen for favicons we import.
1831 if (replaced_id && !thumbnail_db_->HasMappingFor(replaced_id)) 1831 if (replaced_id && !thumbnail_db_->HasMappingFor(replaced_id))
1832 thumbnail_db_->DeleteFavIcon(replaced_id); 1832 thumbnail_db_->DeleteFavIcon(replaced_id);
1833 1833
1834 favicons_changed.insert(*i); 1834 favicons_changed.insert(*i);
1835 } 1835 }
1836 } 1836 }
1837 1837
1838 // Send the notification about the changed favicons. 1838 // Send the notification about the changed favicons.
1839 FavIconChangeDetails* changed_details = new FavIconChangeDetails; 1839 FavIconChangeDetails* changed_details = new FavIconChangeDetails;
1840 changed_details->urls.swap(favicons_changed); 1840 changed_details->urls.swap(favicons_changed);
1841 BroadcastNotifications(NotificationType::FAVICON_CHANGED, changed_details); 1841 BroadcastNotifications(NotificationType::FAVICON_CHANGED, changed_details);
1842 1842
1843 ScheduleCommit(); 1843 ScheduleCommit();
1844 } 1844 }
1845 1845
1846 bool HistoryBackend::AddOrUpdateIconMapping(const GURL& page_url, 1846 bool HistoryBackend::AddOrUpdateIconMapping(const GURL& page_url,
1847 FavIconID id, 1847 FaviconID id,
1848 IconType icon_type, 1848 IconType icon_type,
1849 FavIconID* replaced_icon) { 1849 FaviconID* replaced_icon) {
1850 *replaced_icon = 0; 1850 *replaced_icon = 0;
1851 std::vector<IconMapping> icon_mappings; 1851 std::vector<IconMapping> icon_mappings;
1852 if (!thumbnail_db_->GetIconMappingsForPageURL(page_url, &icon_mappings)) { 1852 if (!thumbnail_db_->GetIconMappingsForPageURL(page_url, &icon_mappings)) {
1853 // There is no mapping add it directly. 1853 // There is no mapping add it directly.
1854 thumbnail_db_->AddIconMapping(page_url, id); 1854 thumbnail_db_->AddIconMapping(page_url, id);
1855 return true; 1855 return true;
1856 } 1856 }
1857 // Iterate all matched icon mappings, 1857 // Iterate all matched icon mappings,
1858 // a. If the given icon id and matched icon id are same, return. 1858 // a. If the given icon id and matched icon id are same, return.
1859 // b. If the given icon type and matched icon type are same, but icon id 1859 // b. If the given icon type and matched icon type are same, but icon id
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
2167 2167
2168 // Create the duplicate favicon table, this is where the favicons we want 2168 // Create the duplicate favicon table, this is where the favicons we want
2169 // to keep will be stored. 2169 // to keep will be stored.
2170 if (!thumbnail_db_->InitTemporaryFavIconsTable()) 2170 if (!thumbnail_db_->InitTemporaryFavIconsTable())
2171 return false; 2171 return false;
2172 2172
2173 if (!thumbnail_db_->InitTemporaryIconMappingTable()) 2173 if (!thumbnail_db_->InitTemporaryIconMappingTable())
2174 return false; 2174 return false;
2175 2175
2176 // This maps existing favicon IDs to the ones in the temporary table. 2176 // This maps existing favicon IDs to the ones in the temporary table.
2177 typedef std::map<FavIconID, FavIconID> FavIconMap; 2177 typedef std::map<FaviconID, FaviconID> FavIconMap;
2178 FavIconMap copied_favicons; 2178 FavIconMap copied_favicons;
2179 2179
2180 // Copy all unique favicons to the temporary table, and update all the 2180 // Copy all unique favicons to the temporary table, and update all the
2181 // URLs to have the new IDs. 2181 // URLs to have the new IDs.
2182 for (std::vector<URLRow>::iterator i = kept_urls->begin(); 2182 for (std::vector<URLRow>::iterator i = kept_urls->begin();
2183 i != kept_urls->end(); ++i) { 2183 i != kept_urls->end(); ++i) {
2184 std::vector<IconMapping> icon_mappings; 2184 std::vector<IconMapping> icon_mappings;
2185 if (!thumbnail_db_->GetIconMappingsForPageURL(i->url(), &icon_mappings)) 2185 if (!thumbnail_db_->GetIconMappingsForPageURL(i->url(), &icon_mappings))
2186 continue; 2186 continue;
2187 2187
2188 for (std::vector<IconMapping>::iterator m = icon_mappings.begin(); 2188 for (std::vector<IconMapping>::iterator m = icon_mappings.begin();
2189 m != icon_mappings.end(); ++m) { 2189 m != icon_mappings.end(); ++m) {
2190 FavIconID old_id = m->icon_id; 2190 FaviconID old_id = m->icon_id;
2191 FavIconID new_id; 2191 FaviconID new_id;
2192 FavIconMap::const_iterator found = copied_favicons.find(old_id); 2192 FavIconMap::const_iterator found = copied_favicons.find(old_id);
2193 if (found == copied_favicons.end()) { 2193 if (found == copied_favicons.end()) {
2194 new_id = thumbnail_db_->CopyToTemporaryFavIconTable(old_id); 2194 new_id = thumbnail_db_->CopyToTemporaryFavIconTable(old_id);
2195 copied_favicons[old_id] = new_id; 2195 copied_favicons[old_id] = new_id;
2196 } else { 2196 } else {
2197 // We already encountered a URL that used this favicon, use the ID we 2197 // We already encountered a URL that used this favicon, use the ID we
2198 // previously got. 2198 // previously got.
2199 new_id = found->second; 2199 new_id = found->second;
2200 } 2200 }
2201 // Add Icon mapping, and we don't care wheteher it suceeded or not. 2201 // Add Icon mapping, and we don't care wheteher it suceeded or not.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2255 return true; 2255 return true;
2256 } 2256 }
2257 2257
2258 BookmarkService* HistoryBackend::GetBookmarkService() { 2258 BookmarkService* HistoryBackend::GetBookmarkService() {
2259 if (bookmark_service_) 2259 if (bookmark_service_)
2260 bookmark_service_->BlockTillLoaded(); 2260 bookmark_service_->BlockTillLoaded();
2261 return bookmark_service_; 2261 return bookmark_service_;
2262 } 2262 }
2263 2263
2264 } // namespace history 2264 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/history_backend.h ('k') | chrome/browser/history/history_backend_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698