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/webdata/keyword_table.h" | 5 #include "chrome/browser/webdata/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 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 base::string16 placeholder_keyword(base::ASCIIToUTF16("dummy")); | 597 base::string16 placeholder_keyword(base::ASCIIToUTF16("dummy")); |
598 std::set<base::string16> keywords; | 598 std::set<base::string16> keywords; |
599 while (s.Step()) { | 599 while (s.Step()) { |
600 base::string16 keyword(s.ColumnString16(1)); | 600 base::string16 keyword(s.ColumnString16(1)); |
601 bool generate_keyword = keyword.empty() || s.ColumnBool(3); | 601 bool generate_keyword = keyword.empty() || s.ColumnBool(3); |
602 if (generate_keyword) | 602 if (generate_keyword) |
603 keyword = placeholder_keyword; | 603 keyword = placeholder_keyword; |
604 TemplateURLData data; | 604 TemplateURLData data; |
605 data.SetKeyword(keyword); | 605 data.SetKeyword(keyword); |
606 data.SetURL(s.ColumnString(2)); | 606 data.SetURL(s.ColumnString(2)); |
607 TemplateURL turl(NULL, data); | 607 TemplateURL turl(data); |
608 // Don't persist extension keywords to disk. These will get added to the | 608 // Don't persist extension keywords to disk. These will get added to the |
609 // TemplateURLService as the extensions are loaded. | 609 // TemplateURLService as the extensions are loaded. |
610 bool delete_entry = turl.GetType() == TemplateURL::OMNIBOX_API_EXTENSION; | 610 bool delete_entry = turl.GetType() == TemplateURL::OMNIBOX_API_EXTENSION; |
611 if (!delete_entry && generate_keyword) { | 611 if (!delete_entry && generate_keyword) { |
612 // Explicitly generate keywords for all rows with the autogenerate bit set | 612 // Explicitly generate keywords for all rows with the autogenerate bit set |
613 // or where the keyword is empty. | 613 // or where the keyword is empty. |
614 SearchTermsData terms_data; | 614 SearchTermsData terms_data; |
615 GURL url(TemplateURLService::GenerateSearchURLUsingTermsData(&turl, | 615 GURL url(TemplateURLService::GenerateSearchURL(&turl, terms_data)); |
616 terms_data)); | |
617 if (!url.is_valid()) { | 616 if (!url.is_valid()) { |
618 delete_entry = true; | 617 delete_entry = true; |
619 } else { | 618 } else { |
620 // Ensure autogenerated keywords are unique. | 619 // Ensure autogenerated keywords are unique. |
621 keyword = TemplateURLService::GenerateKeyword(url); | 620 keyword = TemplateURLService::GenerateKeyword(url); |
622 while (keywords.count(keyword)) | 621 while (keywords.count(keyword)) |
623 keyword.append(base::ASCIIToUTF16("_")); | 622 keyword.append(base::ASCIIToUTF16("_")); |
624 sql::Statement u(db_->GetUniqueStatement( | 623 sql::Statement u(db_->GetUniqueStatement( |
625 "UPDATE keywords_temp SET keyword=? WHERE id=?")); | 624 "UPDATE keywords_temp SET keyword=? WHERE id=?")); |
626 u.BindString16(0, keyword); | 625 u.BindString16(0, keyword); |
(...skipping 13 matching lines...) Expand all Loading... |
640 } | 639 } |
641 } | 640 } |
642 | 641 |
643 // Replace the old table with the new one. | 642 // Replace the old table with the new one. |
644 sql = "DROP TABLE " + name; | 643 sql = "DROP TABLE " + name; |
645 if (!db_->Execute(sql.c_str())) | 644 if (!db_->Execute(sql.c_str())) |
646 return false; | 645 return false; |
647 sql = "ALTER TABLE keywords_temp RENAME TO " + name; | 646 sql = "ALTER TABLE keywords_temp RENAME TO " + name; |
648 return db_->Execute(sql.c_str()); | 647 return db_->Execute(sql.c_str()); |
649 } | 648 } |
OLD | NEW |