| 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/webdata/common/web_database.h" | 5 #include "components/webdata/common/web_database.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "sql/transaction.h" | 10 #include "sql/transaction.h" |
| 11 | 11 |
| 12 // Current version number. Note: when changing the current version number, | 12 // Current version number. Note: when changing the current version number, |
| 13 // corresponding changes must happen in the unit tests, and new migration test | 13 // corresponding changes must happen in the unit tests, and new migration test |
| 14 // added. See |WebDatabaseMigrationTest::kCurrentTestedVersionNumber|. | 14 // added. See |WebDatabaseMigrationTest::kCurrentTestedVersionNumber|. |
| 15 // static | 15 // static |
| 16 const int WebDatabase::kCurrentVersionNumber = 71; | 16 const int WebDatabase::kCurrentVersionNumber = 72; |
| 17 | 17 |
| 18 const int WebDatabase::kDeprecatedVersionNumber = 51; | 18 const int WebDatabase::kDeprecatedVersionNumber = 51; |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 const int kCompatibleVersionNumber = 71; | 22 const int kCompatibleVersionNumber = 72; |
| 23 | 23 |
| 24 // Change the version number and possibly the compatibility version of | 24 // Change the version number and possibly the compatibility version of |
| 25 // |meta_table_|. | 25 // |meta_table_|. |
| 26 void ChangeVersion(sql::MetaTable* meta_table, | 26 void ChangeVersion(sql::MetaTable* meta_table, |
| 27 int version_num, | 27 int version_num, |
| 28 bool update_compatible_version_num) { | 28 bool update_compatible_version_num) { |
| 29 meta_table->SetVersionNumber(version_num); | 29 meta_table->SetVersionNumber(version_num); |
| 30 if (update_compatible_version_num) { | 30 if (update_compatible_version_num) { |
| 31 meta_table->SetCompatibleVersionNumber( | 31 meta_table->SetCompatibleVersionNumber( |
| 32 std::min(version_num, kCompatibleVersionNumber)); | 32 std::min(version_num, kCompatibleVersionNumber)); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 int current_version = std::max(meta_table_.GetVersionNumber(), | 145 int current_version = std::max(meta_table_.GetVersionNumber(), |
| 146 meta_table_.GetCompatibleVersionNumber()); | 146 meta_table_.GetCompatibleVersionNumber()); |
| 147 if (current_version > meta_table_.GetVersionNumber()) | 147 if (current_version > meta_table_.GetVersionNumber()) |
| 148 ChangeVersion(&meta_table_, current_version, false); | 148 ChangeVersion(&meta_table_, current_version, false); |
| 149 | 149 |
| 150 DCHECK_GT(current_version, kDeprecatedVersionNumber); | 150 DCHECK_GT(current_version, kDeprecatedVersionNumber); |
| 151 | 151 |
| 152 for (int next_version = current_version + 1; | 152 for (int next_version = current_version + 1; |
| 153 next_version <= kCurrentVersionNumber; | 153 next_version <= kCurrentVersionNumber; |
| 154 ++next_version) { | 154 ++next_version) { |
| 155 | |
| 156 // Do any database-wide migrations. | 155 // Do any database-wide migrations. |
| 157 bool update_compatible_version = false; | 156 bool update_compatible_version = false; |
| 158 if (!MigrateToVersion(next_version, &update_compatible_version)) | 157 if (!MigrateToVersion(next_version, &update_compatible_version)) |
| 159 return FailedMigrationTo(next_version); | 158 return FailedMigrationTo(next_version); |
| 160 | 159 |
| 161 ChangeVersion(&meta_table_, next_version, update_compatible_version); | 160 ChangeVersion(&meta_table_, next_version, update_compatible_version); |
| 162 | 161 |
| 163 // Give each table a chance to migrate to this version. | 162 // Give each table a chance to migrate to this version. |
| 164 for (TableMap::iterator it = tables_.begin(); it != tables_.end(); ++it) { | 163 for (TableMap::iterator it = tables_.begin(); it != tables_.end(); ++it) { |
| 165 // Any of the tables may set this to true, but by default it is false. | 164 // Any of the tables may set this to true, but by default it is false. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 189 | 188 |
| 190 bool WebDatabase::MigrateToVersion58DropWebAppsAndIntents() { | 189 bool WebDatabase::MigrateToVersion58DropWebAppsAndIntents() { |
| 191 sql::Transaction transaction(&db_); | 190 sql::Transaction transaction(&db_); |
| 192 return transaction.Begin() && | 191 return transaction.Begin() && |
| 193 db_.Execute("DROP TABLE IF EXISTS web_apps") && | 192 db_.Execute("DROP TABLE IF EXISTS web_apps") && |
| 194 db_.Execute("DROP TABLE IF EXISTS web_app_icons") && | 193 db_.Execute("DROP TABLE IF EXISTS web_app_icons") && |
| 195 db_.Execute("DROP TABLE IF EXISTS web_intents") && | 194 db_.Execute("DROP TABLE IF EXISTS web_intents") && |
| 196 db_.Execute("DROP TABLE IF EXISTS web_intents_defaults") && | 195 db_.Execute("DROP TABLE IF EXISTS web_intents_defaults") && |
| 197 transaction.Commit(); | 196 transaction.Commit(); |
| 198 } | 197 } |
| OLD | NEW |