OLD | NEW |
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 1623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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::FAVICON, 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::FAVICON); |
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 } |
1654 | 1654 |
1655 // Save the mapping from all the URLs to the favicon. | 1655 // Save the mapping from all the URLs to the favicon. |
1656 BookmarkService* bookmark_service = GetBookmarkService(); | 1656 BookmarkService* bookmark_service = GetBookmarkService(); |
1657 for (std::set<GURL>::const_iterator url = favicon_usage[i].urls.begin(); | 1657 for (std::set<GURL>::const_iterator url = favicon_usage[i].urls.begin(); |
1658 url != favicon_usage[i].urls.end(); ++url) { | 1658 url != favicon_usage[i].urls.end(); ++url) { |
1659 URLRow url_row; | 1659 URLRow url_row; |
1660 if (!db_->GetRowForURL(*url, &url_row)) { | 1660 if (!db_->GetRowForURL(*url, &url_row)) { |
1661 // If the URL is present as a bookmark, add the url in history to | 1661 // If the URL is present as a bookmark, add the url in history to |
1662 // save the favicon mapping. This will match with what history db does | 1662 // save the favicon mapping. This will match with what history db does |
1663 // for regular bookmarked URLs with favicons - when history db is | 1663 // for regular bookmarked URLs with favicons - when history db is |
1664 // cleaned, we keep an entry in the db with 0 visits as long as that | 1664 // cleaned, we keep an entry in the db with 0 visits as long as that |
1665 // url is bookmarked. | 1665 // url is bookmarked. |
1666 if (bookmark_service && bookmark_service_->IsBookmarked(*url)) { | 1666 if (bookmark_service && bookmark_service_->IsBookmarked(*url)) { |
1667 URLRow url_info(*url); | 1667 URLRow url_info(*url); |
1668 url_info.set_visit_count(0); | 1668 url_info.set_visit_count(0); |
1669 url_info.set_typed_count(0); | 1669 url_info.set_typed_count(0); |
1670 url_info.set_last_visit(base::Time()); | 1670 url_info.set_last_visit(base::Time()); |
1671 url_info.set_hidden(false); | 1671 url_info.set_hidden(false); |
1672 db_->AddURL(url_info); | 1672 db_->AddURL(url_info); |
1673 thumbnail_db_->AddIconMapping(*url, favicon_id); | 1673 thumbnail_db_->AddIconMapping(*url, favicon_id); |
1674 favicons_changed.insert(*url); | 1674 favicons_changed.insert(*url); |
1675 } | 1675 } |
1676 } else { | 1676 } else { |
1677 if (!thumbnail_db_->GetIconMappingForPageURL(*url, FAV_ICON, NULL)) { | 1677 if (!thumbnail_db_->GetIconMappingForPageURL(*url, FAVICON, NULL)) { |
1678 // URL is present in history, update the favicon *only* if it is not | 1678 // URL is present in history, update the favicon *only* if it is not |
1679 // set already. | 1679 // set already. |
1680 thumbnail_db_->AddIconMapping(*url, favicon_id); | 1680 thumbnail_db_->AddIconMapping(*url, favicon_id); |
1681 favicons_changed.insert(*url); | 1681 favicons_changed.insert(*url); |
1682 } | 1682 } |
1683 } | 1683 } |
1684 } | 1684 } |
1685 } | 1685 } |
1686 | 1686 |
1687 if (!favicons_changed.empty()) { | 1687 if (!favicons_changed.empty()) { |
1688 // Send the notification about the changed favicon URLs. | 1688 // Send the notification about the changed favicon URLs. |
1689 FavIconChangeDetails* changed_details = new FavIconChangeDetails; | 1689 FavIconChangeDetails* changed_details = new FavIconChangeDetails; |
1690 changed_details->urls.swap(favicons_changed); | 1690 changed_details->urls.swap(favicons_changed); |
1691 BroadcastNotifications(NotificationType::FAVICON_CHANGED, changed_details); | 1691 BroadcastNotifications(NotificationType::FAVICON_CHANGED, changed_details); |
1692 } | 1692 } |
1693 } | 1693 } |
1694 | 1694 |
1695 void HistoryBackend::UpdateFavIconMappingAndFetchImpl( | 1695 void HistoryBackend::UpdateFavIconMappingAndFetchImpl( |
1696 const GURL* page_url, | 1696 const GURL* page_url, |
1697 const GURL& icon_url, | 1697 const GURL& icon_url, |
1698 scoped_refptr<GetFavIconRequest> request, | 1698 scoped_refptr<GetFavIconRequest> request, |
1699 int icon_types) { | 1699 int icon_types) { |
1700 // Check only a single type was given when the page_url was specified. | 1700 // Check only a single type was given when the page_url was specified. |
1701 DCHECK(!page_url || (page_url && (icon_types == FAV_ICON || | 1701 DCHECK(!page_url || (page_url && (icon_types == FAVICON || |
1702 icon_types == TOUCH_ICON || icon_types == TOUCH_PRECOMPOSED_ICON))); | 1702 icon_types == TOUCH_ICON || icon_types == TOUCH_PRECOMPOSED_ICON))); |
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()) { |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
OLD | NEW |