Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(364)

Side by Side Diff: chrome/browser/webdata/keyword_table.cc

Issue 343823002: Move GenerateSearchURL() and GenerateKeyword() from TemplateURLService to TemplateURL (Closed) Base URL: http://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/search_engines/search_engine_tab_helper.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_split.h" 14 #include "base/strings/string_split.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "chrome/browser/history/history_database.h" 18 #include "chrome/browser/history/history_database.h"
19 #include "chrome/browser/search_engines/template_url.h" 19 #include "chrome/browser/search_engines/template_url.h"
20 #include "chrome/browser/search_engines/template_url_service.h"
21 #include "components/search_engines/search_terms_data.h" 20 #include "components/search_engines/search_terms_data.h"
22 #include "components/webdata/common/web_database.h" 21 #include "components/webdata/common/web_database.h"
23 #include "sql/statement.h" 22 #include "sql/statement.h"
24 #include "sql/transaction.h" 23 #include "sql/transaction.h"
25 #include "url/gurl.h" 24 #include "url/gurl.h"
26 25
27 using base::Time; 26 using base::Time;
28 27
29 // static 28 // static
30 const char KeywordTable::kDefaultSearchProviderKey[] = 29 const char KeywordTable::kDefaultSearchProviderKey[] =
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 data.SetKeyword(keyword); 604 data.SetKeyword(keyword);
606 data.SetURL(s.ColumnString(2)); 605 data.SetURL(s.ColumnString(2));
607 TemplateURL turl(data); 606 TemplateURL turl(data);
608 // Don't persist extension keywords to disk. These will get added to the 607 // Don't persist extension keywords to disk. These will get added to the
609 // TemplateURLService as the extensions are loaded. 608 // TemplateURLService as the extensions are loaded.
610 bool delete_entry = turl.GetType() == TemplateURL::OMNIBOX_API_EXTENSION; 609 bool delete_entry = turl.GetType() == TemplateURL::OMNIBOX_API_EXTENSION;
611 if (!delete_entry && generate_keyword) { 610 if (!delete_entry && generate_keyword) {
612 // Explicitly generate keywords for all rows with the autogenerate bit set 611 // Explicitly generate keywords for all rows with the autogenerate bit set
613 // or where the keyword is empty. 612 // or where the keyword is empty.
614 SearchTermsData terms_data; 613 SearchTermsData terms_data;
615 GURL url(TemplateURLService::GenerateSearchURL(&turl, terms_data)); 614 GURL url(turl.GenerateSearchURL(terms_data));
616 if (!url.is_valid()) { 615 if (!url.is_valid()) {
617 delete_entry = true; 616 delete_entry = true;
618 } else { 617 } else {
619 // Ensure autogenerated keywords are unique. 618 // Ensure autogenerated keywords are unique.
620 keyword = TemplateURLService::GenerateKeyword(url); 619 keyword = TemplateURL::GenerateKeyword(url);
621 while (keywords.count(keyword)) 620 while (keywords.count(keyword))
622 keyword.append(base::ASCIIToUTF16("_")); 621 keyword.append(base::ASCIIToUTF16("_"));
623 sql::Statement u(db_->GetUniqueStatement( 622 sql::Statement u(db_->GetUniqueStatement(
624 "UPDATE keywords_temp SET keyword=? WHERE id=?")); 623 "UPDATE keywords_temp SET keyword=? WHERE id=?"));
625 u.BindString16(0, keyword); 624 u.BindString16(0, keyword);
626 u.BindInt64(1, s.ColumnInt64(0)); 625 u.BindInt64(1, s.ColumnInt64(0));
627 if (!u.Run()) 626 if (!u.Run())
628 return false; 627 return false;
629 } 628 }
630 } 629 }
631 if (delete_entry) { 630 if (delete_entry) {
632 sql::Statement u(db_->GetUniqueStatement( 631 sql::Statement u(db_->GetUniqueStatement(
633 "DELETE FROM keywords_temp WHERE id=?")); 632 "DELETE FROM keywords_temp WHERE id=?"));
634 u.BindInt64(0, s.ColumnInt64(0)); 633 u.BindInt64(0, s.ColumnInt64(0));
635 if (!u.Run()) 634 if (!u.Run())
636 return false; 635 return false;
637 } else { 636 } else {
638 keywords.insert(keyword); 637 keywords.insert(keyword);
639 } 638 }
640 } 639 }
641 640
642 // Replace the old table with the new one. 641 // Replace the old table with the new one.
643 sql = "DROP TABLE " + name; 642 sql = "DROP TABLE " + name;
644 if (!db_->Execute(sql.c_str())) 643 if (!db_->Execute(sql.c_str()))
645 return false; 644 return false;
646 sql = "ALTER TABLE keywords_temp RENAME TO " + name; 645 sql = "ALTER TABLE keywords_temp RENAME TO " + name;
647 return db_->Execute(sql.c_str()); 646 return db_->Execute(sql.c_str());
648 } 647 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/search_engines/search_engine_tab_helper.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698