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

Side by Side Diff: components/search_engines/keyword_table.cc

Issue 1135163002: Omnibox - Strip Extra Whitespace from Custom Search Engine Names (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix more tests that don't set short_name Created 5 years, 7 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/search_engines/keyword_table.h" 5 #include "components/search_engines/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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 // TODO(beaudoin): Check what it would take to use a new table to store 96 // TODO(beaudoin): Check what it would take to use a new table to store
97 // alternate_urls while keeping backups and table signature in a good state. 97 // alternate_urls while keeping backups and table signature in a good state.
98 // See: crbug.com/153520 98 // See: crbug.com/153520
99 base::ListValue alternate_urls_value; 99 base::ListValue alternate_urls_value;
100 for (size_t i = 0; i < data.alternate_urls.size(); ++i) 100 for (size_t i = 0; i < data.alternate_urls.size(); ++i)
101 alternate_urls_value.AppendString(data.alternate_urls[i]); 101 alternate_urls_value.AppendString(data.alternate_urls[i]);
102 std::string alternate_urls; 102 std::string alternate_urls;
103 base::JSONWriter::Write(&alternate_urls_value, &alternate_urls); 103 base::JSONWriter::Write(&alternate_urls_value, &alternate_urls);
104 104
105 s->BindInt64(id_column, data.id); 105 s->BindInt64(id_column, data.id);
106 s->BindString16(starting_column, data.short_name); 106 s->BindString16(starting_column, data.short_name());
107 s->BindString16(starting_column + 1, data.keyword()); 107 s->BindString16(starting_column + 1, data.keyword());
108 s->BindString(starting_column + 2, data.favicon_url.is_valid() ? 108 s->BindString(starting_column + 2, data.favicon_url.is_valid() ?
109 history::URLDatabase::GURLToDatabaseURL(data.favicon_url) : 109 history::URLDatabase::GURLToDatabaseURL(data.favicon_url) :
110 std::string()); 110 std::string());
111 s->BindString(starting_column + 3, data.url()); 111 s->BindString(starting_column + 3, data.url());
112 s->BindBool(starting_column + 4, data.safe_for_autoreplace); 112 s->BindBool(starting_column + 4, data.safe_for_autoreplace);
113 s->BindString(starting_column + 5, data.originating_url.is_valid() ? 113 s->BindString(starting_column + 5, data.originating_url.is_valid() ?
114 history::URLDatabase::GURLToDatabaseURL(data.originating_url) : 114 history::URLDatabase::GURLToDatabaseURL(data.originating_url) :
115 std::string()); 115 std::string());
116 s->BindInt64(starting_column + 6, data.date_created.ToTimeT()); 116 s->BindInt64(starting_column + 6, data.date_created.ToTimeT());
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 bool KeywordTable::MigrateToVersion59RemoveExtensionKeywords() { 284 bool KeywordTable::MigrateToVersion59RemoveExtensionKeywords() {
285 return db_->Execute("DELETE FROM keywords " 285 return db_->Execute("DELETE FROM keywords "
286 "WHERE url LIKE 'chrome-extension://%'"); 286 "WHERE url LIKE 'chrome-extension://%'");
287 } 287 }
288 288
289 // static 289 // static
290 bool KeywordTable::GetKeywordDataFromStatement(const sql::Statement& s, 290 bool KeywordTable::GetKeywordDataFromStatement(const sql::Statement& s,
291 TemplateURLData* data) { 291 TemplateURLData* data) {
292 DCHECK(data); 292 DCHECK(data);
293 293
294 data->short_name = s.ColumnString16(1); 294 data->SetShortName(s.ColumnString16(1));
295 data->SetKeyword(s.ColumnString16(2)); 295 data->SetKeyword(s.ColumnString16(2));
296 // Due to past bugs, we might have persisted entries with empty URLs. Avoid 296 // Due to past bugs, we might have persisted entries with empty URLs. Avoid
297 // reading these out. (GetKeywords() will delete these entries on return.) 297 // reading these out. (GetKeywords() will delete these entries on return.)
298 // NOTE: This code should only be needed as long as we might be reading such 298 // NOTE: This code should only be needed as long as we might be reading such
299 // potentially-old data and can be removed afterward. 299 // potentially-old data and can be removed afterward.
300 if (s.ColumnString(4).empty()) 300 if (s.ColumnString(4).empty())
301 return false; 301 return false;
302 data->SetURL(s.ColumnString(4)); 302 data->SetURL(s.ColumnString(4));
303 data->suggestions_url = s.ColumnString(11); 303 data->suggestions_url = s.ColumnString(11);
304 data->instant_url = s.ColumnString(14); 304 data->instant_url = s.ColumnString(14);
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 } 473 }
474 } 474 }
475 475
476 // Replace the old table with the new one. 476 // Replace the old table with the new one.
477 sql = "DROP TABLE " + name; 477 sql = "DROP TABLE " + name;
478 if (!db_->Execute(sql.c_str())) 478 if (!db_->Execute(sql.c_str()))
479 return false; 479 return false;
480 sql = "ALTER TABLE keywords_temp RENAME TO " + name; 480 sql = "ALTER TABLE keywords_temp RENAME TO " + name;
481 return db_->Execute(sql.c_str()); 481 return db_->Execute(sql.c_str());
482 } 482 }
OLDNEW
« no previous file with comments | « components/search_engines/default_search_manager_unittest.cc ('k') | components/search_engines/keyword_table_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698