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> |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 return data.substr(0, AutofillTable::kMaxDataLength); | 47 return data.substr(0, AutofillTable::kMaxDataLength); |
48 | 48 |
49 return data; | 49 return data; |
50 } | 50 } |
51 | 51 |
52 void BindAutofillProfileToStatement(const AutofillProfile& profile, | 52 void BindAutofillProfileToStatement(const AutofillProfile& profile, |
53 sql::Statement* s) { | 53 sql::Statement* s) { |
54 DCHECK(base::IsValidGUID(profile.guid())); | 54 DCHECK(base::IsValidGUID(profile.guid())); |
55 s->BindString(0, profile.guid()); | 55 s->BindString(0, profile.guid()); |
56 | 56 |
57 string16 text = profile.GetInfo(COMPANY_NAME); | 57 string16 text = profile.GetRawInfo(COMPANY_NAME); |
58 s->BindString16(1, LimitDataSize(text)); | 58 s->BindString16(1, LimitDataSize(text)); |
59 text = profile.GetInfo(ADDRESS_HOME_LINE1); | 59 text = profile.GetRawInfo(ADDRESS_HOME_LINE1); |
60 s->BindString16(2, LimitDataSize(text)); | 60 s->BindString16(2, LimitDataSize(text)); |
61 text = profile.GetInfo(ADDRESS_HOME_LINE2); | 61 text = profile.GetRawInfo(ADDRESS_HOME_LINE2); |
62 s->BindString16(3, LimitDataSize(text)); | 62 s->BindString16(3, LimitDataSize(text)); |
63 text = profile.GetInfo(ADDRESS_HOME_CITY); | 63 text = profile.GetRawInfo(ADDRESS_HOME_CITY); |
64 s->BindString16(4, LimitDataSize(text)); | 64 s->BindString16(4, LimitDataSize(text)); |
65 text = profile.GetInfo(ADDRESS_HOME_STATE); | 65 text = profile.GetRawInfo(ADDRESS_HOME_STATE); |
66 s->BindString16(5, LimitDataSize(text)); | 66 s->BindString16(5, LimitDataSize(text)); |
67 text = profile.GetInfo(ADDRESS_HOME_ZIP); | 67 text = profile.GetRawInfo(ADDRESS_HOME_ZIP); |
68 s->BindString16(6, LimitDataSize(text)); | 68 s->BindString16(6, LimitDataSize(text)); |
69 text = profile.GetInfo(ADDRESS_HOME_COUNTRY); | 69 text = profile.GetRawInfo(ADDRESS_HOME_COUNTRY); |
70 s->BindString16(7, LimitDataSize(text)); | 70 s->BindString16(7, LimitDataSize(text)); |
71 std::string country_code = profile.CountryCode(); | 71 std::string country_code = profile.CountryCode(); |
72 s->BindString(8, country_code); | 72 s->BindString(8, country_code); |
73 s->BindInt64(9, Time::Now().ToTimeT()); | 73 s->BindInt64(9, Time::Now().ToTimeT()); |
74 } | 74 } |
75 | 75 |
76 AutofillProfile* AutofillProfileFromStatement(const sql::Statement& s) { | 76 AutofillProfile* AutofillProfileFromStatement(const sql::Statement& s) { |
77 AutofillProfile* profile = new AutofillProfile; | 77 AutofillProfile* profile = new AutofillProfile; |
78 profile->set_guid(s.ColumnString(0)); | 78 profile->set_guid(s.ColumnString(0)); |
79 DCHECK(base::IsValidGUID(profile->guid())); | 79 DCHECK(base::IsValidGUID(profile->guid())); |
80 | 80 |
81 profile->SetInfo(COMPANY_NAME, s.ColumnString16(1)); | 81 profile->SetRawInfo(COMPANY_NAME, s.ColumnString16(1)); |
82 profile->SetInfo(ADDRESS_HOME_LINE1, s.ColumnString16(2)); | 82 profile->SetRawInfo(ADDRESS_HOME_LINE1, s.ColumnString16(2)); |
83 profile->SetInfo(ADDRESS_HOME_LINE2, s.ColumnString16(3)); | 83 profile->SetRawInfo(ADDRESS_HOME_LINE2, s.ColumnString16(3)); |
84 profile->SetInfo(ADDRESS_HOME_CITY, s.ColumnString16(4)); | 84 profile->SetRawInfo(ADDRESS_HOME_CITY, s.ColumnString16(4)); |
85 profile->SetInfo(ADDRESS_HOME_STATE, s.ColumnString16(5)); | 85 profile->SetRawInfo(ADDRESS_HOME_STATE, s.ColumnString16(5)); |
86 profile->SetInfo(ADDRESS_HOME_ZIP, s.ColumnString16(6)); | 86 profile->SetRawInfo(ADDRESS_HOME_ZIP, s.ColumnString16(6)); |
87 // Intentionally skip column 7, which stores the localized country name. | 87 // Intentionally skip column 7, which stores the localized country name. |
88 profile->SetCountryCode(s.ColumnString(8)); | 88 profile->SetCountryCode(s.ColumnString(8)); |
89 // Intentionally skip column 9, which stores the profile's modification date. | 89 // Intentionally skip column 9, which stores the profile's modification date. |
90 | 90 |
91 return profile; | 91 return profile; |
92 } | 92 } |
93 | 93 |
94 void BindCreditCardToStatement(const CreditCard& credit_card, | 94 void BindCreditCardToStatement(const CreditCard& credit_card, |
95 sql::Statement* s) { | 95 sql::Statement* s) { |
96 DCHECK(base::IsValidGUID(credit_card.guid())); | 96 DCHECK(base::IsValidGUID(credit_card.guid())); |
97 s->BindString(0, credit_card.guid()); | 97 s->BindString(0, credit_card.guid()); |
98 | 98 |
99 string16 text = credit_card.GetInfo(CREDIT_CARD_NAME); | 99 string16 text = credit_card.GetRawInfo(CREDIT_CARD_NAME); |
100 s->BindString16(1, LimitDataSize(text)); | 100 s->BindString16(1, LimitDataSize(text)); |
101 text = credit_card.GetInfo(CREDIT_CARD_EXP_MONTH); | 101 text = credit_card.GetRawInfo(CREDIT_CARD_EXP_MONTH); |
102 s->BindString16(2, LimitDataSize(text)); | 102 s->BindString16(2, LimitDataSize(text)); |
103 text = credit_card.GetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR); | 103 text = credit_card.GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR); |
104 s->BindString16(3, LimitDataSize(text)); | 104 s->BindString16(3, LimitDataSize(text)); |
105 text = credit_card.GetInfo(CREDIT_CARD_NUMBER); | 105 text = credit_card.GetRawInfo(CREDIT_CARD_NUMBER); |
106 std::string encrypted_data; | 106 std::string encrypted_data; |
107 Encryptor::EncryptString16(text, &encrypted_data); | 107 Encryptor::EncryptString16(text, &encrypted_data); |
108 s->BindBlob(4, encrypted_data.data(), | 108 s->BindBlob(4, encrypted_data.data(), |
109 static_cast<int>(encrypted_data.length())); | 109 static_cast<int>(encrypted_data.length())); |
110 s->BindInt64(5, Time::Now().ToTimeT()); | 110 s->BindInt64(5, Time::Now().ToTimeT()); |
111 } | 111 } |
112 | 112 |
113 CreditCard* CreditCardFromStatement(const sql::Statement& s) { | 113 CreditCard* CreditCardFromStatement(const sql::Statement& s) { |
114 CreditCard* credit_card = new CreditCard; | 114 CreditCard* credit_card = new CreditCard; |
115 | 115 |
116 credit_card->set_guid(s.ColumnString(0)); | 116 credit_card->set_guid(s.ColumnString(0)); |
117 DCHECK(base::IsValidGUID(credit_card->guid())); | 117 DCHECK(base::IsValidGUID(credit_card->guid())); |
118 | 118 |
119 credit_card->SetInfo(CREDIT_CARD_NAME, s.ColumnString16(1)); | 119 credit_card->SetRawInfo(CREDIT_CARD_NAME, s.ColumnString16(1)); |
120 credit_card->SetInfo(CREDIT_CARD_EXP_MONTH, s.ColumnString16(2)); | 120 credit_card->SetRawInfo(CREDIT_CARD_EXP_MONTH, s.ColumnString16(2)); |
121 credit_card->SetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, s.ColumnString16(3)); | 121 credit_card->SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, s.ColumnString16(3)); |
122 int encrypted_number_len = s.ColumnByteLength(4); | 122 int encrypted_number_len = s.ColumnByteLength(4); |
123 string16 credit_card_number; | 123 string16 credit_card_number; |
124 if (encrypted_number_len) { | 124 if (encrypted_number_len) { |
125 std::string encrypted_number; | 125 std::string encrypted_number; |
126 encrypted_number.resize(encrypted_number_len); | 126 encrypted_number.resize(encrypted_number_len); |
127 memcpy(&encrypted_number[0], s.ColumnBlob(4), encrypted_number_len); | 127 memcpy(&encrypted_number[0], s.ColumnBlob(4), encrypted_number_len); |
128 Encryptor::DecryptString16(encrypted_number, &credit_card_number); | 128 Encryptor::DecryptString16(encrypted_number, &credit_card_number); |
129 } | 129 } |
130 credit_card->SetInfo(CREDIT_CARD_NUMBER, credit_card_number); | 130 credit_card->SetRawInfo(CREDIT_CARD_NUMBER, credit_card_number); |
131 // Intentionally skip column 5, which stores the modification date. | 131 // Intentionally skip column 5, which stores the modification date. |
132 | 132 |
133 return credit_card; | 133 return credit_card; |
134 } | 134 } |
135 | 135 |
136 bool AddAutofillProfileNamesToProfile(sql::Connection* db, | 136 bool AddAutofillProfileNamesToProfile(sql::Connection* db, |
137 AutofillProfile* profile) { | 137 AutofillProfile* profile) { |
138 sql::Statement s(db->GetUniqueStatement( | 138 sql::Statement s(db->GetUniqueStatement( |
139 "SELECT guid, first_name, middle_name, last_name " | 139 "SELECT guid, first_name, middle_name, last_name " |
140 "FROM autofill_profile_names " | 140 "FROM autofill_profile_names " |
(...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
943 | 943 |
944 // Preserve appropriate modification dates by not updating unchanged profiles. | 944 // Preserve appropriate modification dates by not updating unchanged profiles. |
945 scoped_ptr<AutofillProfile> old_profile(tmp_profile); | 945 scoped_ptr<AutofillProfile> old_profile(tmp_profile); |
946 if (old_profile->Compare(profile) == 0) | 946 if (old_profile->Compare(profile) == 0) |
947 return true; | 947 return true; |
948 | 948 |
949 AutofillProfile new_profile(profile); | 949 AutofillProfile new_profile(profile); |
950 std::vector<string16> values; | 950 std::vector<string16> values; |
951 | 951 |
952 old_profile->GetMultiInfo(NAME_FULL, &values); | 952 old_profile->GetMultiInfo(NAME_FULL, &values); |
953 values[0] = new_profile.GetInfo(NAME_FULL); | 953 values[0] = new_profile.GetRawInfo(NAME_FULL); |
954 new_profile.SetMultiInfo(NAME_FULL, values); | 954 new_profile.SetMultiInfo(NAME_FULL, values); |
955 | 955 |
956 old_profile->GetMultiInfo(EMAIL_ADDRESS, &values); | 956 old_profile->GetMultiInfo(EMAIL_ADDRESS, &values); |
957 values[0] = new_profile.GetInfo(EMAIL_ADDRESS); | 957 values[0] = new_profile.GetRawInfo(EMAIL_ADDRESS); |
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.GetRawInfo(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(base::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. |
(...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(base::IsValidGUID(profile.guid())); | 1785 DCHECK(base::IsValidGUID(profile.guid())); |
1786 | 1786 |
1787 profile.SetInfo(NAME_FIRST, s.ColumnString16(1)); | 1787 profile.SetRawInfo(NAME_FIRST, s.ColumnString16(1)); |
1788 profile.SetInfo(NAME_MIDDLE, s.ColumnString16(2)); | 1788 profile.SetRawInfo(NAME_MIDDLE, s.ColumnString16(2)); |
1789 profile.SetInfo(NAME_LAST, s.ColumnString16(3)); | 1789 profile.SetRawInfo(NAME_LAST, s.ColumnString16(3)); |
1790 profile.SetInfo(EMAIL_ADDRESS, s.ColumnString16(4)); | 1790 profile.SetRawInfo(EMAIL_ADDRESS, s.ColumnString16(4)); |
1791 profile.SetInfo(COMPANY_NAME, s.ColumnString16(5)); | 1791 profile.SetRawInfo(COMPANY_NAME, s.ColumnString16(5)); |
1792 profile.SetInfo(ADDRESS_HOME_LINE1, s.ColumnString16(6)); | 1792 profile.SetRawInfo(ADDRESS_HOME_LINE1, s.ColumnString16(6)); |
1793 profile.SetInfo(ADDRESS_HOME_LINE2, s.ColumnString16(7)); | 1793 profile.SetRawInfo(ADDRESS_HOME_LINE2, s.ColumnString16(7)); |
1794 profile.SetInfo(ADDRESS_HOME_CITY, s.ColumnString16(8)); | 1794 profile.SetRawInfo(ADDRESS_HOME_CITY, s.ColumnString16(8)); |
1795 profile.SetInfo(ADDRESS_HOME_STATE, s.ColumnString16(9)); | 1795 profile.SetRawInfo(ADDRESS_HOME_STATE, s.ColumnString16(9)); |
1796 profile.SetInfo(ADDRESS_HOME_ZIP, s.ColumnString16(10)); | 1796 profile.SetRawInfo(ADDRESS_HOME_ZIP, s.ColumnString16(10)); |
1797 profile.SetInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(11)); | 1797 profile.SetRawInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(11)); |
1798 profile.SetInfo(PHONE_HOME_WHOLE_NUMBER, s.ColumnString16(12)); | 1798 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, s.ColumnString16(12)); |
1799 int64 date_modified = s.ColumnInt64(13); | 1799 int64 date_modified = s.ColumnInt64(13); |
1800 | 1800 |
1801 sql::Statement s_insert(db_->GetUniqueStatement( | 1801 sql::Statement s_insert(db_->GetUniqueStatement( |
1802 "INSERT INTO autofill_profiles_temp" | 1802 "INSERT INTO autofill_profiles_temp" |
1803 "(guid, company_name, address_line_1, address_line_2, city," | 1803 "(guid, company_name, address_line_1, address_line_2, city," |
1804 " state, zipcode, country, date_modified)" | 1804 " state, zipcode, country, date_modified)" |
1805 "VALUES (?,?,?,?,?,?,?,?,?)")); | 1805 "VALUES (?,?,?,?,?,?,?,?,?)")); |
1806 s_insert.BindString(0, profile.guid()); | 1806 s_insert.BindString(0, profile.guid()); |
1807 s_insert.BindString16(1, profile.GetInfo(COMPANY_NAME)); | 1807 s_insert.BindString16(1, profile.GetRawInfo(COMPANY_NAME)); |
1808 s_insert.BindString16(2, profile.GetInfo(ADDRESS_HOME_LINE1)); | 1808 s_insert.BindString16(2, profile.GetRawInfo(ADDRESS_HOME_LINE1)); |
1809 s_insert.BindString16(3, profile.GetInfo(ADDRESS_HOME_LINE2)); | 1809 s_insert.BindString16(3, profile.GetRawInfo(ADDRESS_HOME_LINE2)); |
1810 s_insert.BindString16(4, profile.GetInfo(ADDRESS_HOME_CITY)); | 1810 s_insert.BindString16(4, profile.GetRawInfo(ADDRESS_HOME_CITY)); |
1811 s_insert.BindString16(5, profile.GetInfo(ADDRESS_HOME_STATE)); | 1811 s_insert.BindString16(5, profile.GetRawInfo(ADDRESS_HOME_STATE)); |
1812 s_insert.BindString16(6, profile.GetInfo(ADDRESS_HOME_ZIP)); | 1812 s_insert.BindString16(6, profile.GetRawInfo(ADDRESS_HOME_ZIP)); |
1813 s_insert.BindString16(7, profile.GetInfo(ADDRESS_HOME_COUNTRY)); | 1813 s_insert.BindString16(7, profile.GetRawInfo(ADDRESS_HOME_COUNTRY)); |
1814 s_insert.BindInt64(8, date_modified); | 1814 s_insert.BindInt64(8, date_modified); |
1815 | 1815 |
1816 if (!s_insert.Run()) | 1816 if (!s_insert.Run()) |
1817 return false; | 1817 return false; |
1818 | 1818 |
1819 // Add the other bits: names, emails, and phone numbers. | 1819 // Add the other bits: names, emails, and phone numbers. |
1820 if (!AddAutofillProfilePieces(profile, db_)) | 1820 if (!AddAutofillProfilePieces(profile, db_)) |
1821 return false; | 1821 return false; |
1822 } // endwhile | 1822 } // endwhile |
1823 if (!s.Succeeded()) | 1823 if (!s.Succeeded()) |
(...skipping 154 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 |