OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/autofill_table.h" | 5 #include "chrome/browser/webdata/autofill_table.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
| 14 #include "base/guid.h" |
14 #include "base/i18n/case_conversion.h" | 15 #include "base/i18n/case_conversion.h" |
15 #include "base/logging.h" | 16 #include "base/logging.h" |
16 #include "base/string_number_conversions.h" | 17 #include "base/string_number_conversions.h" |
17 #include "base/time.h" | 18 #include "base/time.h" |
18 #include "base/tuple.h" | 19 #include "base/tuple.h" |
19 #include "chrome/browser/autofill/autofill_country.h" | 20 #include "chrome/browser/autofill/autofill_country.h" |
20 #include "chrome/browser/autofill/autofill_profile.h" | 21 #include "chrome/browser/autofill/autofill_profile.h" |
21 #include "chrome/browser/autofill/autofill_type.h" | 22 #include "chrome/browser/autofill/autofill_type.h" |
22 #include "chrome/browser/autofill/credit_card.h" | 23 #include "chrome/browser/autofill/credit_card.h" |
23 #include "chrome/browser/autofill/personal_data_manager.h" | 24 #include "chrome/browser/autofill/personal_data_manager.h" |
24 #include "chrome/browser/password_manager/encryptor.h" | 25 #include "chrome/browser/password_manager/encryptor.h" |
25 #include "chrome/browser/webdata/autofill_change.h" | 26 #include "chrome/browser/webdata/autofill_change.h" |
26 #include "chrome/browser/webdata/autofill_entry.h" | 27 #include "chrome/browser/webdata/autofill_entry.h" |
27 #include "chrome/common/guid.h" | |
28 #include "sql/statement.h" | 28 #include "sql/statement.h" |
29 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
30 #include "webkit/forms/form_field.h" | 30 #include "webkit/forms/form_field.h" |
31 | 31 |
32 using base::Time; | 32 using base::Time; |
33 using webkit::forms::FormField; | 33 using webkit::forms::FormField; |
34 | 34 |
35 namespace { | 35 namespace { |
36 | 36 |
37 typedef std::vector<Tuple3<int64, string16, string16> > AutofillElementList; | 37 typedef std::vector<Tuple3<int64, string16, string16> > AutofillElementList; |
38 | 38 |
39 // TODO(dhollowa): Find a common place for this. It is duplicated in | 39 // TODO(dhollowa): Find a common place for this. It is duplicated in |
40 // personal_data_manager.cc. | 40 // personal_data_manager.cc. |
41 template<typename T> | 41 template<typename T> |
42 T* address_of(T& v) { | 42 T* address_of(T& v) { |
43 return &v; | 43 return &v; |
44 } | 44 } |
45 | 45 |
46 string16 LimitDataSize(const string16& data) { | 46 string16 LimitDataSize(const string16& data) { |
47 if (data.size() > AutofillTable::kMaxDataLength) | 47 if (data.size() > AutofillTable::kMaxDataLength) |
48 return data.substr(0, AutofillTable::kMaxDataLength); | 48 return data.substr(0, AutofillTable::kMaxDataLength); |
49 | 49 |
50 return data; | 50 return data; |
51 } | 51 } |
52 | 52 |
53 void BindAutofillProfileToStatement(const AutofillProfile& profile, | 53 void BindAutofillProfileToStatement(const AutofillProfile& profile, |
54 sql::Statement* s) { | 54 sql::Statement* s) { |
55 DCHECK(guid::IsValidGUID(profile.guid())); | 55 DCHECK(base::IsValidGUID(profile.guid())); |
56 s->BindString(0, profile.guid()); | 56 s->BindString(0, profile.guid()); |
57 | 57 |
58 string16 text = profile.GetInfo(COMPANY_NAME); | 58 string16 text = profile.GetInfo(COMPANY_NAME); |
59 s->BindString16(1, LimitDataSize(text)); | 59 s->BindString16(1, LimitDataSize(text)); |
60 text = profile.GetInfo(ADDRESS_HOME_LINE1); | 60 text = profile.GetInfo(ADDRESS_HOME_LINE1); |
61 s->BindString16(2, LimitDataSize(text)); | 61 s->BindString16(2, LimitDataSize(text)); |
62 text = profile.GetInfo(ADDRESS_HOME_LINE2); | 62 text = profile.GetInfo(ADDRESS_HOME_LINE2); |
63 s->BindString16(3, LimitDataSize(text)); | 63 s->BindString16(3, LimitDataSize(text)); |
64 text = profile.GetInfo(ADDRESS_HOME_CITY); | 64 text = profile.GetInfo(ADDRESS_HOME_CITY); |
65 s->BindString16(4, LimitDataSize(text)); | 65 s->BindString16(4, LimitDataSize(text)); |
66 text = profile.GetInfo(ADDRESS_HOME_STATE); | 66 text = profile.GetInfo(ADDRESS_HOME_STATE); |
67 s->BindString16(5, LimitDataSize(text)); | 67 s->BindString16(5, LimitDataSize(text)); |
68 text = profile.GetInfo(ADDRESS_HOME_ZIP); | 68 text = profile.GetInfo(ADDRESS_HOME_ZIP); |
69 s->BindString16(6, LimitDataSize(text)); | 69 s->BindString16(6, LimitDataSize(text)); |
70 text = profile.GetInfo(ADDRESS_HOME_COUNTRY); | 70 text = profile.GetInfo(ADDRESS_HOME_COUNTRY); |
71 s->BindString16(7, LimitDataSize(text)); | 71 s->BindString16(7, LimitDataSize(text)); |
72 std::string country_code = profile.CountryCode(); | 72 std::string country_code = profile.CountryCode(); |
73 s->BindString(8, country_code); | 73 s->BindString(8, country_code); |
74 s->BindInt64(9, Time::Now().ToTimeT()); | 74 s->BindInt64(9, Time::Now().ToTimeT()); |
75 } | 75 } |
76 | 76 |
77 AutofillProfile* AutofillProfileFromStatement(const sql::Statement& s) { | 77 AutofillProfile* AutofillProfileFromStatement(const sql::Statement& s) { |
78 AutofillProfile* profile = new AutofillProfile; | 78 AutofillProfile* profile = new AutofillProfile; |
79 profile->set_guid(s.ColumnString(0)); | 79 profile->set_guid(s.ColumnString(0)); |
80 DCHECK(guid::IsValidGUID(profile->guid())); | 80 DCHECK(base::IsValidGUID(profile->guid())); |
81 | 81 |
82 profile->SetInfo(COMPANY_NAME, s.ColumnString16(1)); | 82 profile->SetInfo(COMPANY_NAME, s.ColumnString16(1)); |
83 profile->SetInfo(ADDRESS_HOME_LINE1, s.ColumnString16(2)); | 83 profile->SetInfo(ADDRESS_HOME_LINE1, s.ColumnString16(2)); |
84 profile->SetInfo(ADDRESS_HOME_LINE2, s.ColumnString16(3)); | 84 profile->SetInfo(ADDRESS_HOME_LINE2, s.ColumnString16(3)); |
85 profile->SetInfo(ADDRESS_HOME_CITY, s.ColumnString16(4)); | 85 profile->SetInfo(ADDRESS_HOME_CITY, s.ColumnString16(4)); |
86 profile->SetInfo(ADDRESS_HOME_STATE, s.ColumnString16(5)); | 86 profile->SetInfo(ADDRESS_HOME_STATE, s.ColumnString16(5)); |
87 profile->SetInfo(ADDRESS_HOME_ZIP, s.ColumnString16(6)); | 87 profile->SetInfo(ADDRESS_HOME_ZIP, s.ColumnString16(6)); |
88 // Intentionally skip column 7, which stores the localized country name. | 88 // Intentionally skip column 7, which stores the localized country name. |
89 profile->SetCountryCode(s.ColumnString(8)); | 89 profile->SetCountryCode(s.ColumnString(8)); |
90 // Intentionally skip column 9, which stores the profile's modification date. | 90 // Intentionally skip column 9, which stores the profile's modification date. |
91 | 91 |
92 return profile; | 92 return profile; |
93 } | 93 } |
94 | 94 |
95 void BindCreditCardToStatement(const CreditCard& credit_card, | 95 void BindCreditCardToStatement(const CreditCard& credit_card, |
96 sql::Statement* s) { | 96 sql::Statement* s) { |
97 DCHECK(guid::IsValidGUID(credit_card.guid())); | 97 DCHECK(base::IsValidGUID(credit_card.guid())); |
98 s->BindString(0, credit_card.guid()); | 98 s->BindString(0, credit_card.guid()); |
99 | 99 |
100 string16 text = credit_card.GetInfo(CREDIT_CARD_NAME); | 100 string16 text = credit_card.GetInfo(CREDIT_CARD_NAME); |
101 s->BindString16(1, LimitDataSize(text)); | 101 s->BindString16(1, LimitDataSize(text)); |
102 text = credit_card.GetInfo(CREDIT_CARD_EXP_MONTH); | 102 text = credit_card.GetInfo(CREDIT_CARD_EXP_MONTH); |
103 s->BindString16(2, LimitDataSize(text)); | 103 s->BindString16(2, LimitDataSize(text)); |
104 text = credit_card.GetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR); | 104 text = credit_card.GetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR); |
105 s->BindString16(3, LimitDataSize(text)); | 105 s->BindString16(3, LimitDataSize(text)); |
106 text = credit_card.GetInfo(CREDIT_CARD_NUMBER); | 106 text = credit_card.GetInfo(CREDIT_CARD_NUMBER); |
107 std::string encrypted_data; | 107 std::string encrypted_data; |
108 Encryptor::EncryptString16(text, &encrypted_data); | 108 Encryptor::EncryptString16(text, &encrypted_data); |
109 s->BindBlob(4, encrypted_data.data(), | 109 s->BindBlob(4, encrypted_data.data(), |
110 static_cast<int>(encrypted_data.length())); | 110 static_cast<int>(encrypted_data.length())); |
111 s->BindInt64(5, Time::Now().ToTimeT()); | 111 s->BindInt64(5, Time::Now().ToTimeT()); |
112 } | 112 } |
113 | 113 |
114 CreditCard* CreditCardFromStatement(const sql::Statement& s) { | 114 CreditCard* CreditCardFromStatement(const sql::Statement& s) { |
115 CreditCard* credit_card = new CreditCard; | 115 CreditCard* credit_card = new CreditCard; |
116 | 116 |
117 credit_card->set_guid(s.ColumnString(0)); | 117 credit_card->set_guid(s.ColumnString(0)); |
118 DCHECK(guid::IsValidGUID(credit_card->guid())); | 118 DCHECK(base::IsValidGUID(credit_card->guid())); |
119 | 119 |
120 credit_card->SetInfo(CREDIT_CARD_NAME, s.ColumnString16(1)); | 120 credit_card->SetInfo(CREDIT_CARD_NAME, s.ColumnString16(1)); |
121 credit_card->SetInfo(CREDIT_CARD_EXP_MONTH, s.ColumnString16(2)); | 121 credit_card->SetInfo(CREDIT_CARD_EXP_MONTH, s.ColumnString16(2)); |
122 credit_card->SetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, s.ColumnString16(3)); | 122 credit_card->SetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, s.ColumnString16(3)); |
123 int encrypted_number_len = s.ColumnByteLength(4); | 123 int encrypted_number_len = s.ColumnByteLength(4); |
124 string16 credit_card_number; | 124 string16 credit_card_number; |
125 if (encrypted_number_len) { | 125 if (encrypted_number_len) { |
126 std::string encrypted_number; | 126 std::string encrypted_number; |
127 encrypted_number.resize(encrypted_number_len); | 127 encrypted_number.resize(encrypted_number_len); |
128 memcpy(&encrypted_number[0], s.ColumnBlob(4), encrypted_number_len); | 128 memcpy(&encrypted_number[0], s.ColumnBlob(4), encrypted_number_len); |
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 BindAutofillProfileToStatement(profile, &s); | 875 BindAutofillProfileToStatement(profile, &s); |
876 | 876 |
877 if (!s.Run()) | 877 if (!s.Run()) |
878 return false; | 878 return false; |
879 | 879 |
880 return AddAutofillProfilePieces(profile, db_); | 880 return AddAutofillProfilePieces(profile, db_); |
881 } | 881 } |
882 | 882 |
883 bool AutofillTable::GetAutofillProfile(const std::string& guid, | 883 bool AutofillTable::GetAutofillProfile(const std::string& guid, |
884 AutofillProfile** profile) { | 884 AutofillProfile** profile) { |
885 DCHECK(guid::IsValidGUID(guid)); | 885 DCHECK(base::IsValidGUID(guid)); |
886 DCHECK(profile); | 886 DCHECK(profile); |
887 sql::Statement s(db_->GetUniqueStatement( | 887 sql::Statement s(db_->GetUniqueStatement( |
888 "SELECT guid, company_name, address_line_1, address_line_2, city, state," | 888 "SELECT guid, company_name, address_line_1, address_line_2, city, state," |
889 " zipcode, country, country_code, date_modified " | 889 " zipcode, country, country_code, date_modified " |
890 "FROM autofill_profiles " | 890 "FROM autofill_profiles " |
891 "WHERE guid=?")); | 891 "WHERE guid=?")); |
892 s.BindString(0, guid); | 892 s.BindString(0, guid); |
893 | 893 |
894 if (!s.Step()) | 894 if (!s.Step()) |
895 return false; | 895 return false; |
(...skipping 27 matching lines...) Expand all Loading... |
923 AutofillProfile* profile = NULL; | 923 AutofillProfile* profile = NULL; |
924 if (!GetAutofillProfile(guid, &profile)) | 924 if (!GetAutofillProfile(guid, &profile)) |
925 return false; | 925 return false; |
926 profiles->push_back(profile); | 926 profiles->push_back(profile); |
927 } | 927 } |
928 | 928 |
929 return s.Succeeded(); | 929 return s.Succeeded(); |
930 } | 930 } |
931 | 931 |
932 bool AutofillTable::UpdateAutofillProfile(const AutofillProfile& profile) { | 932 bool AutofillTable::UpdateAutofillProfile(const AutofillProfile& profile) { |
933 DCHECK(guid::IsValidGUID(profile.guid())); | 933 DCHECK(base::IsValidGUID(profile.guid())); |
934 | 934 |
935 // Don't update anything until the trash has been emptied. There may be | 935 // Don't update anything until the trash has been emptied. There may be |
936 // pending modifications to process. | 936 // pending modifications to process. |
937 if (!IsAutofillProfilesTrashEmpty()) | 937 if (!IsAutofillProfilesTrashEmpty()) |
938 return true; | 938 return true; |
939 | 939 |
940 AutofillProfile* tmp_profile = NULL; | 940 AutofillProfile* tmp_profile = NULL; |
941 if (!GetAutofillProfile(profile.guid(), &tmp_profile)) | 941 if (!GetAutofillProfile(profile.guid(), &tmp_profile)) |
942 return false; | 942 return false; |
943 | 943 |
(...skipping 14 matching lines...) Expand all Loading... |
958 new_profile.SetMultiInfo(EMAIL_ADDRESS, values); | 958 new_profile.SetMultiInfo(EMAIL_ADDRESS, values); |
959 | 959 |
960 old_profile->GetMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values); | 960 old_profile->GetMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values); |
961 values[0] = new_profile.GetInfo(PHONE_HOME_WHOLE_NUMBER); | 961 values[0] = new_profile.GetInfo(PHONE_HOME_WHOLE_NUMBER); |
962 new_profile.SetMultiInfo(PHONE_HOME_WHOLE_NUMBER, values); | 962 new_profile.SetMultiInfo(PHONE_HOME_WHOLE_NUMBER, values); |
963 | 963 |
964 return UpdateAutofillProfileMulti(new_profile); | 964 return UpdateAutofillProfileMulti(new_profile); |
965 } | 965 } |
966 | 966 |
967 bool AutofillTable::UpdateAutofillProfileMulti(const AutofillProfile& profile) { | 967 bool AutofillTable::UpdateAutofillProfileMulti(const AutofillProfile& profile) { |
968 DCHECK(guid::IsValidGUID(profile.guid())); | 968 DCHECK(base::IsValidGUID(profile.guid())); |
969 | 969 |
970 // Don't update anything until the trash has been emptied. There may be | 970 // Don't update anything until the trash has been emptied. There may be |
971 // pending modifications to process. | 971 // pending modifications to process. |
972 if (!IsAutofillProfilesTrashEmpty()) | 972 if (!IsAutofillProfilesTrashEmpty()) |
973 return true; | 973 return true; |
974 | 974 |
975 AutofillProfile* tmp_profile = NULL; | 975 AutofillProfile* tmp_profile = NULL; |
976 if (!GetAutofillProfile(profile.guid(), &tmp_profile)) | 976 if (!GetAutofillProfile(profile.guid(), &tmp_profile)) |
977 return false; | 977 return false; |
978 | 978 |
(...skipping 17 matching lines...) Expand all Loading... |
996 return result; | 996 return result; |
997 | 997 |
998 // Remove the old names, emails, and phone numbers. | 998 // Remove the old names, emails, and phone numbers. |
999 if (!RemoveAutofillProfilePieces(profile.guid(), db_)) | 999 if (!RemoveAutofillProfilePieces(profile.guid(), db_)) |
1000 return false; | 1000 return false; |
1001 | 1001 |
1002 return AddAutofillProfilePieces(profile, db_); | 1002 return AddAutofillProfilePieces(profile, db_); |
1003 } | 1003 } |
1004 | 1004 |
1005 bool AutofillTable::RemoveAutofillProfile(const std::string& guid) { | 1005 bool AutofillTable::RemoveAutofillProfile(const std::string& guid) { |
1006 DCHECK(guid::IsValidGUID(guid)); | 1006 DCHECK(base::IsValidGUID(guid)); |
1007 | 1007 |
1008 if (IsAutofillGUIDInTrash(guid)) { | 1008 if (IsAutofillGUIDInTrash(guid)) { |
1009 sql::Statement s_trash(db_->GetUniqueStatement( | 1009 sql::Statement s_trash(db_->GetUniqueStatement( |
1010 "DELETE FROM autofill_profiles_trash WHERE guid = ?")); | 1010 "DELETE FROM autofill_profiles_trash WHERE guid = ?")); |
1011 s_trash.BindString(0, guid); | 1011 s_trash.BindString(0, guid); |
1012 | 1012 |
1013 bool success = s_trash.Run(); | 1013 bool success = s_trash.Run(); |
1014 DCHECK_GT(db_->GetLastChangeCount(), 0) << "Expected item in trash"; | 1014 DCHECK_GT(db_->GetLastChangeCount(), 0) << "Expected item in trash"; |
1015 return success; | 1015 return success; |
1016 } | 1016 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1060 | 1060 |
1061 if (!s.Run()) | 1061 if (!s.Run()) |
1062 return false; | 1062 return false; |
1063 | 1063 |
1064 DCHECK_GT(db_->GetLastChangeCount(), 0); | 1064 DCHECK_GT(db_->GetLastChangeCount(), 0); |
1065 return true; | 1065 return true; |
1066 } | 1066 } |
1067 | 1067 |
1068 bool AutofillTable::GetCreditCard(const std::string& guid, | 1068 bool AutofillTable::GetCreditCard(const std::string& guid, |
1069 CreditCard** credit_card) { | 1069 CreditCard** credit_card) { |
1070 DCHECK(guid::IsValidGUID(guid)); | 1070 DCHECK(base::IsValidGUID(guid)); |
1071 sql::Statement s(db_->GetUniqueStatement( | 1071 sql::Statement s(db_->GetUniqueStatement( |
1072 "SELECT guid, name_on_card, expiration_month, expiration_year, " | 1072 "SELECT guid, name_on_card, expiration_month, expiration_year, " |
1073 "card_number_encrypted, date_modified " | 1073 "card_number_encrypted, date_modified " |
1074 "FROM credit_cards " | 1074 "FROM credit_cards " |
1075 "WHERE guid = ?")); | 1075 "WHERE guid = ?")); |
1076 s.BindString(0, guid); | 1076 s.BindString(0, guid); |
1077 | 1077 |
1078 if (!s.Step()) | 1078 if (!s.Step()) |
1079 return false; | 1079 return false; |
1080 | 1080 |
(...skipping 15 matching lines...) Expand all Loading... |
1096 CreditCard* credit_card = NULL; | 1096 CreditCard* credit_card = NULL; |
1097 if (!GetCreditCard(guid, &credit_card)) | 1097 if (!GetCreditCard(guid, &credit_card)) |
1098 return false; | 1098 return false; |
1099 credit_cards->push_back(credit_card); | 1099 credit_cards->push_back(credit_card); |
1100 } | 1100 } |
1101 | 1101 |
1102 return s.Succeeded(); | 1102 return s.Succeeded(); |
1103 } | 1103 } |
1104 | 1104 |
1105 bool AutofillTable::UpdateCreditCard(const CreditCard& credit_card) { | 1105 bool AutofillTable::UpdateCreditCard(const CreditCard& credit_card) { |
1106 DCHECK(guid::IsValidGUID(credit_card.guid())); | 1106 DCHECK(base::IsValidGUID(credit_card.guid())); |
1107 | 1107 |
1108 CreditCard* tmp_credit_card = NULL; | 1108 CreditCard* tmp_credit_card = NULL; |
1109 if (!GetCreditCard(credit_card.guid(), &tmp_credit_card)) | 1109 if (!GetCreditCard(credit_card.guid(), &tmp_credit_card)) |
1110 return false; | 1110 return false; |
1111 | 1111 |
1112 // Preserve appropriate modification dates by not updating unchanged cards. | 1112 // Preserve appropriate modification dates by not updating unchanged cards. |
1113 scoped_ptr<CreditCard> old_credit_card(tmp_credit_card); | 1113 scoped_ptr<CreditCard> old_credit_card(tmp_credit_card); |
1114 if (*old_credit_card == credit_card) | 1114 if (*old_credit_card == credit_card) |
1115 return true; | 1115 return true; |
1116 | 1116 |
1117 sql::Statement s(db_->GetUniqueStatement( | 1117 sql::Statement s(db_->GetUniqueStatement( |
1118 "UPDATE credit_cards " | 1118 "UPDATE credit_cards " |
1119 "SET guid=?, name_on_card=?, expiration_month=?, " | 1119 "SET guid=?, name_on_card=?, expiration_month=?, " |
1120 " expiration_year=?, card_number_encrypted=?, date_modified=? " | 1120 " expiration_year=?, card_number_encrypted=?, date_modified=? " |
1121 "WHERE guid=?")); | 1121 "WHERE guid=?")); |
1122 BindCreditCardToStatement(credit_card, &s); | 1122 BindCreditCardToStatement(credit_card, &s); |
1123 s.BindString(6, credit_card.guid()); | 1123 s.BindString(6, credit_card.guid()); |
1124 | 1124 |
1125 bool result = s.Run(); | 1125 bool result = s.Run(); |
1126 DCHECK_GT(db_->GetLastChangeCount(), 0); | 1126 DCHECK_GT(db_->GetLastChangeCount(), 0); |
1127 return result; | 1127 return result; |
1128 } | 1128 } |
1129 | 1129 |
1130 bool AutofillTable::RemoveCreditCard(const std::string& guid) { | 1130 bool AutofillTable::RemoveCreditCard(const std::string& guid) { |
1131 DCHECK(guid::IsValidGUID(guid)); | 1131 DCHECK(base::IsValidGUID(guid)); |
1132 sql::Statement s(db_->GetUniqueStatement( | 1132 sql::Statement s(db_->GetUniqueStatement( |
1133 "DELETE FROM credit_cards WHERE guid = ?")); | 1133 "DELETE FROM credit_cards WHERE guid = ?")); |
1134 s.BindString(0, guid); | 1134 s.BindString(0, guid); |
1135 | 1135 |
1136 return s.Run(); | 1136 return s.Run(); |
1137 } | 1137 } |
1138 | 1138 |
1139 bool AutofillTable::RemoveAutofillProfilesAndCreditCardsModifiedBetween( | 1139 bool AutofillTable::RemoveAutofillProfilesAndCreditCardsModifiedBetween( |
1140 const Time& delete_begin, | 1140 const Time& delete_begin, |
1141 const Time& delete_end, | 1141 const Time& delete_end, |
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1634 | 1634 |
1635 // Set all the |guid| fields to valid values. | 1635 // Set all the |guid| fields to valid values. |
1636 | 1636 |
1637 sql::Statement s(db_->GetUniqueStatement("SELECT unique_id " | 1637 sql::Statement s(db_->GetUniqueStatement("SELECT unique_id " |
1638 "FROM autofill_profiles")); | 1638 "FROM autofill_profiles")); |
1639 | 1639 |
1640 while (s.Step()) { | 1640 while (s.Step()) { |
1641 sql::Statement update_s( | 1641 sql::Statement update_s( |
1642 db_->GetUniqueStatement("UPDATE autofill_profiles " | 1642 db_->GetUniqueStatement("UPDATE autofill_profiles " |
1643 "SET guid=? WHERE unique_id=?")); | 1643 "SET guid=? WHERE unique_id=?")); |
1644 update_s.BindString(0, guid::GenerateGUID()); | 1644 update_s.BindString(0, base::GenerateGUID()); |
1645 update_s.BindInt(1, s.ColumnInt(0)); | 1645 update_s.BindInt(1, s.ColumnInt(0)); |
1646 | 1646 |
1647 if (!update_s.Run()) | 1647 if (!update_s.Run()) |
1648 return false; | 1648 return false; |
1649 } | 1649 } |
1650 if (!s.Succeeded()) | 1650 if (!s.Succeeded()) |
1651 return false; | 1651 return false; |
1652 } | 1652 } |
1653 | 1653 |
1654 // Note that we need to check for the guid column's existence due to the | 1654 // Note that we need to check for the guid column's existence due to the |
1655 // fact that for a version 22 database the |autofill_profiles| table | 1655 // fact that for a version 22 database the |autofill_profiles| table |
1656 // gets created fresh with |InitAutofillProfilesTable|. | 1656 // gets created fresh with |InitAutofillProfilesTable|. |
1657 if (!db_->DoesColumnExist("credit_cards", "guid")) { | 1657 if (!db_->DoesColumnExist("credit_cards", "guid")) { |
1658 if (!db_->Execute("ALTER TABLE credit_cards ADD COLUMN " | 1658 if (!db_->Execute("ALTER TABLE credit_cards ADD COLUMN " |
1659 "guid VARCHAR NOT NULL DEFAULT \"\"")) { | 1659 "guid VARCHAR NOT NULL DEFAULT \"\"")) { |
1660 return false; | 1660 return false; |
1661 } | 1661 } |
1662 | 1662 |
1663 // Set all the |guid| fields to valid values. | 1663 // Set all the |guid| fields to valid values. |
1664 | 1664 |
1665 sql::Statement s(db_->GetUniqueStatement("SELECT unique_id " | 1665 sql::Statement s(db_->GetUniqueStatement("SELECT unique_id " |
1666 "FROM credit_cards")); | 1666 "FROM credit_cards")); |
1667 | 1667 |
1668 while (s.Step()) { | 1668 while (s.Step()) { |
1669 sql::Statement update_s( | 1669 sql::Statement update_s( |
1670 db_->GetUniqueStatement("UPDATE credit_cards " | 1670 db_->GetUniqueStatement("UPDATE credit_cards " |
1671 "set guid=? WHERE unique_id=?")); | 1671 "set guid=? WHERE unique_id=?")); |
1672 update_s.BindString(0, guid::GenerateGUID()); | 1672 update_s.BindString(0, base::GenerateGUID()); |
1673 update_s.BindInt(1, s.ColumnInt(0)); | 1673 update_s.BindInt(1, s.ColumnInt(0)); |
1674 | 1674 |
1675 if (!update_s.Run()) | 1675 if (!update_s.Run()) |
1676 return false; | 1676 return false; |
1677 } | 1677 } |
1678 if (!s.Succeeded()) | 1678 if (!s.Succeeded()) |
1679 return false; | 1679 return false; |
1680 } | 1680 } |
1681 | 1681 |
1682 return true; | 1682 return true; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1775 | 1775 |
1776 sql::Statement s(db_->GetUniqueStatement( | 1776 sql::Statement s(db_->GetUniqueStatement( |
1777 "SELECT guid, first_name, middle_name, last_name, email, " | 1777 "SELECT guid, first_name, middle_name, last_name, email, " |
1778 "company_name, address_line_1, address_line_2, city, state, " | 1778 "company_name, address_line_1, address_line_2, city, state, " |
1779 "zipcode, country, phone, date_modified " | 1779 "zipcode, country, phone, date_modified " |
1780 "FROM autofill_profiles")); | 1780 "FROM autofill_profiles")); |
1781 | 1781 |
1782 while (s.Step()) { | 1782 while (s.Step()) { |
1783 AutofillProfile profile; | 1783 AutofillProfile profile; |
1784 profile.set_guid(s.ColumnString(0)); | 1784 profile.set_guid(s.ColumnString(0)); |
1785 DCHECK(guid::IsValidGUID(profile.guid())); | 1785 DCHECK(base::IsValidGUID(profile.guid())); |
1786 | 1786 |
1787 profile.SetInfo(NAME_FIRST, s.ColumnString16(1)); | 1787 profile.SetInfo(NAME_FIRST, s.ColumnString16(1)); |
1788 profile.SetInfo(NAME_MIDDLE, s.ColumnString16(2)); | 1788 profile.SetInfo(NAME_MIDDLE, s.ColumnString16(2)); |
1789 profile.SetInfo(NAME_LAST, s.ColumnString16(3)); | 1789 profile.SetInfo(NAME_LAST, s.ColumnString16(3)); |
1790 profile.SetInfo(EMAIL_ADDRESS, s.ColumnString16(4)); | 1790 profile.SetInfo(EMAIL_ADDRESS, s.ColumnString16(4)); |
1791 profile.SetInfo(COMPANY_NAME, s.ColumnString16(5)); | 1791 profile.SetInfo(COMPANY_NAME, s.ColumnString16(5)); |
1792 profile.SetInfo(ADDRESS_HOME_LINE1, s.ColumnString16(6)); | 1792 profile.SetInfo(ADDRESS_HOME_LINE1, s.ColumnString16(6)); |
1793 profile.SetInfo(ADDRESS_HOME_LINE2, s.ColumnString16(7)); | 1793 profile.SetInfo(ADDRESS_HOME_LINE2, s.ColumnString16(7)); |
1794 profile.SetInfo(ADDRESS_HOME_CITY, s.ColumnString16(8)); | 1794 profile.SetInfo(ADDRESS_HOME_CITY, s.ColumnString16(8)); |
1795 profile.SetInfo(ADDRESS_HOME_STATE, s.ColumnString16(9)); | 1795 profile.SetInfo(ADDRESS_HOME_STATE, s.ColumnString16(9)); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1978 "WHERE guid=?")); | 1978 "WHERE guid=?")); |
1979 s_date.BindInt64(0, date_item->second); | 1979 s_date.BindInt64(0, date_item->second); |
1980 s_date.BindString(1, iter->guid()); | 1980 s_date.BindString(1, iter->guid()); |
1981 | 1981 |
1982 if (!s_date.Run()) | 1982 if (!s_date.Run()) |
1983 return false; | 1983 return false; |
1984 } | 1984 } |
1985 | 1985 |
1986 return true; | 1986 return true; |
1987 } | 1987 } |
OLD | NEW |