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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 while (s.Step()) { | 207 while (s.Step()) { |
208 DCHECK_EQ(profile->guid(), s.ColumnString(0)); | 208 DCHECK_EQ(profile->guid(), s.ColumnString(0)); |
209 first_names.push_back(s.ColumnString16(1)); | 209 first_names.push_back(s.ColumnString16(1)); |
210 middle_names.push_back(s.ColumnString16(2)); | 210 middle_names.push_back(s.ColumnString16(2)); |
211 last_names.push_back(s.ColumnString16(3)); | 211 last_names.push_back(s.ColumnString16(3)); |
212 full_names.push_back(s.ColumnString16(4)); | 212 full_names.push_back(s.ColumnString16(4)); |
213 } | 213 } |
214 if (!s.Succeeded()) | 214 if (!s.Succeeded()) |
215 return false; | 215 return false; |
216 | 216 |
217 profile->SetRawMultiInfo(NAME_FIRST, first_names); | 217 // TODO(estade): update schema so these aren't vectors. |
218 profile->SetRawMultiInfo(NAME_MIDDLE, middle_names); | 218 first_names.resize(1); |
219 profile->SetRawMultiInfo(NAME_LAST, last_names); | 219 middle_names.resize(1); |
220 profile->SetRawMultiInfo(NAME_FULL, full_names); | 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]); |
221 return true; | 227 return true; |
222 } | 228 } |
223 | 229 |
224 bool AddAutofillProfileEmailsToProfile(sql::Connection* db, | 230 bool AddAutofillProfileEmailsToProfile(sql::Connection* db, |
225 AutofillProfile* profile) { | 231 AutofillProfile* profile) { |
226 sql::Statement s(db->GetUniqueStatement( | 232 sql::Statement s(db->GetUniqueStatement( |
227 "SELECT guid, email " | 233 "SELECT guid, email " |
228 "FROM autofill_profile_emails " | 234 "FROM autofill_profile_emails " |
229 "WHERE guid=?")); | 235 "WHERE guid=?")); |
230 s.BindString(0, profile->guid()); | 236 s.BindString(0, profile->guid()); |
231 | 237 |
232 if (!s.is_valid()) | 238 if (!s.is_valid()) |
233 return false; | 239 return false; |
234 | 240 |
235 std::vector<base::string16> emails; | 241 std::vector<base::string16> emails; |
236 while (s.Step()) { | 242 while (s.Step()) { |
237 DCHECK_EQ(profile->guid(), s.ColumnString(0)); | 243 DCHECK_EQ(profile->guid(), s.ColumnString(0)); |
238 emails.push_back(s.ColumnString16(1)); | 244 emails.push_back(s.ColumnString16(1)); |
239 } | 245 } |
240 if (!s.Succeeded()) | 246 if (!s.Succeeded()) |
241 return false; | 247 return false; |
242 | 248 |
243 profile->SetRawMultiInfo(EMAIL_ADDRESS, emails); | 249 // TODO(estade): update schema so this is not a vector. |
| 250 emails.resize(1); |
| 251 profile->SetRawInfo(EMAIL_ADDRESS, emails[0]); |
244 return true; | 252 return true; |
245 } | 253 } |
246 | 254 |
247 bool AddAutofillProfilePhonesToProfile(sql::Connection* db, | 255 bool AddAutofillProfilePhonesToProfile(sql::Connection* db, |
248 AutofillProfile* profile) { | 256 AutofillProfile* profile) { |
249 sql::Statement s(db->GetUniqueStatement( | 257 sql::Statement s(db->GetUniqueStatement( |
250 "SELECT guid, number " | 258 "SELECT guid, number " |
251 "FROM autofill_profile_phones " | 259 "FROM autofill_profile_phones " |
252 "WHERE guid=?")); | 260 "WHERE guid=?")); |
253 s.BindString(0, profile->guid()); | 261 s.BindString(0, profile->guid()); |
254 | 262 |
255 if (!s.is_valid()) | 263 if (!s.is_valid()) |
256 return false; | 264 return false; |
257 | 265 |
258 std::vector<base::string16> numbers; | 266 std::vector<base::string16> numbers; |
259 while (s.Step()) { | 267 while (s.Step()) { |
260 DCHECK_EQ(profile->guid(), s.ColumnString(0)); | 268 DCHECK_EQ(profile->guid(), s.ColumnString(0)); |
261 numbers.push_back(s.ColumnString16(1)); | 269 numbers.push_back(s.ColumnString16(1)); |
262 } | 270 } |
263 if (!s.Succeeded()) | 271 if (!s.Succeeded()) |
264 return false; | 272 return false; |
265 | 273 |
266 profile->SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, numbers); | 274 // TODO(estade): update schema so this isn't a vector. |
| 275 numbers.resize(1); |
| 276 profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, numbers[0]); |
267 return true; | 277 return true; |
268 } | 278 } |
269 | 279 |
270 bool AddAutofillProfileNames(const AutofillProfile& profile, | 280 bool AddAutofillProfileNames(const AutofillProfile& profile, |
271 sql::Connection* db) { | 281 sql::Connection* db) { |
272 std::vector<base::string16> first_names; | 282 // Add the new name. |
273 profile.GetRawMultiInfo(NAME_FIRST, &first_names); | 283 sql::Statement s(db->GetUniqueStatement( |
274 std::vector<base::string16> middle_names; | 284 "INSERT INTO autofill_profile_names" |
275 profile.GetRawMultiInfo(NAME_MIDDLE, &middle_names); | 285 " (guid, first_name, middle_name, last_name, full_name) " |
276 std::vector<base::string16> last_names; | 286 "VALUES (?,?,?,?,?)")); |
277 profile.GetRawMultiInfo(NAME_LAST, &last_names); | 287 s.BindString(0, profile.guid()); |
278 std::vector<base::string16> full_names; | 288 s.BindString16(1, profile.GetRawInfo(NAME_FIRST)); |
279 profile.GetRawMultiInfo(NAME_FULL, &full_names); | 289 s.BindString16(2, profile.GetRawInfo(NAME_MIDDLE)); |
280 DCHECK_EQ(first_names.size(), middle_names.size()); | 290 s.BindString16(3, profile.GetRawInfo(NAME_LAST)); |
281 DCHECK_EQ(first_names.size(), last_names.size()); | 291 s.BindString16(4, profile.GetRawInfo(NAME_FULL)); |
282 DCHECK_EQ(first_names.size(), full_names.size()); | |
283 | 292 |
284 for (size_t i = 0; i < first_names.size(); ++i) { | 293 return s.Run(); |
285 // Add the new name. | |
286 sql::Statement s(db->GetUniqueStatement( | |
287 "INSERT INTO autofill_profile_names" | |
288 " (guid, first_name, middle_name, last_name, full_name) " | |
289 "VALUES (?,?,?,?,?)")); | |
290 s.BindString(0, profile.guid()); | |
291 s.BindString16(1, first_names[i]); | |
292 s.BindString16(2, middle_names[i]); | |
293 s.BindString16(3, last_names[i]); | |
294 s.BindString16(4, full_names[i]); | |
295 | |
296 if (!s.Run()) | |
297 return false; | |
298 } | |
299 return true; | |
300 } | 294 } |
301 | 295 |
302 bool AddAutofillProfileEmails(const AutofillProfile& profile, | 296 bool AddAutofillProfileEmails(const AutofillProfile& profile, |
303 sql::Connection* db) { | 297 sql::Connection* db) { |
304 std::vector<base::string16> emails; | 298 // Add the new email. |
305 profile.GetRawMultiInfo(EMAIL_ADDRESS, &emails); | 299 sql::Statement s(db->GetUniqueStatement( |
306 | |
307 for (size_t i = 0; i < emails.size(); ++i) { | |
308 // Add the new email. | |
309 sql::Statement s(db->GetUniqueStatement( | |
310 "INSERT INTO autofill_profile_emails" | 300 "INSERT INTO autofill_profile_emails" |
311 " (guid, email) " | 301 " (guid, email) " |
312 "VALUES (?,?)")); | 302 "VALUES (?,?)")); |
313 s.BindString(0, profile.guid()); | 303 s.BindString(0, profile.guid()); |
314 s.BindString16(1, emails[i]); | 304 s.BindString16(1, profile.GetRawInfo(EMAIL_ADDRESS)); |
315 | 305 |
316 if (!s.Run()) | 306 return s.Run(); |
317 return false; | |
318 } | |
319 | |
320 return true; | |
321 } | 307 } |
322 | 308 |
323 bool AddAutofillProfilePhones(const AutofillProfile& profile, | 309 bool AddAutofillProfilePhones(const AutofillProfile& profile, |
324 sql::Connection* db) { | 310 sql::Connection* db) { |
325 std::vector<base::string16> numbers; | 311 // Add the new number. |
326 profile.GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &numbers); | 312 sql::Statement s(db->GetUniqueStatement( |
327 | |
328 for (size_t i = 0; i < numbers.size(); ++i) { | |
329 // Add the new number. | |
330 sql::Statement s(db->GetUniqueStatement( | |
331 "INSERT INTO autofill_profile_phones" | 313 "INSERT INTO autofill_profile_phones" |
332 " (guid, number) " | 314 " (guid, number) " |
333 "VALUES (?,?)")); | 315 "VALUES (?,?)")); |
334 s.BindString(0, profile.guid()); | 316 s.BindString(0, profile.guid()); |
335 s.BindString16(1, numbers[i]); | 317 s.BindString16(1, profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); |
336 | 318 |
337 if (!s.Run()) | 319 return s.Run(); |
338 return false; | |
339 } | |
340 | |
341 return true; | |
342 } | 320 } |
343 | 321 |
344 bool AddAutofillProfilePieces(const AutofillProfile& profile, | 322 bool AddAutofillProfilePieces(const AutofillProfile& profile, |
345 sql::Connection* db) { | 323 sql::Connection* db) { |
346 if (!AddAutofillProfileNames(profile, db)) | 324 if (!AddAutofillProfileNames(profile, db)) |
347 return false; | 325 return false; |
348 | 326 |
349 if (!AddAutofillProfileEmails(profile, db)) | 327 if (!AddAutofillProfileEmails(profile, db)) |
350 return false; | 328 return false; |
351 | 329 |
(...skipping 1884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2236 insert.BindString16(index++, profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); | 2214 insert.BindString16(index++, profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); |
2237 insert.BindString(index++, profile.language_code()); | 2215 insert.BindString(index++, profile.language_code()); |
2238 insert.Run(); | 2216 insert.Run(); |
2239 insert.Reset(true); | 2217 insert.Reset(true); |
2240 } | 2218 } |
2241 | 2219 |
2242 return transaction.Commit(); | 2220 return transaction.Commit(); |
2243 } | 2221 } |
2244 | 2222 |
2245 } // namespace autofill | 2223 } // namespace autofill |
OLD | NEW |