OLD | NEW |
---|---|
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 Loading... | |
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( | |
422 SQL_FROM_HERE, | |
423 "SELECT favicons.id, favicons.url, icon_mapping.page_url FROM " | |
424 "favicons, favicon_bitmaps, icon_mapping WHERE favicon_bitmaps.icon_id = " | |
brettw
2017/07/11 19:26:43
Can you express this as an explicit JOIN across th
jkrcal
2017/07/13 20:26:10
Done.
| |
425 "icon_mapping.icon_id AND favicons.id = favicon_bitmaps.icon_id AND " | |
426 "((last_requested=0 AND last_updated=0) OR " | |
brettw
2017/07/11 19:26:43
I like to be explicit about the table names for th
jkrcal
2017/07/13 20:26:10
Done.
| |
427 "(last_requested>0 AND last_requested<?));")); | |
428 old_icons.BindInt64(0, threshold.ToInternalValue()); | |
429 | |
430 std::map<favicon_base::FaviconID, IconMappingsForExpiry> icon_mappings; | |
431 | |
432 while (old_icons.Step()) { | |
433 favicon_base::FaviconID id = old_icons.ColumnInt64(0); | |
434 icon_mappings[id].icon_url = GURL(old_icons.ColumnString(1)); | |
435 icon_mappings[id].page_urls.push_back(GURL(old_icons.ColumnString(2))); | |
436 } | |
437 | |
438 return icon_mappings; | |
439 } | |
440 | |
415 bool ThumbnailDatabase::GetFaviconBitmapIDSizes( | 441 bool ThumbnailDatabase::GetFaviconBitmapIDSizes( |
416 favicon_base::FaviconID icon_id, | 442 favicon_base::FaviconID icon_id, |
417 std::vector<FaviconBitmapIDSize>* bitmap_id_sizes) { | 443 std::vector<FaviconBitmapIDSize>* bitmap_id_sizes) { |
418 DCHECK(icon_id); | 444 DCHECK(icon_id); |
419 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 445 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
420 "SELECT id, width, height FROM favicon_bitmaps WHERE icon_id=?")); | 446 "SELECT id, width, height FROM favicon_bitmaps WHERE icon_id=?")); |
421 statement.BindInt64(0, icon_id); | 447 statement.BindInt64(0, icon_id); |
422 | 448 |
423 bool result = false; | 449 bool result = false; |
424 while (statement.Step()) { | 450 while (statement.Step()) { |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
771 } | 797 } |
772 | 798 |
773 bool ThumbnailDatabase::DeleteIconMappings(const GURL& page_url) { | 799 bool ThumbnailDatabase::DeleteIconMappings(const GURL& page_url) { |
774 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 800 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
775 "DELETE FROM icon_mapping WHERE page_url = ?")); | 801 "DELETE FROM icon_mapping WHERE page_url = ?")); |
776 statement.BindString(0, URLDatabase::GURLToDatabaseURL(page_url)); | 802 statement.BindString(0, URLDatabase::GURLToDatabaseURL(page_url)); |
777 | 803 |
778 return statement.Run(); | 804 return statement.Run(); |
779 } | 805 } |
780 | 806 |
807 bool ThumbnailDatabase::DeleteIconMappingsForFaviconId( | |
808 favicon_base::FaviconID id) { | |
809 sql::Statement statement(db_.GetCachedStatement( | |
810 SQL_FROM_HERE, "DELETE FROM icon_mapping WHERE icon_id=?")); | |
811 statement.BindInt64(0, id); | |
812 return statement.Run(); | |
813 } | |
814 | |
781 bool ThumbnailDatabase::DeleteIconMapping(IconMappingID mapping_id) { | 815 bool ThumbnailDatabase::DeleteIconMapping(IconMappingID mapping_id) { |
782 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 816 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
783 "DELETE FROM icon_mapping WHERE id=?")); | 817 "DELETE FROM icon_mapping WHERE id=?")); |
784 statement.BindInt64(0, mapping_id); | 818 statement.BindInt64(0, mapping_id); |
785 | 819 |
786 return statement.Run(); | 820 return statement.Run(); |
787 } | 821 } |
788 | 822 |
789 bool ThumbnailDatabase::HasMappingFor(favicon_base::FaviconID id) { | 823 bool ThumbnailDatabase::HasMappingFor(favicon_base::FaviconID id) { |
790 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 824 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1108 meta_table_.SetVersionNumber(8); | 1142 meta_table_.SetVersionNumber(8); |
1109 meta_table_.SetCompatibleVersionNumber(std::min(8, kCompatibleVersionNumber)); | 1143 meta_table_.SetCompatibleVersionNumber(std::min(8, kCompatibleVersionNumber)); |
1110 return true; | 1144 return true; |
1111 } | 1145 } |
1112 | 1146 |
1113 bool ThumbnailDatabase::IsFaviconDBStructureIncorrect() { | 1147 bool ThumbnailDatabase::IsFaviconDBStructureIncorrect() { |
1114 return !db_.IsSQLValid("SELECT id, url, icon_type FROM favicons"); | 1148 return !db_.IsSQLValid("SELECT id, url, icon_type FROM favicons"); |
1115 } | 1149 } |
1116 | 1150 |
1117 } // namespace history | 1151 } // namespace history |
OLD | NEW |