Commit 62ef852f authored by ratsunny's avatar ratsunny Committed by Commit bot

Remove obsolete keywords table migrating function

Since the function KeywordTable::MigrateKeywordsTableForVersion45
is not used in codebase, it's safe to remove it.

R=pkasting@chromium.org
BUG=665018

Review-Url: https://codereview.chromium.org/2542933002
Cr-Commit-Position: refs/heads/master@{#436188}
parent 0f77a4ef
......@@ -460,87 +460,3 @@ bool KeywordTable::GetKeywordAsString(TemplateURLID id,
*result = s.ColumnString(0);
return true;
}
bool KeywordTable::MigrateKeywordsTableForVersion45(const std::string& name) {
// Create a new table without the columns we're dropping.
if (!db_->Execute("CREATE TABLE keywords_temp ("
"id INTEGER PRIMARY KEY,"
"short_name VARCHAR NOT NULL,"
"keyword VARCHAR NOT NULL,"
"favicon_url VARCHAR NOT NULL,"
"url VARCHAR NOT NULL,"
"safe_for_autoreplace INTEGER,"
"originating_url VARCHAR,"
"date_created INTEGER DEFAULT 0,"
"usage_count INTEGER DEFAULT 0,"
"input_encodings VARCHAR,"
"show_in_default_list INTEGER,"
"suggest_url VARCHAR,"
"prepopulate_id INTEGER DEFAULT 0,"
"created_by_policy INTEGER DEFAULT 0,"
"instant_url VARCHAR,"
"last_modified INTEGER DEFAULT 0,"
"sync_guid VARCHAR)"))
return false;
std::string sql("INSERT INTO keywords_temp SELECT " +
ColumnsForVersion(46, false) + " FROM " + name);
if (!db_->Execute(sql.c_str()))
return false;
// NOTE: The ORDER BY here ensures that the uniquing process for keywords will
// happen identically on both the normal and backup tables.
sql = "SELECT id, keyword, url, autogenerate_keyword FROM " + name +
" ORDER BY id ASC";
sql::Statement s(db_->GetUniqueStatement(sql.c_str()));
base::string16 placeholder_keyword(base::ASCIIToUTF16("dummy"));
std::set<base::string16> keywords;
while (s.Step()) {
base::string16 keyword(s.ColumnString16(1));
bool generate_keyword = keyword.empty() || s.ColumnBool(3);
if (generate_keyword)
keyword = placeholder_keyword;
TemplateURLData data;
data.SetKeyword(keyword);
data.SetURL(s.ColumnString(2));
TemplateURL turl(data);
// Don't persist extension keywords to disk. These will get added to the
// TemplateURLService as the extensions are loaded.
bool delete_entry = turl.type() == TemplateURL::OMNIBOX_API_EXTENSION;
if (!delete_entry && generate_keyword) {
// Explicitly generate keywords for all rows with the autogenerate bit set
// or where the keyword is empty.
SearchTermsData terms_data;
GURL url(turl.GenerateSearchURL(terms_data));
if (!url.is_valid()) {
delete_entry = true;
} else {
// Ensure autogenerated keywords are unique.
keyword = TemplateURL::GenerateKeyword(url);
while (keywords.count(keyword))
keyword.append(base::ASCIIToUTF16("_"));
sql::Statement u(db_->GetUniqueStatement(
"UPDATE keywords_temp SET keyword=? WHERE id=?"));
u.BindString16(0, keyword);
u.BindInt64(1, s.ColumnInt64(0));
if (!u.Run())
return false;
}
}
if (delete_entry) {
sql::Statement u(db_->GetUniqueStatement(
"DELETE FROM keywords_temp WHERE id=?"));
u.BindInt64(0, s.ColumnInt64(0));
if (!u.Run())
return false;
} else {
keywords.insert(keyword);
}
}
// Replace the old table with the new one.
sql = "DROP TABLE " + name;
if (!db_->Execute(sql.c_str()))
return false;
sql = "ALTER TABLE keywords_temp RENAME TO " + name;
return db_->Execute(sql.c_str());
}
......@@ -166,10 +166,6 @@ class KeywordTable : public WebDatabaseTable {
const std::string& table_name,
std::string* result);
// Migrates table |name| (which should be either "keywords" or
// "keywords_backup") from version 44 to version 45.
bool MigrateKeywordsTableForVersion45(const std::string& name);
DISALLOW_COPY_AND_ASSIGN(KeywordTable);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment