| 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 "components/webdata/autofill/autofill_table.h" | 5 #include "components/webdata/autofill/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 16 matching lines...) Expand all Loading... |
| 27 #include "components/webdata/autofill/autofill_entry.h" | 27 #include "components/webdata/autofill/autofill_entry.h" |
| 28 #include "components/webdata/common/web_database.h" | 28 #include "components/webdata/common/web_database.h" |
| 29 #include "components/webdata/encryptor/encryptor.h" | 29 #include "components/webdata/encryptor/encryptor.h" |
| 30 #include "sql/statement.h" | 30 #include "sql/statement.h" |
| 31 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| 32 | 32 |
| 33 using base::Time; | 33 using base::Time; |
| 34 | 34 |
| 35 namespace { | 35 namespace { |
| 36 | 36 |
| 37 typedef std::vector<Tuple3<int64, string16, string16> > AutofillElementList; | 37 typedef std::vector<Tuple3<int64, base::string16, base::string16> > |
| 38 AutofillElementList; |
| 38 | 39 |
| 39 // TODO(dhollowa): Find a common place for this. It is duplicated in | 40 // TODO(dhollowa): Find a common place for this. It is duplicated in |
| 40 // personal_data_manager.cc. | 41 // personal_data_manager.cc. |
| 41 template<typename T> | 42 template<typename T> |
| 42 T* address_of(T& v) { | 43 T* address_of(T& v) { |
| 43 return &v; | 44 return &v; |
| 44 } | 45 } |
| 45 | 46 |
| 46 string16 LimitDataSize(const string16& data) { | 47 base::string16 LimitDataSize(const base::string16& data) { |
| 47 if (data.size() > AutofillTable::kMaxDataLength) | 48 if (data.size() > AutofillTable::kMaxDataLength) |
| 48 return data.substr(0, AutofillTable::kMaxDataLength); | 49 return data.substr(0, AutofillTable::kMaxDataLength); |
| 49 | 50 |
| 50 return data; | 51 return data; |
| 51 } | 52 } |
| 52 | 53 |
| 53 void BindAutofillProfileToStatement(const AutofillProfile& profile, | 54 void BindAutofillProfileToStatement(const AutofillProfile& profile, |
| 54 sql::Statement* s, | 55 sql::Statement* s, |
| 55 const std::string& app_locale) { | 56 const std::string& app_locale) { |
| 56 DCHECK(base::IsValidGUID(profile.guid())); | 57 DCHECK(base::IsValidGUID(profile.guid())); |
| 57 s->BindString(0, profile.guid()); | 58 s->BindString(0, profile.guid()); |
| 58 | 59 |
| 59 string16 text = profile.GetRawInfo(COMPANY_NAME); | 60 base::string16 text = profile.GetRawInfo(COMPANY_NAME); |
| 60 s->BindString16(1, LimitDataSize(text)); | 61 s->BindString16(1, LimitDataSize(text)); |
| 61 text = profile.GetRawInfo(ADDRESS_HOME_LINE1); | 62 text = profile.GetRawInfo(ADDRESS_HOME_LINE1); |
| 62 s->BindString16(2, LimitDataSize(text)); | 63 s->BindString16(2, LimitDataSize(text)); |
| 63 text = profile.GetRawInfo(ADDRESS_HOME_LINE2); | 64 text = profile.GetRawInfo(ADDRESS_HOME_LINE2); |
| 64 s->BindString16(3, LimitDataSize(text)); | 65 s->BindString16(3, LimitDataSize(text)); |
| 65 text = profile.GetRawInfo(ADDRESS_HOME_CITY); | 66 text = profile.GetRawInfo(ADDRESS_HOME_CITY); |
| 66 s->BindString16(4, LimitDataSize(text)); | 67 s->BindString16(4, LimitDataSize(text)); |
| 67 text = profile.GetRawInfo(ADDRESS_HOME_STATE); | 68 text = profile.GetRawInfo(ADDRESS_HOME_STATE); |
| 68 s->BindString16(5, LimitDataSize(text)); | 69 s->BindString16(5, LimitDataSize(text)); |
| 69 text = profile.GetRawInfo(ADDRESS_HOME_ZIP); | 70 text = profile.GetRawInfo(ADDRESS_HOME_ZIP); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 92 // Intentionally skip column 9, which stores the profile's modification date. | 93 // Intentionally skip column 9, which stores the profile's modification date. |
| 93 | 94 |
| 94 return profile; | 95 return profile; |
| 95 } | 96 } |
| 96 | 97 |
| 97 void BindCreditCardToStatement(const CreditCard& credit_card, | 98 void BindCreditCardToStatement(const CreditCard& credit_card, |
| 98 sql::Statement* s) { | 99 sql::Statement* s) { |
| 99 DCHECK(base::IsValidGUID(credit_card.guid())); | 100 DCHECK(base::IsValidGUID(credit_card.guid())); |
| 100 s->BindString(0, credit_card.guid()); | 101 s->BindString(0, credit_card.guid()); |
| 101 | 102 |
| 102 string16 text = credit_card.GetRawInfo(CREDIT_CARD_NAME); | 103 base::string16 text = credit_card.GetRawInfo(CREDIT_CARD_NAME); |
| 103 s->BindString16(1, LimitDataSize(text)); | 104 s->BindString16(1, LimitDataSize(text)); |
| 104 text = credit_card.GetRawInfo(CREDIT_CARD_EXP_MONTH); | 105 text = credit_card.GetRawInfo(CREDIT_CARD_EXP_MONTH); |
| 105 s->BindString16(2, LimitDataSize(text)); | 106 s->BindString16(2, LimitDataSize(text)); |
| 106 text = credit_card.GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR); | 107 text = credit_card.GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR); |
| 107 s->BindString16(3, LimitDataSize(text)); | 108 s->BindString16(3, LimitDataSize(text)); |
| 108 text = credit_card.GetRawInfo(CREDIT_CARD_NUMBER); | 109 text = credit_card.GetRawInfo(CREDIT_CARD_NUMBER); |
| 109 std::string encrypted_data; | 110 std::string encrypted_data; |
| 110 Encryptor::EncryptString16(text, &encrypted_data); | 111 Encryptor::EncryptString16(text, &encrypted_data); |
| 111 s->BindBlob(4, encrypted_data.data(), | 112 s->BindBlob(4, encrypted_data.data(), |
| 112 static_cast<int>(encrypted_data.length())); | 113 static_cast<int>(encrypted_data.length())); |
| 113 s->BindInt64(5, Time::Now().ToTimeT()); | 114 s->BindInt64(5, Time::Now().ToTimeT()); |
| 114 } | 115 } |
| 115 | 116 |
| 116 CreditCard* CreditCardFromStatement(const sql::Statement& s) { | 117 CreditCard* CreditCardFromStatement(const sql::Statement& s) { |
| 117 CreditCard* credit_card = new CreditCard; | 118 CreditCard* credit_card = new CreditCard; |
| 118 | 119 |
| 119 credit_card->set_guid(s.ColumnString(0)); | 120 credit_card->set_guid(s.ColumnString(0)); |
| 120 DCHECK(base::IsValidGUID(credit_card->guid())); | 121 DCHECK(base::IsValidGUID(credit_card->guid())); |
| 121 | 122 |
| 122 credit_card->SetRawInfo(CREDIT_CARD_NAME, s.ColumnString16(1)); | 123 credit_card->SetRawInfo(CREDIT_CARD_NAME, s.ColumnString16(1)); |
| 123 credit_card->SetRawInfo(CREDIT_CARD_EXP_MONTH, s.ColumnString16(2)); | 124 credit_card->SetRawInfo(CREDIT_CARD_EXP_MONTH, s.ColumnString16(2)); |
| 124 credit_card->SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, s.ColumnString16(3)); | 125 credit_card->SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, s.ColumnString16(3)); |
| 125 int encrypted_number_len = s.ColumnByteLength(4); | 126 int encrypted_number_len = s.ColumnByteLength(4); |
| 126 string16 credit_card_number; | 127 base::string16 credit_card_number; |
| 127 if (encrypted_number_len) { | 128 if (encrypted_number_len) { |
| 128 std::string encrypted_number; | 129 std::string encrypted_number; |
| 129 encrypted_number.resize(encrypted_number_len); | 130 encrypted_number.resize(encrypted_number_len); |
| 130 memcpy(&encrypted_number[0], s.ColumnBlob(4), encrypted_number_len); | 131 memcpy(&encrypted_number[0], s.ColumnBlob(4), encrypted_number_len); |
| 131 Encryptor::DecryptString16(encrypted_number, &credit_card_number); | 132 Encryptor::DecryptString16(encrypted_number, &credit_card_number); |
| 132 } | 133 } |
| 133 credit_card->SetRawInfo(CREDIT_CARD_NUMBER, credit_card_number); | 134 credit_card->SetRawInfo(CREDIT_CARD_NUMBER, credit_card_number); |
| 134 // Intentionally skip column 5, which stores the modification date. | 135 // Intentionally skip column 5, which stores the modification date. |
| 135 | 136 |
| 136 return credit_card; | 137 return credit_card; |
| 137 } | 138 } |
| 138 | 139 |
| 139 bool AddAutofillProfileNamesToProfile(sql::Connection* db, | 140 bool AddAutofillProfileNamesToProfile(sql::Connection* db, |
| 140 AutofillProfile* profile) { | 141 AutofillProfile* profile) { |
| 141 sql::Statement s(db->GetUniqueStatement( | 142 sql::Statement s(db->GetUniqueStatement( |
| 142 "SELECT guid, first_name, middle_name, last_name " | 143 "SELECT guid, first_name, middle_name, last_name " |
| 143 "FROM autofill_profile_names " | 144 "FROM autofill_profile_names " |
| 144 "WHERE guid=?")); | 145 "WHERE guid=?")); |
| 145 s.BindString(0, profile->guid()); | 146 s.BindString(0, profile->guid()); |
| 146 | 147 |
| 147 if (!s.is_valid()) | 148 if (!s.is_valid()) |
| 148 return false; | 149 return false; |
| 149 | 150 |
| 150 std::vector<string16> first_names; | 151 std::vector<base::string16> first_names; |
| 151 std::vector<string16> middle_names; | 152 std::vector<base::string16> middle_names; |
| 152 std::vector<string16> last_names; | 153 std::vector<base::string16> last_names; |
| 153 while (s.Step()) { | 154 while (s.Step()) { |
| 154 DCHECK_EQ(profile->guid(), s.ColumnString(0)); | 155 DCHECK_EQ(profile->guid(), s.ColumnString(0)); |
| 155 first_names.push_back(s.ColumnString16(1)); | 156 first_names.push_back(s.ColumnString16(1)); |
| 156 middle_names.push_back(s.ColumnString16(2)); | 157 middle_names.push_back(s.ColumnString16(2)); |
| 157 last_names.push_back(s.ColumnString16(3)); | 158 last_names.push_back(s.ColumnString16(3)); |
| 158 } | 159 } |
| 159 if (!s.Succeeded()) | 160 if (!s.Succeeded()) |
| 160 return false; | 161 return false; |
| 161 | 162 |
| 162 profile->SetRawMultiInfo(NAME_FIRST, first_names); | 163 profile->SetRawMultiInfo(NAME_FIRST, first_names); |
| 163 profile->SetRawMultiInfo(NAME_MIDDLE, middle_names); | 164 profile->SetRawMultiInfo(NAME_MIDDLE, middle_names); |
| 164 profile->SetRawMultiInfo(NAME_LAST, last_names); | 165 profile->SetRawMultiInfo(NAME_LAST, last_names); |
| 165 return true; | 166 return true; |
| 166 } | 167 } |
| 167 | 168 |
| 168 bool AddAutofillProfileEmailsToProfile(sql::Connection* db, | 169 bool AddAutofillProfileEmailsToProfile(sql::Connection* db, |
| 169 AutofillProfile* profile) { | 170 AutofillProfile* profile) { |
| 170 sql::Statement s(db->GetUniqueStatement( | 171 sql::Statement s(db->GetUniqueStatement( |
| 171 "SELECT guid, email " | 172 "SELECT guid, email " |
| 172 "FROM autofill_profile_emails " | 173 "FROM autofill_profile_emails " |
| 173 "WHERE guid=?")); | 174 "WHERE guid=?")); |
| 174 s.BindString(0, profile->guid()); | 175 s.BindString(0, profile->guid()); |
| 175 | 176 |
| 176 if (!s.is_valid()) | 177 if (!s.is_valid()) |
| 177 return false; | 178 return false; |
| 178 | 179 |
| 179 std::vector<string16> emails; | 180 std::vector<base::string16> emails; |
| 180 while (s.Step()) { | 181 while (s.Step()) { |
| 181 DCHECK_EQ(profile->guid(), s.ColumnString(0)); | 182 DCHECK_EQ(profile->guid(), s.ColumnString(0)); |
| 182 emails.push_back(s.ColumnString16(1)); | 183 emails.push_back(s.ColumnString16(1)); |
| 183 } | 184 } |
| 184 if (!s.Succeeded()) | 185 if (!s.Succeeded()) |
| 185 return false; | 186 return false; |
| 186 | 187 |
| 187 profile->SetRawMultiInfo(EMAIL_ADDRESS, emails); | 188 profile->SetRawMultiInfo(EMAIL_ADDRESS, emails); |
| 188 return true; | 189 return true; |
| 189 } | 190 } |
| 190 | 191 |
| 191 bool AddAutofillProfilePhonesToProfile(sql::Connection* db, | 192 bool AddAutofillProfilePhonesToProfile(sql::Connection* db, |
| 192 AutofillProfile* profile) { | 193 AutofillProfile* profile) { |
| 193 sql::Statement s(db->GetUniqueStatement( | 194 sql::Statement s(db->GetUniqueStatement( |
| 194 "SELECT guid, type, number " | 195 "SELECT guid, type, number " |
| 195 "FROM autofill_profile_phones " | 196 "FROM autofill_profile_phones " |
| 196 "WHERE guid=? AND type=?")); | 197 "WHERE guid=? AND type=?")); |
| 197 | 198 |
| 198 // Value used to be either [(0, phone), (1, fax)] but fax has been removed. | 199 // Value used to be either [(0, phone), (1, fax)] but fax has been removed. |
| 199 s.BindString(0, profile->guid()); | 200 s.BindString(0, profile->guid()); |
| 200 s.BindInt(1, 0); | 201 s.BindInt(1, 0); |
| 201 | 202 |
| 202 if (!s.is_valid()) | 203 if (!s.is_valid()) |
| 203 return false; | 204 return false; |
| 204 | 205 |
| 205 std::vector<string16> numbers; | 206 std::vector<base::string16> numbers; |
| 206 while (s.Step()) { | 207 while (s.Step()) { |
| 207 DCHECK_EQ(profile->guid(), s.ColumnString(0)); | 208 DCHECK_EQ(profile->guid(), s.ColumnString(0)); |
| 208 numbers.push_back(s.ColumnString16(2)); | 209 numbers.push_back(s.ColumnString16(2)); |
| 209 } | 210 } |
| 210 if (!s.Succeeded()) | 211 if (!s.Succeeded()) |
| 211 return false; | 212 return false; |
| 212 | 213 |
| 213 profile->SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, numbers); | 214 profile->SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, numbers); |
| 214 return true; | 215 return true; |
| 215 } | 216 } |
| 216 | 217 |
| 217 bool AddAutofillProfileNames(const AutofillProfile& profile, | 218 bool AddAutofillProfileNames(const AutofillProfile& profile, |
| 218 sql::Connection* db) { | 219 sql::Connection* db) { |
| 219 std::vector<string16> first_names; | 220 std::vector<base::string16> first_names; |
| 220 profile.GetRawMultiInfo(NAME_FIRST, &first_names); | 221 profile.GetRawMultiInfo(NAME_FIRST, &first_names); |
| 221 std::vector<string16> middle_names; | 222 std::vector<base::string16> middle_names; |
| 222 profile.GetRawMultiInfo(NAME_MIDDLE, &middle_names); | 223 profile.GetRawMultiInfo(NAME_MIDDLE, &middle_names); |
| 223 std::vector<string16> last_names; | 224 std::vector<base::string16> last_names; |
| 224 profile.GetRawMultiInfo(NAME_LAST, &last_names); | 225 profile.GetRawMultiInfo(NAME_LAST, &last_names); |
| 225 DCHECK_EQ(first_names.size(), middle_names.size()); | 226 DCHECK_EQ(first_names.size(), middle_names.size()); |
| 226 DCHECK_EQ(middle_names.size(), last_names.size()); | 227 DCHECK_EQ(middle_names.size(), last_names.size()); |
| 227 | 228 |
| 228 for (size_t i = 0; i < first_names.size(); ++i) { | 229 for (size_t i = 0; i < first_names.size(); ++i) { |
| 229 // Add the new name. | 230 // Add the new name. |
| 230 sql::Statement s(db->GetUniqueStatement( | 231 sql::Statement s(db->GetUniqueStatement( |
| 231 "INSERT INTO autofill_profile_names" | 232 "INSERT INTO autofill_profile_names" |
| 232 " (guid, first_name, middle_name, last_name) " | 233 " (guid, first_name, middle_name, last_name) " |
| 233 "VALUES (?,?,?,?)")); | 234 "VALUES (?,?,?,?)")); |
| 234 s.BindString(0, profile.guid()); | 235 s.BindString(0, profile.guid()); |
| 235 s.BindString16(1, first_names[i]); | 236 s.BindString16(1, first_names[i]); |
| 236 s.BindString16(2, middle_names[i]); | 237 s.BindString16(2, middle_names[i]); |
| 237 s.BindString16(3, last_names[i]); | 238 s.BindString16(3, last_names[i]); |
| 238 | 239 |
| 239 if (!s.Run()) | 240 if (!s.Run()) |
| 240 return false; | 241 return false; |
| 241 } | 242 } |
| 242 return true; | 243 return true; |
| 243 } | 244 } |
| 244 | 245 |
| 245 bool AddAutofillProfileEmails(const AutofillProfile& profile, | 246 bool AddAutofillProfileEmails(const AutofillProfile& profile, |
| 246 sql::Connection* db) { | 247 sql::Connection* db) { |
| 247 std::vector<string16> emails; | 248 std::vector<base::string16> emails; |
| 248 profile.GetRawMultiInfo(EMAIL_ADDRESS, &emails); | 249 profile.GetRawMultiInfo(EMAIL_ADDRESS, &emails); |
| 249 | 250 |
| 250 for (size_t i = 0; i < emails.size(); ++i) { | 251 for (size_t i = 0; i < emails.size(); ++i) { |
| 251 // Add the new email. | 252 // Add the new email. |
| 252 sql::Statement s(db->GetUniqueStatement( | 253 sql::Statement s(db->GetUniqueStatement( |
| 253 "INSERT INTO autofill_profile_emails" | 254 "INSERT INTO autofill_profile_emails" |
| 254 " (guid, email) " | 255 " (guid, email) " |
| 255 "VALUES (?,?)")); | 256 "VALUES (?,?)")); |
| 256 s.BindString(0, profile.guid()); | 257 s.BindString(0, profile.guid()); |
| 257 s.BindString16(1, emails[i]); | 258 s.BindString16(1, emails[i]); |
| 258 | 259 |
| 259 if (!s.Run()) | 260 if (!s.Run()) |
| 260 return false; | 261 return false; |
| 261 } | 262 } |
| 262 | 263 |
| 263 return true; | 264 return true; |
| 264 } | 265 } |
| 265 | 266 |
| 266 bool AddAutofillProfilePhones(const AutofillProfile& profile, | 267 bool AddAutofillProfilePhones(const AutofillProfile& profile, |
| 267 sql::Connection* db) { | 268 sql::Connection* db) { |
| 268 std::vector<string16> numbers; | 269 std::vector<base::string16> numbers; |
| 269 profile.GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &numbers); | 270 profile.GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &numbers); |
| 270 | 271 |
| 271 for (size_t i = 0; i < numbers.size(); ++i) { | 272 for (size_t i = 0; i < numbers.size(); ++i) { |
| 272 // Add the new number. | 273 // Add the new number. |
| 273 sql::Statement s(db->GetUniqueStatement( | 274 sql::Statement s(db->GetUniqueStatement( |
| 274 "INSERT INTO autofill_profile_phones" | 275 "INSERT INTO autofill_profile_phones" |
| 275 " (guid, type, number) " | 276 " (guid, type, number) " |
| 276 "VALUES (?,?,?)")); | 277 "VALUES (?,?,?)")); |
| 277 s.BindString(0, profile.guid()); | 278 s.BindString(0, profile.guid()); |
| 278 // Value used to be either [(0, phone), (1, fax)] but fax has been removed. | 279 // Value used to be either [(0, phone), (1, fax)] but fax has been removed. |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 const std::vector<FormFieldData>& elements, | 411 const std::vector<FormFieldData>& elements, |
| 411 std::vector<AutofillChange>* changes) { | 412 std::vector<AutofillChange>* changes) { |
| 412 return AddFormFieldValuesTime(elements, changes, Time::Now()); | 413 return AddFormFieldValuesTime(elements, changes, Time::Now()); |
| 413 } | 414 } |
| 414 | 415 |
| 415 bool AutofillTable::AddFormFieldValue(const FormFieldData& element, | 416 bool AutofillTable::AddFormFieldValue(const FormFieldData& element, |
| 416 std::vector<AutofillChange>* changes) { | 417 std::vector<AutofillChange>* changes) { |
| 417 return AddFormFieldValueTime(element, changes, Time::Now()); | 418 return AddFormFieldValueTime(element, changes, Time::Now()); |
| 418 } | 419 } |
| 419 | 420 |
| 420 bool AutofillTable::GetFormValuesForElementName(const string16& name, | 421 bool AutofillTable::GetFormValuesForElementName( |
| 421 const string16& prefix, | 422 const base::string16& name, |
| 422 std::vector<string16>* values, | 423 const base::string16& prefix, |
| 423 int limit) { | 424 std::vector<base::string16>* values, |
| 425 int limit) { |
| 424 DCHECK(values); | 426 DCHECK(values); |
| 425 sql::Statement s; | 427 sql::Statement s; |
| 426 | 428 |
| 427 if (prefix.empty()) { | 429 if (prefix.empty()) { |
| 428 s.Assign(db_->GetUniqueStatement( | 430 s.Assign(db_->GetUniqueStatement( |
| 429 "SELECT value FROM autofill " | 431 "SELECT value FROM autofill " |
| 430 "WHERE name = ? " | 432 "WHERE name = ? " |
| 431 "ORDER BY count DESC " | 433 "ORDER BY count DESC " |
| 432 "LIMIT ?")); | 434 "LIMIT ?")); |
| 433 s.BindString16(0, name); | 435 s.BindString16(0, name); |
| 434 s.BindInt(1, limit); | 436 s.BindInt(1, limit); |
| 435 } else { | 437 } else { |
| 436 string16 prefix_lower = base::i18n::ToLower(prefix); | 438 base::string16 prefix_lower = base::i18n::ToLower(prefix); |
| 437 string16 next_prefix = prefix_lower; | 439 base::string16 next_prefix = prefix_lower; |
| 438 next_prefix[next_prefix.length() - 1]++; | 440 next_prefix[next_prefix.length() - 1]++; |
| 439 | 441 |
| 440 s.Assign(db_->GetUniqueStatement( | 442 s.Assign(db_->GetUniqueStatement( |
| 441 "SELECT value FROM autofill " | 443 "SELECT value FROM autofill " |
| 442 "WHERE name = ? AND " | 444 "WHERE name = ? AND " |
| 443 "value_lower >= ? AND " | 445 "value_lower >= ? AND " |
| 444 "value_lower < ? " | 446 "value_lower < ? " |
| 445 "ORDER BY count DESC " | 447 "ORDER BY count DESC " |
| 446 "LIMIT ?")); | 448 "LIMIT ?")); |
| 447 s.BindString16(0, name); | 449 s.BindString16(0, name); |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 return s.Run(); | 720 return s.Run(); |
| 719 } | 721 } |
| 720 | 722 |
| 721 bool AutofillTable::AddFormFieldValuesTime( | 723 bool AutofillTable::AddFormFieldValuesTime( |
| 722 const std::vector<FormFieldData>& elements, | 724 const std::vector<FormFieldData>& elements, |
| 723 std::vector<AutofillChange>* changes, | 725 std::vector<AutofillChange>* changes, |
| 724 Time time) { | 726 Time time) { |
| 725 // Only add one new entry for each unique element name. Use |seen_names| to | 727 // Only add one new entry for each unique element name. Use |seen_names| to |
| 726 // track this. Add up to |kMaximumUniqueNames| unique entries per form. | 728 // track this. Add up to |kMaximumUniqueNames| unique entries per form. |
| 727 const size_t kMaximumUniqueNames = 256; | 729 const size_t kMaximumUniqueNames = 256; |
| 728 std::set<string16> seen_names; | 730 std::set<base::string16> seen_names; |
| 729 bool result = true; | 731 bool result = true; |
| 730 for (std::vector<FormFieldData>::const_iterator itr = elements.begin(); | 732 for (std::vector<FormFieldData>::const_iterator itr = elements.begin(); |
| 731 itr != elements.end(); ++itr) { | 733 itr != elements.end(); ++itr) { |
| 732 if (seen_names.size() >= kMaximumUniqueNames) | 734 if (seen_names.size() >= kMaximumUniqueNames) |
| 733 break; | 735 break; |
| 734 if (seen_names.find(itr->name) != seen_names.end()) | 736 if (seen_names.find(itr->name) != seen_names.end()) |
| 735 continue; | 737 continue; |
| 736 result = result && AddFormFieldValueTime(*itr, changes, time); | 738 result = result && AddFormFieldValueTime(*itr, changes, time); |
| 737 seen_names.insert(itr->name); | 739 seen_names.insert(itr->name); |
| 738 } | 740 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 763 | 765 |
| 764 bool AutofillTable::GetAllAutofillEntries(std::vector<AutofillEntry>* entries) { | 766 bool AutofillTable::GetAllAutofillEntries(std::vector<AutofillEntry>* entries) { |
| 765 DCHECK(entries); | 767 DCHECK(entries); |
| 766 sql::Statement s(db_->GetUniqueStatement( | 768 sql::Statement s(db_->GetUniqueStatement( |
| 767 "SELECT name, value, date_created FROM autofill a JOIN " | 769 "SELECT name, value, date_created FROM autofill a JOIN " |
| 768 "autofill_dates ad ON a.pair_id=ad.pair_id")); | 770 "autofill_dates ad ON a.pair_id=ad.pair_id")); |
| 769 | 771 |
| 770 bool first_entry = true; | 772 bool first_entry = true; |
| 771 AutofillKey* current_key_ptr = NULL; | 773 AutofillKey* current_key_ptr = NULL; |
| 772 std::vector<Time>* timestamps_ptr = NULL; | 774 std::vector<Time>* timestamps_ptr = NULL; |
| 773 string16 name, value; | 775 base::string16 name, value; |
| 774 Time time; | 776 Time time; |
| 775 while (s.Step()) { | 777 while (s.Step()) { |
| 776 name = s.ColumnString16(0); | 778 name = s.ColumnString16(0); |
| 777 value = s.ColumnString16(1); | 779 value = s.ColumnString16(1); |
| 778 time = Time::FromTimeT(s.ColumnInt64(2)); | 780 time = Time::FromTimeT(s.ColumnInt64(2)); |
| 779 | 781 |
| 780 if (first_entry) { | 782 if (first_entry) { |
| 781 current_key_ptr = new AutofillKey(name, value); | 783 current_key_ptr = new AutofillKey(name, value); |
| 782 | 784 |
| 783 timestamps_ptr = new std::vector<Time>; | 785 timestamps_ptr = new std::vector<Time>; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 806 if (!first_entry) { | 808 if (!first_entry) { |
| 807 AutofillEntry entry(*current_key_ptr, *timestamps_ptr); | 809 AutofillEntry entry(*current_key_ptr, *timestamps_ptr); |
| 808 entries->push_back(entry); | 810 entries->push_back(entry); |
| 809 delete current_key_ptr; | 811 delete current_key_ptr; |
| 810 delete timestamps_ptr; | 812 delete timestamps_ptr; |
| 811 } | 813 } |
| 812 | 814 |
| 813 return s.Succeeded(); | 815 return s.Succeeded(); |
| 814 } | 816 } |
| 815 | 817 |
| 816 bool AutofillTable::GetAutofillTimestamps(const string16& name, | 818 bool AutofillTable::GetAutofillTimestamps(const base::string16& name, |
| 817 const string16& value, | 819 const base::string16& value, |
| 818 std::vector<Time>* timestamps) { | 820 std::vector<Time>* timestamps) { |
| 819 DCHECK(timestamps); | 821 DCHECK(timestamps); |
| 820 sql::Statement s(db_->GetUniqueStatement( | 822 sql::Statement s(db_->GetUniqueStatement( |
| 821 "SELECT date_created FROM autofill a JOIN " | 823 "SELECT date_created FROM autofill a JOIN " |
| 822 "autofill_dates ad ON a.pair_id=ad.pair_id " | 824 "autofill_dates ad ON a.pair_id=ad.pair_id " |
| 823 "WHERE a.name = ? AND a.value = ?")); | 825 "WHERE a.name = ? AND a.value = ?")); |
| 824 s.BindString16(0, name); | 826 s.BindString16(0, name); |
| 825 s.BindString16(1, value); | 827 s.BindString16(1, value); |
| 826 | 828 |
| 827 while (s.Step()) | 829 while (s.Step()) |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 907 | 909 |
| 908 AutofillChange::Type change_type = | 910 AutofillChange::Type change_type = |
| 909 count == 0 ? AutofillChange::ADD : AutofillChange::UPDATE; | 911 count == 0 ? AutofillChange::ADD : AutofillChange::UPDATE; |
| 910 changes->push_back( | 912 changes->push_back( |
| 911 AutofillChange(change_type, | 913 AutofillChange(change_type, |
| 912 AutofillKey(element.name, element.value))); | 914 AutofillKey(element.name, element.value))); |
| 913 return true; | 915 return true; |
| 914 } | 916 } |
| 915 | 917 |
| 916 | 918 |
| 917 bool AutofillTable::RemoveFormElement(const string16& name, | 919 bool AutofillTable::RemoveFormElement(const base::string16& name, |
| 918 const string16& value) { | 920 const base::string16& value) { |
| 919 // Find the id for that pair. | 921 // Find the id for that pair. |
| 920 sql::Statement s(db_->GetUniqueStatement( | 922 sql::Statement s(db_->GetUniqueStatement( |
| 921 "SELECT pair_id FROM autofill WHERE name = ? AND value= ?")); | 923 "SELECT pair_id FROM autofill WHERE name = ? AND value= ?")); |
| 922 s.BindString16(0, name); | 924 s.BindString16(0, name); |
| 923 s.BindString16(1, value); | 925 s.BindString16(1, value); |
| 924 | 926 |
| 925 if (s.Step()) | 927 if (s.Step()) |
| 926 return RemoveFormElementForID(s.ColumnInt64(0)); | 928 return RemoveFormElementForID(s.ColumnInt64(0)); |
| 927 return false; | 929 return false; |
| 928 } | 930 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1004 AutofillProfile* tmp_profile = NULL; | 1006 AutofillProfile* tmp_profile = NULL; |
| 1005 if (!GetAutofillProfile(profile.guid(), &tmp_profile)) | 1007 if (!GetAutofillProfile(profile.guid(), &tmp_profile)) |
| 1006 return false; | 1008 return false; |
| 1007 | 1009 |
| 1008 // Preserve appropriate modification dates by not updating unchanged profiles. | 1010 // Preserve appropriate modification dates by not updating unchanged profiles. |
| 1009 scoped_ptr<AutofillProfile> old_profile(tmp_profile); | 1011 scoped_ptr<AutofillProfile> old_profile(tmp_profile); |
| 1010 if (old_profile->Compare(profile) == 0) | 1012 if (old_profile->Compare(profile) == 0) |
| 1011 return true; | 1013 return true; |
| 1012 | 1014 |
| 1013 AutofillProfile new_profile(profile); | 1015 AutofillProfile new_profile(profile); |
| 1014 std::vector<string16> values; | 1016 std::vector<base::string16> values; |
| 1015 | 1017 |
| 1016 old_profile->GetRawMultiInfo(NAME_FULL, &values); | 1018 old_profile->GetRawMultiInfo(NAME_FULL, &values); |
| 1017 values[0] = new_profile.GetRawInfo(NAME_FULL); | 1019 values[0] = new_profile.GetRawInfo(NAME_FULL); |
| 1018 new_profile.SetRawMultiInfo(NAME_FULL, values); | 1020 new_profile.SetRawMultiInfo(NAME_FULL, values); |
| 1019 | 1021 |
| 1020 old_profile->GetRawMultiInfo(EMAIL_ADDRESS, &values); | 1022 old_profile->GetRawMultiInfo(EMAIL_ADDRESS, &values); |
| 1021 values[0] = new_profile.GetRawInfo(EMAIL_ADDRESS); | 1023 values[0] = new_profile.GetRawInfo(EMAIL_ADDRESS); |
| 1022 new_profile.SetRawMultiInfo(EMAIL_ADDRESS, values); | 1024 new_profile.SetRawMultiInfo(EMAIL_ADDRESS, values); |
| 1023 | 1025 |
| 1024 old_profile->GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values); | 1026 old_profile->GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values); |
| (...skipping 914 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1939 | 1941 |
| 1940 // Set all the |country_code| fields to match existing |country| values. | 1942 // Set all the |country_code| fields to match existing |country| values. |
| 1941 sql::Statement s(db_->GetUniqueStatement("SELECT guid, country " | 1943 sql::Statement s(db_->GetUniqueStatement("SELECT guid, country " |
| 1942 "FROM autofill_profiles")); | 1944 "FROM autofill_profiles")); |
| 1943 | 1945 |
| 1944 while (s.Step()) { | 1946 while (s.Step()) { |
| 1945 sql::Statement update_s( | 1947 sql::Statement update_s( |
| 1946 db_->GetUniqueStatement("UPDATE autofill_profiles " | 1948 db_->GetUniqueStatement("UPDATE autofill_profiles " |
| 1947 "SET country_code=? WHERE guid=?")); | 1949 "SET country_code=? WHERE guid=?")); |
| 1948 | 1950 |
| 1949 string16 country = s.ColumnString16(1); | 1951 base::string16 country = s.ColumnString16(1); |
| 1950 update_s.BindString(0, AutofillCountry::GetCountryCode(country, | 1952 update_s.BindString(0, AutofillCountry::GetCountryCode(country, |
| 1951 app_locale_)); | 1953 app_locale_)); |
| 1952 update_s.BindString(1, s.ColumnString(0)); | 1954 update_s.BindString(1, s.ColumnString(0)); |
| 1953 | 1955 |
| 1954 if (!update_s.Run()) | 1956 if (!update_s.Run()) |
| 1955 return false; | 1957 return false; |
| 1956 } | 1958 } |
| 1957 if (!s.Succeeded()) | 1959 if (!s.Succeeded()) |
| 1958 return false; | 1960 return false; |
| 1959 } | 1961 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2041 "WHERE guid=?")); | 2043 "WHERE guid=?")); |
| 2042 s_date.BindInt64(0, date_item->second); | 2044 s_date.BindInt64(0, date_item->second); |
| 2043 s_date.BindString(1, iter->guid()); | 2045 s_date.BindString(1, iter->guid()); |
| 2044 | 2046 |
| 2045 if (!s_date.Run()) | 2047 if (!s_date.Run()) |
| 2046 return false; | 2048 return false; |
| 2047 } | 2049 } |
| 2048 | 2050 |
| 2049 return true; | 2051 return true; |
| 2050 } | 2052 } |
| OLD | NEW |