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

Side by Side Diff: components/history/core/browser/thumbnail_database.cc

Issue 1005783003: Fix ThumbnailDatabase::RetainDataForPageUrls() to drop unretained page mappings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « chrome/browser/history/thumbnail_database_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 1006 matching lines...) Expand 10 before | Expand all | Expand 10 after
1017 enumerator->statement_.BindInt(0, type); 1017 enumerator->statement_.BindInt(0, type);
1018 return enumerator->statement_.is_valid(); 1018 return enumerator->statement_.is_valid();
1019 } 1019 }
1020 1020
1021 bool ThumbnailDatabase::RetainDataForPageUrls( 1021 bool ThumbnailDatabase::RetainDataForPageUrls(
1022 const std::vector<GURL>& urls_to_keep) { 1022 const std::vector<GURL>& urls_to_keep) {
1023 sql::Transaction transaction(&db_); 1023 sql::Transaction transaction(&db_);
1024 if (!transaction.Begin()) 1024 if (!transaction.Begin())
1025 return false; 1025 return false;
1026 1026
1027 // Populate temp.retained_urls with |urls_to_keep|.
1028 {
1029 const char kCreateRetainedUrls[] =
1030 "CREATE TEMP TABLE retained_urls (url LONGVARCHAR PRIMARY KEY)";
1031 if (!db_.Execute(kCreateRetainedUrls))
1032 return false;
1033
1034 const char kRetainedUrlSql[] =
1035 "INSERT OR IGNORE INTO temp.retained_urls (url) VALUES (?)";
1036 sql::Statement statement(db_.GetUniqueStatement(kRetainedUrlSql));
1037 for (const GURL& url : urls_to_keep) {
1038 statement.BindString(0, URLDatabase::GURLToDatabaseURL(url));
1039 if (!statement.Run())
1040 return false;
1041 statement.Reset(true);
1042 }
1043 }
1044
1027 // temp.icon_id_mapping generates new icon ids as consecutive 1045 // temp.icon_id_mapping generates new icon ids as consecutive
1028 // integers starting from 1, and maps them to the old icon ids. 1046 // integers starting from 1, and maps them to the old icon ids.
1029 { 1047 {
1030 const char kIconMappingCreate[] = 1048 const char kIconMappingCreate[] =
1031 "CREATE TEMP TABLE icon_id_mapping " 1049 "CREATE TEMP TABLE icon_id_mapping "
1032 "(" 1050 "("
1033 "new_icon_id INTEGER PRIMARY KEY," 1051 "new_icon_id INTEGER PRIMARY KEY,"
1034 "old_icon_id INTEGER NOT NULL UNIQUE" 1052 "old_icon_id INTEGER NOT NULL UNIQUE"
1035 ")"; 1053 ")";
1036 if (!db_.Execute(kIconMappingCreate)) 1054 if (!db_.Execute(kIconMappingCreate))
1037 return false; 1055 return false;
1038 1056
1039 // Insert the icon ids for retained urls, skipping duplicates. 1057 // Insert the icon ids for retained urls, skipping duplicates.
1040 const char kIconMappingSql[] = 1058 const char kIconMappingSql[] =
1041 "INSERT OR IGNORE INTO temp.icon_id_mapping (old_icon_id) " 1059 "INSERT OR IGNORE INTO temp.icon_id_mapping (old_icon_id) "
1042 "SELECT icon_id FROM icon_mapping WHERE page_url = ?"; 1060 "SELECT icon_id FROM icon_mapping "
1043 sql::Statement statement(db_.GetUniqueStatement(kIconMappingSql)); 1061 "JOIN temp.retained_urls "
1044 for (std::vector<GURL>::const_iterator 1062 "ON (temp.retained_urls.url = icon_mapping.page_url)";
1045 i = urls_to_keep.begin(); i != urls_to_keep.end(); ++i) { 1063 if (!db_.Execute(kIconMappingSql))
1046 statement.BindString(0, URLDatabase::GURLToDatabaseURL(*i)); 1064 return false;
1047 if (!statement.Run())
1048 return false;
1049 statement.Reset(true);
1050 }
1051 } 1065 }
1052 1066
1053 const char kRenameIconMappingTable[] = 1067 const char kRenameIconMappingTable[] =
1054 "ALTER TABLE icon_mapping RENAME TO old_icon_mapping"; 1068 "ALTER TABLE icon_mapping RENAME TO old_icon_mapping";
1055 const char kCopyIconMapping[] = 1069 const char kCopyIconMapping[] =
1056 "INSERT INTO icon_mapping (page_url, icon_id) " 1070 "INSERT INTO icon_mapping (page_url, icon_id) "
1057 "SELECT old.page_url, mapping.new_icon_id " 1071 "SELECT temp.retained_urls.url, mapping.new_icon_id "
1058 "FROM old_icon_mapping AS old " 1072 "FROM temp.retained_urls "
1073 "JOIN old_icon_mapping AS old "
1074 "ON (temp.retained_urls.url = old.page_url) "
1059 "JOIN temp.icon_id_mapping AS mapping " 1075 "JOIN temp.icon_id_mapping AS mapping "
1060 "ON (old.icon_id = mapping.old_icon_id)"; 1076 "ON (old.icon_id = mapping.old_icon_id)";
1061 const char kDropOldIconMappingTable[] = "DROP TABLE old_icon_mapping"; 1077 const char kDropOldIconMappingTable[] = "DROP TABLE old_icon_mapping";
1062 1078
1063 const char kRenameFaviconsTable[] = 1079 const char kRenameFaviconsTable[] =
1064 "ALTER TABLE favicons RENAME TO old_favicons"; 1080 "ALTER TABLE favicons RENAME TO old_favicons";
1065 const char kCopyFavicons[] = 1081 const char kCopyFavicons[] =
1066 "INSERT INTO favicons (id, url, icon_type) " 1082 "INSERT INTO favicons (id, url, icon_type) "
1067 "SELECT mapping.new_icon_id, old.url, old.icon_type " 1083 "SELECT mapping.new_icon_id, old.url, old.icon_type "
1068 "FROM old_favicons AS old " 1084 "FROM old_favicons AS old "
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 return false; 1126 return false;
1111 } 1127 }
1112 1128
1113 // Recreate the indices. 1129 // Recreate the indices.
1114 // TODO(shess): UNIQUE indices could fail due to duplication. This 1130 // TODO(shess): UNIQUE indices could fail due to duplication. This
1115 // could happen in case of corruption. 1131 // could happen in case of corruption.
1116 if (!InitIndices(&db_)) 1132 if (!InitIndices(&db_))
1117 return false; 1133 return false;
1118 1134
1119 const char kIconMappingDrop[] = "DROP TABLE temp.icon_id_mapping"; 1135 const char kIconMappingDrop[] = "DROP TABLE temp.icon_id_mapping";
1120 if (!db_.Execute(kIconMappingDrop)) 1136 const char kRetainedUrlsDrop[] = "DROP TABLE temp.retained_urls";
1137 if (!db_.Execute(kIconMappingDrop) || !db_.Execute(kRetainedUrlsDrop))
1121 return false; 1138 return false;
1122 1139
1123 return transaction.Commit(); 1140 return transaction.Commit();
1124 } 1141 }
1125 1142
1126 sql::InitStatus ThumbnailDatabase::OpenDatabase(sql::Connection* db, 1143 sql::InitStatus ThumbnailDatabase::OpenDatabase(sql::Connection* db,
1127 const base::FilePath& db_name) { 1144 const base::FilePath& db_name) {
1128 size_t startup_kb = 0; 1145 size_t startup_kb = 0;
1129 int64 size_64; 1146 int64 size_64;
1130 if (base::GetFileSize(db_name, &size_64)) 1147 if (base::GetFileSize(db_name, &size_64))
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1313 meta_table_.SetVersionNumber(7); 1330 meta_table_.SetVersionNumber(7);
1314 meta_table_.SetCompatibleVersionNumber(std::min(7, kCompatibleVersionNumber)); 1331 meta_table_.SetCompatibleVersionNumber(std::min(7, kCompatibleVersionNumber));
1315 return true; 1332 return true;
1316 } 1333 }
1317 1334
1318 bool ThumbnailDatabase::IsFaviconDBStructureIncorrect() { 1335 bool ThumbnailDatabase::IsFaviconDBStructureIncorrect() {
1319 return !db_.IsSQLValid("SELECT id, url, icon_type FROM favicons"); 1336 return !db_.IsSQLValid("SELECT id, url, icon_type FROM favicons");
1320 } 1337 }
1321 1338
1322 } // namespace history 1339 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/thumbnail_database_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698