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 <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1034 "old_icon_id INTEGER NOT NULL UNIQUE" | 1034 "old_icon_id INTEGER NOT NULL UNIQUE" |
| 1035 ")"; | 1035 ")"; |
| 1036 if (!db_.Execute(kIconMappingCreate)) | 1036 if (!db_.Execute(kIconMappingCreate)) |
| 1037 return false; | 1037 return false; |
| 1038 | 1038 |
| 1039 // Insert the icon ids for retained urls, skipping duplicates. | 1039 // Insert the icon ids for retained urls, skipping duplicates. |
| 1040 const char kIconMappingSql[] = | 1040 const char kIconMappingSql[] = |
| 1041 "INSERT OR IGNORE INTO temp.icon_id_mapping (old_icon_id) " | 1041 "INSERT OR IGNORE INTO temp.icon_id_mapping (old_icon_id) " |
| 1042 "SELECT icon_id FROM icon_mapping WHERE page_url = ?"; | 1042 "SELECT icon_id FROM icon_mapping WHERE page_url = ?"; |
| 1043 sql::Statement statement(db_.GetUniqueStatement(kIconMappingSql)); | 1043 sql::Statement statement(db_.GetUniqueStatement(kIconMappingSql)); |
| 1044 for (std::vector<GURL>::const_iterator | 1044 for (const GURL& url : urls_to_keep) { |
| 1045 i = urls_to_keep.begin(); i != urls_to_keep.end(); ++i) { | 1045 statement.BindString(0, URLDatabase::GURLToDatabaseURL(url)); |
| 1046 statement.BindString(0, URLDatabase::GURLToDatabaseURL(*i)); | |
| 1047 if (!statement.Run()) | 1046 if (!statement.Run()) |
| 1048 return false; | 1047 return false; |
| 1049 statement.Reset(true); | 1048 statement.Reset(true); |
| 1049 } | |
| 1050 } | |
| 1051 | |
| 1052 { | |
| 1053 const char kCreateRetainedUrls[] = | |
| 1054 "CREATE TEMP TABLE retained_urls (url LONGVARCHAR PRIMARY KEY)"; | |
| 1055 if (!db_.Execute(kCreateRetainedUrls)) | |
| 1056 return false; | |
| 1057 | |
| 1058 const char kRetainedUrlSql[] = | |
| 1059 "INSERT OR IGNORE INTO temp.retained_urls (url) VALUES (?)"; | |
| 1060 sql::Statement statement(db_.GetUniqueStatement(kRetainedUrlSql)); | |
| 1061 for (const GURL& url : urls_to_keep) { | |
| 1062 statement.BindString(0, URLDatabase::GURLToDatabaseURL(url)); | |
| 1063 if (!statement.Run()) | |
| 1064 return false; | |
| 1065 statement.Reset(true); | |
|
Scott Hess - ex-Googler
2015/03/18 18:27:25
Given this table, can the earlier loop be rewritte
| |
| 1050 } | 1066 } |
| 1051 } | 1067 } |
| 1052 | 1068 |
| 1053 const char kRenameIconMappingTable[] = | 1069 const char kRenameIconMappingTable[] = |
| 1054 "ALTER TABLE icon_mapping RENAME TO old_icon_mapping"; | 1070 "ALTER TABLE icon_mapping RENAME TO old_icon_mapping"; |
| 1055 const char kCopyIconMapping[] = | 1071 const char kCopyIconMapping[] = |
| 1056 "INSERT INTO icon_mapping (page_url, icon_id) " | 1072 "INSERT INTO icon_mapping (page_url, icon_id) " |
| 1057 "SELECT old.page_url, mapping.new_icon_id " | 1073 "SELECT retained_urls.url, mapping.new_icon_id " |
| 1058 "FROM old_icon_mapping AS old " | 1074 "FROM temp.retained_urls AS retained_urls " |
|
Scott Hess - ex-Googler
2015/03/18 18:27:25
I don't think the AS adds much, since these lines
| |
| 1075 "JOIN old_icon_mapping AS old " | |
| 1076 "ON (retained_urls.url = old.page_url) " | |
| 1059 "JOIN temp.icon_id_mapping AS mapping " | 1077 "JOIN temp.icon_id_mapping AS mapping " |
| 1060 "ON (old.icon_id = mapping.old_icon_id)"; | 1078 "ON (old.icon_id = mapping.old_icon_id)"; |
| 1061 const char kDropOldIconMappingTable[] = "DROP TABLE old_icon_mapping"; | 1079 const char kDropOldIconMappingTable[] = "DROP TABLE old_icon_mapping"; |
| 1062 | 1080 |
| 1063 const char kRenameFaviconsTable[] = | 1081 const char kRenameFaviconsTable[] = |
| 1064 "ALTER TABLE favicons RENAME TO old_favicons"; | 1082 "ALTER TABLE favicons RENAME TO old_favicons"; |
| 1065 const char kCopyFavicons[] = | 1083 const char kCopyFavicons[] = |
| 1066 "INSERT INTO favicons (id, url, icon_type) " | 1084 "INSERT INTO favicons (id, url, icon_type) " |
| 1067 "SELECT mapping.new_icon_id, old.url, old.icon_type " | 1085 "SELECT mapping.new_icon_id, old.url, old.icon_type " |
| 1068 "FROM old_favicons AS old " | 1086 "FROM old_favicons AS old " |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1110 return false; | 1128 return false; |
| 1111 } | 1129 } |
| 1112 | 1130 |
| 1113 // Recreate the indices. | 1131 // Recreate the indices. |
| 1114 // TODO(shess): UNIQUE indices could fail due to duplication. This | 1132 // TODO(shess): UNIQUE indices could fail due to duplication. This |
| 1115 // could happen in case of corruption. | 1133 // could happen in case of corruption. |
| 1116 if (!InitIndices(&db_)) | 1134 if (!InitIndices(&db_)) |
| 1117 return false; | 1135 return false; |
| 1118 | 1136 |
| 1119 const char kIconMappingDrop[] = "DROP TABLE temp.icon_id_mapping"; | 1137 const char kIconMappingDrop[] = "DROP TABLE temp.icon_id_mapping"; |
| 1120 if (!db_.Execute(kIconMappingDrop)) | 1138 const char kRetainedUrlsDrop[] = "DROP TABLE temp.retained_urls"; |
| 1139 if (!db_.Execute(kIconMappingDrop) || !db_.Execute(kRetainedUrlsDrop)) | |
| 1121 return false; | 1140 return false; |
| 1122 | 1141 |
| 1123 return transaction.Commit(); | 1142 return transaction.Commit(); |
| 1124 } | 1143 } |
| 1125 | 1144 |
| 1126 sql::InitStatus ThumbnailDatabase::OpenDatabase(sql::Connection* db, | 1145 sql::InitStatus ThumbnailDatabase::OpenDatabase(sql::Connection* db, |
| 1127 const base::FilePath& db_name) { | 1146 const base::FilePath& db_name) { |
| 1128 size_t startup_kb = 0; | 1147 size_t startup_kb = 0; |
| 1129 int64 size_64; | 1148 int64 size_64; |
| 1130 if (base::GetFileSize(db_name, &size_64)) | 1149 if (base::GetFileSize(db_name, &size_64)) |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1313 meta_table_.SetVersionNumber(7); | 1332 meta_table_.SetVersionNumber(7); |
| 1314 meta_table_.SetCompatibleVersionNumber(std::min(7, kCompatibleVersionNumber)); | 1333 meta_table_.SetCompatibleVersionNumber(std::min(7, kCompatibleVersionNumber)); |
| 1315 return true; | 1334 return true; |
| 1316 } | 1335 } |
| 1317 | 1336 |
| 1318 bool ThumbnailDatabase::IsFaviconDBStructureIncorrect() { | 1337 bool ThumbnailDatabase::IsFaviconDBStructureIncorrect() { |
| 1319 return !db_.IsSQLValid("SELECT id, url, icon_type FROM favicons"); | 1338 return !db_.IsSQLValid("SELECT id, url, icon_type FROM favicons"); |
| 1320 } | 1339 } |
| 1321 | 1340 |
| 1322 } // namespace history | 1341 } // namespace history |
| OLD | NEW |