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

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: 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 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 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 void ThumbnailDatabase::Vacuum() { 405 void ThumbnailDatabase::Vacuum() {
406 DCHECK(db_.transaction_nesting() == 0) << 406 DCHECK(db_.transaction_nesting() == 0) <<
407 "Can not have a transaction when vacuuming."; 407 "Can not have a transaction when vacuuming.";
408 ignore_result(db_.Execute("VACUUM")); 408 ignore_result(db_.Execute("VACUUM"));
409 } 409 }
410 410
411 void ThumbnailDatabase::TrimMemory(bool aggressively) { 411 void ThumbnailDatabase::TrimMemory(bool aggressively) {
412 db_.TrimMemory(aggressively); 412 db_.TrimMemory(aggressively);
413 } 413 }
414 414
415 std::map<favicon_base::FaviconID, IconMappingsForExpiry>
416 ThumbnailDatabase::GetOldOnDemandFavicons(base::Time threshold) {
417 // Restrict to on-demand bitmaps (i.e. with last_requested != 0).
418 // TODO(jkrcal): In M63, remove the "(last_requested=0 AND last_updated=0)"
419 // clause which is only transitional - to clean up expired icons (previously,
420 // on-demand favicons were stored as expired on-visit favicons).
421 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.
422 SQL_FROM_HERE,
423 "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
424 "favicons JOIN favicon_bitmaps ON (favicon_bitmaps.icon_id = "
425 "favicons.id) JOIN icon_mapping ON (icon_mapping.icon_id = "
426 "favicon_bitmaps.icon_id) WHERE ((favicon_bitmaps.last_requested=0 AND "
427 "favicon_bitmaps.last_updated=0) OR (favicon_bitmaps.last_requested>0 "
428 "AND favicon_bitmaps.last_requested<?));"));
429 old_icons.BindInt64(0, threshold.ToInternalValue());
430
431 std::map<favicon_base::FaviconID, IconMappingsForExpiry> icon_mappings;
432
433 while (old_icons.Step()) {
434 favicon_base::FaviconID id = old_icons.ColumnInt64(0);
435 icon_mappings[id].icon_url = GURL(old_icons.ColumnString(1));
436 icon_mappings[id].page_urls.push_back(GURL(old_icons.ColumnString(2)));
437 }
438
439 return icon_mappings;
440 }
441
415 bool ThumbnailDatabase::GetFaviconBitmapIDSizes( 442 bool ThumbnailDatabase::GetFaviconBitmapIDSizes(
416 favicon_base::FaviconID icon_id, 443 favicon_base::FaviconID icon_id,
417 std::vector<FaviconBitmapIDSize>* bitmap_id_sizes) { 444 std::vector<FaviconBitmapIDSize>* bitmap_id_sizes) {
418 DCHECK(icon_id); 445 DCHECK(icon_id);
419 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, 446 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
420 "SELECT id, width, height FROM favicon_bitmaps WHERE icon_id=?")); 447 "SELECT id, width, height FROM favicon_bitmaps WHERE icon_id=?"));
421 statement.BindInt64(0, icon_id); 448 statement.BindInt64(0, icon_id);
422 449
423 bool result = false; 450 bool result = false;
424 while (statement.Step()) { 451 while (statement.Step()) {
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 } 798 }
772 799
773 bool ThumbnailDatabase::DeleteIconMappings(const GURL& page_url) { 800 bool ThumbnailDatabase::DeleteIconMappings(const GURL& page_url) {
774 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, 801 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
775 "DELETE FROM icon_mapping WHERE page_url = ?")); 802 "DELETE FROM icon_mapping WHERE page_url = ?"));
776 statement.BindString(0, URLDatabase::GURLToDatabaseURL(page_url)); 803 statement.BindString(0, URLDatabase::GURLToDatabaseURL(page_url));
777 804
778 return statement.Run(); 805 return statement.Run();
779 } 806 }
780 807
808 bool ThumbnailDatabase::DeleteIconMappingsForFaviconId(
809 favicon_base::FaviconID id) {
810 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.
811 SQL_FROM_HERE, "DELETE FROM icon_mapping WHERE icon_id=?"));
812 statement.BindInt64(0, id);
813 return statement.Run();
814 }
815
781 bool ThumbnailDatabase::DeleteIconMapping(IconMappingID mapping_id) { 816 bool ThumbnailDatabase::DeleteIconMapping(IconMappingID mapping_id) {
782 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, 817 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
783 "DELETE FROM icon_mapping WHERE id=?")); 818 "DELETE FROM icon_mapping WHERE id=?"));
784 statement.BindInt64(0, mapping_id); 819 statement.BindInt64(0, mapping_id);
785 820
786 return statement.Run(); 821 return statement.Run();
787 } 822 }
788 823
789 bool ThumbnailDatabase::HasMappingFor(favicon_base::FaviconID id) { 824 bool ThumbnailDatabase::HasMappingFor(favicon_base::FaviconID id) {
790 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, 825 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 meta_table_.SetVersionNumber(8); 1143 meta_table_.SetVersionNumber(8);
1109 meta_table_.SetCompatibleVersionNumber(std::min(8, kCompatibleVersionNumber)); 1144 meta_table_.SetCompatibleVersionNumber(std::min(8, kCompatibleVersionNumber));
1110 return true; 1145 return true;
1111 } 1146 }
1112 1147
1113 bool ThumbnailDatabase::IsFaviconDBStructureIncorrect() { 1148 bool ThumbnailDatabase::IsFaviconDBStructureIncorrect() {
1114 return !db_.IsSQLValid("SELECT id, url, icon_type FROM favicons"); 1149 return !db_.IsSQLValid("SELECT id, url, icon_type FROM favicons");
1115 } 1150 }
1116 1151
1117 } // namespace history 1152 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698