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

Side by Side Diff: chrome/browser/history/shortcuts_database.cc

Issue 134853004: Migrate old Shortcuts DB data to conform to new type values (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed Peter's comments - 2 Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/history/shortcuts_database.h" 5 #include "chrome/browser/history/shortcuts_database.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/guid.h" 10 #include "base/guid.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "sql/meta_table.h"
14 #include "sql/statement.h" 15 #include "sql/statement.h"
15 #include "sql/transaction.h" 16 #include "sql/transaction.h"
16 17
17 namespace { 18 namespace {
18 19
20 // Current version number. We write databases at the "current" version number,
21 // but any previous version that can read the "compatible" one can make do with
22 // or database without *too* many bad effects.
Peter Kasting 2014/02/12 00:27:50 Nit: or -> our
Anuj 2014/02/12 23:54:40 Done.
23 const int kCurrentVersionNumber = 1;
24 const int kCompatibleVersionNumber = 1;
25
19 void BindShortcutToStatement( 26 void BindShortcutToStatement(
20 const history::ShortcutsBackend::Shortcut& shortcut, 27 const history::ShortcutsBackend::Shortcut& shortcut,
21 sql::Statement* s) { 28 sql::Statement* s) {
22 DCHECK(base::IsValidGUID(shortcut.id)); 29 DCHECK(base::IsValidGUID(shortcut.id));
23 s->BindString(0, shortcut.id); 30 s->BindString(0, shortcut.id);
24 s->BindString16(1, shortcut.text); 31 s->BindString16(1, shortcut.text);
25 s->BindString16(2, shortcut.match_core.fill_into_edit); 32 s->BindString16(2, shortcut.match_core.fill_into_edit);
26 s->BindString(3, shortcut.match_core.destination_url.spec()); 33 s->BindString(3, shortcut.match_core.destination_url.spec());
27 s->BindString16(4, shortcut.match_core.contents); 34 s->BindString16(4, shortcut.match_core.contents);
28 s->BindString(5, AutocompleteMatch::ClassificationsToString( 35 s->BindString(5, AutocompleteMatch::ClassificationsToString(
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 "keyword VARCHAR, last_access_time INTEGER, " 177 "keyword VARCHAR, last_access_time INTEGER, "
171 "number_of_hits INTEGER)"); 178 "number_of_hits INTEGER)");
172 } 179 }
173 180
174 // The first version of the shortcuts table lacked the fill_into_edit, 181 // The first version of the shortcuts table lacked the fill_into_edit,
175 // transition, type, and keyword columns. 182 // transition, type, and keyword columns.
176 if (!db_.DoesColumnExist("omni_box_shortcuts", "fill_into_edit")) { 183 if (!db_.DoesColumnExist("omni_box_shortcuts", "fill_into_edit")) {
177 // Perform the upgrade in a transaction to ensure it doesn't happen 184 // Perform the upgrade in a transaction to ensure it doesn't happen
178 // incompletely. 185 // incompletely.
179 sql::Transaction transaction(&db_); 186 sql::Transaction transaction(&db_);
180 transaction.Begin(); 187 transaction.Begin();
Peter Kasting 2014/02/12 00:27:50 Change this block to something like: if (!trans
Anuj 2014/02/12 23:54:40 Done. I will let compiler deal with Mr. De Morgan.
181 return 188 return
182 db_.Execute("ALTER TABLE omni_box_shortcuts " 189 db_.Execute("ALTER TABLE omni_box_shortcuts "
183 "ADD COLUMN fill_into_edit VARCHAR") && 190 "ADD COLUMN fill_into_edit VARCHAR") &&
184 db_.Execute("UPDATE omni_box_shortcuts SET fill_into_edit = url") && 191 db_.Execute("UPDATE omni_box_shortcuts SET fill_into_edit = url") &&
185 db_.Execute("ALTER TABLE omni_box_shortcuts " 192 db_.Execute("ALTER TABLE omni_box_shortcuts "
186 "ADD COLUMN transition INTEGER") && 193 "ADD COLUMN transition INTEGER") &&
187 db_.Execute(base::StringPrintf( 194 db_.Execute(base::StringPrintf(
188 "UPDATE omni_box_shortcuts SET transition = %d", 195 "UPDATE omni_box_shortcuts SET transition = %d",
189 static_cast<int>(content::PAGE_TRANSITION_TYPED)).c_str()) && 196 static_cast<int>(content::PAGE_TRANSITION_TYPED)).c_str()) &&
190 db_.Execute("ALTER TABLE omni_box_shortcuts ADD COLUMN type INTEGER") && 197 db_.Execute("ALTER TABLE omni_box_shortcuts ADD COLUMN type INTEGER") &&
191 db_.Execute(base::StringPrintf( 198 db_.Execute(base::StringPrintf(
192 "UPDATE omni_box_shortcuts SET type = %d", 199 "UPDATE omni_box_shortcuts SET type = %d",
193 static_cast<int>(AutocompleteMatchType::HISTORY_TITLE)).c_str()) && 200 static_cast<int>(AutocompleteMatchType::HISTORY_TITLE)).c_str()) &&
194 db_.Execute("ALTER TABLE omni_box_shortcuts " 201 db_.Execute("ALTER TABLE omni_box_shortcuts "
195 "ADD COLUMN keyword VARCHAR") && 202 "ADD COLUMN keyword VARCHAR") &&
196 transaction.Commit(); 203 transaction.Commit();
197 } 204 }
198 205
206 if (!sql::MetaTable::DoesTableExist(&db_)) {
207 meta_table_.Init(&db_, kCurrentVersionNumber, kCompatibleVersionNumber);
208 sql::Transaction transaction(&db_);
209 transaction.Begin();
Peter Kasting 2014/02/12 00:27:50 Nit: Include this call in the return statement Yo
Anuj 2014/02/12 23:54:40 Done.
210 return
211 // Migrate old SEARCH_OTHER_ENGINE values to the new type value.
212 db_.Execute(base::StringPrintf("UPDATE omni_box_shortcuts "
213 "SET type = 13 WHERE type = 9").c_str()) &&
214 // Migrate old EXTENSION_APP values to the new type value.
215 db_.Execute(base::StringPrintf("UPDATE omni_box_shortcuts "
216 "SET type = 14 WHERE type = 10").c_str()) &&
217 // Migrate old CONTACT values to the new type value.
218 db_.Execute(base::StringPrintf("UPDATE omni_box_shortcuts "
219 "SET type = 15 WHERE type = 11").c_str()) &&
220 // Migrate old BOOKMARK_TITLE values to the new type value.
221 db_.Execute(base::StringPrintf("UPDATE omni_box_shortcuts "
222 "SET type = 16 WHERE type = 12").c_str()) &&
223 transaction.Commit();
224 }
199 return true; 225 return true;
200 } 226 }
201 227
202 } // namespace history 228 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698