Chromium Code Reviews| Index: components/autofill/core/browser/webdata/autofill_table.cc |
| diff --git a/components/autofill/core/browser/webdata/autofill_table.cc b/components/autofill/core/browser/webdata/autofill_table.cc |
| index ce7cebe3908b9a7bfec8ce9444e0588a0c05a768..cdf5afb4459a8c3afd0b854b91afd12cab1382f1 100644 |
| --- a/components/autofill/core/browser/webdata/autofill_table.cc |
| +++ b/components/autofill/core/browser/webdata/autofill_table.cc |
| @@ -89,6 +89,7 @@ void BindAutofillProfileToStatement(const AutofillProfile& profile, |
| s->BindString16(index++, GetInfo(profile, ADDRESS_HOME_ZIP)); |
| s->BindString16(index++, GetInfo(profile, ADDRESS_HOME_SORTING_CODE)); |
| s->BindString16(index++, GetInfo(profile, ADDRESS_HOME_COUNTRY)); |
| + s->BindString(index++, profile.language_code()); |
| s->BindInt64(index++, Time::Now().ToTimeT()); |
| s->BindString(index++, profile.origin()); |
| } |
| @@ -109,6 +110,7 @@ scoped_ptr<AutofillProfile> AutofillProfileFromStatement( |
| profile->SetRawInfo(ADDRESS_HOME_ZIP, s.ColumnString16(index++)); |
| profile->SetRawInfo(ADDRESS_HOME_SORTING_CODE, s.ColumnString16(index++)); |
| profile->SetRawInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(index++)); |
| + profile->set_language_code(s.ColumnString(index++)); |
| // Intentionally skip column 9, which stores the profile's modification date. |
| index++; |
| profile->set_origin(s.ColumnString(index++)); |
| @@ -442,6 +444,9 @@ bool AutofillTable::MigrateToVersion(int version, |
| case 55: |
| *update_compatible_version = true; |
| return MigrateToVersion55MergeAutofillDatesTable(); |
| + case 56: |
| + *update_compatible_version = true; |
| + return MigrateToVersion56AddProfileLanguageCodeForFormatting(); |
| } |
| return true; |
| } |
| @@ -549,7 +554,7 @@ bool AutofillTable::RemoveFormElementsAddedBetween( |
| // Precisely, compute the average amount of time between increments to the |
| // count in the original range [date_created, date_last_used]: |
| // avg_delta = (date_last_used_orig - date_created_orig) / (count - 1) |
| - // The count can be exressed as |
| + // The count can be expressed as |
| // count = 1 + (date_last_used - date_created) / avg_delta |
| // Hence, update the count to |
| // count_new = 1 + (date_last_used_new - date_created_new) / avg_delta |
| @@ -803,8 +808,9 @@ bool AutofillTable::AddAutofillProfile(const AutofillProfile& profile) { |
| sql::Statement s(db_->GetUniqueStatement( |
| "INSERT INTO autofill_profiles" |
| "(guid, company_name, street_address, dependent_locality, city, state," |
| - " zipcode, sorting_code, country_code, date_modified, origin)" |
| - "VALUES (?,?,?,?,?,?,?,?,?,?,?)")); |
| + " zipcode, sorting_code, country_code, language_code, date_modified," |
| + " origin)" |
| + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?)")); |
| BindAutofillProfileToStatement(profile, &s); |
| if (!s.Run()) |
| @@ -819,7 +825,8 @@ bool AutofillTable::GetAutofillProfile(const std::string& guid, |
| DCHECK(profile); |
| sql::Statement s(db_->GetUniqueStatement( |
| "SELECT guid, company_name, street_address, dependent_locality, city," |
| - " state, zipcode, sorting_code, country_code, date_modified, origin " |
| + " state, zipcode, sorting_code, country_code, language_code," |
| + " date_modified, origin " |
| "FROM autofill_profiles " |
| "WHERE guid=?")); |
| s.BindString(0, guid); |
| @@ -884,10 +891,10 @@ bool AutofillTable::UpdateAutofillProfile(const AutofillProfile& profile) { |
| "UPDATE autofill_profiles " |
| "SET guid=?, company_name=?, street_address=?, dependent_locality=?, " |
| " city=?, state=?, zipcode=?, sorting_code=?, country_code=?, " |
| - " date_modified=?, origin=? " |
| + " language_code=?, date_modified=?, origin=? " |
| "WHERE guid=?")); |
| BindAutofillProfileToStatement(profile, &s); |
| - s.BindString(11, profile.guid()); |
| + s.BindString(12, profile.guid()); |
| bool result = s.Run(); |
| DCHECK_GT(db_->GetLastChangeCount(), 0); |
| @@ -1271,7 +1278,8 @@ bool AutofillTable::InitProfilesTable() { |
| "sorting_code VARCHAR, " |
| "country_code VARCHAR, " |
| "date_modified INTEGER NOT NULL DEFAULT 0, " |
| - "origin VARCHAR DEFAULT '')")) { |
| + "origin VARCHAR DEFAULT '', " |
| + "language_code VARCHAR)")) { |
|
Ilya Sherman
2014/03/29 01:24:42
nit: Please sort this between country_code and dat
Scott Hess - ex-Googler
2014/03/31 17:46:38
It should be at the end to match the ALTER TABLE.
please use gerrit instead
2014/04/02 21:54:52
Keeping the field at the end to enable using ALTER
|
| NOTREACHED(); |
| return false; |
| } |
| @@ -2260,4 +2268,22 @@ bool AutofillTable::MigrateToVersion55MergeAutofillDatesTable() { |
| return transaction.Commit(); |
| } |
| +bool AutofillTable::MigrateToVersion56AddProfileLanguageCodeForFormatting() { |
| + sql::Transaction transaction(db_); |
| + if (!transaction.Begin()) |
| + return false; |
| + |
| + // Test the existence of the |language_code| column as an indication that a |
| + // migration is needed. It is possible that this column already exists because |
| + // the table was newly created when migrating from a pre-version-23 database. |
|
Ilya Sherman
2014/03/29 01:24:42
This sort of thing should no longer be needed. It
Scott Hess - ex-Googler
2014/03/31 17:46:38
I agree, no reason for a commit if there's only a
please use gerrit instead
2014/04/02 21:54:52
Since the existence check is no longer necessary (
Scott Hess - ex-Googler
2014/04/02 22:20:22
Unfortunately, Chromium's overall schema version m
|
| + if (!db_->DoesColumnExist("autofill_profiles", "language_code")) { |
| + if (!db_->Execute("ALTER TABLE autofill_profiles " |
| + "ADD COLUMN language_code VARCHAR")) { |
| + return false; |
| + } |
| + } |
| + |
| + return transaction.Commit(); |
| +} |
| + |
| } // namespace autofill |