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 "chrome/browser/webdata/web_database.h" | 5 #include "chrome/browser/webdata/web_database.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "chrome/browser/diagnostics/sqlite_diagnostics.h" | 9 #include "chrome/browser/diagnostics/sqlite_diagnostics.h" |
| 10 #include "chrome/browser/webdata/autofill_table.h" | 10 #include "chrome/browser/webdata/autofill_table.h" |
| 11 #include "chrome/browser/webdata/keyword_table.h" | 11 #include "chrome/browser/webdata/keyword_table.h" |
| 12 #include "chrome/browser/webdata/logins_table.h" | 12 #include "chrome/browser/webdata/logins_table.h" |
| 13 #include "chrome/browser/webdata/token_service_table.h" | 13 #include "chrome/browser/webdata/token_service_table.h" |
| 14 #include "chrome/browser/webdata/web_apps_table.h" | 14 #include "chrome/browser/webdata/web_apps_table.h" |
| 15 #include "chrome/browser/webdata/web_intents_table.h" | 15 #include "chrome/browser/webdata/web_intents_table.h" |
| 16 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
| 17 #include "sql/statement.h" | 17 #include "sql/statement.h" |
| 18 #include "sql/transaction.h" | 18 #include "sql/transaction.h" |
| 19 | 19 |
| 20 // Current version number. Note: when changing the current version number, | 20 // Current version number. Note: when changing the current version number, |
| 21 // corresponding changes must happen in the unit tests, and new migration test | 21 // corresponding changes must happen in the unit tests, and new migration test |
| 22 // added. See |WebDatabaseMigrationTest::kCurrentTestedVersionNumber|. | 22 // added. See |WebDatabaseMigrationTest::kCurrentTestedVersionNumber|. |
| 23 // static | 23 // static |
| 24 const int WebDatabase::kCurrentVersionNumber = 47; | 24 const int WebDatabase::kCurrentVersionNumber = 48; |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 const int kCompatibleVersionNumber = 47; | 28 const int kCompatibleVersionNumber = 48; |
| 29 | 29 |
| 30 // Change the version number and possibly the compatibility version of | 30 // Change the version number and possibly the compatibility version of |
| 31 // |meta_table_|. | 31 // |meta_table_|. |
| 32 void ChangeVersion(sql::MetaTable* meta_table, | 32 void ChangeVersion(sql::MetaTable* meta_table, |
| 33 int version_num, | 33 int version_num, |
| 34 bool update_compatible_version_num) { | 34 bool update_compatible_version_num) { |
| 35 meta_table->SetVersionNumber(version_num); | 35 meta_table->SetVersionNumber(version_num); |
| 36 if (update_compatible_version_num) { | 36 if (update_compatible_version_num) { |
| 37 meta_table->SetCompatibleVersionNumber( | 37 meta_table->SetCompatibleVersionNumber( |
| 38 std::min(version_num, kCompatibleVersionNumber)); | 38 std::min(version_num, kCompatibleVersionNumber)); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 // If the migration fails we return an error to caller and do not commit | 151 // If the migration fails we return an error to caller and do not commit |
| 152 // the migration. | 152 // the migration. |
| 153 sql::InitStatus migration_status = MigrateOldVersionsAsNeeded(); | 153 sql::InitStatus migration_status = MigrateOldVersionsAsNeeded(); |
| 154 if (migration_status != sql::INIT_OK) | 154 if (migration_status != sql::INIT_OK) |
| 155 return migration_status; | 155 return migration_status; |
| 156 | 156 |
| 157 return transaction.Commit() ? sql::INIT_OK : sql::INIT_FAILURE; | 157 return transaction.Commit() ? sql::INIT_OK : sql::INIT_FAILURE; |
| 158 } | 158 } |
| 159 | 159 |
| 160 sql::InitStatus WebDatabase::MigrateOldVersionsAsNeeded() { | 160 sql::InitStatus WebDatabase::MigrateOldVersionsAsNeeded() { |
| 161 // Some malware tries to force protector to re-sign things by lowering the | 161 // Some malware tried to force protector to re-sign things by lowering the |
|
Peter Kasting
2012/12/11 20:09:06
Nit: In the future, people won't know what protect
Ivan Korotkov
2012/12/12 17:02:57
Done.
| |
| 162 // version number, causing migration to fail. Ensure the version number is at | 162 // version number, causing migration to fail. Ensure the version number is at |
| 163 // least as high as the compatible version number. | 163 // least as high as the compatible version number. |
| 164 int current_version = std::max(meta_table_.GetVersionNumber(), | 164 int current_version = std::max(meta_table_.GetVersionNumber(), |
| 165 meta_table_.GetCompatibleVersionNumber()); | 165 meta_table_.GetCompatibleVersionNumber()); |
| 166 if (current_version > meta_table_.GetVersionNumber()) | 166 if (current_version > meta_table_.GetVersionNumber()) |
| 167 ChangeVersion(&meta_table_, current_version, false); | 167 ChangeVersion(&meta_table_, current_version, false); |
| 168 | 168 |
| 169 // Migrate if necessary. | 169 // Migrate if necessary. |
| 170 switch (current_version) { | 170 switch (current_version) { |
| 171 // Versions 1 - 19 are unhandled. Version numbers greater than | 171 // Versions 1 - 19 are unhandled. Version numbers greater than |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 ChangeVersion(&meta_table_, 46, true); | 343 ChangeVersion(&meta_table_, 46, true); |
| 344 // FALL THROUGH | 344 // FALL THROUGH |
| 345 | 345 |
| 346 case 46: | 346 case 46: |
| 347 if (!keyword_table_->MigrateToVersion47AddAlternateURLsColumn()) | 347 if (!keyword_table_->MigrateToVersion47AddAlternateURLsColumn()) |
| 348 return FailedMigrationTo(47); | 348 return FailedMigrationTo(47); |
| 349 | 349 |
| 350 ChangeVersion(&meta_table_, 47, true); | 350 ChangeVersion(&meta_table_, 47, true); |
| 351 // FALL THROUGH | 351 // FALL THROUGH |
| 352 | 352 |
| 353 case 47: | |
| 354 if (!keyword_table_->MigrateToVersion48RemoveKeywordsBackup()) | |
| 355 return FailedMigrationTo(48); | |
| 356 | |
| 357 ChangeVersion(&meta_table_, 48, true); | |
| 358 // FALL THROUGH | |
| 359 | |
| 353 // Add successive versions here. Each should set the version number and | 360 // Add successive versions here. Each should set the version number and |
| 354 // compatible version number as appropriate, then fall through to the next | 361 // compatible version number as appropriate, then fall through to the next |
| 355 // case. | 362 // case. |
| 356 | 363 |
| 357 case kCurrentVersionNumber: | 364 case kCurrentVersionNumber: |
| 358 // No migration needed. | 365 // No migration needed. |
| 359 return sql::INIT_OK; | 366 return sql::INIT_OK; |
| 360 } | 367 } |
| 361 } | 368 } |
| OLD | NEW |