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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 // For this database, schema migrations are deprecated after two | 72 // For this database, schema migrations are deprecated after two |
| 73 // years. This means that the oldest non-deprecated version should be | 73 // years. This means that the oldest non-deprecated version should be |
| 74 // two years old or greater (thus the migrations to get there are | 74 // two years old or greater (thus the migrations to get there are |
| 75 // older). Databases containing deprecated versions will be cleared | 75 // older). Databases containing deprecated versions will be cleared |
| 76 // at startup. Since this database is a cache, losing old data is not | 76 // at startup. Since this database is a cache, losing old data is not |
| 77 // fatal (in fact, very old data may be expired immediately at startup | 77 // fatal (in fact, very old data may be expired immediately at startup |
| 78 // anyhow). | 78 // anyhow). |
| 79 | 79 |
| 80 // Version 7: 911a634d/r209424 by qsr@chromium.org on 2013-07-01 | 80 // Version 7: 911a634d/r209424 by qsr@chromium.org on 2013-07-01 |
| 81 // Version 6: 610f923b/r152367 by pkotwicz@chromium.org on 2012-08-20 | 81 // Version 6: 610f923b/r152367 by pkotwicz@chromium.org on 2012-08-20 |
| 82 // Version 5: e2ee8ae9/r105004 by groby@chromium.org on 2011-10-12 | 82 // Version 5: e2ee8ae9/r105004 by groby@chromium.org on 2011-10-12 |
|
Scott Hess - ex-Googler
2015/03/24 19:28:25
Mark this line (deprecated).
Roger McFarlane (Chromium)
2015/03/24 22:26:57
Done.
| |
| 83 // Version 4: 5f104d76/r77288 by sky@chromium.org on 2011-03-08 (deprecated) | 83 // Version 4: 5f104d76/r77288 by sky@chromium.org on 2011-03-08 (deprecated) |
| 84 // Version 3: 09911bf3/r15 by initial.commit on 2008-07-26 (deprecated) | 84 // Version 3: 09911bf3/r15 by initial.commit on 2008-07-26 (deprecated) |
| 85 | 85 |
| 86 // Version number of the database. | 86 // Version number of the database. |
| 87 // NOTE(shess): When changing the version, add a new golden file for | 87 // NOTE(shess): When changing the version, add a new golden file for |
| 88 // the new version and a test to verify that Init() works with it. | 88 // the new version and a test to verify that Init() works with it. |
| 89 const int kCurrentVersionNumber = 7; | 89 const int kCurrentVersionNumber = 7; |
| 90 const int kCompatibleVersionNumber = 7; | 90 const int kCompatibleVersionNumber = 7; |
| 91 const int kDeprecatedVersionNumber = 4; // and earlier. | 91 const int kDeprecatedVersionNumber = 5; // and earlier. |
| 92 | 92 |
| 93 void FillIconMapping(const sql::Statement& statement, | 93 void FillIconMapping(const sql::Statement& statement, |
| 94 const GURL& page_url, | 94 const GURL& page_url, |
| 95 IconMapping* icon_mapping) { | 95 IconMapping* icon_mapping) { |
| 96 icon_mapping->mapping_id = statement.ColumnInt64(0); | 96 icon_mapping->mapping_id = statement.ColumnInt64(0); |
| 97 icon_mapping->icon_id = statement.ColumnInt64(1); | 97 icon_mapping->icon_id = statement.ColumnInt64(1); |
| 98 icon_mapping->icon_type = | 98 icon_mapping->icon_type = |
| 99 static_cast<favicon_base::IconType>(statement.ColumnInt(2)); | 99 static_cast<favicon_base::IconType>(statement.ColumnInt(2)); |
| 100 icon_mapping->icon_url = GURL(statement.ColumnString(3)); | 100 icon_mapping->icon_url = GURL(statement.ColumnString(3)); |
| 101 icon_mapping->page_url = page_url; | 101 icon_mapping->page_url = page_url; |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 431 // creating the recover virtual table for corrupt.meta. The table | 431 // creating the recover virtual table for corrupt.meta. The table |
| 432 // may not exist, or the database may be too far gone. Either | 432 // may not exist, or the database may be too far gone. Either |
| 433 // way, unclear how to resolve. | 433 // way, unclear how to resolve. |
| 434 sql::Recovery::Rollback(recovery.Pass()); | 434 sql::Recovery::Rollback(recovery.Pass()); |
| 435 RecordRecoveryEvent(RECOVERY_EVENT_FAILED_META_VERSION); | 435 RecordRecoveryEvent(RECOVERY_EVENT_FAILED_META_VERSION); |
| 436 return; | 436 return; |
| 437 } | 437 } |
| 438 | 438 |
| 439 // This code may be able to fetch version information that the regular | 439 // This code may be able to fetch version information that the regular |
| 440 // deprecation path cannot. | 440 // deprecation path cannot. |
| 441 // NOTE(shess): v5 and v6 are currently not deprecated in the normal Init() | 441 // NOTE(shess,rogerm): v6 is not currently deprecated in the normal Init() |
| 442 // path, but are deprecated in the recovery path in the interest of keeping | 442 // path, but is deprecated in the recovery path in the interest of keeping |
| 443 // the code simple. http://crbug.com/327485 for numbers. | 443 // the code simple. http://crbug.com/327485 for numbers. |
| 444 DCHECK_LE(kDeprecatedVersionNumber, 6); | 444 DCHECK_LE(kDeprecatedVersionNumber, 6); |
| 445 if (version <= 6) { | 445 if (version <= 6) { |
| 446 sql::Recovery::Unrecoverable(recovery.Pass()); | 446 sql::Recovery::Unrecoverable(recovery.Pass()); |
| 447 RecordRecoveryEvent(RECOVERY_EVENT_DEPRECATED); | 447 RecordRecoveryEvent(RECOVERY_EVENT_DEPRECATED); |
| 448 return; | 448 return; |
| 449 } | 449 } |
| 450 | 450 |
| 451 // Earlier versions have been handled or deprecated, later versions should be | 451 // Earlier versions have been handled or deprecated, later versions should be |
| 452 // impossible. | 452 // impossible. |
| (...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1233 } | 1233 } |
| 1234 | 1234 |
| 1235 if (cur_version < 7 && !db_.DoesColumnExist("favicons", "sizes")) { | 1235 if (cur_version < 7 && !db_.DoesColumnExist("favicons", "sizes")) { |
| 1236 LOG(ERROR) << "Raze because of missing favicon.sizes"; | 1236 LOG(ERROR) << "Raze because of missing favicon.sizes"; |
| 1237 RecordInvalidStructure(STRUCTURE_EVENT_VERSION5); | 1237 RecordInvalidStructure(STRUCTURE_EVENT_VERSION5); |
| 1238 | 1238 |
| 1239 db_.RazeAndClose(); | 1239 db_.RazeAndClose(); |
| 1240 return sql::INIT_FAILURE; | 1240 return sql::INIT_FAILURE; |
| 1241 } | 1241 } |
| 1242 | 1242 |
| 1243 if (cur_version == 5) { | |
| 1244 ++cur_version; | |
| 1245 if (!UpgradeToVersion6()) | |
| 1246 return CantUpgradeToVersion(cur_version); | |
| 1247 } | |
| 1248 | |
| 1249 if (cur_version == 6) { | 1243 if (cur_version == 6) { |
| 1250 ++cur_version; | 1244 ++cur_version; |
| 1251 if (!UpgradeToVersion7()) | 1245 if (!UpgradeToVersion7()) |
| 1252 return CantUpgradeToVersion(cur_version); | 1246 return CantUpgradeToVersion(cur_version); |
| 1253 } | 1247 } |
| 1254 | 1248 |
| 1255 LOG_IF(WARNING, cur_version < kCurrentVersionNumber) << | 1249 LOG_IF(WARNING, cur_version < kCurrentVersionNumber) << |
| 1256 "Thumbnail database version " << cur_version << " is too old to handle."; | 1250 "Thumbnail database version " << cur_version << " is too old to handle."; |
| 1257 | 1251 |
| 1258 // Initialization is complete. | 1252 // Initialization is complete. |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 1276 return sql::INIT_OK; | 1270 return sql::INIT_OK; |
| 1277 } | 1271 } |
| 1278 | 1272 |
| 1279 sql::InitStatus ThumbnailDatabase::CantUpgradeToVersion(int cur_version) { | 1273 sql::InitStatus ThumbnailDatabase::CantUpgradeToVersion(int cur_version) { |
| 1280 LOG(WARNING) << "Unable to update to thumbnail database to version " << | 1274 LOG(WARNING) << "Unable to update to thumbnail database to version " << |
| 1281 cur_version << "."; | 1275 cur_version << "."; |
| 1282 db_.Close(); | 1276 db_.Close(); |
| 1283 return sql::INIT_FAILURE; | 1277 return sql::INIT_FAILURE; |
| 1284 } | 1278 } |
| 1285 | 1279 |
| 1286 bool ThumbnailDatabase::UpgradeToVersion6() { | |
| 1287 // Move bitmap data from favicons to favicon_bitmaps. | |
| 1288 bool success = | |
| 1289 db_.Execute("INSERT INTO favicon_bitmaps (icon_id, last_updated, " | |
| 1290 "image_data, width, height)" | |
| 1291 "SELECT id, last_updated, image_data, 0, 0 FROM favicons") && | |
| 1292 db_.Execute("CREATE TABLE temp_favicons (" | |
| 1293 "id INTEGER PRIMARY KEY," | |
| 1294 "url LONGVARCHAR NOT NULL," | |
| 1295 "icon_type INTEGER DEFAULT 1," | |
| 1296 // default icon_type FAVICON to be consistent with | |
| 1297 // past migration. | |
| 1298 "sizes LONGVARCHAR)") && | |
| 1299 db_.Execute("INSERT INTO temp_favicons (id, url, icon_type) " | |
| 1300 "SELECT id, url, icon_type FROM favicons") && | |
| 1301 db_.Execute("DROP TABLE favicons") && | |
| 1302 db_.Execute("ALTER TABLE temp_favicons RENAME TO favicons"); | |
| 1303 // NOTE(shess): v7 will re-create the index. | |
| 1304 if (!success) | |
| 1305 return false; | |
| 1306 | |
| 1307 meta_table_.SetVersionNumber(6); | |
| 1308 meta_table_.SetCompatibleVersionNumber(std::min(6, kCompatibleVersionNumber)); | |
| 1309 return true; | |
| 1310 } | |
| 1311 | |
| 1312 bool ThumbnailDatabase::UpgradeToVersion7() { | 1280 bool ThumbnailDatabase::UpgradeToVersion7() { |
| 1313 // Sizes column was never used, remove it. | 1281 // Sizes column was never used, remove it. |
| 1314 bool success = | 1282 bool success = |
| 1315 db_.Execute("CREATE TABLE temp_favicons (" | 1283 db_.Execute("CREATE TABLE temp_favicons (" |
| 1316 "id INTEGER PRIMARY KEY," | 1284 "id INTEGER PRIMARY KEY," |
| 1317 "url LONGVARCHAR NOT NULL," | 1285 "url LONGVARCHAR NOT NULL," |
| 1318 // default icon_type FAVICON to be consistent with | 1286 // default icon_type FAVICON to be consistent with |
| 1319 // past migration. | 1287 // past migration. |
| 1320 "icon_type INTEGER DEFAULT 1)") && | 1288 "icon_type INTEGER DEFAULT 1)") && |
| 1321 db_.Execute("INSERT INTO temp_favicons (id, url, icon_type) " | 1289 db_.Execute("INSERT INTO temp_favicons (id, url, icon_type) " |
| 1322 "SELECT id, url, icon_type FROM favicons") && | 1290 "SELECT id, url, icon_type FROM favicons") && |
| 1323 db_.Execute("DROP TABLE favicons") && | 1291 db_.Execute("DROP TABLE favicons") && |
| 1324 db_.Execute("ALTER TABLE temp_favicons RENAME TO favicons") && | 1292 db_.Execute("ALTER TABLE temp_favicons RENAME TO favicons") && |
| 1325 db_.Execute("CREATE INDEX IF NOT EXISTS favicons_url ON favicons(url)"); | 1293 db_.Execute("CREATE INDEX IF NOT EXISTS favicons_url ON favicons(url)"); |
| 1326 | 1294 |
| 1327 if (!success) | 1295 if (!success) |
| 1328 return false; | 1296 return false; |
| 1329 | 1297 |
| 1330 meta_table_.SetVersionNumber(7); | 1298 meta_table_.SetVersionNumber(7); |
| 1331 meta_table_.SetCompatibleVersionNumber(std::min(7, kCompatibleVersionNumber)); | 1299 meta_table_.SetCompatibleVersionNumber(std::min(7, kCompatibleVersionNumber)); |
| 1332 return true; | 1300 return true; |
| 1333 } | 1301 } |
| 1334 | 1302 |
| 1335 bool ThumbnailDatabase::IsFaviconDBStructureIncorrect() { | 1303 bool ThumbnailDatabase::IsFaviconDBStructureIncorrect() { |
| 1336 return !db_.IsSQLValid("SELECT id, url, icon_type FROM favicons"); | 1304 return !db_.IsSQLValid("SELECT id, url, icon_type FROM favicons"); |
| 1337 } | 1305 } |
| 1338 | 1306 |
| 1339 } // namespace history | 1307 } // namespace history |
| OLD | NEW |