Chromium Code Reviews| 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). This is | |
| 418 // called rarely during history expiration cleanup and hence not worth | |
| 419 // caching. | |
| 420 // TODO(jkrcal): In M63, remove the "(last_requested=0 AND last_updated=0)" | |
| 421 // clause which is only transitional - to clean up expired icons (previously, | |
| 422 // on-demand favicons were stored as expired on-visit favicons). | |
| 423 sql::Statement old_icons(db_.GetUniqueStatement( | |
| 424 "SELECT favicons.id, favicons.url, icon_mapping.page_url " | |
| 425 "FROM favicons " | |
| 426 "JOIN favicon_bitmaps ON (favicon_bitmaps.icon_id = favicons.id) " | |
| 427 "JOIN icon_mapping ON (icon_mapping.icon_id = favicon_bitmaps.icon_id) " | |
| 428 "WHERE ((favicon_bitmaps.last_requested = 0 AND " | |
| 429 " favicon_bitmaps.last_updated = 0) OR " | |
| 430 " (favicon_bitmaps.last_requested > 0 AND " | |
| 431 " favicon_bitmaps.last_requested < ?))")); | |
| 432 old_icons.BindInt64(0, threshold.ToInternalValue()); | |
|
jkrcal
2017/07/25 13:40:17
I've ignored a presubmit warning to avoid deprecat
| |
| 433 | |
| 434 std::map<favicon_base::FaviconID, IconMappingsForExpiry> icon_mappings; | |
| 435 | |
| 436 while (old_icons.Step()) { | |
| 437 favicon_base::FaviconID id = old_icons.ColumnInt64(0); | |
| 438 icon_mappings[id].icon_url = GURL(old_icons.ColumnString(1)); | |
| 439 icon_mappings[id].page_urls.push_back(GURL(old_icons.ColumnString(2))); | |
| 440 } | |
| 441 | |
| 442 return icon_mappings; | |
| 443 } | |
| 444 | |
| 415 bool ThumbnailDatabase::GetFaviconBitmapIDSizes( | 445 bool ThumbnailDatabase::GetFaviconBitmapIDSizes( |
| 416 favicon_base::FaviconID icon_id, | 446 favicon_base::FaviconID icon_id, |
| 417 std::vector<FaviconBitmapIDSize>* bitmap_id_sizes) { | 447 std::vector<FaviconBitmapIDSize>* bitmap_id_sizes) { |
| 418 DCHECK(icon_id); | 448 DCHECK(icon_id); |
| 419 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 449 sql::Statement statement(db_.GetCachedStatement( |
| 450 SQL_FROM_HERE, | |
| 420 "SELECT id, width, height FROM favicon_bitmaps WHERE icon_id=?")); | 451 "SELECT id, width, height FROM favicon_bitmaps WHERE icon_id=?")); |
| 421 statement.BindInt64(0, icon_id); | 452 statement.BindInt64(0, icon_id); |
| 422 | 453 |
| 423 bool result = false; | 454 bool result = false; |
| 424 while (statement.Step()) { | 455 while (statement.Step()) { |
| 425 result = true; | 456 result = true; |
| 426 if (!bitmap_id_sizes) | 457 if (!bitmap_id_sizes) |
| 427 return result; | 458 return result; |
| 428 | 459 |
| 429 FaviconBitmapIDSize bitmap_id_size; | 460 FaviconBitmapIDSize bitmap_id_size; |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 771 } | 802 } |
| 772 | 803 |
| 773 bool ThumbnailDatabase::DeleteIconMappings(const GURL& page_url) { | 804 bool ThumbnailDatabase::DeleteIconMappings(const GURL& page_url) { |
| 774 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 805 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
| 775 "DELETE FROM icon_mapping WHERE page_url = ?")); | 806 "DELETE FROM icon_mapping WHERE page_url = ?")); |
| 776 statement.BindString(0, URLDatabase::GURLToDatabaseURL(page_url)); | 807 statement.BindString(0, URLDatabase::GURLToDatabaseURL(page_url)); |
| 777 | 808 |
| 778 return statement.Run(); | 809 return statement.Run(); |
| 779 } | 810 } |
| 780 | 811 |
| 812 bool ThumbnailDatabase::DeleteIconMappingsForFaviconId( | |
| 813 favicon_base::FaviconID id) { | |
| 814 // This is called rarely during history expiration cleanup and hence not | |
| 815 // worth caching. | |
| 816 sql::Statement statement( | |
| 817 db_.GetUniqueStatement("DELETE FROM icon_mapping WHERE icon_id=?")); | |
| 818 statement.BindInt64(0, id); | |
| 819 return statement.Run(); | |
| 820 } | |
| 821 | |
| 781 bool ThumbnailDatabase::DeleteIconMapping(IconMappingID mapping_id) { | 822 bool ThumbnailDatabase::DeleteIconMapping(IconMappingID mapping_id) { |
| 782 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 823 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
| 783 "DELETE FROM icon_mapping WHERE id=?")); | 824 "DELETE FROM icon_mapping WHERE id=?")); |
| 784 statement.BindInt64(0, mapping_id); | 825 statement.BindInt64(0, mapping_id); |
| 785 | 826 |
| 786 return statement.Run(); | 827 return statement.Run(); |
| 787 } | 828 } |
| 788 | 829 |
| 789 bool ThumbnailDatabase::HasMappingFor(favicon_base::FaviconID id) { | 830 bool ThumbnailDatabase::HasMappingFor(favicon_base::FaviconID id) { |
| 790 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 831 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); | 1149 meta_table_.SetVersionNumber(8); |
| 1109 meta_table_.SetCompatibleVersionNumber(std::min(8, kCompatibleVersionNumber)); | 1150 meta_table_.SetCompatibleVersionNumber(std::min(8, kCompatibleVersionNumber)); |
| 1110 return true; | 1151 return true; |
| 1111 } | 1152 } |
| 1112 | 1153 |
| 1113 bool ThumbnailDatabase::IsFaviconDBStructureIncorrect() { | 1154 bool ThumbnailDatabase::IsFaviconDBStructureIncorrect() { |
| 1114 return !db_.IsSQLValid("SELECT id, url, icon_type FROM favicons"); | 1155 return !db_.IsSQLValid("SELECT id, url, icon_type FROM favicons"); |
| 1115 } | 1156 } |
| 1116 | 1157 |
| 1117 } // namespace history | 1158 } // namespace history |
| OLD | NEW |