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