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

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

Issue 11552020: Add search_terms_replacement_key field to TemplateURL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Answered PK's comments. Created 8 years 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 | Annotate | Revision Log
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"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 columns.push_back("logo_id"); 57 columns.push_back("logo_id");
58 } 58 }
59 columns.push_back("created_by_policy"); 59 columns.push_back("created_by_policy");
60 columns.push_back("instant_url"); 60 columns.push_back("instant_url");
61 columns.push_back("last_modified"); 61 columns.push_back("last_modified");
62 columns.push_back("sync_guid"); 62 columns.push_back("sync_guid");
63 if (version >= 47) { 63 if (version >= 47) {
64 // Column added in version 47. 64 // Column added in version 47.
65 columns.push_back("alternate_urls"); 65 columns.push_back("alternate_urls");
66 } 66 }
67 if (version >= 49) {
68 // Column added in version 49.
69 columns.push_back("search_terms_replacement_key");
70 }
67 71
68 return JoinString(columns, std::string(concatenated ? " || " : ", ")); 72 return JoinString(columns, std::string(concatenated ? " || " : ", "));
69 } 73 }
70 74
71 75
72 // Inserts the data from |data| into |s|. |s| is assumed to have slots for all 76 // Inserts the data from |data| into |s|. |s| is assumed to have slots for all
73 // the columns in the keyword table. |id_column| is the slot number to bind 77 // the columns in the keyword table. |id_column| is the slot number to bind
74 // |data|'s |id| to; |starting_column| is the slot number of the first of a 78 // |data|'s |id| to; |starting_column| is the slot number of the first of a
75 // contiguous set of slots to bind all the other fields to. 79 // contiguous set of slots to bind all the other fields to.
76 void BindURLToStatement(const TemplateURLData& data, 80 void BindURLToStatement(const TemplateURLData& data,
(...skipping 25 matching lines...) Expand all
102 s->BindInt(starting_column + 7, data.usage_count); 106 s->BindInt(starting_column + 7, data.usage_count);
103 s->BindString(starting_column + 8, JoinString(data.input_encodings, ';')); 107 s->BindString(starting_column + 8, JoinString(data.input_encodings, ';'));
104 s->BindBool(starting_column + 9, data.show_in_default_list); 108 s->BindBool(starting_column + 9, data.show_in_default_list);
105 s->BindString(starting_column + 10, data.suggestions_url); 109 s->BindString(starting_column + 10, data.suggestions_url);
106 s->BindInt(starting_column + 11, data.prepopulate_id); 110 s->BindInt(starting_column + 11, data.prepopulate_id);
107 s->BindBool(starting_column + 12, data.created_by_policy); 111 s->BindBool(starting_column + 12, data.created_by_policy);
108 s->BindString(starting_column + 13, data.instant_url); 112 s->BindString(starting_column + 13, data.instant_url);
109 s->BindInt64(starting_column + 14, data.last_modified.ToTimeT()); 113 s->BindInt64(starting_column + 14, data.last_modified.ToTimeT());
110 s->BindString(starting_column + 15, data.sync_guid); 114 s->BindString(starting_column + 15, data.sync_guid);
111 s->BindString(starting_column + 16, alternate_urls); 115 s->BindString(starting_column + 16, alternate_urls);
116 s->BindString(starting_column + 17, data.search_terms_replacement_key);
112 } 117 }
113 118
114 } // anonymous namespace 119 } // anonymous namespace
115 120
116 KeywordTable::KeywordTable(sql::Connection* db, sql::MetaTable* meta_table) 121 KeywordTable::KeywordTable(sql::Connection* db, sql::MetaTable* meta_table)
117 : WebDatabaseTable(db, meta_table) { 122 : WebDatabaseTable(db, meta_table) {
118 } 123 }
119 124
120 KeywordTable::~KeywordTable() {} 125 KeywordTable::~KeywordTable() {}
121 126
(...skipping 10 matching lines...) Expand all
132 "date_created INTEGER DEFAULT 0," 137 "date_created INTEGER DEFAULT 0,"
133 "usage_count INTEGER DEFAULT 0," 138 "usage_count INTEGER DEFAULT 0,"
134 "input_encodings VARCHAR," 139 "input_encodings VARCHAR,"
135 "show_in_default_list INTEGER," 140 "show_in_default_list INTEGER,"
136 "suggest_url VARCHAR," 141 "suggest_url VARCHAR,"
137 "prepopulate_id INTEGER DEFAULT 0," 142 "prepopulate_id INTEGER DEFAULT 0,"
138 "created_by_policy INTEGER DEFAULT 0," 143 "created_by_policy INTEGER DEFAULT 0,"
139 "instant_url VARCHAR," 144 "instant_url VARCHAR,"
140 "last_modified INTEGER DEFAULT 0," 145 "last_modified INTEGER DEFAULT 0,"
141 "sync_guid VARCHAR," 146 "sync_guid VARCHAR,"
142 "alternate_urls VARCHAR)"); 147 "alternate_urls VARCHAR,"
148 "search_terms_replacement_key VARCHAR)");
143 } 149 }
144 150
145 bool KeywordTable::IsSyncable() { 151 bool KeywordTable::IsSyncable() {
146 return true; 152 return true;
147 } 153 }
148 154
149 bool KeywordTable::AddKeyword(const TemplateURLData& data) { 155 bool KeywordTable::AddKeyword(const TemplateURLData& data) {
150 DCHECK(data.id); 156 DCHECK(data.id);
151 std::string query("INSERT INTO keywords (" + GetKeywordColumns() + 157 std::string query("INSERT INTO keywords (" + GetKeywordColumns() +
152 ") VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); 158 ") VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
153 sql::Statement s(db_->GetUniqueStatement(query.c_str())); 159 sql::Statement s(db_->GetUniqueStatement(query.c_str()));
154 BindURLToStatement(data, &s, 0, 1); 160 BindURLToStatement(data, &s, 0, 1);
155 161
156 return s.Run(); 162 return s.Run();
157 } 163 }
158 164
159 bool KeywordTable::RemoveKeyword(TemplateURLID id) { 165 bool KeywordTable::RemoveKeyword(TemplateURLID id) {
160 DCHECK(id); 166 DCHECK(id);
161 sql::Statement s( 167 sql::Statement s(
162 db_->GetUniqueStatement("DELETE FROM keywords WHERE id = ?")); 168 db_->GetUniqueStatement("DELETE FROM keywords WHERE id = ?"));
(...skipping 22 matching lines...) Expand all
185 return succeeded; 191 return succeeded;
186 } 192 }
187 193
188 bool KeywordTable::UpdateKeyword(const TemplateURLData& data) { 194 bool KeywordTable::UpdateKeyword(const TemplateURLData& data) {
189 DCHECK(data.id); 195 DCHECK(data.id);
190 sql::Statement s(db_->GetUniqueStatement("UPDATE keywords SET short_name=?, " 196 sql::Statement s(db_->GetUniqueStatement("UPDATE keywords SET short_name=?, "
191 "keyword=?, favicon_url=?, url=?, safe_for_autoreplace=?, " 197 "keyword=?, favicon_url=?, url=?, safe_for_autoreplace=?, "
192 "originating_url=?, date_created=?, usage_count=?, input_encodings=?, " 198 "originating_url=?, date_created=?, usage_count=?, input_encodings=?, "
193 "show_in_default_list=?, suggest_url=?, prepopulate_id=?, " 199 "show_in_default_list=?, suggest_url=?, prepopulate_id=?, "
194 "created_by_policy=?, instant_url=?, last_modified=?, sync_guid=?, " 200 "created_by_policy=?, instant_url=?, last_modified=?, sync_guid=?, "
195 "alternate_urls=? WHERE id=?")); 201 "alternate_urls=?, search_terms_replacement_key=? WHERE id=?"));
196 BindURLToStatement(data, &s, 17, 0); // "17" binds id() as the last item. 202 BindURLToStatement(data, &s, 18, 0); // "18" binds id() as the last item.
197 203
198 return s.Run(); 204 return s.Run();
199 } 205 }
200 206
201 bool KeywordTable::SetDefaultSearchProviderID(int64 id) { 207 bool KeywordTable::SetDefaultSearchProviderID(int64 id) {
202 return meta_table_->SetValue(kDefaultSearchProviderKey, id); 208 return meta_table_->SetValue(kDefaultSearchProviderKey, id);
203 } 209 }
204 210
205 int64 KeywordTable::GetDefaultSearchProviderID() { 211 int64 KeywordTable::GetDefaultSearchProviderID() {
206 int64 value = kInvalidTemplateURLID; 212 int64 value = kInvalidTemplateURLID;
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 if (!meta_table_->DeleteKey("Default Search Provider ID Backup") || 364 if (!meta_table_->DeleteKey("Default Search Provider ID Backup") ||
359 !meta_table_->DeleteKey("Default Search Provider ID Backup Signature")) 365 !meta_table_->DeleteKey("Default Search Provider ID Backup Signature"))
360 return false; 366 return false;
361 367
362 if (!db_->Execute("DROP TABLE keywords_backup")) 368 if (!db_->Execute("DROP TABLE keywords_backup"))
363 return false; 369 return false;
364 370
365 return transaction.Commit(); 371 return transaction.Commit();
366 } 372 }
367 373
374 bool KeywordTable::MigrateToVersion49AddSearchTermsReplacementKeyColumn() {
375 sql::Transaction transaction(db_);
376
377 // Fill the |search_terms_replacement_key| column with empty strings;
378 // See comments in MigrateToVersion47AddAlternateURLsColumn().
379 if (!transaction.Begin() ||
380 !db_->Execute("ALTER TABLE keywords ADD COLUMN "
381 "search_terms_replacement_key VARCHAR DEFAULT ''"))
382 return false;
383
384 return transaction.Commit();
385 }
386
368 // static 387 // static
369 bool KeywordTable::GetKeywordDataFromStatement(const sql::Statement& s, 388 bool KeywordTable::GetKeywordDataFromStatement(const sql::Statement& s,
370 TemplateURLData* data) { 389 TemplateURLData* data) {
371 DCHECK(data); 390 DCHECK(data);
372 391
373 data->short_name = s.ColumnString16(1); 392 data->short_name = s.ColumnString16(1);
374 data->SetKeyword(s.ColumnString16(2)); 393 data->SetKeyword(s.ColumnString16(2));
375 // Due to past bugs, we might have persisted entries with empty URLs. Avoid 394 // Due to past bugs, we might have persisted entries with empty URLs. Avoid
376 // reading these out. (GetKeywords() will delete these entries on return.) 395 // reading these out. (GetKeywords() will delete these entries on return.)
377 // NOTE: This code should only be needed as long as we might be reading such 396 // NOTE: This code should only be needed as long as we might be reading such
(...skipping 21 matching lines...) Expand all
399 scoped_ptr<Value> value(json_reader.ReadToValue(s.ColumnString(17))); 418 scoped_ptr<Value> value(json_reader.ReadToValue(s.ColumnString(17)));
400 ListValue* alternate_urls_value; 419 ListValue* alternate_urls_value;
401 if (value.get() && value->GetAsList(&alternate_urls_value)) { 420 if (value.get() && value->GetAsList(&alternate_urls_value)) {
402 std::string alternate_url; 421 std::string alternate_url;
403 for (size_t i = 0; i < alternate_urls_value->GetSize(); ++i) { 422 for (size_t i = 0; i < alternate_urls_value->GetSize(); ++i) {
404 if (alternate_urls_value->GetString(i, &alternate_url)) 423 if (alternate_urls_value->GetString(i, &alternate_url))
405 data->alternate_urls.push_back(alternate_url); 424 data->alternate_urls.push_back(alternate_url);
406 } 425 }
407 } 426 }
408 427
428 data->search_terms_replacement_key = s.ColumnString(18);
429
409 return true; 430 return true;
410 } 431 }
411 432
412 bool KeywordTable::GetTableContents(const char* table_name, 433 bool KeywordTable::GetTableContents(const char* table_name,
413 int table_version, 434 int table_version,
414 std::string* contents) { 435 std::string* contents) {
415 DCHECK(contents); 436 DCHECK(contents);
416 437
417 if (!db_->DoesTableExist(table_name)) 438 if (!db_->DoesTableExist(table_name))
418 return false; 439 return false;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 } 548 }
528 } 549 }
529 550
530 // Replace the old table with the new one. 551 // Replace the old table with the new one.
531 sql = "DROP TABLE " + name; 552 sql = "DROP TABLE " + name;
532 if (!db_->Execute(sql.c_str())) 553 if (!db_->Execute(sql.c_str()))
533 return false; 554 return false;
534 sql = "ALTER TABLE keywords_temp RENAME TO " + name; 555 sql = "ALTER TABLE keywords_temp RENAME TO " + name;
535 return db_->Execute(sql.c_str()); 556 return db_->Execute(sql.c_str());
536 } 557 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698