Chromium Code Reviews| 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/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. | |
| 23 const int kCurrentVersionNumber = 28; | |
|
Anuj
2014/02/10 22:18:44
Not sure what version numbers I should use here.
Peter Kasting
2014/02/10 22:29:47
If you didn't have a table before, use version 1 (
| |
| 24 const int kCompatibleVersionNumber = 16; | |
| 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 // transition | 157 // transition |
| 151 static_cast<AutocompleteMatch::Type>(s.ColumnInt(9)), | 158 static_cast<AutocompleteMatch::Type>(s.ColumnInt(9)), |
| 152 // type | 159 // type |
| 153 s.ColumnString16(10)), // keyword | 160 s.ColumnString16(10)), // keyword |
| 154 base::Time::FromInternalValue(s.ColumnInt64(11)), | 161 base::Time::FromInternalValue(s.ColumnInt64(11)), |
| 155 // last_access_time | 162 // last_access_time |
| 156 s.ColumnInt(12)))); // number_of_hits | 163 s.ColumnInt(12)))); // number_of_hits |
| 157 } | 164 } |
| 158 } | 165 } |
| 159 | 166 |
| 167 //static | |
| 168 int ShortcutsDatabase::GetCurrentVersion() { | |
|
Peter Kasting
2014/02/10 22:29:47
It doesn't seem like we need this as its own funct
Anuj
2014/02/11 07:20:04
Done.
| |
| 169 return kCurrentVersionNumber; | |
| 170 } | |
| 171 | |
| 160 ShortcutsDatabase::~ShortcutsDatabase() { | 172 ShortcutsDatabase::~ShortcutsDatabase() { |
| 161 } | 173 } |
| 162 | 174 |
| 163 bool ShortcutsDatabase::EnsureTable() { | 175 bool ShortcutsDatabase::EnsureTable() { |
| 164 if (!db_.DoesTableExist("omni_box_shortcuts")) { | 176 if (!db_.DoesTableExist("omni_box_shortcuts")) { |
| 165 return db_.Execute( | 177 return db_.Execute( |
| 166 "CREATE TABLE omni_box_shortcuts (id VARCHAR PRIMARY KEY, " | 178 "CREATE TABLE omni_box_shortcuts (id VARCHAR PRIMARY KEY, " |
| 167 "text VARCHAR, fill_into_edit VARCHAR, url VARCHAR, " | 179 "text VARCHAR, fill_into_edit VARCHAR, url VARCHAR, " |
| 168 "contents VARCHAR, contents_class VARCHAR, description VARCHAR, " | 180 "contents VARCHAR, contents_class VARCHAR, description VARCHAR, " |
| 169 "description_class VARCHAR, transition INTEGER, type INTEGER, " | 181 "description_class VARCHAR, transition INTEGER, type INTEGER, " |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 189 static_cast<int>(content::PAGE_TRANSITION_TYPED)).c_str()) && | 201 static_cast<int>(content::PAGE_TRANSITION_TYPED)).c_str()) && |
| 190 db_.Execute("ALTER TABLE omni_box_shortcuts ADD COLUMN type INTEGER") && | 202 db_.Execute("ALTER TABLE omni_box_shortcuts ADD COLUMN type INTEGER") && |
| 191 db_.Execute(base::StringPrintf( | 203 db_.Execute(base::StringPrintf( |
| 192 "UPDATE omni_box_shortcuts SET type = %d", | 204 "UPDATE omni_box_shortcuts SET type = %d", |
| 193 static_cast<int>(AutocompleteMatchType::HISTORY_TITLE)).c_str()) && | 205 static_cast<int>(AutocompleteMatchType::HISTORY_TITLE)).c_str()) && |
| 194 db_.Execute("ALTER TABLE omni_box_shortcuts " | 206 db_.Execute("ALTER TABLE omni_box_shortcuts " |
| 195 "ADD COLUMN keyword VARCHAR") && | 207 "ADD COLUMN keyword VARCHAR") && |
| 196 transaction.Commit(); | 208 transaction.Commit(); |
| 197 } | 209 } |
| 198 | 210 |
| 211 if (sql::MetaTable::DoesTableExist(&db_)) { | |
|
Peter Kasting
2014/02/10 22:29:47
Don't you mean !exist?
Anuj
2014/02/11 07:20:04
Done.
| |
| 212 meta_table_.Init(&db_, GetCurrentVersion(), kCompatibleVersionNumber); | |
| 213 // With new suggestion types being added, following values have changed: | |
|
Peter Kasting
2014/02/10 22:29:47
This comment is more confusing than helpful. We d
Anuj
2014/02/11 07:20:04
Done.
| |
| 214 // SEARCH_OTHER_ENGINE -> SEARCH_SUGGEST_ENTITY | |
| 215 // EXTENSION_APP -> SEARCH_SUGGEST_INFINITE | |
| 216 // CONTACT -> SEARCH_SUGGEST_PERSONALIZED | |
| 217 // BOOKMARK_TITLE -> SEARCH_SUGGEST_PROFILE | |
| 218 sql::Transaction transaction(&db_); | |
| 219 transaction.Begin(); | |
| 220 // Migrate old SEARCH_OTHER_ENGINE values to the new type value. | |
| 221 // The ENTITY suggestion values always have a description and always have a | |
| 222 // https google search url with gs_ssp parameter. The old | |
| 223 // SEARCH_OTHER_ENGINE entries will definitely fail the url check, but empty | |
| 224 // description test is also sufficient and faster. | |
| 225 db_.Execute(base::StringPrintf("UPDATE omni_box_shortcuts " | |
| 226 "SET type = 13 " // New SEARCH_OTHER_ENGINE | |
| 227 "where type = 9 AND " // Old SEARCH_OTHER_ENGINE | |
| 228 "(description = '' OR " | |
| 229 "url NOT REGEXP '^https://www\\.google\\..*/search\\?.*&?gs_ssp=.*')") | |
| 230 .c_str()) && | |
| 231 // Migrate old EXTENSION_APP values to the new type value. | |
| 232 // The INFINITE suggestions are not launched. So it is safe to update all | |
| 233 // of them to EXTENSION_APP type wherever the url is not a google search. | |
| 234 db_.Execute(base::StringPrintf("UPDATE omni_box_shortcuts " | |
| 235 "SET type = 14 " // New EXTENSION_APP | |
| 236 "where type = 10 AND " // Old EXTENSION_APP | |
| 237 "url NOT REGEXP '^https://www\\.google\\..*/search\\?.*xssi=t.*')") | |
| 238 .c_str()) && | |
| 239 // Migrate old CONTACT values to the new type value. | |
| 240 // The PERSONALIZED suggestions are a https google search url. | |
| 241 db_.Execute(base::StringPrintf("UPDATE omni_box_shortcuts " | |
| 242 "SET type = 15 " // New CONTACT | |
| 243 "where type = 11 AND " // Old CONTACT | |
| 244 "url NOT REGEXP '^https://www\\.google\\..*/search\\?.*xssi=t.*')") | |
| 245 .c_str()) && | |
| 246 // Migrate old BOOKMARK_TITLE values to the new type value. | |
| 247 // The PROFILE suggestion values always have a description and always have | |
| 248 // a https google search url with tbs parameter. The old BOOKMARK_TITLE | |
| 249 // entries will definitely fail the url check, but empty description test | |
| 250 // is also sufficient and faster. | |
| 251 db_.Execute(base::StringPrintf("UPDATE omni_box_shortcuts " | |
| 252 "SET type = 16 " // New BOOKMARK_TITLE | |
| 253 "where type = 12 AND " // Old BOOKMARK_TITLE | |
| 254 "(description = '' OR " | |
| 255 "url NOT REGEXP '^https://www\\.google\\..*/search\\?.*&?tbs=.*')") | |
| 256 .c_str()) && | |
| 257 transaction.Commit(); | |
| 258 } | |
| 199 return true; | 259 return true; |
| 200 } | 260 } |
| 201 | 261 |
| 202 } // namespace history | 262 } // namespace history |
| OLD | NEW |