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

Unified Diff: components/history/core/browser/thumbnail_database.cc

Issue 1004373002: Add last_requested field to the favicon_bitmaps table of the favicons database. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments Created 5 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 side-by-side diff with in-line comments
Download patch
Index: components/history/core/browser/thumbnail_database.cc
diff --git a/components/history/core/browser/thumbnail_database.cc b/components/history/core/browser/thumbnail_database.cc
index e82888492a36db72869d5b2fc5544556922ceaa8..274350f4dd010880b26b4d2646ef7991b5c9d574 100644
--- a/components/history/core/browser/thumbnail_database.cc
+++ b/components/history/core/browser/thumbnail_database.cc
@@ -58,14 +58,17 @@ namespace history {
// the |id| field in the appropriate row in the |favicons|
// table.
//
-// id Unique ID.
-// icon_id The ID of the favicon that the bitmap is associated to.
-// last_updated The time at which this favicon was inserted into the
+// id Unique ID.
+// icon_id The ID of the favicon that the bitmap is associated to.
+// last_updated The time at which this favicon was inserted into the
// table. This is used to determine if it needs to be
// redownloaded from the web.
-// image_data PNG encoded data of the favicon.
-// width Pixel width of |image_data|.
-// height Pixel height of |image_data|.
+// last_requested The time at which this bitmap was last requested. This is
+// used to determine the priority with which the bitmap
+// should be retained on cleanup.
+// image_data PNG encoded data of the favicon.
+// width Pixel width of |image_data|.
+// height Pixel height of |image_data|.
namespace {
@@ -77,18 +80,19 @@ namespace {
// fatal (in fact, very old data may be expired immediately at startup
// anyhow).
+// Version 8: ???????? by rogerm@chromium.org on 2015-??-??
// Version 7: 911a634d/r209424 by qsr@chromium.org on 2013-07-01
// Version 6: 610f923b/r152367 by pkotwicz@chromium.org on 2012-08-20
-// Version 5: e2ee8ae9/r105004 by groby@chromium.org on 2011-10-12
+// Version 5: e2ee8ae9/r105004 by groby@chromium.org on 2011-10-12 (deprecated)
Scott Hess - ex-Googler 2015/03/19 21:32:22 Cool beans. I was going to suggest that earlier,
Roger McFarlane (Chromium) 2015/03/20 14:40:59 With they way recovery/upgrade is done, it was mes
// Version 4: 5f104d76/r77288 by sky@chromium.org on 2011-03-08 (deprecated)
// Version 3: 09911bf3/r15 by initial.commit on 2008-07-26 (deprecated)
// Version number of the database.
// NOTE(shess): When changing the version, add a new golden file for
// the new version and a test to verify that Init() works with it.
-const int kCurrentVersionNumber = 7;
-const int kCompatibleVersionNumber = 7;
-const int kDeprecatedVersionNumber = 4; // and earlier.
+const int kCurrentVersionNumber = 8;
+const int kCompatibleVersionNumber = 8;
+const int kDeprecatedVersionNumber = 5; // and earlier.
void FillIconMapping(const sql::Statement& statement,
const GURL& page_url,
@@ -310,7 +314,10 @@ bool InitTables(sql::Connection* db) {
"last_updated INTEGER DEFAULT 0,"
"image_data BLOB,"
"width INTEGER DEFAULT 0,"
- "height INTEGER DEFAULT 0"
+ "height INTEGER DEFAULT 0,"
+ // This field is at the end so that fresh tables and migrated tables have
+ // the same layout.
+ "last_requested INTEGER DEFAULT 0"
")";
if (!db->Execute(kFaviconBitmapsSql))
return false;
@@ -396,7 +403,7 @@ void RecoverDatabaseOrRaze(sql::Connection* db, const base::FilePath& db_path) {
// NOTE(shess): This code is currently specific to the version
// number. I am working on simplifying things to loosen the
// dependency, meanwhile contact me if you need to bump the version.
- DCHECK_EQ(7, kCurrentVersionNumber);
+ DCHECK_EQ(8, kCurrentVersionNumber);
// TODO(shess): Reset back after?
db->reset_error_callback();
@@ -448,9 +455,8 @@ void RecoverDatabaseOrRaze(sql::Connection* db, const base::FilePath& db_path) {
return;
}
- // Earlier versions have been handled or deprecated, later versions should be
- // impossible.
- if (version != 7) {
+ // Earlier versions have been handled or deprecated.
+ if (version < 7) {
sql::Recovery::Unrecoverable(recovery.Pass());
RecordRecoveryEvent(RECOVERY_EVENT_FAILED_META_WRONG_VERSION);
return;
@@ -613,11 +619,24 @@ sql::InitStatus ThumbnailDatabase::Init(const base::FilePath& db_name) {
}
void ThumbnailDatabase::ComputeDatabaseMetrics() {
- sql::Statement favicon_count(
- db_.GetCachedStatement(SQL_FROM_HERE, "SELECT COUNT(*) FROM favicons"));
- UMA_HISTOGRAM_COUNTS_10000(
- "History.NumFaviconsInDB",
- favicon_count.Step() ? favicon_count.ColumnInt(0) : 0);
+ // Count all icon files referenced by the DB.
+ {
+ sql::Statement favicon_count(
+ db_.GetCachedStatement(SQL_FROM_HERE, "SELECT COUNT(*) FROM favicons"));
+ UMA_HISTOGRAM_COUNTS_10000(
+ "History.NumFaviconsInDB",
+ favicon_count.Step() ? favicon_count.ColumnInt(0) : 0);
+ }
+
+ // Count all bitmap resources cached in the DB.
+ {
+ sql::Statement bitmap_count(
+ db_.GetCachedStatement(
+ SQL_FROM_HERE, "SELECT COUNT(*) FROM favicon_bitmaps"));
+ UMA_HISTOGRAM_COUNTS_10000(
+ "History.NumBitmapsInDB",
+ bitmap_count.Step() ? bitmap_count.ColumnInt(0) : 0);
+ }
}
void ThumbnailDatabase::BeginTransaction() {
@@ -727,6 +746,22 @@ bool ThumbnailDatabase::GetFaviconBitmap(
return true;
}
+bool ThumbnailDatabase::GetFaviconBitmapLastRequestedTime(
+ FaviconBitmapID bitmap_id,
+ base::Time* last_requested) {
+ DCHECK(bitmap_id);
+ DCHECK(last_requested);
+ sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
+ "SELECT last_requested FROM favicon_bitmaps WHERE id=?"));
+ statement.BindInt64(0, bitmap_id);
+
+ if (!statement.Step())
+ return false;
+
+ *last_requested = base::Time::FromInternalValue(statement.ColumnInt64(0));
+ return true;
+}
+
FaviconBitmapID ThumbnailDatabase::AddFaviconBitmap(
favicon_base::FaviconID icon_id,
const scoped_refptr<base::RefCountedMemory>& icon_data,
@@ -782,6 +817,17 @@ bool ThumbnailDatabase::SetFaviconBitmapLastUpdateTime(
return statement.Run();
}
+bool ThumbnailDatabase::SetFaviconBitmapLastRequestedTime(
+ FaviconBitmapID bitmap_id,
+ base::Time time) {
+ DCHECK(bitmap_id);
+ sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
+ "UPDATE favicon_bitmaps SET last_requested=? WHERE id=?"));
+ statement.BindInt64(0, time.ToInternalValue());
+ statement.BindInt64(1, bitmap_id);
+ return statement.Run();
+}
+
bool ThumbnailDatabase::DeleteFaviconBitmap(FaviconBitmapID bitmap_id) {
sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
"DELETE FROM favicon_bitmaps WHERE id=?"));
@@ -1086,6 +1132,8 @@ bool ThumbnailDatabase::RetainDataForPageUrls(
"ON (old.id = mapping.old_icon_id)";
const char kDropOldFaviconsTable[] = "DROP TABLE old_favicons";
+ // Note that we allow the last_requested field to be reset to the default
+ // value (0).
const char kRenameFaviconBitmapsTable[] =
"ALTER TABLE favicon_bitmaps RENAME TO old_favicon_bitmaps";
const char kCopyFaviconBitmaps[] =
@@ -1194,7 +1242,7 @@ sql::InitStatus ThumbnailDatabase::InitImpl(const base::FilePath& db_name) {
#endif
// thumbnails table has been obsolete for a long time, remove any
huangs 2015/03/19 19:14:11 NIT: unwrap?
beaudoin 2015/03/19 21:36:54 I'm fine leaving it wrapped, 90% of the multi-line
Roger McFarlane (Chromium) 2015/03/20 14:41:00 Acknowledged.
Roger McFarlane (Chromium) 2015/03/20 14:41:00 Done.
- // detrious.
+ // detritus.
ignore_result(db_.Execute("DROP TABLE IF EXISTS thumbnails"));
// At some point, operations involving temporary tables weren't done
@@ -1252,6 +1300,12 @@ sql::InitStatus ThumbnailDatabase::InitImpl(const base::FilePath& db_name) {
return CantUpgradeToVersion(cur_version);
}
+ if (cur_version == 7) {
+ ++cur_version;
+ if (!UpgradeToVersion8())
+ return CantUpgradeToVersion(cur_version);
+ }
+
LOG_IF(WARNING, cur_version < kCurrentVersionNumber) <<
"Thumbnail database version " << cur_version << " is too old to handle.";
@@ -1332,6 +1386,19 @@ bool ThumbnailDatabase::UpgradeToVersion7() {
return true;
}
+bool ThumbnailDatabase::UpgradeToVersion8() {
+ // Add the last_requested column to the favicon_bitmaps table.
+ const char kFaviconBitmapsAddLastRequestedSql[] =
+ "ALTER TABLE favicon_bitmaps ADD COLUMN last_requested INTEGER DEFAULT 0";
+ if (!db_.Execute(kFaviconBitmapsAddLastRequestedSql))
+ return false;
+
+
huangs 2015/03/19 19:14:11 NIT: extra space. I recently learned about "git c
Roger McFarlane (Chromium) 2015/03/20 14:41:00 Done.
+ meta_table_.SetVersionNumber(8);
+ meta_table_.SetCompatibleVersionNumber(std::min(8, kCompatibleVersionNumber));
+ return true;
+}
+
bool ThumbnailDatabase::IsFaviconDBStructureIncorrect() {
return !db_.IsSQLValid("SELECT id, url, icon_type FROM favicons");
}

Powered by Google App Engine
This is Rietveld 408576698