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

Unified Diff: chrome/browser/webdata/web_database.cc

Issue 6484022: Autofill i18n: Set postal code and state field labels based on the selected country. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Still needs tests Created 9 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/webdata/web_database.cc
diff --git a/chrome/browser/webdata/web_database.cc b/chrome/browser/webdata/web_database.cc
index d97698abfff7e9c01b54cdfe7e4ff0c6d53511d7..19964b32710f845673994b5b593f148abb791629 100644
--- a/chrome/browser/webdata/web_database.cc
+++ b/chrome/browser/webdata/web_database.cc
@@ -16,6 +16,7 @@
#include "base/string_util.h"
#include "base/tuple.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/autofill/autofill_country.h"
#include "chrome/browser/autofill/autofill_profile.h"
#include "chrome/browser/autofill/autofill_type.h"
#include "chrome/browser/autofill/credit_card.h"
@@ -123,7 +124,9 @@ using webkit_glue::PasswordForm;
// city
// state
// zipcode
-// country
+// country The country name. Deprecated, should be removed once
+// the stable channel reaches version 11.
+// country_code
// phone
// fax
// date_modified The date on which this profile was last modified.
@@ -165,8 +168,8 @@ typedef std::vector<Tuple3<int64, string16, string16> > AutofillElementList;
// Current version number. Note: when changing the current version number,
// corresponding changes must happen in the unit tests, and new migration test
// added. See |WebDatabaseMigrationTest::kCurrentTestedVersionNumber|.
-const int kCurrentVersionNumber = 32;
-const int kCompatibleVersionNumber = 32;
+const int kCurrentVersionNumber = 33;
+const int kCompatibleVersionNumber = 33;
// ID of the url column in keywords.
const int kUrlIdPosition = 16;
@@ -281,11 +284,13 @@ void BindAutoFillProfileToStatement(const AutoFillProfile& profile,
s->BindString16(11, LimitDataSize(text));
text = profile.GetFieldText(AutoFillType(ADDRESS_HOME_COUNTRY));
s->BindString16(12, LimitDataSize(text));
+ std::string country_code = profile.CountryCode();
+ s->BindString(13, country_code);
text = profile.GetFieldText(AutoFillType(PHONE_HOME_WHOLE_NUMBER));
- s->BindString16(13, LimitDataSize(text));
- text = profile.GetFieldText(AutoFillType(PHONE_FAX_WHOLE_NUMBER));
s->BindString16(14, LimitDataSize(text));
- s->BindInt64(15, Time::Now().ToTimeT());
+ text = profile.GetFieldText(AutoFillType(PHONE_FAX_WHOLE_NUMBER));
+ s->BindString16(15, LimitDataSize(text));
+ s->BindInt64(16, Time::Now().ToTimeT());
}
AutoFillProfile* AutoFillProfileFromStatement(const sql::Statement& s) {
@@ -315,13 +320,13 @@ AutoFillProfile* AutoFillProfileFromStatement(const sql::Statement& s) {
s.ColumnString16(10));
profile->SetInfo(AutoFillType(ADDRESS_HOME_ZIP),
s.ColumnString16(11));
- profile->SetInfo(AutoFillType(ADDRESS_HOME_COUNTRY),
- s.ColumnString16(12));
+ // Intentionally skip column 12, which stores the localized country name.
+ profile->SetCountryCode(s.ColumnString(13));
profile->SetInfo(AutoFillType(PHONE_HOME_WHOLE_NUMBER),
- s.ColumnString16(13));
- profile->SetInfo(AutoFillType(PHONE_FAX_WHOLE_NUMBER),
s.ColumnString16(14));
- // Intentionally skip column 15, which stores the profile's modification date.
+ profile->SetInfo(AutoFillType(PHONE_FAX_WHOLE_NUMBER),
+ s.ColumnString16(15));
+ // Intentionally skip column 16, which stores the profile's modification date.
return profile;
}
@@ -734,6 +739,7 @@ bool WebDatabase::InitAutoFillProfilesTable() {
"state VARCHAR, "
"zipcode VARCHAR, "
"country VARCHAR, "
+ "country_code VARCHAR, "
"phone VARCHAR, "
"fax VARCHAR, "
"date_modified INTEGER NOT NULL DEFAULT 0)")) {
@@ -1609,8 +1615,8 @@ bool WebDatabase::AddAutoFillProfile(const AutoFillProfile& profile) {
"INSERT INTO autofill_profiles"
"(guid, label, first_name, middle_name, last_name, email,"
" company_name, address_line_1, address_line_2, city, state, zipcode,"
- " country, phone, fax, date_modified)"
- "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"));
+ " country, country_code, phone, fax, date_modified)"
+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"));
if (!s) {
NOTREACHED() << "Statement prepare failed";
return false;
@@ -1633,7 +1639,7 @@ bool WebDatabase::GetAutoFillProfile(const std::string& guid,
sql::Statement s(db_.GetUniqueStatement(
"SELECT guid, label, first_name, middle_name, last_name, email, "
"company_name, address_line_1, address_line_2, city, state, zipcode, "
- "country, phone, fax, date_modified "
+ "country, country_code, phone, fax, date_modified "
"FROM autofill_profiles "
"WHERE guid = ?"));
if (!s) {
@@ -1658,7 +1664,7 @@ bool WebDatabase::GetAutoFillProfiles(
sql::Statement s(db_.GetUniqueStatement(
"SELECT guid, label, first_name, middle_name, last_name, email, "
"company_name, address_line_1, address_line_2, city, state, zipcode, "
- "country, phone, fax, date_modified "
+ "country, country_code, phone, fax, date_modified "
"FROM autofill_profiles"));
if (!s) {
NOTREACHED() << "Statement prepare failed";
@@ -1687,8 +1693,8 @@ bool WebDatabase::UpdateAutoFillProfile(const AutoFillProfile& profile) {
"UPDATE autofill_profiles "
"SET guid=?, label=?, first_name=?, middle_name=?, last_name=?, "
" email=?, company_name=?, address_line_1=?, address_line_2=?, "
- " city=?, state=?, zipcode=?, country=?, phone=?, fax=?, "
- " date_modified=? "
+ " city=?, state=?, zipcode=?, country=?, country_code=?, phone=?, "
+ " fax=?, date_modified=? "
"WHERE guid=?"));
if (!s) {
NOTREACHED() << "Statement prepare failed";
@@ -1696,7 +1702,7 @@ bool WebDatabase::UpdateAutoFillProfile(const AutoFillProfile& profile) {
}
BindAutoFillProfileToStatement(profile, &s);
- s.BindString(16, profile.guid());
+ s.BindString(17, profile.guid());
bool result = s.Run();
DCHECK_GT(db_.GetLastChangeCount(), 0);
return result;
@@ -2533,6 +2539,58 @@ sql::InitStatus WebDatabase::MigrateOldVersionsAsNeeded(){
// FALL THROUGH
+ case 32:
+ // Add |country_code| column to |autofill_profiles| table.
+ // Note that we need to check for the column's existence due to the fact
+ // that for a version 22 database the |autofill_profiles| table gets
+ // created fresh with |InitAutoFillProfilesTable|.
+ if (!db_.DoesColumnExist("autofill_profiles", "country_code")) {
+ if (!db_.Execute("ALTER TABLE autofill_profiles ADD COLUMN "
+ "country_code VARCHAR")) {
+ LOG(WARNING) << "Unable to update web database to version 33.";
+ NOTREACHED();
+ return sql::INIT_FAILURE;
+ }
+
+ // Set all the |country_code| fields to match existing |country| values.
+ {
+ sql::Statement s(db_.GetUniqueStatement("SELECT guid, country "
+ "FROM autofill_profiles"));
+
+ if (!s) {
+ LOG(WARNING) << "Unable to update web database to version 33.";
+ NOTREACHED();
+ return sql::INIT_FAILURE;
+ }
+
+ while (s.Step()) {
+ sql::Statement update_s(
+ db_.GetUniqueStatement("UPDATE autofill_profiles "
+ "SET country_code=? WHERE guid=?"));
+ if (!update_s) {
+ LOG(WARNING) << "Unable to update web database to version 33.";
+ NOTREACHED();
+ return sql::INIT_FAILURE;
+ }
+ string16 country = s.ColumnString16(1);
+ update_s.BindString(0, AutoFillCountry::GetCountryCode(country));
+ update_s.BindString(1, s.ColumnString(0));
+
+ if (!update_s.Run()) {
+ LOG(WARNING) << "Unable to update web database to version 33.";
+ NOTREACHED();
+ return sql::INIT_FAILURE;
+ }
+ }
+ }
+ }
+
+ meta_table_.SetVersionNumber(33);
+ meta_table_.SetCompatibleVersionNumber(
+ std::min(33, kCompatibleVersionNumber));
+
+ // FALL THROUGH
+
// Add successive versions here. Each should set the version number and
// compatible version number as appropriate, then fall through to the next
// case.

Powered by Google App Engine
This is Rietveld 408576698