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 bf8603aafd8b593ea67166186141f3fa4131d13a..da69cc9ddfa0fba5c5d71553474662c92480f296 100644 |
--- a/components/autofill/core/browser/webdata/autofill_table.cc |
+++ b/components/autofill/core/browser/webdata/autofill_table.cc |
@@ -45,13 +45,13 @@ |
#include "ui/base/l10n/l10n_util.h" |
#include "url/gurl.h" |
-using base::ASCIIToUTF16; |
-using base::Time; |
-using base::TimeDelta; |
- |
namespace autofill { |
namespace { |
+using ::base::ASCIIToUTF16; |
+using ::base::Time; |
+using ::base::TimeDelta; |
Peter Kasting
2017/04/26 01:27:28
Nit: Any particular reason to move these?
(I'd lo
please use gerrit instead
2017/04/26 16:34:15
There's a wealth of explanations in go/totw/119. T
|
+ |
// The period after which autocomplete entries should expire in days. |
const int64_t kExpirationPeriodInDays = 60; |
@@ -228,11 +228,11 @@ bool AddAutofillProfileEmailsToProfile(sql::Connection* db, |
AutofillProfile* profile) { |
// TODO(estade): update schema so that multiple emails are not associated per |
// unique profile guid. Please refer https://crbug.com/497934. |
- sql::Statement s(db->GetUniqueStatement( |
- "SELECT guid, email " |
- "FROM autofill_profile_emails " |
- "WHERE guid=?" |
- "LIMIT 1")); |
+ sql::Statement s( |
+ db->GetUniqueStatement("SELECT guid, email " |
+ "FROM autofill_profile_emails " |
+ "WHERE guid=?" |
+ "LIMIT 1")); |
s.BindString(0, profile->guid()); |
if (!s.is_valid()) |
@@ -249,11 +249,11 @@ bool AddAutofillProfilePhonesToProfile(sql::Connection* db, |
AutofillProfile* profile) { |
// TODO(estade): update schema so that multiple phone numbers are not |
// associated per unique profile guid. Please refer https://crbug.com/497934. |
- sql::Statement s(db->GetUniqueStatement( |
- "SELECT guid, number " |
- "FROM autofill_profile_phones " |
- "WHERE guid=?" |
- "LIMIT 1")); |
+ sql::Statement s( |
+ db->GetUniqueStatement("SELECT guid, number " |
+ "FROM autofill_profile_phones " |
+ "WHERE guid=?" |
+ "LIMIT 1")); |
s.BindString(0, profile->guid()); |
if (!s.is_valid()) |
@@ -285,10 +285,10 @@ bool AddAutofillProfileNames(const AutofillProfile& profile, |
bool AddAutofillProfileEmails(const AutofillProfile& profile, |
sql::Connection* db) { |
// Add the new email. |
- sql::Statement s(db->GetUniqueStatement( |
- "INSERT INTO autofill_profile_emails" |
- " (guid, email) " |
- "VALUES (?,?)")); |
+ sql::Statement s( |
+ db->GetUniqueStatement("INSERT INTO autofill_profile_emails" |
+ " (guid, email) " |
+ "VALUES (?,?)")); |
s.BindString(0, profile.guid()); |
s.BindString16(1, profile.GetRawInfo(EMAIL_ADDRESS)); |
@@ -298,10 +298,10 @@ bool AddAutofillProfileEmails(const AutofillProfile& profile, |
bool AddAutofillProfilePhones(const AutofillProfile& profile, |
sql::Connection* db) { |
// Add the new number. |
- sql::Statement s(db->GetUniqueStatement( |
- "INSERT INTO autofill_profile_phones" |
- " (guid, number) " |
- "VALUES (?,?)")); |
+ sql::Statement s( |
+ db->GetUniqueStatement("INSERT INTO autofill_profile_phones" |
+ " (guid, number) " |
+ "VALUES (?,?)")); |
s.BindString(0, profile.guid()); |
s.BindString16(1, profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); |
@@ -412,8 +412,7 @@ AutofillTable::AutofillTable() |
DCHECK(autofill_table_encryptor_); |
} |
-AutofillTable::~AutofillTable() { |
-} |
+AutofillTable::~AutofillTable() {} |
AutofillTable* AutofillTable::FromWebDatabase(WebDatabase* db) { |
return static_cast<AutofillTable*>(db->GetTable(GetKey())); |
@@ -483,6 +482,9 @@ bool AutofillTable::MigrateToVersion(int version, |
case 71: |
*update_compatible_version = true; |
return MigrateToVersion71AddHasConvertedAndBillingAddressIdMetadata(); |
+ case 72: |
+ *update_compatible_version = false; |
Peter Kasting
2017/04/26 01:27:28
Wait, shouldn't this be true?
please use gerrit instead
2017/04/26 16:34:15
Is there any documentation to read up on why this
Peter Kasting
2017/04/26 17:47:56
You need to set this to true iff you need to bump
|
+ return MigrateToVersion72RenameCardTypeToIssuerNetwork(); |
} |
return true; |
} |
@@ -508,11 +510,11 @@ bool AutofillTable::GetFormValuesForElementName( |
if (prefix.empty()) { |
sql::Statement s; |
- s.Assign(db_->GetUniqueStatement( |
- "SELECT value FROM autofill " |
- "WHERE name = ? " |
- "ORDER BY count DESC " |
- "LIMIT ?")); |
+ s.Assign( |
+ db_->GetUniqueStatement("SELECT value FROM autofill " |
+ "WHERE name = ? " |
+ "ORDER BY count DESC " |
+ "LIMIT ?")); |
s.BindString16(0, name); |
s.BindInt(1, limit); |
@@ -527,13 +529,13 @@ bool AutofillTable::GetFormValuesForElementName( |
next_prefix.back()++; |
sql::Statement s1; |
- s1.Assign(db_->GetUniqueStatement( |
- "SELECT value FROM autofill " |
- "WHERE name = ? AND " |
- "value_lower >= ? AND " |
- "value_lower < ? " |
- "ORDER BY count DESC " |
- "LIMIT ?")); |
+ s1.Assign( |
+ db_->GetUniqueStatement("SELECT value FROM autofill " |
+ "WHERE name = ? AND " |
+ "value_lower >= ? AND " |
+ "value_lower < ? " |
+ "ORDER BY count DESC " |
+ "LIMIT ?")); |
s1.BindString16(0, name); |
s1.BindString16(1, prefix_lower); |
s1.BindString16(2, next_prefix); |
@@ -629,14 +631,12 @@ bool AutofillTable::RemoveFormElementsAddedBetween( |
AutofillUpdate updated_entry; |
updated_entry.name = name; |
updated_entry.value = value; |
- updated_entry.date_created = |
- date_created_time_t < delete_begin_time_t ? |
- date_created_time_t : |
- delete_end_time_t; |
- updated_entry.date_last_used = |
- date_last_used_time_t >= delete_end_time_t ? |
- date_last_used_time_t : |
- delete_begin_time_t - 1; |
+ updated_entry.date_created = date_created_time_t < delete_begin_time_t |
+ ? date_created_time_t |
+ : delete_end_time_t; |
+ updated_entry.date_last_used = date_last_used_time_t >= delete_end_time_t |
+ ? date_last_used_time_t |
+ : delete_begin_time_t - 1; |
updated_entry.count = |
1 + |
Round(1.0 * (count - 1) * |
@@ -663,8 +663,8 @@ bool AutofillTable::RemoveFormElementsAddedBetween( |
return false; |
for (size_t i = 0; i < updates.size(); ++i) { |
sql::Statement s_update(db_->GetUniqueStatement( |
- "UPDATE autofill SET date_created = ?, date_last_used = ?, count = ?" |
- "WHERE name = ? AND value = ?")); |
+ "UPDATE autofill SET date_created = ?, date_last_used = ?, count = ?" |
+ "WHERE name = ? AND value = ?")); |
s_update.BindInt64(0, updates[i].date_created); |
s_update.BindInt64(1, updates[i].date_last_used); |
s_update.BindInt(2, updates[i].count); |
@@ -701,8 +701,8 @@ bool AutofillTable::RemoveExpiredFormElements( |
if (!select_for_delete.Succeeded()) |
return false; |
- sql::Statement delete_data_statement(db_->GetUniqueStatement( |
- "DELETE FROM autofill WHERE date_last_used < ?")); |
+ sql::Statement delete_data_statement( |
+ db_->GetUniqueStatement("DELETE FROM autofill WHERE date_last_used < ?")); |
delete_data_statement.BindInt64(0, expiration_time.ToTimeT()); |
if (!delete_data_statement.Run()) |
return false; |
@@ -731,9 +731,8 @@ bool AutofillTable::AddFormFieldValuesTime( |
return result; |
} |
-int AutofillTable::GetCountOfValuesContainedBetween( |
- const Time& begin, |
- const Time& end) { |
+int AutofillTable::GetCountOfValuesContainedBetween(const Time& begin, |
+ const Time& end) { |
const time_t begin_time_t = begin.ToTimeT(); |
const time_t end_time_t = GetEndTime(end); |
@@ -875,7 +874,6 @@ bool AutofillTable::AddFormFieldValueTime(const FormFieldData& element, |
return true; |
} |
- |
bool AutofillTable::RemoveFormElement(const base::string16& name, |
const base::string16& value) { |
sql::Statement s(db_->GetUniqueStatement( |
@@ -937,10 +935,10 @@ bool AutofillTable::GetAutofillProfiles( |
DCHECK(profiles); |
profiles->clear(); |
- sql::Statement s(db_->GetUniqueStatement( |
- "SELECT guid " |
- "FROM autofill_profiles " |
- "ORDER BY date_modified DESC, guid")); |
+ sql::Statement s( |
+ db_->GetUniqueStatement("SELECT guid " |
+ "FROM autofill_profiles " |
+ "ORDER BY date_modified DESC, guid")); |
while (s.Step()) { |
std::string guid = s.ColumnString(0); |
@@ -1024,25 +1022,25 @@ void AutofillTable::SetServerProfiles( |
return; |
// Delete all old ones first. |
- sql::Statement delete_old(db_->GetUniqueStatement( |
- "DELETE FROM server_addresses")); |
+ sql::Statement delete_old( |
+ db_->GetUniqueStatement("DELETE FROM server_addresses")); |
delete_old.Run(); |
sql::Statement insert(db_->GetUniqueStatement( |
"INSERT INTO server_addresses(" |
- "id," |
- "recipient_name," |
- "company_name," |
- "street_address," |
- "address_1," // ADDRESS_HOME_STATE |
- "address_2," // ADDRESS_HOME_CITY |
- "address_3," // ADDRESS_HOME_DEPENDENT_LOCALITY |
- "address_4," // Not supported in AutofillProfile yet. |
- "postal_code," // ADDRESS_HOME_ZIP |
- "sorting_code," // ADDRESS_HOME_SORTING_CODE |
- "country_code," // ADDRESS_HOME_COUNTRY |
- "phone_number," // PHONE_HOME_WHOLE_NUMBER |
- "language_code) " |
+ "id," |
+ "recipient_name," |
+ "company_name," |
+ "street_address," |
+ "address_1," // ADDRESS_HOME_STATE |
+ "address_2," // ADDRESS_HOME_CITY |
+ "address_3," // ADDRESS_HOME_DEPENDENT_LOCALITY |
+ "address_4," // Not supported in AutofillProfile yet. |
+ "postal_code," // ADDRESS_HOME_ZIP |
+ "sorting_code," // ADDRESS_HOME_SORTING_CODE |
+ "country_code," // ADDRESS_HOME_COUNTRY |
+ "phone_number," // PHONE_HOME_WHOLE_NUMBER |
+ "language_code) " |
"VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)")); |
for (const auto& profile : profiles) { |
DCHECK(profile.record_type() == AutofillProfile::SERVER_PROFILE); |
@@ -1074,7 +1072,7 @@ void AutofillTable::SetServerProfiles( |
// Delete metadata that's no longer relevant. |
sql::Statement metadata_delete(db_->GetUniqueStatement( |
"DELETE FROM server_address_metadata WHERE id NOT IN " |
- "(SELECT id FROM server_addresses)")); |
+ "(SELECT id FROM server_addresses)")); |
metadata_delete.Run(); |
transaction.Commit(); |
@@ -1133,8 +1131,8 @@ bool AutofillTable::RemoveAutofillProfile(const std::string& guid) { |
return success; |
} |
- sql::Statement s(db_->GetUniqueStatement( |
- "DELETE FROM autofill_profiles WHERE guid = ?")); |
+ sql::Statement s( |
+ db_->GetUniqueStatement("DELETE FROM autofill_profiles WHERE guid = ?")); |
s.BindString(0, guid); |
if (!s.Run()) |
@@ -1144,26 +1142,25 @@ bool AutofillTable::RemoveAutofillProfile(const std::string& guid) { |
} |
bool AutofillTable::ClearAutofillProfiles() { |
- sql::Statement s1(db_->GetUniqueStatement( |
- "DELETE FROM autofill_profiles")); |
+ sql::Statement s1(db_->GetUniqueStatement("DELETE FROM autofill_profiles")); |
if (!s1.Run()) |
return false; |
- sql::Statement s2(db_->GetUniqueStatement( |
- "DELETE FROM autofill_profile_names")); |
+ sql::Statement s2( |
+ db_->GetUniqueStatement("DELETE FROM autofill_profile_names")); |
if (!s2.Run()) |
return false; |
- sql::Statement s3(db_->GetUniqueStatement( |
- "DELETE FROM autofill_profile_emails")); |
+ sql::Statement s3( |
+ db_->GetUniqueStatement("DELETE FROM autofill_profile_emails")); |
if (!s3.Run()) |
return false; |
- sql::Statement s4(db_->GetUniqueStatement( |
- "DELETE FROM autofill_profile_phones")); |
+ sql::Statement s4( |
+ db_->GetUniqueStatement("DELETE FROM autofill_profile_phones")); |
return s4.Run(); |
} |
@@ -1190,8 +1187,8 @@ std::unique_ptr<CreditCard> AutofillTable::GetCreditCard( |
DCHECK(base::IsValidGUID(guid)); |
sql::Statement s(db_->GetUniqueStatement( |
"SELECT guid, name_on_card, expiration_month, expiration_year, " |
- "card_number_encrypted, use_count, use_date, date_modified, " |
- "origin, billing_address_id " |
+ "card_number_encrypted, use_count, use_date, date_modified, " |
+ "origin, billing_address_id " |
"FROM credit_cards " |
"WHERE guid = ?")); |
s.BindString(0, guid); |
@@ -1207,10 +1204,10 @@ bool AutofillTable::GetCreditCards( |
DCHECK(credit_cards); |
credit_cards->clear(); |
- sql::Statement s(db_->GetUniqueStatement( |
- "SELECT guid " |
- "FROM credit_cards " |
- "ORDER BY date_modified DESC, guid")); |
+ sql::Statement s( |
+ db_->GetUniqueStatement("SELECT guid " |
+ "FROM credit_cards " |
+ "ORDER BY date_modified DESC, guid")); |
while (s.Step()) { |
std::string guid = s.ColumnString(0); |
@@ -1234,7 +1231,7 @@ bool AutofillTable::GetServerCreditCards( |
"masked.id," // 2 |
"metadata.use_count," // 3 |
"metadata.use_date," // 4 |
- "type," // 5 |
+ "network," // 5 |
"status," // 6 |
"name_on_card," // 7 |
"exp_month," // 8 |
@@ -1251,29 +1248,29 @@ bool AutofillTable::GetServerCreditCards( |
base::string16 full_card_number = |
UnencryptedCardFromColumn(s, index++, *autofill_table_encryptor_); |
base::string16 last_four = s.ColumnString16(index++); |
- CreditCard::RecordType record_type = full_card_number.empty() ? |
- CreditCard::MASKED_SERVER_CARD : |
- CreditCard::FULL_SERVER_CARD; |
+ CreditCard::RecordType record_type = full_card_number.empty() |
+ ? CreditCard::MASKED_SERVER_CARD |
+ : CreditCard::FULL_SERVER_CARD; |
std::string server_id = s.ColumnString(index++); |
std::unique_ptr<CreditCard> card = |
base::MakeUnique<CreditCard>(record_type, server_id); |
- card->SetRawInfo( |
- CREDIT_CARD_NUMBER, |
- record_type == CreditCard::MASKED_SERVER_CARD ? last_four |
- : full_card_number); |
+ card->SetRawInfo(CREDIT_CARD_NUMBER, |
+ record_type == CreditCard::MASKED_SERVER_CARD |
+ ? last_four |
+ : full_card_number); |
card->set_use_count(s.ColumnInt64(index++)); |
card->set_use_date(Time::FromInternalValue(s.ColumnInt64(index++))); |
// Modification date is not tracked for server cards. Explicitly set it here |
// to override the default value of AutofillClock::Now(). |
card->set_modification_date(Time()); |
- std::string card_type = s.ColumnString(index++); |
+ std::string card_network = s.ColumnString(index++); |
if (record_type == CreditCard::MASKED_SERVER_CARD) { |
- // The type must be set after setting the number to override the |
- // autodetected type. |
- card->SetTypeForMaskedCard(card_type.c_str()); |
+ // The issuer network must be set after setting the number to override the |
+ // autodetected issuer network. |
+ card->SetNetworkForMaskedCard(card_network.c_str()); |
} else { |
- DCHECK_EQ(CreditCard::GetCreditCardType(full_card_number), card_type); |
+ DCHECK_EQ(CreditCard::GetCardNetwork(full_card_number), card_network); |
} |
card->SetServerStatus(ServerStatusStringToEnum(s.ColumnString(index++))); |
@@ -1292,7 +1289,7 @@ void AutofillTable::AddMaskedCreditCards( |
sql::Statement masked_insert( |
db_->GetUniqueStatement("INSERT INTO masked_credit_cards(" |
"id," // 0 |
- "type," // 1 |
+ "network," // 1 |
"status," // 2 |
"name_on_card," // 3 |
"last_four," // 4 |
@@ -1302,7 +1299,7 @@ void AutofillTable::AddMaskedCreditCards( |
for (const CreditCard& card : credit_cards) { |
DCHECK_EQ(CreditCard::MASKED_SERVER_CARD, card.record_type()); |
masked_insert.BindString(0, card.server_id()); |
- masked_insert.BindString(1, card.type()); |
+ masked_insert.BindString(1, card.network()); |
masked_insert.BindString(2, |
ServerStatusEnumToString(card.GetServerStatus())); |
masked_insert.BindString16(3, card.GetRawInfo(CREDIT_CARD_NAME_FULL)); |
@@ -1335,12 +1332,12 @@ void AutofillTable::SetServerCreditCards( |
// Delete all items in the unmasked table that aren't in the new set. |
sql::Statement unmasked_delete(db_->GetUniqueStatement( |
"DELETE FROM unmasked_credit_cards WHERE id NOT IN " |
- "(SELECT id FROM masked_credit_cards)")); |
+ "(SELECT id FROM masked_credit_cards)")); |
unmasked_delete.Run(); |
// Do the same for metadata. |
sql::Statement metadata_delete(db_->GetUniqueStatement( |
"DELETE FROM server_card_metadata WHERE id NOT IN " |
- "(SELECT id FROM masked_credit_cards)")); |
+ "(SELECT id FROM masked_credit_cards)")); |
metadata_delete.Run(); |
transaction.Commit(); |
@@ -1363,7 +1360,7 @@ bool AutofillTable::AddFullServerCreditCard(const CreditCard& credit_card) { |
masked.set_record_type(CreditCard::MASKED_SERVER_CARD); |
masked.SetNumber(credit_card.LastFourDigits()); |
masked.RecordAndLogUse(); |
- DCHECK(!masked.type().empty()); |
+ DCHECK(!masked.network().empty()); |
AddMaskedCreditCards({masked}); |
AddUnmaskedCreditCard(credit_card.server_id(), credit_card.number()); |
@@ -1437,8 +1434,8 @@ bool AutofillTable::MaskServerCreditCard(const std::string& id) { |
bool AutofillTable::UpdateServerCardMetadata(const CreditCard& credit_card) { |
DCHECK_NE(CreditCard::LOCAL_CARD, credit_card.record_type()); |
- sql::Statement remove(db_->GetUniqueStatement( |
- "DELETE FROM server_card_metadata WHERE id = ?")); |
+ sql::Statement remove( |
+ db_->GetUniqueStatement("DELETE FROM server_card_metadata WHERE id = ?")); |
remove.BindString(0, credit_card.server_id()); |
remove.Run(); |
@@ -1490,28 +1487,28 @@ bool AutofillTable::ClearAllServerData() { |
if (!transaction.Begin()) |
return false; // Some error, nothing was changed. |
- sql::Statement masked(db_->GetUniqueStatement( |
- "DELETE FROM masked_credit_cards")); |
+ sql::Statement masked( |
+ db_->GetUniqueStatement("DELETE FROM masked_credit_cards")); |
masked.Run(); |
bool changed = db_->GetLastChangeCount() > 0; |
- sql::Statement unmasked(db_->GetUniqueStatement( |
- "DELETE FROM unmasked_credit_cards")); |
+ sql::Statement unmasked( |
+ db_->GetUniqueStatement("DELETE FROM unmasked_credit_cards")); |
unmasked.Run(); |
changed |= db_->GetLastChangeCount() > 0; |
- sql::Statement addresses(db_->GetUniqueStatement( |
- "DELETE FROM server_addresses")); |
+ sql::Statement addresses( |
+ db_->GetUniqueStatement("DELETE FROM server_addresses")); |
addresses.Run(); |
changed |= db_->GetLastChangeCount() > 0; |
- sql::Statement card_metadata(db_->GetUniqueStatement( |
- "DELETE FROM server_card_metadata")); |
+ sql::Statement card_metadata( |
+ db_->GetUniqueStatement("DELETE FROM server_card_metadata")); |
card_metadata.Run(); |
changed |= db_->GetLastChangeCount() > 0; |
- sql::Statement address_metadata(db_->GetUniqueStatement( |
- "DELETE FROM server_address_metadata")); |
+ sql::Statement address_metadata( |
+ db_->GetUniqueStatement("DELETE FROM server_address_metadata")); |
address_metadata.Run(); |
changed |= db_->GetLastChangeCount() > 0; |
@@ -1532,8 +1529,8 @@ bool AutofillTable::UpdateCreditCard(const CreditCard& credit_card) { |
sql::Statement s(db_->GetUniqueStatement( |
"UPDATE credit_cards " |
"SET guid=?, name_on_card=?, expiration_month=?," |
- "expiration_year=?, card_number_encrypted=?, use_count=?, use_date=?," |
- "date_modified=?, origin=?, billing_address_id=?" |
+ "expiration_year=?, card_number_encrypted=?, use_count=?, use_date=?," |
+ "date_modified=?, origin=?, billing_address_id=?" |
"WHERE guid=?1")); |
BindCreditCardToStatement(credit_card, |
update_modification_date |
@@ -1548,8 +1545,8 @@ bool AutofillTable::UpdateCreditCard(const CreditCard& credit_card) { |
bool AutofillTable::RemoveCreditCard(const std::string& guid) { |
DCHECK(base::IsValidGUID(guid)); |
- sql::Statement s(db_->GetUniqueStatement( |
- "DELETE FROM credit_cards WHERE guid = ?")); |
+ sql::Statement s( |
+ db_->GetUniqueStatement("DELETE FROM credit_cards WHERE guid = ?")); |
s.BindString(0, guid); |
return s.Run(); |
@@ -1615,9 +1612,9 @@ bool AutofillTable::RemoveAutofillDataModifiedBetween( |
return false; |
// Remove unmasked credit cards in the time range. |
- sql::Statement s_unmasked_cards(db_->GetUniqueStatement( |
- "DELETE FROM unmasked_credit_cards " |
- "WHERE unmask_date >= ? AND unmask_date < ?")); |
+ sql::Statement s_unmasked_cards( |
+ db_->GetUniqueStatement("DELETE FROM unmasked_credit_cards " |
+ "WHERE unmask_date >= ? AND unmask_date < ?")); |
s_unmasked_cards.BindInt64(0, delete_begin.ToInternalValue()); |
s_unmasked_cards.BindInt64(1, delete_end.ToInternalValue()); |
return s_unmasked_cards.Run(); |
@@ -1697,9 +1694,9 @@ bool AutofillTable::GetAutofillProfilesInTrash( |
std::vector<std::string>* guids) { |
guids->clear(); |
- sql::Statement s(db_->GetUniqueStatement( |
- "SELECT guid " |
- "FROM autofill_profiles_trash")); |
+ sql::Statement s( |
+ db_->GetUniqueStatement("SELECT guid " |
+ "FROM autofill_profiles_trash")); |
while (s.Step()) { |
std::string guid = s.ColumnString(0); |
@@ -1710,36 +1707,35 @@ bool AutofillTable::GetAutofillProfilesInTrash( |
} |
bool AutofillTable::EmptyAutofillProfilesTrash() { |
- sql::Statement s(db_->GetUniqueStatement( |
- "DELETE FROM autofill_profiles_trash")); |
+ sql::Statement s( |
+ db_->GetUniqueStatement("DELETE FROM autofill_profiles_trash")); |
return s.Run(); |
} |
- |
bool AutofillTable::AddAutofillGUIDToTrash(const std::string& guid) { |
- sql::Statement s(db_->GetUniqueStatement( |
- "INSERT INTO autofill_profiles_trash" |
- " (guid) " |
- "VALUES (?)")); |
+ sql::Statement s( |
+ db_->GetUniqueStatement("INSERT INTO autofill_profiles_trash" |
+ " (guid) " |
+ "VALUES (?)")); |
s.BindString(0, guid); |
return s.Run(); |
} |
bool AutofillTable::IsAutofillProfilesTrashEmpty() { |
- sql::Statement s(db_->GetUniqueStatement( |
- "SELECT guid " |
- "FROM autofill_profiles_trash")); |
+ sql::Statement s( |
+ db_->GetUniqueStatement("SELECT guid " |
+ "FROM autofill_profiles_trash")); |
return !s.Step(); |
} |
bool AutofillTable::IsAutofillGUIDInTrash(const std::string& guid) { |
- sql::Statement s(db_->GetUniqueStatement( |
- "SELECT guid " |
- "FROM autofill_profiles_trash " |
- "WHERE guid = ?")); |
+ sql::Statement s( |
+ db_->GetUniqueStatement("SELECT guid " |
+ "FROM autofill_profiles_trash " |
+ "WHERE guid = ?")); |
s.BindString(0, guid); |
return s.Step(); |
@@ -1872,8 +1868,8 @@ bool AutofillTable::InitMainTable() { |
!db_->Execute("CREATE INDEX autofill_name ON autofill (name)") || |
!db_->Execute("CREATE INDEX autofill_name_value_lower ON " |
"autofill (name, value_lower)")) { |
- NOTREACHED(); |
- return false; |
+ NOTREACHED(); |
+ return false; |
} |
} |
return true; |
@@ -1980,7 +1976,7 @@ bool AutofillTable::InitMaskedCreditCardsTable() { |
"id VARCHAR," |
"status VARCHAR," |
"name_on_card VARCHAR," |
- "type VARCHAR," |
+ "network VARCHAR," |
"last_four VARCHAR," |
"exp_month INTEGER DEFAULT 0," |
"exp_year INTEGER DEFAULT 0)")) { |
@@ -2035,7 +2031,7 @@ bool AutofillTable::InitServerAddressesTable() { |
"postal_code VARCHAR," |
"sorting_code VARCHAR," |
"country_code VARCHAR," |
- "language_code VARCHAR, " // Space required. |
+ "language_code VARCHAR, " // Space required. |
"recipient_name VARCHAR, " // Ditto. |
"phone_number VARCHAR)")) { |
NOTREACHED(); |
@@ -2243,18 +2239,19 @@ bool AutofillTable::MigrateToVersion55MergeAutofillDatesTable() { |
return false; |
} |
- |
return transaction.Commit(); |
} |
bool AutofillTable::MigrateToVersion56AddProfileLanguageCodeForFormatting() { |
- return db_->Execute("ALTER TABLE autofill_profiles " |
- "ADD COLUMN language_code VARCHAR"); |
+ return db_->Execute( |
+ "ALTER TABLE autofill_profiles " |
+ "ADD COLUMN language_code VARCHAR"); |
Peter Kasting
2017/04/26 01:27:28
Nit: This all fits on one line now (two places)
please use gerrit instead
2017/04/26 16:34:15
Done.
|
} |
bool AutofillTable::MigrateToVersion57AddFullNameField() { |
- return db_->Execute("ALTER TABLE autofill_profile_names " |
- "ADD COLUMN full_name VARCHAR"); |
+ return db_->Execute( |
+ "ALTER TABLE autofill_profile_names " |
+ "ADD COLUMN full_name VARCHAR"); |
} |
bool AutofillTable::MigrateToVersion60AddServerCards() { |
@@ -2418,25 +2415,25 @@ bool AutofillTable::MigrateToVersion65AddServerMetadataTables() { |
// Get existing server addresses and generate IDs for them. |
sql::Statement s(db_->GetUniqueStatement( |
"SELECT " |
- "id," |
- "recipient_name," |
- "company_name," |
- "street_address," |
- "address_1," // ADDRESS_HOME_STATE |
- "address_2," // ADDRESS_HOME_CITY |
- "address_3," // ADDRESS_HOME_DEPENDENT_LOCALITY |
- "address_4," // Not supported in AutofillProfile yet. |
- "postal_code," // ADDRESS_HOME_ZIP |
- "sorting_code," // ADDRESS_HOME_SORTING_CODE |
- "country_code," // ADDRESS_HOME_COUNTRY |
- "phone_number," // PHONE_HOME_WHOLE_NUMBER |
- "language_code " |
+ "id," |
+ "recipient_name," |
+ "company_name," |
+ "street_address," |
+ "address_1," // ADDRESS_HOME_STATE |
+ "address_2," // ADDRESS_HOME_CITY |
+ "address_3," // ADDRESS_HOME_DEPENDENT_LOCALITY |
+ "address_4," // Not supported in AutofillProfile yet. |
+ "postal_code," // ADDRESS_HOME_ZIP |
+ "sorting_code," // ADDRESS_HOME_SORTING_CODE |
+ "country_code," // ADDRESS_HOME_COUNTRY |
+ "phone_number," // PHONE_HOME_WHOLE_NUMBER |
+ "language_code " |
"FROM server_addresses addresses")); |
std::vector<AutofillProfile> profiles; |
while (s.Step()) { |
int index = 0; |
- AutofillProfile profile( |
- AutofillProfile::SERVER_PROFILE, s.ColumnString(index++)); |
+ AutofillProfile profile(AutofillProfile::SERVER_PROFILE, |
+ s.ColumnString(index++)); |
base::string16 recipient_name = s.ColumnString16(index++); |
profile.SetRawInfo(COMPANY_NAME, s.ColumnString16(index++)); |
@@ -2460,25 +2457,25 @@ bool AutofillTable::MigrateToVersion65AddServerMetadataTables() { |
} |
// Reinsert with the generated IDs. |
- sql::Statement delete_old(db_->GetUniqueStatement( |
- "DELETE FROM server_addresses")); |
+ sql::Statement delete_old( |
+ db_->GetUniqueStatement("DELETE FROM server_addresses")); |
delete_old.Run(); |
sql::Statement insert(db_->GetUniqueStatement( |
"INSERT INTO server_addresses(" |
- "id," |
- "recipient_name," |
- "company_name," |
- "street_address," |
- "address_1," // ADDRESS_HOME_STATE |
- "address_2," // ADDRESS_HOME_CITY |
- "address_3," // ADDRESS_HOME_DEPENDENT_LOCALITY |
- "address_4," // Not supported in AutofillProfile yet. |
- "postal_code," // ADDRESS_HOME_ZIP |
- "sorting_code," // ADDRESS_HOME_SORTING_CODE |
- "country_code," // ADDRESS_HOME_COUNTRY |
- "phone_number," // PHONE_HOME_WHOLE_NUMBER |
- "language_code) " |
+ "id," |
+ "recipient_name," |
+ "company_name," |
+ "street_address," |
+ "address_1," // ADDRESS_HOME_STATE |
+ "address_2," // ADDRESS_HOME_CITY |
+ "address_3," // ADDRESS_HOME_DEPENDENT_LOCALITY |
+ "address_4," // Not supported in AutofillProfile yet. |
+ "postal_code," // ADDRESS_HOME_ZIP |
+ "sorting_code," // ADDRESS_HOME_SORTING_CODE |
+ "country_code," // ADDRESS_HOME_COUNTRY |
+ "phone_number," // PHONE_HOME_WHOLE_NUMBER |
+ "language_code) " |
"VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)")); |
for (const AutofillProfile& profile : profiles) { |
int index = 0; |
@@ -2591,4 +2588,38 @@ bool AutofillTable:: |
return transaction.Commit(); |
} |
+bool AutofillTable::MigrateToVersion72RenameCardTypeToIssuerNetwork() { |
+ sql::Transaction transaction(db_); |
+ if (!transaction.Begin()) |
+ return false; |
+ |
+ if (db_->DoesTableExist("masked_credit_cards_temp") || |
Peter Kasting
2017/04/26 01:27:28
It seems like if this table exists, it will block
please use gerrit instead
2017/04/26 16:34:15
Good point. Fixed in both places.
|
+ !db_->Execute("CREATE TABLE masked_credit_cards_temp (" |
+ "id VARCHAR," |
+ "status VARCHAR," |
+ "name_on_card VARCHAR," |
+ "network VARCHAR," |
+ "last_four VARCHAR," |
+ "exp_month INTEGER DEFAULT 0," |
+ "exp_year INTEGER DEFAULT 0)")) { |
+ return false; |
+ } |
+ if (!db_->Execute("INSERT INTO masked_credit_cards_temp " |
+ "(id, status, name_on_card, network, last_four, " |
+ "exp_month, exp_year) " |
+ "SELECT id, status, name_on_card, type, last_four, " |
+ "exp_month, exp_year " |
+ "FROM masked_credit_cards")) { |
+ return false; |
+ } |
+ if (!db_->Execute("DROP TABLE masked_credit_cards")) |
+ return false; |
+ if (!db_->Execute("ALTER TABLE masked_credit_cards_temp " |
+ "RENAME TO masked_credit_cards")) { |
+ return false; |
+ } |
+ |
+ return transaction.Commit(); |
Peter Kasting
2017/04/26 01:27:28
Nit: Up to you, but you could also write this sort
please use gerrit instead
2017/04/26 16:34:15
Done.
|
+} |
+ |
} // namespace autofill |