Index: chrome/browser/history/shortcuts_database.cc |
diff --git a/chrome/browser/history/shortcuts_database.cc b/chrome/browser/history/shortcuts_database.cc |
index ab9a73d7b319263ce4bc15866a1ac7b3cb07859b..9531bbeabb3c87c678cf6fefedd4b68069cf7097 100644 |
--- a/chrome/browser/history/shortcuts_database.cc |
+++ b/chrome/browser/history/shortcuts_database.cc |
@@ -12,6 +12,7 @@ |
#include "base/time/time.h" |
#include "chrome/common/autocomplete_match_type.h" |
#include "content/public/common/page_transition_types.h" |
+#include "sql/meta_table.h" |
#include "sql/statement.h" |
#include "sql/transaction.h" |
@@ -20,6 +21,12 @@ |
namespace { |
+// Current version number. We write databases at the "current" version number, |
+// but any previous version that can read the "compatible" one can make do with |
+// our database without *too* many bad effects. |
+const int kCurrentVersionNumber = 1; |
+const int kCompatibleVersionNumber = 1; |
+ |
void BindShortcutToStatement( |
const history::ShortcutsDatabase::Shortcut& shortcut, |
sql::Statement* s) { |
@@ -228,8 +235,7 @@ bool ShortcutsDatabase::EnsureTable() { |
// Perform the upgrade in a transaction to ensure it doesn't happen |
// incompletely. |
sql::Transaction transaction(&db_); |
- transaction.Begin(); |
- return |
+ if (!(transaction.Begin() && |
db_.Execute("ALTER TABLE omni_box_shortcuts " |
"ADD COLUMN fill_into_edit VARCHAR") && |
db_.Execute("UPDATE omni_box_shortcuts SET fill_into_edit = url") && |
@@ -244,9 +250,31 @@ bool ShortcutsDatabase::EnsureTable() { |
static_cast<int>(AutocompleteMatchType::HISTORY_TITLE)).c_str()) && |
db_.Execute("ALTER TABLE omni_box_shortcuts " |
"ADD COLUMN keyword VARCHAR") && |
- transaction.Commit(); |
+ transaction.Commit())) { |
+ return false; |
+ } |
} |
+ if (!sql::MetaTable::DoesTableExist(&db_)) { |
+ meta_table_.Init(&db_, kCurrentVersionNumber, kCompatibleVersionNumber); |
+ sql::Transaction transaction(&db_); |
+ if (!(transaction.Begin() && |
+ // Migrate old SEARCH_OTHER_ENGINE values to the new type value. |
+ db_.Execute(base::StringPrintf("UPDATE omni_box_shortcuts " |
+ "SET type = 13 WHERE type = 9").c_str()) && |
+ // Migrate old EXTENSION_APP values to the new type value. |
+ db_.Execute(base::StringPrintf("UPDATE omni_box_shortcuts " |
+ "SET type = 14 WHERE type = 10").c_str()) && |
+ // Migrate old CONTACT values to the new type value. |
+ db_.Execute(base::StringPrintf("UPDATE omni_box_shortcuts " |
+ "SET type = 15 WHERE type = 11").c_str()) && |
+ // Migrate old BOOKMARK_TITLE values to the new type value. |
+ db_.Execute(base::StringPrintf("UPDATE omni_box_shortcuts " |
+ "SET type = 16 WHERE type = 12").c_str()) && |
+ transaction.Commit())) { |
+ return false; |
+ } |
+ } |
return true; |
} |