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

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

Issue 2542933002: Remove obsolete keywords table migrating function (Closed)
Patch Set: Created 4 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
« no previous file with comments | « components/search_engines/keyword_table.h ('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 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 << ", ignoring."; 439 << ", ignoring.";
440 return true; 440 return true;
441 } 441 }
442 442
443 if (!s.Succeeded()) 443 if (!s.Succeeded())
444 return false; 444 return false;
445 445
446 *result = s.ColumnString(0); 446 *result = s.ColumnString(0);
447 return true; 447 return true;
448 } 448 }
449
450 bool KeywordTable::MigrateKeywordsTableForVersion45(const std::string& name) {
451 // Create a new table without the columns we're dropping.
452 if (!db_->Execute("CREATE TABLE keywords_temp ("
453 "id INTEGER PRIMARY KEY,"
454 "short_name VARCHAR NOT NULL,"
455 "keyword VARCHAR NOT NULL,"
456 "favicon_url VARCHAR NOT NULL,"
457 "url VARCHAR NOT NULL,"
458 "safe_for_autoreplace INTEGER,"
459 "originating_url VARCHAR,"
460 "date_created INTEGER DEFAULT 0,"
461 "usage_count INTEGER DEFAULT 0,"
462 "input_encodings VARCHAR,"
463 "show_in_default_list INTEGER,"
464 "suggest_url VARCHAR,"
465 "prepopulate_id INTEGER DEFAULT 0,"
466 "created_by_policy INTEGER DEFAULT 0,"
467 "instant_url VARCHAR,"
468 "last_modified INTEGER DEFAULT 0,"
469 "sync_guid VARCHAR)"))
470 return false;
471 std::string sql("INSERT INTO keywords_temp SELECT " +
472 ColumnsForVersion(46, false) + " FROM " + name);
473 if (!db_->Execute(sql.c_str()))
474 return false;
475
476 // NOTE: The ORDER BY here ensures that the uniquing process for keywords will
477 // happen identically on both the normal and backup tables.
478 sql = "SELECT id, keyword, url, autogenerate_keyword FROM " + name +
479 " ORDER BY id ASC";
480 sql::Statement s(db_->GetUniqueStatement(sql.c_str()));
481 base::string16 placeholder_keyword(base::ASCIIToUTF16("dummy"));
482 std::set<base::string16> keywords;
483 while (s.Step()) {
484 base::string16 keyword(s.ColumnString16(1));
485 bool generate_keyword = keyword.empty() || s.ColumnBool(3);
486 if (generate_keyword)
487 keyword = placeholder_keyword;
488 TemplateURLData data;
489 data.SetKeyword(keyword);
490 data.SetURL(s.ColumnString(2));
491 TemplateURL turl(data);
492 // Don't persist extension keywords to disk. These will get added to the
493 // TemplateURLService as the extensions are loaded.
494 bool delete_entry = turl.type() == TemplateURL::OMNIBOX_API_EXTENSION;
495 if (!delete_entry && generate_keyword) {
496 // Explicitly generate keywords for all rows with the autogenerate bit set
497 // or where the keyword is empty.
498 SearchTermsData terms_data;
499 GURL url(turl.GenerateSearchURL(terms_data));
500 if (!url.is_valid()) {
501 delete_entry = true;
502 } else {
503 // Ensure autogenerated keywords are unique.
504 keyword = TemplateURL::GenerateKeyword(url);
505 while (keywords.count(keyword))
506 keyword.append(base::ASCIIToUTF16("_"));
507 sql::Statement u(db_->GetUniqueStatement(
508 "UPDATE keywords_temp SET keyword=? WHERE id=?"));
509 u.BindString16(0, keyword);
510 u.BindInt64(1, s.ColumnInt64(0));
511 if (!u.Run())
512 return false;
513 }
514 }
515 if (delete_entry) {
516 sql::Statement u(db_->GetUniqueStatement(
517 "DELETE FROM keywords_temp WHERE id=?"));
518 u.BindInt64(0, s.ColumnInt64(0));
519 if (!u.Run())
520 return false;
521 } else {
522 keywords.insert(keyword);
523 }
524 }
525
526 // Replace the old table with the new one.
527 sql = "DROP TABLE " + name;
528 if (!db_->Execute(sql.c_str()))
529 return false;
530 sql = "ALTER TABLE keywords_temp RENAME TO " + name;
531 return db_->Execute(sql.c_str());
532 }
OLDNEW
« no previous file with comments | « components/search_engines/keyword_table.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698