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

Side by Side Diff: components/history/core/browser/thumbnail_database.cc

Issue 2903573002: [Thumbnails DB] Add functionality to clear unused on-demand favicons. (Closed)
Patch Set: Created 3 years, 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "components/history/core/browser/thumbnail_database.h" 5 #include "components/history/core/browser/thumbnail_database.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <algorithm> 9 #include <algorithm>
10 #include <string> 10 #include <string>
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 // test-expectation framework that the error was handled. 266 // test-expectation framework that the error was handled.
267 ignore_result(sql::Connection::IsExpectedSqliteError(extended_error)); 267 ignore_result(sql::Connection::IsExpectedSqliteError(extended_error));
268 return; 268 return;
269 } 269 }
270 270
271 // The default handling is to assert on debug and to ignore on release. 271 // The default handling is to assert on debug and to ignore on release.
272 if (!sql::Connection::IsExpectedSqliteError(extended_error)) 272 if (!sql::Connection::IsExpectedSqliteError(extended_error))
273 DLOG(FATAL) << db->GetErrorMessage(); 273 DLOG(FATAL) << db->GetErrorMessage();
274 } 274 }
275 275
276 void DeleteOrphanagedFaviconBitmaps(sql::Connection* db) {
277 sql::Statement favicons(db->GetCachedStatement(
278 SQL_FROM_HERE,
279 "DELETE FROM favicon_bitmaps WHERE NOT EXISTS (SELECT id FROM favicons "
280 "WHERE favicon_bitmaps.icon_id = favicons.id)"));
281 favicons.Run();
282 }
283
284 void DeleteOrphanagedMappings(sql::Connection* db) {
285 sql::Statement mappings(db->GetCachedStatement(
286 SQL_FROM_HERE,
287 "DELETE FROM icon_mapping WHERE NOT EXISTS (SELECT id FROM favicons "
288 "WHERE favicons.id = icon_mapping.icon_id)"));
289 mappings.Run();
290 }
291
276 void FillStatementForAddFaviconBitmap( 292 void FillStatementForAddFaviconBitmap(
277 favicon_base::FaviconID icon_id, 293 favicon_base::FaviconID icon_id,
278 const scoped_refptr<base::RefCountedMemory>& icon_data, 294 const scoped_refptr<base::RefCountedMemory>& icon_data,
279 base::Time time, 295 base::Time time,
280 const gfx::Size& pixel_size, 296 const gfx::Size& pixel_size,
281 sql::Statement* statement) { 297 sql::Statement* statement) {
282 DCHECK(statement); 298 DCHECK(statement);
283 DCHECK(icon_id); 299 DCHECK(icon_id);
284 statement->BindInt64(0, icon_id); 300 statement->BindInt64(0, icon_id);
285 if (icon_data.get() && icon_data->size()) { 301 if (icon_data.get() && icon_data->size()) {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 void ThumbnailDatabase::Vacuum() { 443 void ThumbnailDatabase::Vacuum() {
428 DCHECK(db_.transaction_nesting() == 0) << 444 DCHECK(db_.transaction_nesting() == 0) <<
429 "Can not have a transaction when vacuuming."; 445 "Can not have a transaction when vacuuming.";
430 ignore_result(db_.Execute("VACUUM")); 446 ignore_result(db_.Execute("VACUUM"));
431 } 447 }
432 448
433 void ThumbnailDatabase::TrimMemory(bool aggressively) { 449 void ThumbnailDatabase::TrimMemory(bool aggressively) {
434 db_.TrimMemory(aggressively); 450 db_.TrimMemory(aggressively);
435 } 451 }
436 452
453 void ThumbnailDatabase::ClearOldOnDemandFavicons(
454 base::Time expiration_threshold) {
455 // Select all bitmaps (and their page URLs) that have not been accessed for a
456 // while. Restrict to on-demand bitmaps (i.e. with last_requested != 0).
457 sql::Statement delete_candidates(db_.GetCachedStatement(
458 SQL_FROM_HERE,
459 "SELECT favicon_bitmaps.icon_id, icon_mapping.page_url FROM "
460 "favicon_bitmaps, icon_mapping WHERE favicon_bitmaps.icon_id = "
461 "icon_mapping.icon_id AND favicon_bitmaps.last_requested>0 AND "
462 "favicon_bitmaps.last_requested<?;"));
pkotwicz 2017/05/24 17:05:03 If: 1) SetOnDemandFavicons() is called 2) SetFavic
jkrcal 2017/06/21 17:19:20 This has been fixed in the preceding CL: it holds
jkrcal 2017/06/22 11:22:11 Pinging this question.
pkotwicz 2017/06/22 20:32:22 I don't see a problem in expiring the icons
jkrcal 2017/07/06 17:01:48 Done.
463 delete_candidates.BindInt64(0, expiration_threshold.ToInternalValue());
464
465 std::set<FaviconBitmapID> ids_of_bookmarked_favicons;
466 std::set<FaviconBitmapID> ids_to_delete;
467 // Multiple page URLs may map to the same favicon. We omit the favicon_bitmap
468 // from cleaning if at least one of its associated page URLs is bookmarked.
469 while (delete_candidates.Step()) {
470 FaviconBitmapID bitmap_id = delete_candidates.ColumnInt64(0);
pkotwicz 2017/05/24 17:05:03 The "id" column in the favicon_bitmaps table is th
jkrcal 2017/06/21 17:19:20 Ah, thanks! Done (incl. variable names).
471 if (ids_of_bookmarked_favicons.count(bitmap_id))
472 continue;
473
474 if (backend_client_ && backend_client_->IsBookmarked(
475 GURL(delete_candidates.ColumnString(1)))) {
476 ids_of_bookmarked_favicons.insert(bitmap_id);
477 ids_to_delete.erase(bitmap_id);
pkotwicz 2017/05/24 17:05:03 Is it possible for |bitmap_id| to have been added
jkrcal 2017/06/21 17:19:20 Yes, if first some non-bookmarked page with this i
pkotwicz 2017/06/21 19:50:17 Ahhh. I see now. Thank you for the explanation
478 continue;
479 }
480
481 ids_to_delete.insert(bitmap_id);
482 }
483
484 for (FaviconBitmapID bitmap_id : ids_to_delete) {
485 sql::Statement statement(db_.GetCachedStatement(
486 SQL_FROM_HERE, "DELETE FROM favicons WHERE id=?"));
487 statement.BindInt64(0, bitmap_id);
488 statement.Run();
489 }
490
491 // The bitmaps and mappings for all deleted favicons are deleted at once.
492 DeleteOrphanagedFaviconBitmaps(&db_);
493 DeleteOrphanagedMappings(&db_);
494 }
495
437 bool ThumbnailDatabase::GetFaviconBitmapIDSizes( 496 bool ThumbnailDatabase::GetFaviconBitmapIDSizes(
438 favicon_base::FaviconID icon_id, 497 favicon_base::FaviconID icon_id,
439 std::vector<FaviconBitmapIDSize>* bitmap_id_sizes) { 498 std::vector<FaviconBitmapIDSize>* bitmap_id_sizes) {
440 DCHECK(icon_id); 499 DCHECK(icon_id);
441 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, 500 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
442 "SELECT id, width, height FROM favicon_bitmaps WHERE icon_id=?")); 501 "SELECT id, width, height FROM favicon_bitmaps WHERE icon_id=?"));
443 statement.BindInt64(0, icon_id); 502 statement.BindInt64(0, icon_id);
444 503
445 bool result = false; 504 bool result = false;
446 while (statement.Step()) { 505 while (statement.Step()) {
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after
1112 meta_table_.SetVersionNumber(8); 1171 meta_table_.SetVersionNumber(8);
1113 meta_table_.SetCompatibleVersionNumber(std::min(8, kCompatibleVersionNumber)); 1172 meta_table_.SetCompatibleVersionNumber(std::min(8, kCompatibleVersionNumber));
1114 return true; 1173 return true;
1115 } 1174 }
1116 1175
1117 bool ThumbnailDatabase::IsFaviconDBStructureIncorrect() { 1176 bool ThumbnailDatabase::IsFaviconDBStructureIncorrect() {
1118 return !db_.IsSQLValid("SELECT id, url, icon_type FROM favicons"); 1177 return !db_.IsSQLValid("SELECT id, url, icon_type FROM favicons");
1119 } 1178 }
1120 1179
1121 } // namespace history 1180 } // namespace history
OLDNEW
« no previous file with comments | « components/history/core/browser/thumbnail_database.h ('k') | components/history/core/browser/thumbnail_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698