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 1686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 == FAVICON || | 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 FaviconData favicon; |
1708 bool expired = true; | |
1709 scoped_refptr<RefCountedBytes> data; | |
1710 | 1708 |
1711 if (thumbnail_db_.get()) { | 1709 if (thumbnail_db_.get()) { |
1712 IconType returned_icon_type; | |
1713 const FaviconID favicon_id = | 1710 const FaviconID favicon_id = |
1714 thumbnail_db_->GetFaviconIDForFaviconURL( | 1711 thumbnail_db_->GetFaviconIDForFaviconURL( |
1715 icon_url, icon_types, &returned_icon_type); | 1712 icon_url, icon_types, &favicon.icon_type); |
1716 if (favicon_id) { | 1713 if (favicon_id) { |
1717 data = new RefCountedBytes; | 1714 scoped_refptr<RefCountedBytes> data = new RefCountedBytes(); |
1718 know_favicon = true; | 1715 favicon.known_icon = true; |
1719 Time last_updated; | 1716 Time last_updated; |
1720 if (thumbnail_db_->GetFavicon(favicon_id, &last_updated, &data->data, | 1717 if (thumbnail_db_->GetFavicon(favicon_id, &last_updated, &data->data, |
1721 NULL)) { | 1718 NULL)) { |
1722 expired = (Time::Now() - last_updated) > | 1719 favicon.expired = (Time::Now() - last_updated) > |
1723 TimeDelta::FromDays(kFaviconRefetchDays); | 1720 TimeDelta::FromDays(kFaviconRefetchDays); |
| 1721 favicon.image_data = data; |
1724 } | 1722 } |
1725 | 1723 |
1726 if (page_url) | 1724 if (page_url) |
1727 SetFaviconMapping(*page_url, favicon_id, returned_icon_type); | 1725 SetFaviconMapping(*page_url, favicon_id, favicon.icon_type); |
1728 } | 1726 } |
1729 // else case, haven't cached entry yet. Caller is responsible for | 1727 // else case, haven't cached entry yet. Caller is responsible for |
1730 // downloading the favicon and invoking SetFavicon. | 1728 // downloading the favicon and invoking SetFavicon. |
1731 } | 1729 } |
1732 request->ForwardResult(GetFaviconRequest::TupleType( | 1730 request->ForwardResult(GetFaviconRequest::TupleType( |
1733 request->handle(), know_favicon, data, expired, | 1731 request->handle(), favicon)); |
1734 icon_url)); | |
1735 } | 1732 } |
1736 | 1733 |
1737 void HistoryBackend::GetFaviconForURL( | 1734 void HistoryBackend::GetFaviconForURL( |
1738 scoped_refptr<GetFaviconRequest> request, | 1735 scoped_refptr<GetFaviconRequest> request, |
1739 const GURL& page_url, | 1736 const GURL& page_url, |
1740 int icon_types) { | 1737 int icon_types) { |
1741 if (request->canceled()) | 1738 if (request->canceled()) |
1742 return; | 1739 return; |
1743 | 1740 |
1744 bool know_favicon = false; | 1741 FaviconData favicon; |
1745 bool expired = false; | |
1746 GURL icon_url; | |
1747 | |
1748 scoped_refptr<RefCountedBytes> data; | |
1749 | 1742 |
1750 if (db_.get() && thumbnail_db_.get()) { | 1743 if (db_.get() && thumbnail_db_.get()) { |
1751 // Time the query. | 1744 // Time the query. |
1752 TimeTicks beginning_time = TimeTicks::Now(); | 1745 TimeTicks beginning_time = TimeTicks::Now(); |
1753 | 1746 |
1754 std::vector<IconMapping> icon_mappings; | 1747 std::vector<IconMapping> icon_mappings; |
1755 data = new RefCountedBytes; | |
1756 Time last_updated; | 1748 Time last_updated; |
| 1749 scoped_refptr<RefCountedBytes> data = new RefCountedBytes(); |
1757 if (thumbnail_db_->GetIconMappingsForPageURL(page_url, &icon_mappings) && | 1750 if (thumbnail_db_->GetIconMappingsForPageURL(page_url, &icon_mappings) && |
1758 (icon_mappings.front().icon_type & icon_types) && | 1751 (icon_mappings.front().icon_type & icon_types) && |
1759 thumbnail_db_->GetFavicon(icon_mappings.front().icon_id, &last_updated, | 1752 thumbnail_db_->GetFavicon(icon_mappings.front().icon_id, &last_updated, |
1760 &data->data, &icon_url)) { | 1753 &data->data, &favicon.icon_url)) { |
1761 know_favicon = true; | 1754 favicon.known_icon = true; |
1762 expired = (Time::Now() - last_updated) > | 1755 favicon.expired = (Time::Now() - last_updated) > |
1763 TimeDelta::FromDays(kFaviconRefetchDays); | 1756 TimeDelta::FromDays(kFaviconRefetchDays); |
| 1757 favicon.icon_type = icon_mappings.front().icon_type; |
| 1758 favicon.image_data = data; |
1764 } | 1759 } |
1765 | 1760 |
1766 UMA_HISTOGRAM_TIMES("History.GetFavIconForURL", // historical name | 1761 UMA_HISTOGRAM_TIMES("History.GetFavIconForURL", // historical name |
1767 TimeTicks::Now() - beginning_time); | 1762 TimeTicks::Now() - beginning_time); |
1768 } | 1763 } |
1769 | 1764 |
1770 request->ForwardResult( | 1765 request->ForwardResult( |
1771 GetFaviconRequest::TupleType(request->handle(), know_favicon, data, | 1766 GetFaviconRequest::TupleType(request->handle(), favicon)); |
1772 expired, icon_url)); | |
1773 } | 1767 } |
1774 | 1768 |
1775 void HistoryBackend::SetFavicon( | 1769 void HistoryBackend::SetFavicon( |
1776 const GURL& page_url, | 1770 const GURL& page_url, |
1777 const GURL& icon_url, | 1771 const GURL& icon_url, |
1778 scoped_refptr<RefCountedMemory> data, | 1772 scoped_refptr<RefCountedMemory> data, |
1779 IconType icon_type) { | 1773 IconType icon_type) { |
1780 DCHECK(data.get()); | 1774 DCHECK(data.get()); |
1781 if (!thumbnail_db_.get() || !db_.get()) | 1775 if (!thumbnail_db_.get() || !db_.get()) |
1782 return; | 1776 return; |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2255 return true; | 2249 return true; |
2256 } | 2250 } |
2257 | 2251 |
2258 BookmarkService* HistoryBackend::GetBookmarkService() { | 2252 BookmarkService* HistoryBackend::GetBookmarkService() { |
2259 if (bookmark_service_) | 2253 if (bookmark_service_) |
2260 bookmark_service_->BlockTillLoaded(); | 2254 bookmark_service_->BlockTillLoaded(); |
2261 return bookmark_service_; | 2255 return bookmark_service_; |
2262 } | 2256 } |
2263 | 2257 |
2264 } // namespace history | 2258 } // namespace history |
OLD | NEW |