| Index: chrome/browser/history/thumbnail_database.cc
|
| diff --git a/chrome/browser/history/thumbnail_database.cc b/chrome/browser/history/thumbnail_database.cc
|
| index 497fe857a22a5a4c9acc70e1846e5dcadb3a602c..dbcfa39dc6630abe4616ad8a8f932ce1c11f5f02 100644
|
| --- a/chrome/browser/history/thumbnail_database.cc
|
| +++ b/chrome/browser/history/thumbnail_database.cc
|
| @@ -22,6 +22,7 @@
|
| #include "sql/transaction.h"
|
| #include "ui/gfx/favicon_size.h"
|
| #include "ui/gfx/image/image_util.h"
|
| +#include "ui/gfx/size.h"
|
|
|
| #if defined(OS_MACOSX)
|
| #include "base/mac/mac_util.h"
|
| @@ -34,6 +35,8 @@ static void FillIconMapping(const sql::Statement& statement,
|
| icon_mapping->icon_id = statement.ColumnInt64(1);
|
| icon_mapping->icon_type =
|
| static_cast<history::IconType>(statement.ColumnInt(2));
|
| + icon_mapping->icon_pixel_size =
|
| + gfx::Size(statement.ColumnInt(3), statement.ColumnInt(4));
|
| icon_mapping->page_url = page_url;
|
| }
|
|
|
| @@ -403,21 +406,30 @@ bool ThumbnailDatabase::SetFaviconLastUpdateTime(FaviconID icon_id,
|
| return statement.Run();
|
| }
|
|
|
| -FaviconID ThumbnailDatabase::GetFaviconIDForFaviconURL(const GURL& icon_url,
|
| - int required_icon_type,
|
| - IconType* icon_type) {
|
| +void ThumbnailDatabase::GetFaviconIDsForFaviconURL(
|
| + const GURL& icon_url,
|
| + int required_icon_type,
|
| + std::vector<FaviconIDAndSize>* favicon_id_size_listing) {
|
| sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
|
| - "SELECT id, icon_type FROM favicons WHERE url=? AND (icon_type & ? > 0) "
|
| - "ORDER BY icon_type DESC"));
|
| + "SELECT id, icon_type, width, height FROM favicons "
|
| + "WHERE url=? AND (icon_type & ? > 0) ORDER BY icon_type DESC"));
|
| statement.BindString(0, URLDatabase::GURLToDatabaseURL(icon_url));
|
| statement.BindInt(1, required_icon_type);
|
|
|
| - if (!statement.Step())
|
| - return 0; // not cached
|
| -
|
| - if (icon_type)
|
| - *icon_type = static_cast<IconType>(statement.ColumnInt(1));
|
| - return statement.ColumnInt64(0);
|
| + IconType chosen_icon_type = INVALID_ICON;
|
| + while (statement.Step()) {
|
| + IconType icon_type = static_cast<IconType>(statement.ColumnInt(1));
|
| + if (chosen_icon_type == INVALID_ICON)
|
| + chosen_icon_type = icon_type;
|
| + else if (icon_type != chosen_icon_type)
|
| + break;
|
| +
|
| + FaviconIDAndSize favicon_id_size;
|
| + favicon_id_size.icon_id = statement.ColumnInt64(0);
|
| + favicon_id_size.icon_size = gfx::Size(statement.ColumnInt(2),
|
| + statement.ColumnInt(3));
|
| + favicon_id_size_listing->push_back(favicon_id_size);
|
| + }
|
| }
|
|
|
| bool ThumbnailDatabase::GetFavicon(
|
| @@ -425,11 +437,12 @@ bool ThumbnailDatabase::GetFavicon(
|
| base::Time* last_updated,
|
| std::vector<unsigned char>* png_icon_data,
|
| GURL* icon_url,
|
| + gfx::Size* pixel_size,
|
| IconType* icon_type) {
|
| DCHECK(icon_id);
|
|
|
| sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
|
| - "SELECT last_updated, image_data, url, icon_type "
|
| + "SELECT last_updated, image_data, url, icon_type, width, height "
|
| "FROM favicons WHERE id=?"));
|
| statement.BindInt64(0, icon_id);
|
|
|
| @@ -444,20 +457,22 @@ bool ThumbnailDatabase::GetFavicon(
|
| *icon_url = GURL(statement.ColumnString(2));
|
| if (icon_type)
|
| *icon_type = static_cast<history::IconType>(statement.ColumnInt(3));
|
| + if (pixel_size)
|
| + *pixel_size = gfx::Size(statement.ColumnInt(4), statement.ColumnInt(5));
|
|
|
| return true;
|
| }
|
|
|
| FaviconID ThumbnailDatabase::AddFavicon(const GURL& icon_url,
|
| + const gfx::Size& pixel_size,
|
| IconType icon_type) {
|
| - int default_size = icon_type == FAVICON ? gfx::kFaviconSize : 0;
|
| sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
|
| "INSERT INTO favicons (url, icon_type, width, height) VALUES "
|
| "(?, ?, ?, ?)"));
|
| statement.BindString(0, URLDatabase::GURLToDatabaseURL(icon_url));
|
| statement.BindInt(1, icon_type);
|
| - statement.BindInt(2, default_size);
|
| - statement.BindInt(3, default_size);
|
| + statement.BindInt(2, pixel_size.width());
|
| + statement.BindInt(3, pixel_size.height());
|
|
|
| if (!statement.Run())
|
| return 0;
|
| @@ -472,30 +487,33 @@ bool ThumbnailDatabase::DeleteFavicon(FaviconID id) {
|
| return statement.Run();
|
| }
|
|
|
| -bool ThumbnailDatabase::GetIconMappingForPageURL(const GURL& page_url,
|
| - IconType required_icon_type,
|
| - IconMapping* icon_mapping) {
|
| - std::vector<IconMapping> icon_mappings;
|
| - if (!GetIconMappingsForPageURL(page_url, &icon_mappings))
|
| +bool ThumbnailDatabase::GetIconMappingsForPageURL(
|
| + const GURL& page_url,
|
| + int required_icon_types,
|
| + std::vector<IconMapping>* icon_mappings) {
|
| + std::vector<IconMapping> unfiltered_icon_mappings;
|
| + if (!GetIconMappingsForPageURL(page_url, &unfiltered_icon_mappings))
|
| return false;
|
|
|
| - for (std::vector<IconMapping>::iterator m = icon_mappings.begin();
|
| - m != icon_mappings.end(); ++m) {
|
| - if (m->icon_type == required_icon_type) {
|
| - if (icon_mapping != NULL)
|
| - *icon_mapping = *m;
|
| - return true;
|
| + for (std::vector<IconMapping>::iterator m = unfiltered_icon_mappings.begin();
|
| + m != unfiltered_icon_mappings.end(); ++m) {
|
| + if (m->icon_type & required_icon_types) {
|
| + if (icon_mappings == NULL)
|
| + return true;
|
| +
|
| + icon_mappings->push_back(*m);
|
| }
|
| }
|
|
|
| - return false;
|
| + return (icon_mappings == NULL) ? false : !icon_mappings->empty();
|
| }
|
|
|
| bool ThumbnailDatabase::GetIconMappingsForPageURL(
|
| const GURL& page_url,
|
| std::vector<IconMapping>* mapping_data) {
|
| sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
|
| - "SELECT icon_mapping.id, icon_mapping.icon_id, favicons.icon_type "
|
| + "SELECT icon_mapping.id, icon_mapping.icon_id, favicons.icon_type, "
|
| + "favicons.width, favicons.height "
|
| "FROM icon_mapping "
|
| "INNER JOIN favicons "
|
| "ON icon_mapping.icon_id = favicons.id "
|
|
|