| Index: chrome/browser/webdata/keyword_table.cc
|
| diff --git a/chrome/browser/webdata/keyword_table.cc b/chrome/browser/webdata/keyword_table.cc
|
| index 47d485216639f33faed44c592da86976e42e90d5..65febe6c314fe3bf247c3f728bdf8544aa42dea8 100644
|
| --- a/chrome/browser/webdata/keyword_table.cc
|
| +++ b/chrome/browser/webdata/keyword_table.cc
|
| @@ -38,7 +38,8 @@ const char KeywordTable::kBackupSignatureKey[] =
|
| const char KeywordTable::kKeywordColumns[] = "id, short_name, keyword, "
|
| "favicon_url, url, safe_for_autoreplace, originating_url, date_created, "
|
| "usage_count, input_encodings, show_in_default_list, suggest_url, "
|
| - "prepopulate_id, created_by_policy, instant_url, last_modified, sync_guid";
|
| + "prepopulate_id, created_by_policy, instant_url, last_modified, sync_guid, "
|
| + "alternate_urls";
|
|
|
| namespace {
|
|
|
| @@ -58,17 +59,24 @@ const char kKeywordColumnsVersion44[] = "id, short_name, keyword, favicon_url, "
|
| "input_encodings, show_in_default_list, suggest_url, prepopulate_id, "
|
| "autogenerate_keyword, logo_id, created_by_policy, instant_url, "
|
| "last_modified, sync_guid";
|
| -// NOTE: Remember to change what |kKeywordColumnsVersion45| says if the column
|
| -// set in |kKeywordColumns| changes, and update any code that needs to switch
|
| -// column sets based on a version number!
|
| -const char* const kKeywordColumnsVersion45 = KeywordTable::kKeywordColumns;
|
| +// The set of columns from version 45 through version 46 (inclusively).
|
| +const char kKeywordColumnsVersion46Concatenated[] = "id || short_name || "
|
| + "keyword || favicon_url || url || safe_for_autoreplace || "
|
| + "originating_url || date_created || usage_count || input_encodings || "
|
| + "show_in_default_list || suggest_url || prepopulate_id || "
|
| + "created_by_policy || instant_url || last_modified || sync_guid";
|
| +const char kKeywordColumnsVersion46[] = "id, short_name, keyword, "
|
| + "favicon_url, url, safe_for_autoreplace, originating_url, date_created, "
|
| + "usage_count, input_encodings, show_in_default_list, suggest_url, "
|
| + "prepopulate_id, created_by_policy, instant_url, last_modified, sync_guid";
|
|
|
| // The current columns.
|
| -const char kKeywordColumnsConcatenated[] = "id || short_name || keyword || "
|
| - "favicon_url || url || safe_for_autoreplace || originating_url || "
|
| - "date_created || usage_count || input_encodings || show_in_default_list || "
|
| - "suggest_url || prepopulate_id || created_by_policy || instant_url || "
|
| - "last_modified || sync_guid";
|
| +const char kKeywordColumnsConcatenated[] = "id || short_name || "
|
| + "keyword || favicon_url || url || safe_for_autoreplace || "
|
| + "originating_url || date_created || usage_count || input_encodings || "
|
| + "show_in_default_list || suggest_url || prepopulate_id || "
|
| + "created_by_policy || instant_url || last_modified || sync_guid || "
|
| + "alternate_urls";
|
|
|
| // Inserts the data from |data| into |s|. |s| is assumed to have slots for all
|
| // the columns in the keyword table. |id_column| is the slot number to bind
|
| @@ -99,6 +107,7 @@ void BindURLToStatement(const TemplateURLData& data,
|
| s->BindString(starting_column + 13, data.instant_url);
|
| s->BindInt64(starting_column + 14, data.last_modified.ToTimeT());
|
| s->BindString(starting_column + 15, data.sync_guid);
|
| + s->BindString(starting_column + 16, data.SerializeAlternateURLs());
|
| }
|
|
|
| // Signs search provider id and returns its signature.
|
| @@ -140,7 +149,8 @@ bool KeywordTable::Init() {
|
| "created_by_policy INTEGER DEFAULT 0,"
|
| "instant_url VARCHAR,"
|
| "last_modified INTEGER DEFAULT 0,"
|
| - "sync_guid VARCHAR)") &&
|
| + "sync_guid VARCHAR,"
|
| + "alternate_urls VARCHAR)") &&
|
| UpdateBackupSignature(WebDatabase::kCurrentVersionNumber));
|
| }
|
|
|
| @@ -151,7 +161,7 @@ bool KeywordTable::IsSyncable() {
|
| bool KeywordTable::AddKeyword(const TemplateURLData& data) {
|
| DCHECK(data.id);
|
| std::string query("INSERT INTO keywords (" + std::string(kKeywordColumns) +
|
| - ") VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
|
| + ") VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
|
| sql::Statement s(db_->GetUniqueStatement(query.c_str()));
|
| BindURLToStatement(data, &s, 0, 1);
|
|
|
| @@ -193,9 +203,9 @@ bool KeywordTable::UpdateKeyword(const TemplateURLData& data) {
|
| "keyword=?, favicon_url=?, url=?, safe_for_autoreplace=?, "
|
| "originating_url=?, date_created=?, usage_count=?, input_encodings=?, "
|
| "show_in_default_list=?, suggest_url=?, prepopulate_id=?, "
|
| - "created_by_policy=?, instant_url=?, last_modified=?, sync_guid=? WHERE "
|
| - "id=?"));
|
| - BindURLToStatement(data, &s, 16, 0); // "16" binds id() as the last item.
|
| + "created_by_policy=?, instant_url=?, last_modified=?, sync_guid=?, "
|
| + "alternate_urls=? WHERE id=?"));
|
| + BindURLToStatement(data, &s, 17, 0); // "17" binds id() as the last item.
|
|
|
| return s.Run() && UpdateBackupSignature(WebDatabase::kCurrentVersionNumber);
|
| }
|
| @@ -397,6 +407,26 @@ bool KeywordTable::MigrateToVersion45RemoveLogoIDAndAutogenerateColumns() {
|
| return transaction.Commit();
|
| }
|
|
|
| +bool KeywordTable::MigrateToVersion47AddAlternateUrlsColumn() {
|
| + sql::Transaction transaction(db_);
|
| +
|
| + // Fill the |alternate_urls| column with empty strings, otherwise it breaks
|
| + // code relying on |kKeywordColumnsConcatenated|.
|
| + if (!transaction.Begin() ||
|
| + !db_->Execute("ALTER TABLE keywords ADD COLUMN "
|
| + "alternate_urls VARCHAR DEFAULT ''"))
|
| + return false;
|
| +
|
| + if (db_->DoesTableExist("keywords_backup")) {
|
| + if (!db_->Execute("ALTER TABLE keywords_backup ADD COLUMN "
|
| + "alternate_urls VARCHAR DEFAULT ''") ||
|
| + !SignBackup(47))
|
| + return false;
|
| + }
|
| +
|
| + return transaction.Commit();
|
| +}
|
| +
|
| // static
|
| bool KeywordTable::GetKeywordDataFromStatement(const sql::Statement& s,
|
| TemplateURLData* data) {
|
| @@ -424,6 +454,7 @@ bool KeywordTable::GetKeywordDataFromStatement(const sql::Statement& s,
|
| data->usage_count = s.ColumnInt(8);
|
| data->prepopulate_id = s.ColumnInt(12);
|
| data->sync_guid = s.ColumnString(16);
|
| + data->DeserializeAndSetAlternateURLs(s.ColumnString(17));
|
| return true;
|
| }
|
|
|
| @@ -455,9 +486,12 @@ bool KeywordTable::GetTableContents(const char* table_name,
|
| return false;
|
|
|
| contents->clear();
|
| - std::string query("SELECT " +
|
| - std::string((table_version <= 44) ?
|
| - kKeywordColumnsVersion44Concatenated : kKeywordColumnsConcatenated) +
|
| + const char* keywords_columns_concatenated = kKeywordColumnsConcatenated;
|
| + if (table_version <= 44)
|
| + keywords_columns_concatenated = kKeywordColumnsVersion44Concatenated;
|
| + else if (table_version <= 46)
|
| + keywords_columns_concatenated = kKeywordColumnsVersion46Concatenated;
|
| + std::string query("SELECT " + std::string(keywords_columns_concatenated) +
|
| " FROM " + std::string(table_name) + " ORDER BY id ASC");
|
| sql::Statement s((table_version == WebDatabase::kCurrentVersionNumber) ?
|
| db_->GetCachedStatement(sql::StatementID(table_name), query.c_str()) :
|
| @@ -483,10 +517,13 @@ bool KeywordTable::UpdateBackupSignature(int table_version) {
|
| !db_->Execute("DROP TABLE keywords_backup"))
|
| return false;
|
|
|
| + const char* keywords_columns = kKeywordColumns;
|
| + if (table_version <= 44)
|
| + keywords_columns = kKeywordColumnsVersion44;
|
| + else if (table_version <= 46)
|
| + keywords_columns = kKeywordColumnsVersion46;
|
| std::string query("CREATE TABLE keywords_backup AS SELECT " +
|
| - std::string((table_version <= 44) ?
|
| - kKeywordColumnsVersion44 : kKeywordColumns) +
|
| - " FROM keywords ORDER BY id ASC");
|
| + std::string(keywords_columns) + " FROM keywords ORDER BY id ASC");
|
| if (!db_->Execute(query.c_str())) {
|
| LOG(ERROR) << "Failed to create keywords_backup table.";
|
| return false;
|
| @@ -575,7 +612,7 @@ bool KeywordTable::MigrateKeywordsTableForVersion45(const std::string& name) {
|
| "sync_guid VARCHAR)"))
|
| return false;
|
| std::string sql("INSERT INTO keywords_temp SELECT " +
|
| - std::string(kKeywordColumnsVersion45) + " FROM " + name);
|
| + std::string(kKeywordColumnsVersion46) + " FROM " + name);
|
| if (!db_->Execute(sql.c_str()))
|
| return false;
|
|
|
|
|