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" |
(...skipping 140 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 |
| 162 // version number, causing migration to fail. Ensure the version number is at |
| 163 // least as high as the compatible version number. |
| 164 int current_version = std::max(meta_table_.GetVersionNumber(), |
| 165 meta_table_.GetCompatibleVersionNumber()); |
| 166 if (current_version < meta_table_.GetCompatibleVersionNumber()) |
| 167 ChangeVersion(&meta_table_, current_version, false); |
| 168 |
161 // Migrate if necessary. | 169 // Migrate if necessary. |
162 int current_version = meta_table_.GetVersionNumber(); | |
163 switch (current_version) { | 170 switch (current_version) { |
164 // Versions 1 - 19 are unhandled. Version numbers greater than | 171 // Versions 1 - 19 are unhandled. Version numbers greater than |
165 // kCurrentVersionNumber should have already been weeded out by the caller. | 172 // kCurrentVersionNumber should have already been weeded out by the caller. |
166 default: | 173 default: |
167 // When the version is too old, we return failure error code. The schema | 174 // When the version is too old, we return failure error code. The schema |
168 // is too out of date to migrate. | 175 // is too out of date to migrate. |
169 // There should not be a released product that makes a database too old to | 176 // There should not be a released product that makes a database too old to |
170 // migrate. If we do encounter such a legacy database, we will need a | 177 // migrate. If we do encounter such a legacy database, we will need a |
171 // better solution to handle it (i.e., pop up a dialog to tell the user, | 178 // better solution to handle it (i.e., pop up a dialog to tell the user, |
172 // erase all their prefs and start over, etc.). | 179 // erase all their prefs and start over, etc.). |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 | 338 |
332 // Add successive versions here. Each should set the version number and | 339 // Add successive versions here. Each should set the version number and |
333 // compatible version number as appropriate, then fall through to the next | 340 // compatible version number as appropriate, then fall through to the next |
334 // case. | 341 // case. |
335 | 342 |
336 case kCurrentVersionNumber: | 343 case kCurrentVersionNumber: |
337 // No migration needed. | 344 // No migration needed. |
338 return sql::INIT_OK; | 345 return sql::INIT_OK; |
339 } | 346 } |
340 } | 347 } |
OLD | NEW |