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

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

Issue 2903573002: [Thumbnails DB] Add functionality to clear unused on-demand favicons. (Closed)
Patch Set: Brett's comments Created 3 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
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 c8b430f4f71d8dd70f0111995c5ce74297cec7d9..8a7290182b783c4f110b40fdfc86a42d553529e2 100644
--- a/components/history/core/browser/thumbnail_database.cc
+++ b/components/history/core/browser/thumbnail_database.cc
@@ -412,6 +412,33 @@ void ThumbnailDatabase::TrimMemory(bool aggressively) {
db_.TrimMemory(aggressively);
}
+std::map<favicon_base::FaviconID, IconMappingsForExpiry>
+ThumbnailDatabase::GetOldOnDemandFavicons(base::Time threshold) {
+ // Restrict to on-demand bitmaps (i.e. with last_requested != 0).
+ // TODO(jkrcal): In M63, remove the "(last_requested=0 AND last_updated=0)"
+ // clause which is only transitional - to clean up expired icons (previously,
+ // on-demand favicons were stored as expired on-visit favicons).
+ sql::Statement old_icons(db_.GetCachedStatement(
brettw 2017/07/13 23:50:17 Can you make this be a non-cached ("unique") state
mastiz 2017/07/18 07:48:19 Done.
+ SQL_FROM_HERE,
+ "SELECT favicons.id, favicons.url, icon_mapping.page_url FROM "
brettw 2017/07/13 23:50:16 Can you wrap this SQL string like code so it's rea
mastiz 2017/07/18 07:48:19 Done, with slight modifications because indentatio
+ "favicons JOIN favicon_bitmaps ON (favicon_bitmaps.icon_id = "
+ "favicons.id) JOIN icon_mapping ON (icon_mapping.icon_id = "
+ "favicon_bitmaps.icon_id) WHERE ((favicon_bitmaps.last_requested=0 AND "
+ "favicon_bitmaps.last_updated=0) OR (favicon_bitmaps.last_requested>0 "
+ "AND favicon_bitmaps.last_requested<?));"));
+ old_icons.BindInt64(0, threshold.ToInternalValue());
+
+ std::map<favicon_base::FaviconID, IconMappingsForExpiry> icon_mappings;
+
+ while (old_icons.Step()) {
+ favicon_base::FaviconID id = old_icons.ColumnInt64(0);
+ icon_mappings[id].icon_url = GURL(old_icons.ColumnString(1));
+ icon_mappings[id].page_urls.push_back(GURL(old_icons.ColumnString(2)));
+ }
+
+ return icon_mappings;
+}
+
bool ThumbnailDatabase::GetFaviconBitmapIDSizes(
favicon_base::FaviconID icon_id,
std::vector<FaviconBitmapIDSize>* bitmap_id_sizes) {
@@ -778,6 +805,14 @@ bool ThumbnailDatabase::DeleteIconMappings(const GURL& page_url) {
return statement.Run();
}
+bool ThumbnailDatabase::DeleteIconMappingsForFaviconId(
+ favicon_base::FaviconID id) {
+ sql::Statement statement(db_.GetCachedStatement(
brettw 2017/07/13 23:50:17 Maybe do a unique statement here too. Might be wor
mastiz 2017/07/18 07:48:19 Done.
+ SQL_FROM_HERE, "DELETE FROM icon_mapping WHERE icon_id=?"));
+ statement.BindInt64(0, id);
+ return statement.Run();
+}
+
bool ThumbnailDatabase::DeleteIconMapping(IconMappingID mapping_id) {
sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
"DELETE FROM icon_mapping WHERE id=?"));

Powered by Google App Engine
This is Rietveld 408576698