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

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: Peter's comments #4 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 // Select all bitmaps (and their page URLs) that have not been accessed for a
418 // while. Restrict to on-demand bitmaps (i.e. with last_requested != 0).
pkotwicz 2017/07/10 19:50:19 Nit: Remove the sentence: "Select all bitmaps (and
jkrcal 2017/07/11 13:19:35 Done.
419 // TODO(jkrcal): In M63, remove the "(last_requested=0 AND last_updated=0)"
420 // clause which is only transitional - to clean up on demand favicons stored
421 // before this function has been implemented.
422 sql::Statement old_icons(db_.GetCachedStatement(
423 SQL_FROM_HERE,
424 "SELECT favicons.id, favicons.url, icon_mapping.page_url FROM "
425 "favicons, favicon_bitmaps, icon_mapping WHERE favicon_bitmaps.icon_id = "
426 "icon_mapping.icon_id AND favicons.id = favicon_bitmaps.icon_id AND "
427 "((last_requested=0 AND last_updated=0) OR "
428 "(last_requested>0 AND last_requested<?));"));
pkotwicz 2017/07/10 19:50:19 Can (last_requested=0 AND last_updated=0) OR (las
jkrcal 2017/07/11 13:19:35 Yes, you are right. Still, I would stick to the cu
pkotwicz 2017/07/11 14:41:04 Fair enough
429 old_icons.BindInt64(0, threshold.ToInternalValue());
430
431 std::map<favicon_base::FaviconID, IconMappingsForExpiry> favicons;
pkotwicz 2017/07/10 19:50:19 Maybe rename this variable to |icon_mappings|
jkrcal 2017/07/11 13:19:35 Done.
432
433 while (old_icons.Step()) {
434 favicon_base::FaviconID id = old_icons.ColumnInt64(0);
435 favicons[id].icon_url = GURL(old_icons.ColumnString(1));
436 favicons[id].page_urls.push_back(GURL(old_icons.ColumnString(2)));
437 }
438
439 return favicons;
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(
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