| 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 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 return MigrateToVersion48RemoveKeywordsBackup(); | 228 return MigrateToVersion48RemoveKeywordsBackup(); |
| 229 case 49: | 229 case 49: |
| 230 *update_compatible_version = true; | 230 *update_compatible_version = true; |
| 231 return MigrateToVersion49AddSearchTermsReplacementKeyColumn(); | 231 return MigrateToVersion49AddSearchTermsReplacementKeyColumn(); |
| 232 case 52: | 232 case 52: |
| 233 *update_compatible_version = true; | 233 *update_compatible_version = true; |
| 234 return MigrateToVersion52AddImageSearchAndPOSTSupport(); | 234 return MigrateToVersion52AddImageSearchAndPOSTSupport(); |
| 235 case 53: | 235 case 53: |
| 236 *update_compatible_version = true; | 236 *update_compatible_version = true; |
| 237 return MigrateToVersion53AddNewTabURLColumn(); | 237 return MigrateToVersion53AddNewTabURLColumn(); |
| 238 case 59: |
| 239 *update_compatible_version = true; |
| 240 return MigrateToVersion59RemoveExtensionKeywords(); |
| 238 } | 241 } |
| 239 | 242 |
| 240 return true; | 243 return true; |
| 241 } | 244 } |
| 242 | 245 |
| 243 bool KeywordTable::PerformOperations(const Operations& operations) { | 246 bool KeywordTable::PerformOperations(const Operations& operations) { |
| 244 sql::Transaction transaction(db_); | 247 sql::Transaction transaction(db_); |
| 245 if (!transaction.Begin()) | 248 if (!transaction.Begin()) |
| 246 return false; | 249 return false; |
| 247 | 250 |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 db_->Execute("ALTER TABLE keywords ADD COLUMN image_url_post_params " | 447 db_->Execute("ALTER TABLE keywords ADD COLUMN image_url_post_params " |
| 445 "VARCHAR DEFAULT ''") && | 448 "VARCHAR DEFAULT ''") && |
| 446 transaction.Commit(); | 449 transaction.Commit(); |
| 447 } | 450 } |
| 448 | 451 |
| 449 bool KeywordTable::MigrateToVersion53AddNewTabURLColumn() { | 452 bool KeywordTable::MigrateToVersion53AddNewTabURLColumn() { |
| 450 return db_->Execute("ALTER TABLE keywords ADD COLUMN new_tab_url " | 453 return db_->Execute("ALTER TABLE keywords ADD COLUMN new_tab_url " |
| 451 "VARCHAR DEFAULT ''"); | 454 "VARCHAR DEFAULT ''"); |
| 452 } | 455 } |
| 453 | 456 |
| 457 bool KeywordTable::MigrateToVersion59RemoveExtensionKeywords() { |
| 458 return db_->Execute("DELETE FROM keywords " |
| 459 "WHERE url LIKE 'chrome-extension://%'"); |
| 460 } |
| 461 |
| 454 // static | 462 // static |
| 455 bool KeywordTable::GetKeywordDataFromStatement(const sql::Statement& s, | 463 bool KeywordTable::GetKeywordDataFromStatement(const sql::Statement& s, |
| 456 TemplateURLData* data) { | 464 TemplateURLData* data) { |
| 457 DCHECK(data); | 465 DCHECK(data); |
| 458 | 466 |
| 459 data->short_name = s.ColumnString16(1); | 467 data->short_name = s.ColumnString16(1); |
| 460 data->SetKeyword(s.ColumnString16(2)); | 468 data->SetKeyword(s.ColumnString16(2)); |
| 461 // Due to past bugs, we might have persisted entries with empty URLs. Avoid | 469 // Due to past bugs, we might have persisted entries with empty URLs. Avoid |
| 462 // reading these out. (GetKeywords() will delete these entries on return.) | 470 // reading these out. (GetKeywords() will delete these entries on return.) |
| 463 // NOTE: This code should only be needed as long as we might be reading such | 471 // NOTE: This code should only be needed as long as we might be reading such |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 } | 646 } |
| 639 } | 647 } |
| 640 | 648 |
| 641 // Replace the old table with the new one. | 649 // Replace the old table with the new one. |
| 642 sql = "DROP TABLE " + name; | 650 sql = "DROP TABLE " + name; |
| 643 if (!db_->Execute(sql.c_str())) | 651 if (!db_->Execute(sql.c_str())) |
| 644 return false; | 652 return false; |
| 645 sql = "ALTER TABLE keywords_temp RENAME TO " + name; | 653 sql = "ALTER TABLE keywords_temp RENAME TO " + name; |
| 646 return db_->Execute(sql.c_str()); | 654 return db_->Execute(sql.c_str()); |
| 647 } | 655 } |
| OLD | NEW |