diff options
author | dhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-27 00:22:23 +0000 |
---|---|---|
committer | dhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-27 00:22:23 +0000 |
commit | aa382fee25074e025294ae8e312360965d47e2e4 (patch) | |
tree | 252968511606328d0673dd7e813a341b9e023070 /chrome | |
parent | 77700831c1d0a328a5fada182adfab6dd86d937e (diff) | |
download | chromium_src-aa382fee25074e025294ae8e312360965d47e2e4.zip chromium_src-aa382fee25074e025294ae8e312360965d47e2e4.tar.gz chromium_src-aa382fee25074e025294ae8e312360965d47e2e4.tar.bz2 |
AutoFill crash in CreditCard::SetInfo().
Fix for crash seen in the field. The AutoFillType class was not thread-safe. These changes
make it so. Also adds unit tests that cover mappings from type to group and subgroup, and
out of range conditions.
BUG=42341
TEST=AutoFillTypeTest
Review URL: http://codereview.chromium.org/1789001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45650 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/autofill/autofill_type.cc | 231 | ||||
-rw-r--r-- | chrome/browser/autofill/autofill_type.h | 24 | ||||
-rw-r--r-- | chrome/browser/autofill/autofill_type_unittest.cc | 60 | ||||
-rw-r--r-- | chrome/browser/webdata/web_database.cc | 81 | ||||
-rw-r--r-- | chrome/browser/webdata/web_database.h | 26 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 1 |
6 files changed, 270 insertions, 153 deletions
diff --git a/chrome/browser/autofill/autofill_type.cc b/chrome/browser/autofill/autofill_type.cc index 46c2aef..030b12cb 100644 --- a/chrome/browser/autofill/autofill_type.cc +++ b/chrome/browser/autofill/autofill_type.cc @@ -7,99 +7,164 @@ #include "base/basictypes.h" #include "base/logging.h" -// TODO(jhawkins) all of the Human Readable names will need to be added to a -// resource file and localized because they are used in the confirmation -// dialog. -AutoFillType::AutoFillTypeDefinition kAutoFillTypeDefinitions[] = { - { NO_SERVER_DATA, AutoFillType::NO_GROUP, AutoFillType::NO_SUBGROUP, "No Server Data" }, - { UNKNOWN_TYPE, AutoFillType::NO_GROUP, AutoFillType::NO_SUBGROUP, "Unknown Type" }, - { EMPTY_TYPE, AutoFillType::NO_GROUP, AutoFillType::NO_SUBGROUP, "Empty Type" }, - - { NAME_FIRST, AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP, "First Name" }, - { NAME_MIDDLE, AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP, "Middle Name" }, - { NAME_LAST, AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP, "Last Name" }, - { NAME_MIDDLE_INITIAL, AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP, "Middle Initial" }, - { NAME_FULL, AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP, "Full Name" }, - { NAME_SUFFIX, AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP, "Name Suffix" }, - - { EMAIL_ADDRESS, AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP, "Email Address" }, - { COMPANY_NAME, AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP, "Company Name" }, - - { PHONE_HOME_NUMBER, AutoFillType::PHONE_HOME, AutoFillType::PHONE_NUMBER, "Home Phone Number" }, - { PHONE_HOME_CITY_CODE, AutoFillType::PHONE_HOME, AutoFillType::PHONE_CITY_CODE, "Home Area Code" }, - { PHONE_HOME_COUNTRY_CODE, AutoFillType::PHONE_HOME, AutoFillType::PHONE_COUNTRY_CODE, "Home Country Code" }, - { PHONE_HOME_CITY_AND_NUMBER, AutoFillType::PHONE_HOME, AutoFillType::PHONE_CITY_AND_NUMBER, "Home Phone Number" }, - { PHONE_HOME_WHOLE_NUMBER, AutoFillType::PHONE_HOME, AutoFillType::PHONE_WHOLE_NUMBER, "Home Phone Number" }, - - { PHONE_FAX_NUMBER, AutoFillType::PHONE_FAX, AutoFillType::PHONE_NUMBER, "Fax Number" }, - { PHONE_FAX_CITY_CODE, AutoFillType::PHONE_FAX, AutoFillType::PHONE_CITY_CODE, "Fax Area Code" }, - { PHONE_FAX_COUNTRY_CODE, AutoFillType::PHONE_FAX, AutoFillType::PHONE_COUNTRY_CODE, "Fax Country Code" }, - { PHONE_FAX_CITY_AND_NUMBER, AutoFillType::PHONE_FAX, AutoFillType::PHONE_CITY_AND_NUMBER, "Fax Number" }, - { PHONE_FAX_WHOLE_NUMBER, AutoFillType::PHONE_FAX, AutoFillType::PHONE_WHOLE_NUMBER, "Fax Number" }, - - { ADDRESS_HOME_LINE1, AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_LINE1, "Home Address Line 1" }, - { ADDRESS_HOME_LINE2, AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_LINE2, "Home Address Line 2" }, - { ADDRESS_HOME_APT_NUM, AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_APT_NUM, "Home Address Apartment Number" }, - { ADDRESS_HOME_CITY, AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_CITY, "Home Address City" }, - { ADDRESS_HOME_STATE, AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_STATE, "Home Address State" }, - { ADDRESS_HOME_ZIP, AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_ZIP, "Home Address Zip Code" }, - { ADDRESS_HOME_COUNTRY, AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_COUNTRY, "Home Address Country" }, - - { ADDRESS_BILLING_LINE1, AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_LINE1, "Billing Address Line 1" }, - { ADDRESS_BILLING_LINE2, AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_LINE2, "Billing Address Line 2" }, - { ADDRESS_BILLING_APT_NUM, AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_APT_NUM, "Billing Address Apartment Number" }, - { ADDRESS_BILLING_CITY, AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_CITY, "Billing Address City" }, - { ADDRESS_BILLING_STATE, AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_STATE, "Billing Address State" }, - { ADDRESS_BILLING_ZIP, AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_ZIP, "Billing Address Zip Code" }, - { ADDRESS_BILLING_COUNTRY, AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_COUNTRY, "Billing Address Country" }, - - { CREDIT_CARD_NAME, AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP, "Name on Credit Card" }, - { CREDIT_CARD_NUMBER, AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP, "Credit Card Number" }, - { CREDIT_CARD_EXP_MONTH, AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP, "Credit Card Expiration Month" }, - { CREDIT_CARD_EXP_2_DIGIT_YEAR, AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP, "Credit Card Expiration Year" }, - { CREDIT_CARD_EXP_4_DIGIT_YEAR, AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP, "Credit Card Expiration Year" }, - { CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR, AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP, "Credit Card Expiration Date" }, - { CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR, AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP, "Credit Card Expiration Date" }, - { CREDIT_CARD_TYPE, AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP, "Credit Card Type" }, - { CREDIT_CARD_VERIFICATION_CODE, AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP, "Credit Card Verification Number" }, - - { MAX_VALID_FIELD_TYPE, AutoFillType::NO_GROUP, AutoFillType::NO_SUBGROUP, "" }, +namespace { + +const AutoFillType::AutoFillTypeDefinition kUnknownAutoFillTypeDefinition = { + /* UNKNOWN_TYPE */ AutoFillType::NO_GROUP, AutoFillType::NO_SUBGROUP }; -bool AutoFillType::initialized_ = false; -AutoFillType AutoFillType::types_[MAX_VALID_FIELD_TYPE + 1]; +AutoFillType::AutoFillTypeDefinition kAutoFillTypeDefinitions[] = { + // NO_SERVER_DATA + { AutoFillType::NO_GROUP, AutoFillType::NO_SUBGROUP }, + // UNKNOWN_TYPE + kUnknownAutoFillTypeDefinition, + // EMPTY_TYPE + { AutoFillType::NO_GROUP, AutoFillType::NO_SUBGROUP }, + + // NAME_FIRST + { AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP }, + // NAME_MIDDLE + { AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP }, + // NAME_LAST + { AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP }, + // NAME_MIDDLE_INITIAL + { AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP }, + // NAME_FULL + { AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP }, + // NAME_SUFFIX + { AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP }, + + // EMAIL_ADDRESS + { AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP }, + + // PHONE_HOME_NUMBER + { AutoFillType::PHONE_HOME, AutoFillType::PHONE_NUMBER }, + // PHONE_HOME_CITY_CODE + { AutoFillType::PHONE_HOME, AutoFillType::PHONE_CITY_CODE }, + // PHONE_HOME_COUNTRY_CODE + { AutoFillType::PHONE_HOME, AutoFillType::PHONE_COUNTRY_CODE }, + // PHONE_HOME_CITY_AND_NUMBER + { AutoFillType::PHONE_HOME, AutoFillType::PHONE_CITY_AND_NUMBER }, + // PHONE_HOME_WHOLE_NUMBER + { AutoFillType::PHONE_HOME, AutoFillType::PHONE_WHOLE_NUMBER }, + + // Work phone numbers (values [15,19]) are deprecated. + kUnknownAutoFillTypeDefinition, + kUnknownAutoFillTypeDefinition, + kUnknownAutoFillTypeDefinition, + kUnknownAutoFillTypeDefinition, + kUnknownAutoFillTypeDefinition, + + // PHONE_FAX_NUMBER + { AutoFillType::PHONE_FAX, AutoFillType::PHONE_NUMBER }, + // PHONE_FAX_CITY_CODE + { AutoFillType::PHONE_FAX, AutoFillType::PHONE_CITY_CODE }, + // PHONE_FAX_COUNTRY_CODE + { AutoFillType::PHONE_FAX, AutoFillType::PHONE_COUNTRY_CODE }, + // PHONE_FAX_CITY_AND_NUMBER + { AutoFillType::PHONE_FAX, AutoFillType::PHONE_CITY_AND_NUMBER }, + // PHONE_FAX_WHOLE_NUMBER + { AutoFillType::PHONE_FAX, AutoFillType::PHONE_WHOLE_NUMBER }, + + // Cell phone numbers (values [25, 29]) are deprecated. + kUnknownAutoFillTypeDefinition, + kUnknownAutoFillTypeDefinition, + kUnknownAutoFillTypeDefinition, + kUnknownAutoFillTypeDefinition, + kUnknownAutoFillTypeDefinition, + + // ADDRESS_HOME_LINE1 + { AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_LINE1 }, + // ADDRESS_HOME_LINE2 + { AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_LINE2 }, + // ADDRESS_HOME_APT_NUM + { AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_APT_NUM }, + // ADDRESS_HOME_CITY + { AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_CITY }, + // ADDRESS_HOME_STATE + { AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_STATE }, + // ADDRESS_HOME_ZIP + { AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_ZIP }, + // ADDRESS_HOME_COUNTRY + { AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_COUNTRY }, + + // ADDRESS_BILLING_LINE1 + { AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_LINE1 }, + // ADDRESS_BILLING_LINE2 + { AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_LINE2 }, + // ADDRESS_BILLING_APT_NUM + { AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_APT_NUM }, + // ADDRESS_BILLING_CITY + { AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_CITY }, + // ADDRESS_BILLING_STATE + { AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_STATE }, + // ADDRESS_BILLING_ZIP + { AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_ZIP }, + // ADDRESS_BILLING_COUNTRY + { AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_COUNTRY }, + + // ADDRESS_SHIPPING values [44,50] are deprecated. + kUnknownAutoFillTypeDefinition, + kUnknownAutoFillTypeDefinition, + kUnknownAutoFillTypeDefinition, + kUnknownAutoFillTypeDefinition, + kUnknownAutoFillTypeDefinition, + kUnknownAutoFillTypeDefinition, + kUnknownAutoFillTypeDefinition, + + // CREDIT_CARD_NAME + { AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP }, + // CREDIT_CARD_NUMBER + { AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP }, + // CREDIT_CARD_EXP_MONTH + { AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP }, + // CREDIT_CARD_EXP_2_DIGIT_YEAR + { AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP }, + // CREDIT_CARD_EXP_4_DIGIT_YEAR + { AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP }, + // CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR + { AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP }, + // CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR + { AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP }, + // CREDIT_CARD_TYPE + { AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP }, + // CREDIT_CARD_VERIFICATION_CODE + { AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP }, + + // COMPANY_NAME + { AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP }, +}; -AutoFillType::AutoFillType(AutoFillTypeDefinition* definition) - : autofill_type_definition_(definition) { - DCHECK(definition != NULL); -} +} // namespace AutoFillType::AutoFillType(AutoFillFieldType field_type) { - StaticInitialize(); - DCHECK(initialized_); - - if (field_type < 0 || field_type > MAX_VALID_FIELD_TYPE || - types_[field_type].autofill_type_definition_ == NULL) { - field_type = UNKNOWN_TYPE; - } + if ((field_type < NO_SERVER_DATA || field_type >= MAX_VALID_FIELD_TYPE) || + (field_type >= 15 && field_type <= 19) || + (field_type >= 25 && field_type <= 29) || + (field_type >= 44 && field_type <= 50)) + field_type_ = UNKNOWN_TYPE; + else + field_type_ = field_type; +} - autofill_type_definition_ = types_[field_type].autofill_type_definition_; +AutoFillType::AutoFillType(const AutoFillType& autofill_type) { + *this = autofill_type; } -// TODO(jhawkins): refactor this class to not require static initialization. -void AutoFillType::StaticInitialize() { - // Can be called more than once (in unit tests for example). - if (initialized_) - return; +AutoFillType& AutoFillType::operator=(const AutoFillType& autofill_type) { + if (this != &autofill_type) + this->field_type_ = autofill_type.field_type_; + return *this; +} - initialized_ = true; +AutoFillFieldType AutoFillType::field_type() const { + return field_type_; +} - InitializeFieldTypeMap(); +FieldTypeGroup AutoFillType::group() const { + return kAutoFillTypeDefinitions[field_type_].group; } -void AutoFillType::InitializeFieldTypeMap() { - for (size_t i = 0; i < arraysize(kAutoFillTypeDefinitions); ++i) { - AutoFillType type(&kAutoFillTypeDefinitions[i]); - types_[type.field_type()] = type; - } +FieldTypeSubGroup AutoFillType::subgroup() const { + return kAutoFillTypeDefinitions[field_type_].subgroup; } diff --git a/chrome/browser/autofill/autofill_type.h b/chrome/browser/autofill/autofill_type.h index 18d093c..0fc692a 100644 --- a/chrome/browser/autofill/autofill_type.h +++ b/chrome/browser/autofill/autofill_type.h @@ -46,32 +46,20 @@ class AutoFillType { }; struct AutoFillTypeDefinition { - AutoFillFieldType field_type; FieldTypeGroup group; FieldTypeSubGroup subgroup; - std::string name; }; - AutoFillType() {} - explicit AutoFillType(AutoFillTypeDefinition* definition); explicit AutoFillType(AutoFillFieldType field_type); + AutoFillType(const AutoFillType& autofill_type); + AutoFillType& operator=(const AutoFillType& autofill_type); - AutoFillFieldType field_type() const { - return autofill_type_definition_->field_type; - } - FieldTypeGroup group() const { return autofill_type_definition_->group; } - FieldTypeSubGroup subgroup() const { - return autofill_type_definition_->subgroup; - } + AutoFillFieldType field_type() const; + FieldTypeGroup group() const; + FieldTypeSubGroup subgroup() const; private: - static void StaticInitialize(); - static void InitializeFieldTypeMap(); - - static bool initialized_; - static AutoFillType types_[MAX_VALID_FIELD_TYPE + 1]; - - const AutoFillTypeDefinition* autofill_type_definition_; + AutoFillFieldType field_type_; }; typedef AutoFillType::FieldTypeGroup FieldTypeGroup; diff --git a/chrome/browser/autofill/autofill_type_unittest.cc b/chrome/browser/autofill/autofill_type_unittest.cc new file mode 100644 index 0000000..d610717 --- /dev/null +++ b/chrome/browser/autofill/autofill_type_unittest.cc @@ -0,0 +1,60 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/autofill/autofill_type.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace { + +TEST(AutoFillTypeTest, Basic) { + // No server data. + AutoFillType none(NO_SERVER_DATA); + EXPECT_EQ(NO_SERVER_DATA, none.field_type()); + EXPECT_EQ(AutoFillType::NO_GROUP, none.group()); + EXPECT_EQ(AutoFillType::NO_SUBGROUP, none.subgroup()); + + // Unknown type. + AutoFillType unknown(UNKNOWN_TYPE); + EXPECT_EQ(UNKNOWN_TYPE, unknown.field_type()); + EXPECT_EQ(AutoFillType::NO_GROUP, unknown.group()); + EXPECT_EQ(AutoFillType::NO_SUBGROUP, unknown.subgroup()); + + // Type with group but no subgroup. + AutoFillType first(NAME_FIRST); + EXPECT_EQ(NAME_FIRST, first.field_type()); + EXPECT_EQ(AutoFillType::CONTACT_INFO, first.group()); + EXPECT_EQ(AutoFillType::NO_SUBGROUP, first.subgroup()); + + // Type with group and subgroup. + AutoFillType phone(PHONE_HOME_NUMBER); + EXPECT_EQ(PHONE_HOME_NUMBER, phone.field_type()); + EXPECT_EQ(AutoFillType::PHONE_HOME, phone.group()); + EXPECT_EQ(AutoFillType::PHONE_NUMBER, phone.subgroup()); + + // Last value, to check any offset errors. + AutoFillType last(COMPANY_NAME); + EXPECT_EQ(COMPANY_NAME, last.field_type()); + EXPECT_EQ(AutoFillType::CONTACT_INFO, last.group()); + EXPECT_EQ(AutoFillType::NO_SUBGROUP, last.subgroup()); + + // Boundary (error) condition. + AutoFillType boundary(MAX_VALID_FIELD_TYPE); + EXPECT_EQ(UNKNOWN_TYPE, boundary.field_type()); + EXPECT_EQ(AutoFillType::NO_GROUP, boundary.group()); + EXPECT_EQ(AutoFillType::NO_SUBGROUP, boundary.subgroup()); + + // Beyond the boundary (error) condition. + AutoFillType beyond(static_cast<AutoFillFieldType>(MAX_VALID_FIELD_TYPE+10)); + EXPECT_EQ(UNKNOWN_TYPE, beyond.field_type()); + EXPECT_EQ(AutoFillType::NO_GROUP, beyond.group()); + EXPECT_EQ(AutoFillType::NO_SUBGROUP, beyond.subgroup()); + + // In-between value. Missing from enum but within range. Error condition. + AutoFillType between(static_cast<AutoFillFieldType>(16)); + EXPECT_EQ(UNKNOWN_TYPE, between.field_type()); + EXPECT_EQ(AutoFillType::NO_GROUP, between.group()); + EXPECT_EQ(AutoFillType::NO_SUBGROUP, between.subgroup()); +} + +} // namespace diff --git a/chrome/browser/webdata/web_database.cc b/chrome/browser/webdata/web_database.cc index e3ba7dc..70cdd74 100644 --- a/chrome/browser/webdata/web_database.cc +++ b/chrome/browser/webdata/web_database.cc @@ -1549,37 +1549,37 @@ bool WebDatabase::GetAutoFillProfileForID(int profile_id, return s.Succeeded(); } -static void BindCreditCardToStatement(const CreditCard& creditcard, +static void BindCreditCardToStatement(const CreditCard& credit_card, sql::Statement* s) { - s->BindString(0, UTF16ToUTF8(creditcard.Label())); - s->BindInt(1, creditcard.unique_id()); + s->BindString(0, UTF16ToUTF8(credit_card.Label())); + s->BindInt(1, credit_card.unique_id()); - string16 text = creditcard.GetFieldText(AutoFillType(CREDIT_CARD_NAME)); + string16 text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_NAME)); s->BindString(2, UTF16ToUTF8(text)); - text = creditcard.GetFieldText(AutoFillType(CREDIT_CARD_TYPE)); + text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_TYPE)); s->BindString(3, UTF16ToUTF8(text)); text.clear(); // No unencrypted cc info. s->BindString(4, UTF16ToUTF8(text)); - text = creditcard.GetFieldText(AutoFillType(CREDIT_CARD_EXP_MONTH)); + text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_EXP_MONTH)); s->BindString(5, UTF16ToUTF8(text)); - text = creditcard.GetFieldText(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR)); + text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR)); s->BindString(6, UTF16ToUTF8(text)); text.clear(); s->BindString(7, UTF16ToUTF8(text)); - s->BindString(8, UTF16ToUTF8(creditcard.billing_address())); - s->BindString(9, UTF16ToUTF8(creditcard.shipping_address())); - text = creditcard.GetFieldText(AutoFillType(CREDIT_CARD_NUMBER)); + s->BindString(8, UTF16ToUTF8(credit_card.billing_address())); + s->BindString(9, UTF16ToUTF8(credit_card.shipping_address())); + text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_NUMBER)); std::string encrypted_data; Encryptor::EncryptString16(text, &encrypted_data); s->BindBlob(10, encrypted_data.data(), static_cast<int>(encrypted_data.length())); - text = creditcard.GetFieldText(AutoFillType(CREDIT_CARD_VERIFICATION_CODE)); + text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_VERIFICATION_CODE)); Encryptor::EncryptString16(text, &encrypted_data); s->BindBlob(11, encrypted_data.data(), static_cast<int>(encrypted_data.length())); } -bool WebDatabase::AddCreditCard(const CreditCard& creditcard) { +bool WebDatabase::AddCreditCard(const CreditCard& credit_card) { sql::Statement s(db_.GetUniqueStatement( "INSERT INTO credit_cards" "(label, unique_id, name_on_card, type, card_number," @@ -1591,7 +1591,7 @@ bool WebDatabase::AddCreditCard(const CreditCard& creditcard) { return false; } - BindCreditCardToStatement(creditcard, &s); + BindCreditCardToStatement(credit_card, &s); if (!s.Run()) { NOTREACHED(); @@ -1603,11 +1603,11 @@ bool WebDatabase::AddCreditCard(const CreditCard& creditcard) { } static CreditCard* CreditCardFromStatement(const sql::Statement& s) { - CreditCard* creditcard = new CreditCard( + CreditCard* credit_card = new CreditCard( UTF8ToUTF16(s.ColumnString(0)), s.ColumnInt(1)); - creditcard->SetInfo(AutoFillType(CREDIT_CARD_NAME), + credit_card->SetInfo(AutoFillType(CREDIT_CARD_NAME), UTF8ToUTF16(s.ColumnString(2))); - creditcard->SetInfo(AutoFillType(CREDIT_CARD_TYPE), + credit_card->SetInfo(AutoFillType(CREDIT_CARD_TYPE), UTF8ToUTF16(s.ColumnString(3))); string16 credit_card_number = UTF8ToUTF16(s.ColumnString(4)); // It could be non-empty prior to version 23. After that it encrypted in @@ -1621,10 +1621,10 @@ static CreditCard* CreditCardFromStatement(const sql::Statement& s) { Encryptor::DecryptString16(encrypted_cc, &credit_card_number); } } - creditcard->SetInfo(AutoFillType(CREDIT_CARD_NUMBER), credit_card_number); - creditcard->SetInfo(AutoFillType(CREDIT_CARD_EXP_MONTH), + credit_card->SetInfo(AutoFillType(CREDIT_CARD_NUMBER), credit_card_number); + credit_card->SetInfo(AutoFillType(CREDIT_CARD_EXP_MONTH), UTF8ToUTF16(s.ColumnString(5))); - creditcard->SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), + credit_card->SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), UTF8ToUTF16(s.ColumnString(6))); string16 credit_card_verification_code = UTF8ToUTF16(s.ColumnString(7)); @@ -1639,19 +1639,19 @@ static CreditCard* CreditCardFromStatement(const sql::Statement& s) { Encryptor::DecryptString16(encrypted_cc, &credit_card_verification_code); } } - creditcard->SetInfo(AutoFillType(CREDIT_CARD_VERIFICATION_CODE), + credit_card->SetInfo(AutoFillType(CREDIT_CARD_VERIFICATION_CODE), credit_card_verification_code); - creditcard->set_billing_address(UTF8ToUTF16(s.ColumnString(8))); - creditcard->set_shipping_address(UTF8ToUTF16(s.ColumnString(9))); + credit_card->set_billing_address(UTF8ToUTF16(s.ColumnString(8))); + credit_card->set_shipping_address(UTF8ToUTF16(s.ColumnString(9))); // Column 10 is processed above. // Column 11 is processed above. - return creditcard; + return credit_card; } bool WebDatabase::GetCreditCardForLabel(const string16& label, - CreditCard** creditcard) { - DCHECK(creditcard); + CreditCard** credit_card) { + DCHECK(credit_card); sql::Statement s(db_.GetUniqueStatement( "SELECT * FROM credit_cards " "WHERE label = ?")); @@ -1664,12 +1664,13 @@ bool WebDatabase::GetCreditCardForLabel(const string16& label, if (!s.Step()) return false; - *creditcard = CreditCardFromStatement(s); + *credit_card = CreditCardFromStatement(s); return s.Succeeded(); } -bool WebDatabase::GetCreditCardForID(int card_id, CreditCard** card) { +bool WebDatabase::GetCreditCardForID(int credit_card_id, + CreditCard** credit_card) { sql::Statement s(db_.GetUniqueStatement( "SELECT * FROM credit_cards " "WHERE unique_id = ?")); @@ -1678,19 +1679,19 @@ bool WebDatabase::GetCreditCardForID(int card_id, CreditCard** card) { return false; } - s.BindInt(0, card_id); + s.BindInt(0, credit_card_id); if (!s.Step()) return false; - *card = CreditCardFromStatement(s); + *credit_card = CreditCardFromStatement(s); return s.Succeeded(); } bool WebDatabase::GetCreditCards( - std::vector<CreditCard*>* creditcards) { - DCHECK(creditcards); - creditcards->clear(); + std::vector<CreditCard*>* credit_cards) { + DCHECK(credit_cards); + credit_cards->clear(); sql::Statement s(db_.GetUniqueStatement("SELECT * FROM credit_cards")); if (!s) { @@ -1699,13 +1700,13 @@ bool WebDatabase::GetCreditCards( } while (s.Step()) - creditcards->push_back(CreditCardFromStatement(s)); + credit_cards->push_back(CreditCardFromStatement(s)); return s.Succeeded(); } -bool WebDatabase::UpdateCreditCard(const CreditCard& creditcard) { - DCHECK(creditcard.unique_id()); +bool WebDatabase::UpdateCreditCard(const CreditCard& credit_card) { + DCHECK(credit_card.unique_id()); sql::Statement s(db_.GetUniqueStatement( "UPDATE credit_cards " "SET label=?, unique_id=?, name_on_card=?, type=?, card_number=?, " @@ -1718,15 +1719,15 @@ bool WebDatabase::UpdateCreditCard(const CreditCard& creditcard) { return false; } - BindCreditCardToStatement(creditcard, &s); - s.BindInt(12, creditcard.unique_id()); + BindCreditCardToStatement(credit_card, &s); + s.BindInt(12, credit_card.unique_id()); bool result = s.Run(); DCHECK_GT(db_.GetLastChangeCount(), 0); return result; } -bool WebDatabase::RemoveCreditCard(int creditcard_id) { - DCHECK_NE(0, creditcard_id); +bool WebDatabase::RemoveCreditCard(int credit_card_id) { + DCHECK_NE(0, credit_card_id); sql::Statement s(db_.GetUniqueStatement( "DELETE FROM credit_cards WHERE unique_id = ?")); if (!s) { @@ -1734,7 +1735,7 @@ bool WebDatabase::RemoveCreditCard(int creditcard_id) { return false; } - s.BindInt(0, creditcard_id); + s.BindInt(0, credit_card_id); return s.Run(); } diff --git a/chrome/browser/webdata/web_database.h b/chrome/browser/webdata/web_database.h index 07f30a9..18837309 100644 --- a/chrome/browser/webdata/web_database.h +++ b/chrome/browser/webdata/web_database.h @@ -237,24 +237,26 @@ class WebDatabase { virtual bool GetAutoFillProfiles(std::vector<AutoFillProfile*>* profiles); // Records a single credit card in the credit_cards table. - bool AddCreditCard(const CreditCard& creditcard); + bool AddCreditCard(const CreditCard& credit_card); - // Updates the database values for the specified profile. - bool UpdateCreditCard(const CreditCard& profile); + // Updates the database values for the specified credit card. + bool UpdateCreditCard(const CreditCard& credit_card); - // Removes a row from the autofill_profiles table. |profile_id| is the - // unique ID of the profile to remove. - bool RemoveCreditCard(int profile_id); + // Removes a row from the credit_cards table. |credit_card_id| is the + // unique ID of the credit card to remove. + bool RemoveCreditCard(int credit_card_id); - // Retrieves a profile with label |label|. The caller owns |profile|. + // Retrieves a credit card with label |label|. The caller owns + // |credit_card_id|. bool GetCreditCardForLabel(const string16& label, - CreditCard** profile); + CreditCard** credit_card); - // Retrieves credit card for a card with unique id |card_id|. - bool GetCreditCardForID(int card_id, CreditCard** card); + // Retrieves credit card for a card with unique id |credit_card_id|. + bool GetCreditCardForID(int credit_card_id, CreditCard** credit_card); - // Retrieves all profiles in the database. Caller owns the returned profiles. - virtual bool GetCreditCards(std::vector<CreditCard*>* profiles); + // Retrieves all credit cards in the database. Caller owns the returned + // credit cards. + virtual bool GetCreditCards(std::vector<CreditCard*>* credit_cards); ////////////////////////////////////////////////////////////////////////////// // diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 45c3602..f8d15b3 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -565,6 +565,7 @@ 'browser/autofill/autofill_infobar_delegate_unittest.cc', 'browser/autofill/autofill_manager_unittest.cc', 'browser/autofill/autofill_profile_unittest.cc', + 'browser/autofill/autofill_type_unittest.cc', 'browser/autofill/autofill_xml_parser_unittest.cc', 'browser/autofill/billing_address_unittest.cc', 'browser/autofill/credit_card_field_unittest.cc', |