| 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 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 bool delete_entry = turl.GetType() == TemplateURL::OMNIBOX_API_EXTENSION; | 445 bool delete_entry = turl.GetType() == TemplateURL::OMNIBOX_API_EXTENSION; |
| 446 if (!delete_entry && generate_keyword) { | 446 if (!delete_entry && generate_keyword) { |
| 447 // Explicitly generate keywords for all rows with the autogenerate bit set | 447 // Explicitly generate keywords for all rows with the autogenerate bit set |
| 448 // or where the keyword is empty. | 448 // or where the keyword is empty. |
| 449 SearchTermsData terms_data; | 449 SearchTermsData terms_data; |
| 450 GURL url(turl.GenerateSearchURL(terms_data)); | 450 GURL url(turl.GenerateSearchURL(terms_data)); |
| 451 if (!url.is_valid()) { | 451 if (!url.is_valid()) { |
| 452 delete_entry = true; | 452 delete_entry = true; |
| 453 } else { | 453 } else { |
| 454 // Ensure autogenerated keywords are unique. | 454 // Ensure autogenerated keywords are unique. |
| 455 keyword = TemplateURL::GenerateKeyword(url); | 455 keyword = TemplateURL::GenerateKeyword( |
| 456 url, terms_data.GetAcceptLanguages()); |
| 456 while (keywords.count(keyword)) | 457 while (keywords.count(keyword)) |
| 457 keyword.append(base::ASCIIToUTF16("_")); | 458 keyword.append(base::ASCIIToUTF16("_")); |
| 458 sql::Statement u(db_->GetUniqueStatement( | 459 sql::Statement u(db_->GetUniqueStatement( |
| 459 "UPDATE keywords_temp SET keyword=? WHERE id=?")); | 460 "UPDATE keywords_temp SET keyword=? WHERE id=?")); |
| 460 u.BindString16(0, keyword); | 461 u.BindString16(0, keyword); |
| 461 u.BindInt64(1, s.ColumnInt64(0)); | 462 u.BindInt64(1, s.ColumnInt64(0)); |
| 462 if (!u.Run()) | 463 if (!u.Run()) |
| 463 return false; | 464 return false; |
| 464 } | 465 } |
| 465 } | 466 } |
| 466 if (delete_entry) { | 467 if (delete_entry) { |
| 467 sql::Statement u(db_->GetUniqueStatement( | 468 sql::Statement u(db_->GetUniqueStatement( |
| 468 "DELETE FROM keywords_temp WHERE id=?")); | 469 "DELETE FROM keywords_temp WHERE id=?")); |
| 469 u.BindInt64(0, s.ColumnInt64(0)); | 470 u.BindInt64(0, s.ColumnInt64(0)); |
| 470 if (!u.Run()) | 471 if (!u.Run()) |
| 471 return false; | 472 return false; |
| 472 } else { | 473 } else { |
| 473 keywords.insert(keyword); | 474 keywords.insert(keyword); |
| 474 } | 475 } |
| 475 } | 476 } |
| 476 | 477 |
| 477 // Replace the old table with the new one. | 478 // Replace the old table with the new one. |
| 478 sql = "DROP TABLE " + name; | 479 sql = "DROP TABLE " + name; |
| 479 if (!db_->Execute(sql.c_str())) | 480 if (!db_->Execute(sql.c_str())) |
| 480 return false; | 481 return false; |
| 481 sql = "ALTER TABLE keywords_temp RENAME TO " + name; | 482 sql = "ALTER TABLE keywords_temp RENAME TO " + name; |
| 482 return db_->Execute(sql.c_str()); | 483 return db_->Execute(sql.c_str()); |
| 483 } | 484 } |
| OLD | NEW |