OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/search_engines/keyword_table.h" | 5 #include "components/search_engines/keyword_table.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 } | 186 } |
187 | 187 |
188 bool KeywordTable::IsSyncable() { | 188 bool KeywordTable::IsSyncable() { |
189 return true; | 189 return true; |
190 } | 190 } |
191 | 191 |
192 bool KeywordTable::MigrateToVersion(int version, | 192 bool KeywordTable::MigrateToVersion(int version, |
193 bool* update_compatible_version) { | 193 bool* update_compatible_version) { |
194 // Migrate if necessary. | 194 // Migrate if necessary. |
195 switch (version) { | 195 switch (version) { |
196 case 21: | |
197 *update_compatible_version = true; | |
198 return MigrateToVersion21AutoGenerateKeywordColumn(); | |
199 case 25: | |
200 *update_compatible_version = true; | |
201 return MigrateToVersion25AddLogoIDColumn(); | |
202 case 26: | |
203 *update_compatible_version = true; | |
204 return MigrateToVersion26AddCreatedByPolicyColumn(); | |
205 case 28: | |
206 *update_compatible_version = true; | |
207 return MigrateToVersion28SupportsInstantColumn(); | |
208 case 29: | |
209 *update_compatible_version = true; | |
210 return MigrateToVersion29InstantURLToSupportsInstant(); | |
211 case 38: | |
212 *update_compatible_version = true; | |
213 return MigrateToVersion38AddLastModifiedColumn(); | |
214 case 39: | |
215 *update_compatible_version = true; | |
216 return MigrateToVersion39AddSyncGUIDColumn(); | |
217 case 44: | |
218 *update_compatible_version = true; | |
219 return MigrateToVersion44AddDefaultSearchProviderBackup(); | |
220 case 45: | |
221 *update_compatible_version = true; | |
222 return MigrateToVersion45RemoveLogoIDAndAutogenerateColumns(); | |
223 case 47: | |
224 *update_compatible_version = true; | |
225 return MigrateToVersion47AddAlternateURLsColumn(); | |
226 case 48: | |
227 *update_compatible_version = true; | |
228 return MigrateToVersion48RemoveKeywordsBackup(); | |
229 case 49: | |
230 *update_compatible_version = true; | |
231 return MigrateToVersion49AddSearchTermsReplacementKeyColumn(); | |
232 case 52: | |
233 *update_compatible_version = true; | |
234 return MigrateToVersion52AddImageSearchAndPOSTSupport(); | |
235 case 53: | 196 case 53: |
236 *update_compatible_version = true; | 197 *update_compatible_version = true; |
237 return MigrateToVersion53AddNewTabURLColumn(); | 198 return MigrateToVersion53AddNewTabURLColumn(); |
238 case 59: | 199 case 59: |
239 *update_compatible_version = true; | 200 *update_compatible_version = true; |
240 return MigrateToVersion59RemoveExtensionKeywords(); | 201 return MigrateToVersion59RemoveExtensionKeywords(); |
241 } | 202 } |
242 | 203 |
243 return true; | 204 return true; |
244 } | 205 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
308 int KeywordTable::GetBuiltinKeywordVersion() { | 269 int KeywordTable::GetBuiltinKeywordVersion() { |
309 int version = 0; | 270 int version = 0; |
310 return meta_table_->GetValue(kBuiltinKeywordVersion, &version) ? version : 0; | 271 return meta_table_->GetValue(kBuiltinKeywordVersion, &version) ? version : 0; |
311 } | 272 } |
312 | 273 |
313 // static | 274 // static |
314 std::string KeywordTable::GetKeywordColumns() { | 275 std::string KeywordTable::GetKeywordColumns() { |
315 return ColumnsForVersion(WebDatabase::kCurrentVersionNumber, false); | 276 return ColumnsForVersion(WebDatabase::kCurrentVersionNumber, false); |
316 } | 277 } |
317 | 278 |
318 bool KeywordTable::MigrateToVersion21AutoGenerateKeywordColumn() { | |
319 return db_->Execute("ALTER TABLE keywords ADD COLUMN autogenerate_keyword " | |
320 "INTEGER DEFAULT 0"); | |
321 } | |
322 | |
323 bool KeywordTable::MigrateToVersion25AddLogoIDColumn() { | |
324 return db_->Execute( | |
325 "ALTER TABLE keywords ADD COLUMN logo_id INTEGER DEFAULT 0"); | |
326 } | |
327 | |
328 bool KeywordTable::MigrateToVersion26AddCreatedByPolicyColumn() { | |
329 return db_->Execute("ALTER TABLE keywords ADD COLUMN created_by_policy " | |
330 "INTEGER DEFAULT 0"); | |
331 } | |
332 | |
333 bool KeywordTable::MigrateToVersion28SupportsInstantColumn() { | |
334 return db_->Execute("ALTER TABLE keywords ADD COLUMN supports_instant " | |
335 "INTEGER DEFAULT 0"); | |
336 } | |
337 | |
338 bool KeywordTable::MigrateToVersion29InstantURLToSupportsInstant() { | |
339 sql::Transaction transaction(db_); | |
340 return transaction.Begin() && | |
341 db_->Execute("ALTER TABLE keywords ADD COLUMN instant_url VARCHAR") && | |
342 db_->Execute("CREATE TABLE keywords_temp (" | |
343 "id INTEGER PRIMARY KEY," | |
344 "short_name VARCHAR NOT NULL," | |
345 "keyword VARCHAR NOT NULL," | |
346 "favicon_url VARCHAR NOT NULL," | |
347 "url VARCHAR NOT NULL," | |
348 "safe_for_autoreplace INTEGER," | |
349 "originating_url VARCHAR," | |
350 "date_created INTEGER DEFAULT 0," | |
351 "usage_count INTEGER DEFAULT 0," | |
352 "input_encodings VARCHAR," | |
353 "show_in_default_list INTEGER," | |
354 "suggest_url VARCHAR," | |
355 "prepopulate_id INTEGER DEFAULT 0," | |
356 "autogenerate_keyword INTEGER DEFAULT 0," | |
357 "logo_id INTEGER DEFAULT 0," | |
358 "created_by_policy INTEGER DEFAULT 0," | |
359 "instant_url VARCHAR)") && | |
360 db_->Execute("INSERT INTO keywords_temp SELECT id, short_name, keyword, " | |
361 "favicon_url, url, safe_for_autoreplace, originating_url, " | |
362 "date_created, usage_count, input_encodings, " | |
363 "show_in_default_list, suggest_url, prepopulate_id, " | |
364 "autogenerate_keyword, logo_id, created_by_policy, " | |
365 "instant_url FROM keywords") && | |
366 db_->Execute("DROP TABLE keywords") && | |
367 db_->Execute("ALTER TABLE keywords_temp RENAME TO keywords") && | |
368 transaction.Commit(); | |
369 } | |
370 | |
371 bool KeywordTable::MigrateToVersion38AddLastModifiedColumn() { | |
372 return db_->Execute( | |
373 "ALTER TABLE keywords ADD COLUMN last_modified INTEGER DEFAULT 0"); | |
374 } | |
375 | |
376 bool KeywordTable::MigrateToVersion39AddSyncGUIDColumn() { | |
377 return db_->Execute("ALTER TABLE keywords ADD COLUMN sync_guid VARCHAR"); | |
378 } | |
379 | |
380 bool KeywordTable::MigrateToVersion44AddDefaultSearchProviderBackup() { | |
381 std::string query("CREATE TABLE keywords_backup AS SELECT " + | |
382 ColumnsForVersion(44, false) + " FROM keywords ORDER BY id ASC"); | |
383 sql::Transaction transaction(db_); | |
384 return transaction.Begin() && | |
385 meta_table_->SetValue("Default Search Provider ID Backup", | |
386 GetDefaultSearchProviderID()) && | |
387 (!db_->DoesTableExist("keywords_backup") || | |
388 db_->Execute("DROP TABLE keywords_backup")) && | |
389 db_->Execute(query.c_str()) && | |
390 transaction.Commit(); | |
391 } | |
392 | |
393 bool KeywordTable::MigrateToVersion45RemoveLogoIDAndAutogenerateColumns() { | |
394 sql::Transaction transaction(db_); | |
395 if (!transaction.Begin()) | |
396 return false; | |
397 | |
398 // The version 43 migration should have been written to do this, but since it | |
399 // wasn't, we'll do it now. Unfortunately a previous change deleted this for | |
400 // some users, so we can't be sure this will succeed (so don't bail on error). | |
401 meta_table_->DeleteKey("Default Search Provider Backup"); | |
402 | |
403 return MigrateKeywordsTableForVersion45("keywords") && | |
404 MigrateKeywordsTableForVersion45("keywords_backup") && | |
405 meta_table_->SetValue("Default Search Provider ID Backup Signature", | |
406 std::string()) && | |
407 transaction.Commit(); | |
408 } | |
409 | |
410 bool KeywordTable::MigrateToVersion47AddAlternateURLsColumn() { | |
411 sql::Transaction transaction(db_); | |
412 return transaction.Begin() && | |
413 db_->Execute("ALTER TABLE keywords ADD COLUMN " | |
414 "alternate_urls VARCHAR DEFAULT ''") && | |
415 db_->Execute("ALTER TABLE keywords_backup ADD COLUMN " | |
416 "alternate_urls VARCHAR DEFAULT ''") && | |
417 meta_table_->SetValue("Default Search Provider ID Backup Signature", | |
418 std::string()) && | |
419 transaction.Commit(); | |
420 } | |
421 | |
422 bool KeywordTable::MigrateToVersion48RemoveKeywordsBackup() { | |
423 sql::Transaction transaction(db_); | |
424 return transaction.Begin() && | |
425 meta_table_->DeleteKey("Default Search Provider ID Backup") && | |
426 meta_table_->DeleteKey("Default Search Provider ID Backup Signature") && | |
427 db_->Execute("DROP TABLE keywords_backup") && | |
428 transaction.Commit(); | |
429 } | |
430 | |
431 bool KeywordTable::MigrateToVersion49AddSearchTermsReplacementKeyColumn() { | |
432 return db_->Execute("ALTER TABLE keywords ADD COLUMN " | |
433 "search_terms_replacement_key VARCHAR DEFAULT ''"); | |
434 } | |
435 | |
436 bool KeywordTable::MigrateToVersion52AddImageSearchAndPOSTSupport() { | |
437 sql::Transaction transaction(db_); | |
438 return transaction.Begin() && | |
439 db_->Execute("ALTER TABLE keywords ADD COLUMN image_url " | |
440 "VARCHAR DEFAULT ''") && | |
441 db_->Execute("ALTER TABLE keywords ADD COLUMN search_url_post_params " | |
442 "VARCHAR DEFAULT ''") && | |
443 db_->Execute("ALTER TABLE keywords ADD COLUMN suggest_url_post_params " | |
444 "VARCHAR DEFAULT ''") && | |
445 db_->Execute("ALTER TABLE keywords ADD COLUMN instant_url_post_params " | |
446 "VARCHAR DEFAULT ''") && | |
447 db_->Execute("ALTER TABLE keywords ADD COLUMN image_url_post_params " | |
448 "VARCHAR DEFAULT ''") && | |
449 transaction.Commit(); | |
450 } | |
451 | |
452 bool KeywordTable::MigrateToVersion53AddNewTabURLColumn() { | 279 bool KeywordTable::MigrateToVersion53AddNewTabURLColumn() { |
453 return db_->Execute("ALTER TABLE keywords ADD COLUMN new_tab_url " | 280 return db_->Execute("ALTER TABLE keywords ADD COLUMN new_tab_url " |
454 "VARCHAR DEFAULT ''"); | 281 "VARCHAR"); |
Scott Hess - ex-Googler
2015/02/27 06:49:38
Is there a strong argument for changing this? It
Peter Kasting
2015/02/27 09:15:25
I had assumed that the two were equivalent. If th
Scott Hess - ex-Googler
2015/02/27 17:00:21
They are probably functionally equivalent, but the
Evan Stade
2015/02/27 19:31:17
oops, I meant to leave this alone. This was part o
Evan Stade
2015/02/28 00:13:41
reverted
| |
455 } | 282 } |
456 | 283 |
457 bool KeywordTable::MigrateToVersion59RemoveExtensionKeywords() { | 284 bool KeywordTable::MigrateToVersion59RemoveExtensionKeywords() { |
458 return db_->Execute("DELETE FROM keywords " | 285 return db_->Execute("DELETE FROM keywords " |
459 "WHERE url LIKE 'chrome-extension://%'"); | 286 "WHERE url LIKE 'chrome-extension://%'"); |
460 } | 287 } |
461 | 288 |
462 // static | 289 // static |
463 bool KeywordTable::GetKeywordDataFromStatement(const sql::Statement& s, | 290 bool KeywordTable::GetKeywordDataFromStatement(const sql::Statement& s, |
464 TemplateURLData* data) { | 291 TemplateURLData* data) { |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
646 } | 473 } |
647 } | 474 } |
648 | 475 |
649 // Replace the old table with the new one. | 476 // Replace the old table with the new one. |
650 sql = "DROP TABLE " + name; | 477 sql = "DROP TABLE " + name; |
651 if (!db_->Execute(sql.c_str())) | 478 if (!db_->Execute(sql.c_str())) |
652 return false; | 479 return false; |
653 sql = "ALTER TABLE keywords_temp RENAME TO " + name; | 480 sql = "ALTER TABLE keywords_temp RENAME TO " + name; |
654 return db_->Execute(sql.c_str()); | 481 return db_->Execute(sql.c_str()); |
655 } | 482 } |
OLD | NEW |