Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6664)

Unified Diff: chrome/browser/history/shortcuts_database.cc

Issue 213433002: Migrate old Shortcuts DB data to conform to new type values (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Work around Windows Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/history/shortcuts_database.h ('k') | chrome/browser/history/shortcuts_database_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
« no previous file with comments | « chrome/browser/history/shortcuts_database.h ('k') | chrome/browser/history/shortcuts_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698