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

Unified Diff: chrome/browser/history/thumbnail_database.cc

Issue 10815068: Changes favicon database to support storing bitmaps of different sizes for the same icon_url (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/history/thumbnail_database.h ('k') | chrome/browser/history/thumbnail_database_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/history/thumbnail_database.cc
diff --git a/chrome/browser/history/thumbnail_database.cc b/chrome/browser/history/thumbnail_database.cc
index 0397f961e3859bec530897d2e8c13f3bcc8d212f..02ae044c0186febc01ce7b750aaf995d91dc77df 100644
--- a/chrome/browser/history/thumbnail_database.cc
+++ b/chrome/browser/history/thumbnail_database.cc
@@ -20,6 +20,7 @@
#include "chrome/common/thumbnail_score.h"
#include "sql/statement.h"
#include "sql/transaction.h"
+#include "ui/gfx/favicon_size.h"
#include "ui/gfx/image/image_util.h"
#if defined(OS_MACOSX)
@@ -39,8 +40,8 @@ static void FillIconMapping(const sql::Statement& statement,
namespace history {
// Version number of the database.
-static const int kCurrentVersionNumber = 5;
-static const int kCompatibleVersionNumber = 5;
+static const int kCurrentVersionNumber = 6;
+static const int kCompatibleVersionNumber = 6;
// Use 90 quality (out of 100) which is pretty high, because we're very
// sensitive to artifacts for these small sized, highly detailed images.
@@ -66,7 +67,7 @@ ThumbnailDatabase::ThumbnailDatabase()
}
sql::InitStatus ThumbnailDatabase::CantUpgradeToVersion(int cur_version) {
- LOG(WARNING) << "Unable to update to thumbnail database to version 4" <<
+ LOG(WARNING) << "Unable to update to thumbnail database to version " <<
cur_version << ".";
db_.Close();
return sql::INIT_FAILURE;
@@ -127,10 +128,17 @@ sql::InitStatus ThumbnailDatabase::Init(
}
if (cur_version == 4) {
+ ++cur_version;
if (!UpgradeToVersion5())
return CantUpgradeToVersion(cur_version);
}
+ if (cur_version == 5) {
+ ++cur_version;
+ if (!UpgradeToVersion6())
+ return CantUpgradeToVersion(cur_version);
+ }
+
LOG_IF(WARNING, cur_version < kCurrentVersionNumber) <<
"Thumbnail database version " << cur_version << " is too old to handle.";
@@ -225,7 +233,7 @@ bool ThumbnailDatabase::InitFaviconsTable(sql::Connection* db,
// Set the default icon_type as FAVICON to be consistent with
// table upgrade in UpgradeToVersion4().
"icon_type INTEGER DEFAULT 1,"
- "sizes LONGVARCHAR)");
+ "size INTEGER)");
sky 2012/07/24 04:38:47 Doesn't this assume the size is a rectangle?
if (!db->Execute(sql.c_str()))
return false;
}
@@ -443,9 +451,10 @@ FaviconID ThumbnailDatabase::AddFavicon(const GURL& icon_url,
IconType icon_type) {
sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
- "INSERT INTO favicons (url, icon_type) VALUES (?, ?)"));
+ "INSERT INTO favicons (url, icon_type, size) VALUES (?, ?, ?)"));
statement.BindString(0, URLDatabase::GURLToDatabaseURL(icon_url));
statement.BindInt(1, icon_type);
+ statement.BindInt(2, icon_type == FAVICON ? gfx::kFaviconSize : 0);
if (!statement.Run())
return 0;
@@ -608,8 +617,9 @@ bool ThumbnailDatabase::CommitTemporaryIconMappingTable() {
FaviconID ThumbnailDatabase::CopyToTemporaryFaviconTable(FaviconID source) {
sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
- "INSERT INTO temp_favicons (url, last_updated, image_data, icon_type)"
- "SELECT url, last_updated, image_data, icon_type "
+ "INSERT INTO temp_favicons (url, last_updated, image_data, icon_type, "
+ "size)"
+ "SELECT url, last_updated, image_data, icon_type, size "
"FROM favicons WHERE id = ?"));
statement.BindInt64(0, source);
@@ -786,4 +796,30 @@ bool ThumbnailDatabase::UpgradeToVersion5() {
return true;
}
+bool ThumbnailDatabase::UpgradeToVersion6() {
+ bool success =
+ db_.Execute("CREATE TABLE favicons_temp ("
+ "id INTEGER PRIMARY KEY,"
+ "url LONGVARCHAR NOT NULL,"
+ "last_updated INTEGER DEFAULT 0,"
+ "image_data BLOB,"
+ "icon_type INTEGER DEFAULT 1,"
+ "size INTEGER DEFAULT 0)") &&
+ db_.Execute("INSERT INTO favicons_temp (id, url, last_updated, "
+ "image_data, icon_type)"
+ "SELECT id, url, last_updated, image_data, icon_type FROM "
+ "favicons") &&
+ db_.Execute("DROP TABLE favicons") &&
+ db_.Execute("ALTER TABLE favicons_temp RENAME TO favicons");
+
+ // In version 4 & 5 of the database, favicons of type FAVICON are assumed to
+ // be 16px in size.
+ success &= db_.Execute(
+ "UPDATE favicons SET size = '16' WHERE icon_type = '1'");
+
+ meta_table_.SetVersionNumber(6);
+ meta_table_.SetCompatibleVersionNumber(std::min(6, kCompatibleVersionNumber));
+ return success;
+}
+
} // namespace history
« no previous file with comments | « chrome/browser/history/thumbnail_database.h ('k') | chrome/browser/history/thumbnail_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698