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

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

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

Powered by Google App Engine
This is Rietveld 408576698