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

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

Issue 3239006: Fix credit card table migration step. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/webdata/web_database.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 (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/web_database.h" 5 #include "chrome/browser/webdata/web_database.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 439
440 // Version check. 440 // Version check.
441 if (!meta_table_.Init(&db_, kCurrentVersionNumber, kCompatibleVersionNumber)) 441 if (!meta_table_.Init(&db_, kCurrentVersionNumber, kCompatibleVersionNumber))
442 return sql::INIT_FAILURE; 442 return sql::INIT_FAILURE;
443 if (meta_table_.GetCompatibleVersionNumber() > kCurrentVersionNumber) { 443 if (meta_table_.GetCompatibleVersionNumber() > kCurrentVersionNumber) {
444 LOG(WARNING) << "Web database is too new."; 444 LOG(WARNING) << "Web database is too new.";
445 return sql::INIT_TOO_NEW; 445 return sql::INIT_TOO_NEW;
446 } 446 }
447 447
448 // Initialize the tables. 448 // Initialize the tables.
449 bool credit_card_table_created = false;
449 if (!InitKeywordsTable() || !InitLoginsTable() || !InitWebAppIconsTable() || 450 if (!InitKeywordsTable() || !InitLoginsTable() || !InitWebAppIconsTable() ||
450 !InitWebAppsTable() || !InitAutofillTable() || 451 !InitWebAppsTable() || !InitAutofillTable() ||
451 !InitAutofillDatesTable() || !InitAutoFillProfilesTable() || 452 !InitAutofillDatesTable() || !InitAutoFillProfilesTable() ||
452 !InitCreditCardsTable() || !InitTokenServiceTable()) { 453 !InitCreditCardsTable(&credit_card_table_created) ||
454 !InitTokenServiceTable()) {
453 LOG(WARNING) << "Unable to initialize the web database."; 455 LOG(WARNING) << "Unable to initialize the web database.";
454 return sql::INIT_FAILURE; 456 return sql::INIT_FAILURE;
455 } 457 }
456 458
457 // If the file on disk is an older database version, bring it up to date. 459 // If the file on disk is an older database version, bring it up to date.
458 MigrateOldVersionsAsNeeded(); 460 MigrateOldVersionsAsNeeded(credit_card_table_created);
459 461
460 return transaction.Commit() ? sql::INIT_OK : sql::INIT_FAILURE; 462 return transaction.Commit() ? sql::INIT_OK : sql::INIT_FAILURE;
461 } 463 }
462 464
463 bool WebDatabase::SetWebAppImage(const GURL& url, const SkBitmap& image) { 465 bool WebDatabase::SetWebAppImage(const GURL& url, const SkBitmap& image) {
464 // Don't bother with a cached statement since this will be a relatively 466 // Don't bother with a cached statement since this will be a relatively
465 // infrequent operation. 467 // infrequent operation.
466 sql::Statement s(db_.GetUniqueStatement( 468 sql::Statement s(db_.GetUniqueStatement(
467 "INSERT OR REPLACE INTO web_app_icons " 469 "INSERT OR REPLACE INTO web_app_icons "
468 "(url, width, height, image) VALUES (?, ?, ?, ?)")); 470 "(url, width, height, image) VALUES (?, ?, ?, ?)"));
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 } 754 }
753 if (!db_.Execute("CREATE INDEX autofill_profiles_label_index " 755 if (!db_.Execute("CREATE INDEX autofill_profiles_label_index "
754 "ON autofill_profiles (label)")) { 756 "ON autofill_profiles (label)")) {
755 NOTREACHED(); 757 NOTREACHED();
756 return false; 758 return false;
757 } 759 }
758 } 760 }
759 return true; 761 return true;
760 } 762 }
761 763
762 bool WebDatabase::InitCreditCardsTable() { 764 bool WebDatabase::InitCreditCardsTable(bool* table_was_created) {
763 if (!db_.DoesTableExist("credit_cards")) { 765 if (!db_.DoesTableExist("credit_cards")) {
764 if (!db_.Execute("CREATE TABLE credit_cards ( " 766 if (!db_.Execute("CREATE TABLE credit_cards ( "
765 "label VARCHAR, " 767 "label VARCHAR, "
766 "unique_id INTEGER PRIMARY KEY, " 768 "unique_id INTEGER PRIMARY KEY, "
767 "name_on_card VARCHAR, " 769 "name_on_card VARCHAR, "
768 "type VARCHAR, " 770 "type VARCHAR, "
769 "card_number VARCHAR, " 771 "card_number VARCHAR, "
770 "expiration_month INTEGER, " 772 "expiration_month INTEGER, "
771 "expiration_year INTEGER, " 773 "expiration_year INTEGER, "
772 "verification_code VARCHAR, " 774 "verification_code VARCHAR, "
773 "billing_address VARCHAR, " 775 "billing_address VARCHAR, "
774 "shipping_address VARCHAR, " 776 "shipping_address VARCHAR, "
775 "card_number_encrypted BLOB, " 777 "card_number_encrypted BLOB, "
776 "verification_code_encrypted BLOB)")) { 778 "verification_code_encrypted BLOB)")) {
777 NOTREACHED(); 779 NOTREACHED();
778 return false; 780 return false;
779 } 781 }
782 *table_was_created = true;
780 if (!db_.Execute("CREATE INDEX credit_cards_label_index " 783 if (!db_.Execute("CREATE INDEX credit_cards_label_index "
781 "ON credit_cards (label)")) { 784 "ON credit_cards (label)")) {
782 NOTREACHED(); 785 NOTREACHED();
783 return false; 786 return false;
784 } 787 }
785 } 788 }
786 return true; 789 return true;
787 } 790 }
788 791
789 bool WebDatabase::InitWebAppIconsTable() { 792 bool WebDatabase::InitWebAppIconsTable() {
(...skipping 1073 matching lines...) Expand 10 before | Expand all | Expand 10 after
1863 return false; 1866 return false;
1864 } 1867 }
1865 s.BindInt64(0, pair_id); 1868 s.BindInt64(0, pair_id);
1866 if (s.Run()) { 1869 if (s.Run()) {
1867 return RemoveFormElementForTimeRange(pair_id, base::Time(), base::Time(), 1870 return RemoveFormElementForTimeRange(pair_id, base::Time(), base::Time(),
1868 NULL); 1871 NULL);
1869 } 1872 }
1870 return false; 1873 return false;
1871 } 1874 }
1872 1875
1873 void WebDatabase::MigrateOldVersionsAsNeeded() { 1876 void WebDatabase::MigrateOldVersionsAsNeeded(bool credit_card_table_created) {
1874 // Migrate if necessary. 1877 // Migrate if necessary.
1875 int current_version = meta_table_.GetVersionNumber(); 1878 int current_version = meta_table_.GetVersionNumber();
1876 switch (current_version) { 1879 switch (current_version) {
1877 // Versions 1 - 19 are unhandled. Version numbers greater than 1880 // Versions 1 - 19 are unhandled. Version numbers greater than
1878 // kCurrentVersionNumber should have already been weeded out by the caller. 1881 // kCurrentVersionNumber should have already been weeded out by the caller.
1879 default: 1882 default:
1880 // When the version is too old, we just try to continue anyway. There 1883 // When the version is too old, we just try to continue anyway. There
1881 // should not be a released product that makes a database too old for us 1884 // should not be a released product that makes a database too old for us
1882 // to handle. 1885 // to handle.
1883 LOG(WARNING) << "Web database version " << current_version << 1886 LOG(WARNING) << "Web database version " << current_version <<
(...skipping 16 matching lines...) Expand all
1900 case 21: 1903 case 21:
1901 if (!ClearAutofillEmptyValueElements()) { 1904 if (!ClearAutofillEmptyValueElements()) {
1902 NOTREACHED() << "Failed to clean-up autofill DB."; 1905 NOTREACHED() << "Failed to clean-up autofill DB.";
1903 } 1906 }
1904 meta_table_.SetVersionNumber(22); 1907 meta_table_.SetVersionNumber(22);
1905 // No change in the compatibility version number. 1908 // No change in the compatibility version number.
1906 1909
1907 // FALL THROUGH 1910 // FALL THROUGH
1908 1911
1909 case 22: 1912 case 22:
1910 // Add the card_number_encrypted column. 1913 // Add the card_number_encrypted column if credit card table was not
1911 if (!db_.Execute("ALTER TABLE credit_cards ADD COLUMN " 1914 // created in this build.
1912 "card_number_encrypted BLOB DEFAULT NULL")) { 1915 if (!credit_card_table_created) {
1913 NOTREACHED(); 1916 if (!db_.Execute("ALTER TABLE credit_cards ADD COLUMN "
1914 LOG(WARNING) << "Unable to update web database to version 23."; 1917 "card_number_encrypted BLOB DEFAULT NULL")) {
1915 return; 1918 NOTREACHED();
1916 } 1919 LOG(WARNING) << "Unable to update web database to version 23.";
1917 if (!db_.Execute("ALTER TABLE credit_cards ADD COLUMN " 1920 return;
1918 "verification_code_encrypted BLOB DEFAULT NULL")) { 1921 }
1919 NOTREACHED(); 1922 if (!db_.Execute("ALTER TABLE credit_cards ADD COLUMN "
1920 LOG(WARNING) << "Unable to update web database to version 23."; 1923 "verification_code_encrypted BLOB DEFAULT NULL")) {
1921 return; 1924 NOTREACHED();
1925 LOG(WARNING) << "Unable to update web database to version 23.";
1926 return;
1927 }
1922 } 1928 }
1923 meta_table_.SetVersionNumber(23); 1929 meta_table_.SetVersionNumber(23);
1924 1930
1925 // FALL THROUGH 1931 // FALL THROUGH
1926 1932
1927 case 23: { 1933 case 23: {
1928 // One-time cleanup for Chromium bug 38364. In the presence of 1934 // One-time cleanup for Chromium bug 38364. In the presence of
1929 // multi-byte UTF-8 characters, that bug could cause AutoFill strings 1935 // multi-byte UTF-8 characters, that bug could cause AutoFill strings
1930 // to grow larger and more corrupt with each save. The cleanup removes 1936 // to grow larger and more corrupt with each save. The cleanup removes
1931 // any row with a string field larger than a reasonable size. The string 1937 // any row with a string field larger than a reasonable size. The string
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1997 2003
1998 // Add successive versions here. Each should set the version number and 2004 // Add successive versions here. Each should set the version number and
1999 // compatible version number as appropriate, then fall through to the next 2005 // compatible version number as appropriate, then fall through to the next
2000 // case. 2006 // case.
2001 2007
2002 case kCurrentVersionNumber: 2008 case kCurrentVersionNumber:
2003 // No migration needed. 2009 // No migration needed.
2004 return; 2010 return;
2005 } 2011 }
2006 } 2012 }
OLDNEW
« no previous file with comments | « chrome/browser/webdata/web_database.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698