OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/autofill/core/browser/webdata/autofill_table.h" | 5 #include "components/autofill/core/browser/webdata/autofill_table.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <limits> | 9 #include <limits> |
10 #include <map> | 10 #include <map> |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 credit_card->set_use_date(base::Time::FromTimeT(s.ColumnInt64(index++))); | 184 credit_card->set_use_date(base::Time::FromTimeT(s.ColumnInt64(index++))); |
185 credit_card->set_modification_date( | 185 credit_card->set_modification_date( |
186 base::Time::FromTimeT(s.ColumnInt64(index++))); | 186 base::Time::FromTimeT(s.ColumnInt64(index++))); |
187 credit_card->set_origin(s.ColumnString(index++)); | 187 credit_card->set_origin(s.ColumnString(index++)); |
188 | 188 |
189 return credit_card.Pass(); | 189 return credit_card.Pass(); |
190 } | 190 } |
191 | 191 |
192 bool AddAutofillProfileNamesToProfile(sql::Connection* db, | 192 bool AddAutofillProfileNamesToProfile(sql::Connection* db, |
193 AutofillProfile* profile) { | 193 AutofillProfile* profile) { |
194 // TODO(estade): update schema so that multiple names are not associated per | |
195 // unique profile guid. Please refer https://crbug.com/497934. | |
194 sql::Statement s(db->GetUniqueStatement( | 196 sql::Statement s(db->GetUniqueStatement( |
195 "SELECT guid, first_name, middle_name, last_name, full_name " | 197 "SELECT guid, first_name, middle_name, last_name, full_name " |
196 "FROM autofill_profile_names " | 198 "FROM autofill_profile_names " |
197 "WHERE guid=?")); | 199 "WHERE guid=?" |
200 "LIMIT 1")); | |
Scott Hess - ex-Googler
2015/08/12 21:31:29
Note that if you have multiple items with the same
| |
198 s.BindString(0, profile->guid()); | 201 s.BindString(0, profile->guid()); |
199 | 202 |
200 if (!s.is_valid()) | 203 if (!s.is_valid()) |
201 return false; | 204 return false; |
202 | 205 |
203 std::vector<base::string16> first_names; | 206 if (s.Step()) { |
204 std::vector<base::string16> middle_names; | |
205 std::vector<base::string16> last_names; | |
206 std::vector<base::string16> full_names; | |
207 while (s.Step()) { | |
208 DCHECK_EQ(profile->guid(), s.ColumnString(0)); | 207 DCHECK_EQ(profile->guid(), s.ColumnString(0)); |
209 first_names.push_back(s.ColumnString16(1)); | 208 profile->SetRawInfo(NAME_FIRST, s.ColumnString16(1)); |
210 middle_names.push_back(s.ColumnString16(2)); | 209 profile->SetRawInfo(NAME_MIDDLE, s.ColumnString16(2)); |
211 last_names.push_back(s.ColumnString16(3)); | 210 profile->SetRawInfo(NAME_LAST, s.ColumnString16(3)); |
212 full_names.push_back(s.ColumnString16(4)); | 211 profile->SetRawInfo(NAME_FULL, s.ColumnString16(4)); |
213 } | 212 } |
214 if (!s.Succeeded()) | 213 return s.Succeeded(); |
215 return false; | |
216 | |
217 // TODO(estade): update schema so these aren't vectors. | |
218 first_names.resize(1); | |
219 middle_names.resize(1); | |
220 last_names.resize(1); | |
221 full_names.resize(1); | |
222 | |
223 profile->SetRawInfo(NAME_FIRST, first_names[0]); | |
224 profile->SetRawInfo(NAME_MIDDLE, middle_names[0]); | |
225 profile->SetRawInfo(NAME_LAST, last_names[0]); | |
226 profile->SetRawInfo(NAME_FULL, full_names[0]); | |
227 return true; | |
228 } | 214 } |
229 | 215 |
230 bool AddAutofillProfileEmailsToProfile(sql::Connection* db, | 216 bool AddAutofillProfileEmailsToProfile(sql::Connection* db, |
231 AutofillProfile* profile) { | 217 AutofillProfile* profile) { |
218 // TODO(estade): update schema so that multiple emails are not associated per | |
219 // unique profile guid. Please refer https://crbug.com/497934. | |
232 sql::Statement s(db->GetUniqueStatement( | 220 sql::Statement s(db->GetUniqueStatement( |
233 "SELECT guid, email " | 221 "SELECT guid, email " |
234 "FROM autofill_profile_emails " | 222 "FROM autofill_profile_emails " |
235 "WHERE guid=?")); | 223 "WHERE guid=?" |
224 "LIMIT 1")); | |
236 s.BindString(0, profile->guid()); | 225 s.BindString(0, profile->guid()); |
237 | 226 |
238 if (!s.is_valid()) | 227 if (!s.is_valid()) |
239 return false; | 228 return false; |
240 | 229 |
241 std::vector<base::string16> emails; | 230 if (s.Step()) { |
242 while (s.Step()) { | |
243 DCHECK_EQ(profile->guid(), s.ColumnString(0)); | 231 DCHECK_EQ(profile->guid(), s.ColumnString(0)); |
244 emails.push_back(s.ColumnString16(1)); | 232 profile->SetRawInfo(EMAIL_ADDRESS, s.ColumnString16(1)); |
245 } | 233 } |
246 if (!s.Succeeded()) | 234 return s.Succeeded(); |
247 return false; | |
248 | |
249 // TODO(estade): update schema so this is not a vector. | |
250 emails.resize(1); | |
251 profile->SetRawInfo(EMAIL_ADDRESS, emails[0]); | |
252 return true; | |
253 } | 235 } |
254 | 236 |
255 bool AddAutofillProfilePhonesToProfile(sql::Connection* db, | 237 bool AddAutofillProfilePhonesToProfile(sql::Connection* db, |
256 AutofillProfile* profile) { | 238 AutofillProfile* profile) { |
239 // TODO(estade): update schema so that multiple phone numbers are not | |
240 // associated per unique profile guid. Please refer https://crbug.com/497934. | |
257 sql::Statement s(db->GetUniqueStatement( | 241 sql::Statement s(db->GetUniqueStatement( |
258 "SELECT guid, number " | 242 "SELECT guid, number " |
259 "FROM autofill_profile_phones " | 243 "FROM autofill_profile_phones " |
260 "WHERE guid=?")); | 244 "WHERE guid=?" |
245 "LIMIT 1")); | |
261 s.BindString(0, profile->guid()); | 246 s.BindString(0, profile->guid()); |
262 | 247 |
263 if (!s.is_valid()) | 248 if (!s.is_valid()) |
264 return false; | 249 return false; |
265 | 250 |
266 std::vector<base::string16> numbers; | 251 if (s.Step()) { |
267 while (s.Step()) { | |
268 DCHECK_EQ(profile->guid(), s.ColumnString(0)); | 252 DCHECK_EQ(profile->guid(), s.ColumnString(0)); |
269 numbers.push_back(s.ColumnString16(1)); | 253 profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, s.ColumnString16(1)); |
270 } | 254 } |
271 if (!s.Succeeded()) | 255 return s.Succeeded(); |
272 return false; | |
273 | |
274 // TODO(estade): update schema so this isn't a vector. | |
275 numbers.resize(1); | |
276 profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, numbers[0]); | |
277 return true; | |
278 } | 256 } |
279 | 257 |
280 bool AddAutofillProfileNames(const AutofillProfile& profile, | 258 bool AddAutofillProfileNames(const AutofillProfile& profile, |
281 sql::Connection* db) { | 259 sql::Connection* db) { |
282 // Add the new name. | 260 // Add the new name. |
283 sql::Statement s(db->GetUniqueStatement( | 261 sql::Statement s(db->GetUniqueStatement( |
284 "INSERT INTO autofill_profile_names" | 262 "INSERT INTO autofill_profile_names" |
285 " (guid, first_name, middle_name, last_name, full_name) " | 263 " (guid, first_name, middle_name, last_name, full_name) " |
286 "VALUES (?,?,?,?,?)")); | 264 "VALUES (?,?,?,?,?)")); |
287 s.BindString(0, profile.guid()); | 265 s.BindString(0, profile.guid()); |
(...skipping 1926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2214 insert.BindString16(index++, profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); | 2192 insert.BindString16(index++, profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); |
2215 insert.BindString(index++, profile.language_code()); | 2193 insert.BindString(index++, profile.language_code()); |
2216 insert.Run(); | 2194 insert.Run(); |
2217 insert.Reset(true); | 2195 insert.Reset(true); |
2218 } | 2196 } |
2219 | 2197 |
2220 return transaction.Commit(); | 2198 return transaction.Commit(); |
2221 } | 2199 } |
2222 | 2200 |
2223 } // namespace autofill | 2201 } // namespace autofill |
OLD | NEW |