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 == FAV_ICON || | 1701 DCHECK(!page_url || (page_url && (icon_types == FAV_ICON || |
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 FaviconService::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) { |
1714 scoped_refptr<RefCountedBytes> data; | |
sky
2011/03/10 17:54:44
Does this really work? Don't you need to set favic
michaelbai
2011/03/11 01:11:28
The new RefCountedBytes is actually in next line,
sky
2011/03/11 01:19:26
My mistake.
michaelbai
2011/03/11 16:56:19
data is the member of RefCountedBytes, the type of
sky
2011/03/11 17:56:45
GAH! Sorry. I get it.
I'm tempted to say the callb
| |
1717 data = new RefCountedBytes; | 1715 data = new RefCountedBytes; |
1718 know_favicon = true; | 1716 favicon.known_icon = true; |
1719 Time last_updated; | 1717 Time last_updated; |
1720 if (thumbnail_db_->GetFavIcon(favicon_id, &last_updated, &data->data, | 1718 if (thumbnail_db_->GetFavIcon(favicon_id, &last_updated, |
1719 &data->data, | |
1721 NULL)) { | 1720 NULL)) { |
1722 expired = (Time::Now() - last_updated) > | 1721 favicon.expired = (Time::Now() - last_updated) > |
1723 TimeDelta::FromDays(kFavIconRefetchDays); | 1722 TimeDelta::FromDays(kFavIconRefetchDays); |
1723 favicon.image_data = data; | |
1724 } | 1724 } |
1725 | 1725 |
1726 if (page_url) | 1726 if (page_url) |
1727 SetFavIconMapping(*page_url, favicon_id, returned_icon_type); | 1727 SetFavIconMapping(*page_url, favicon_id, favicon.icon_type); |
1728 } | 1728 } |
1729 // else case, haven't cached entry yet. Caller is responsible for | 1729 // else case, haven't cached entry yet. Caller is responsible for |
1730 // downloading the favicon and invoking SetFavIcon. | 1730 // downloading the favicon and invoking SetFavIcon. |
1731 } | 1731 } |
1732 request->ForwardResult(GetFavIconRequest::TupleType( | 1732 request->ForwardResult(GetFavIconRequest::TupleType( |
1733 request->handle(), know_favicon, data, expired, | 1733 request->handle(), favicon)); |
1734 icon_url)); | |
1735 } | 1734 } |
1736 | 1735 |
1737 void HistoryBackend::GetFavIconForURL( | 1736 void HistoryBackend::GetFavIconForURL( |
1738 scoped_refptr<GetFavIconRequest> request, | 1737 scoped_refptr<GetFavIconRequest> request, |
1739 const GURL& page_url, | 1738 const GURL& page_url, |
1740 int icon_types) { | 1739 int icon_types) { |
1741 if (request->canceled()) | 1740 if (request->canceled()) |
1742 return; | 1741 return; |
1743 | 1742 |
1744 bool know_favicon = false; | 1743 FaviconService::FaviconData favicon; |
1745 bool expired = false; | |
1746 GURL icon_url; | |
1747 | |
1748 scoped_refptr<RefCountedBytes> data; | |
1749 | 1744 |
1750 if (db_.get() && thumbnail_db_.get()) { | 1745 if (db_.get() && thumbnail_db_.get()) { |
1751 // Time the query. | 1746 // Time the query. |
1752 TimeTicks beginning_time = TimeTicks::Now(); | 1747 TimeTicks beginning_time = TimeTicks::Now(); |
1753 | 1748 |
1754 std::vector<IconMapping> icon_mappings; | 1749 std::vector<IconMapping> icon_mappings; |
1750 Time last_updated; | |
1751 scoped_refptr<RefCountedBytes> data; | |
sky
2011/03/10 17:54:44
Same comment as above here.
michaelbai
2011/03/11 01:11:28
Moved new RefCountedBytes up
| |
1755 data = new RefCountedBytes; | 1752 data = new RefCountedBytes; |
1756 Time last_updated; | |
1757 if (thumbnail_db_->GetIconMappingsForPageURL(page_url, &icon_mappings) && | 1753 if (thumbnail_db_->GetIconMappingsForPageURL(page_url, &icon_mappings) && |
1758 (icon_mappings.front().icon_type & icon_types) && | 1754 (icon_mappings.front().icon_type & icon_types) && |
1759 thumbnail_db_->GetFavIcon(icon_mappings.front().icon_id, &last_updated, | 1755 thumbnail_db_->GetFavIcon(icon_mappings.front().icon_id, &last_updated, |
1760 &data->data, &icon_url)) { | 1756 &data->data, &favicon.icon_url)) { |
1761 know_favicon = true; | 1757 favicon.known_icon = true; |
1762 expired = (Time::Now() - last_updated) > | 1758 favicon.expired = (Time::Now() - last_updated) > |
1763 TimeDelta::FromDays(kFavIconRefetchDays); | 1759 TimeDelta::FromDays(kFavIconRefetchDays); |
1760 favicon.icon_type = icon_mappings.front().icon_type; | |
1761 favicon.image_data = data; | |
1764 } | 1762 } |
1765 | 1763 |
1766 UMA_HISTOGRAM_TIMES("History.GetFavIconForURL", | 1764 UMA_HISTOGRAM_TIMES("History.GetFavIconForURL", |
1767 TimeTicks::Now() - beginning_time); | 1765 TimeTicks::Now() - beginning_time); |
1768 } | 1766 } |
1769 | 1767 |
1770 request->ForwardResult( | 1768 request->ForwardResult( |
1771 GetFavIconRequest::TupleType(request->handle(), know_favicon, data, | 1769 GetFavIconRequest::TupleType(request->handle(), favicon)); |
1772 expired, icon_url)); | |
1773 } | 1770 } |
1774 | 1771 |
1775 void HistoryBackend::SetFavIcon( | 1772 void HistoryBackend::SetFavIcon( |
1776 const GURL& page_url, | 1773 const GURL& page_url, |
1777 const GURL& icon_url, | 1774 const GURL& icon_url, |
1778 scoped_refptr<RefCountedMemory> data, | 1775 scoped_refptr<RefCountedMemory> data, |
1779 IconType icon_type) { | 1776 IconType icon_type) { |
1780 DCHECK(data.get()); | 1777 DCHECK(data.get()); |
1781 if (!thumbnail_db_.get() || !db_.get()) | 1778 if (!thumbnail_db_.get() || !db_.get()) |
1782 return; | 1779 return; |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2255 return true; | 2252 return true; |
2256 } | 2253 } |
2257 | 2254 |
2258 BookmarkService* HistoryBackend::GetBookmarkService() { | 2255 BookmarkService* HistoryBackend::GetBookmarkService() { |
2259 if (bookmark_service_) | 2256 if (bookmark_service_) |
2260 bookmark_service_->BlockTillLoaded(); | 2257 bookmark_service_->BlockTillLoaded(); |
2261 return bookmark_service_; | 2258 return bookmark_service_; |
2262 } | 2259 } |
2263 | 2260 |
2264 } // namespace history | 2261 } // namespace history |
OLD | NEW |