OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 " |
141 "WHERE guid=?")); | 141 "WHERE guid=?")); |
142 if (!s) { | 142 s.BindString(0, profile->guid()); |
143 NOTREACHED() << "Statement prepare failed"; | 143 |
144 if (!s.is_valid()) | |
144 return false; | 145 return false; |
145 } | |
146 s.BindString(0, profile->guid()); | |
147 | 146 |
148 std::vector<string16> first_names; | 147 std::vector<string16> first_names; |
149 std::vector<string16> middle_names; | 148 std::vector<string16> middle_names; |
150 std::vector<string16> last_names; | 149 std::vector<string16> last_names; |
151 while (s.Step()) { | 150 while (s.Step()) { |
152 DCHECK_EQ(profile->guid(), s.ColumnString(0)); | 151 DCHECK_EQ(profile->guid(), s.ColumnString(0)); |
153 first_names.push_back(s.ColumnString16(1)); | 152 first_names.push_back(s.ColumnString16(1)); |
154 middle_names.push_back(s.ColumnString16(2)); | 153 middle_names.push_back(s.ColumnString16(2)); |
155 last_names.push_back(s.ColumnString16(3)); | 154 last_names.push_back(s.ColumnString16(3)); |
156 } | 155 } |
157 profile->SetMultiInfo(NAME_FIRST, first_names); | 156 profile->SetMultiInfo(NAME_FIRST, first_names); |
158 profile->SetMultiInfo(NAME_MIDDLE, middle_names); | 157 profile->SetMultiInfo(NAME_MIDDLE, middle_names); |
159 profile->SetMultiInfo(NAME_LAST, last_names); | 158 profile->SetMultiInfo(NAME_LAST, last_names); |
160 return true; | 159 return true; |
161 } | 160 } |
162 | 161 |
163 bool AddAutofillProfileEmailsToProfile(sql::Connection* db, | 162 bool AddAutofillProfileEmailsToProfile(sql::Connection* db, |
164 AutofillProfile* profile) { | 163 AutofillProfile* profile) { |
165 sql::Statement s(db->GetUniqueStatement( | 164 sql::Statement s(db->GetUniqueStatement( |
166 "SELECT guid, email " | 165 "SELECT guid, email " |
167 "FROM autofill_profile_emails " | 166 "FROM autofill_profile_emails " |
168 "WHERE guid=?")); | 167 "WHERE guid=?")); |
169 if (!s) { | 168 s.BindString(0, profile->guid()); |
170 NOTREACHED() << "Statement prepare failed"; | 169 |
170 if (!s.is_valid()) | |
171 return false; | 171 return false; |
172 } | |
173 s.BindString(0, profile->guid()); | |
174 | 172 |
175 std::vector<string16> emails; | 173 std::vector<string16> emails; |
176 while (s.Step()) { | 174 while (s.Step()) { |
177 DCHECK_EQ(profile->guid(), s.ColumnString(0)); | 175 DCHECK_EQ(profile->guid(), s.ColumnString(0)); |
178 emails.push_back(s.ColumnString16(1)); | 176 emails.push_back(s.ColumnString16(1)); |
179 } | 177 } |
180 profile->SetMultiInfo(EMAIL_ADDRESS, emails); | 178 profile->SetMultiInfo(EMAIL_ADDRESS, emails); |
181 return true; | 179 return true; |
182 } | 180 } |
183 | 181 |
184 bool AddAutofillProfilePhonesToProfile(sql::Connection* db, | 182 bool AddAutofillProfilePhonesToProfile(sql::Connection* db, |
185 AutofillProfile* profile) { | 183 AutofillProfile* profile) { |
186 sql::Statement s(db->GetUniqueStatement( | 184 sql::Statement s(db->GetUniqueStatement( |
187 "SELECT guid, type, number " | 185 "SELECT guid, type, number " |
188 "FROM autofill_profile_phones " | 186 "FROM autofill_profile_phones " |
189 "WHERE guid=? AND type=?")); | 187 "WHERE guid=? AND type=?")); |
190 if (!s) { | 188 |
191 NOTREACHED() << "Statement prepare failed"; | 189 // Value used to be either [(0, phone), (1, fax)] but fax has been removed. |
190 s.BindString(0, profile->guid()); | |
191 s.BindInt(1, 0); | |
192 | |
193 if (!s.is_valid()) | |
192 return false; | 194 return false; |
193 } | |
194 s.BindString(0, profile->guid()); | |
195 // Value used to be either [(0, phone), (1, fax)] but fax has been removed. | |
196 s.BindInt(1, 0); | |
197 | 195 |
198 std::vector<string16> numbers; | 196 std::vector<string16> numbers; |
199 while (s.Step()) { | 197 while (s.Step()) { |
Scott Hess - ex-Googler
2011/12/15 23:02:57
Step() could return false either because it has re
Greg Billock
2011/12/16 17:26:58
If it returns false we'll exit the loop, right? Bu
| |
200 DCHECK_EQ(profile->guid(), s.ColumnString(0)); | 198 DCHECK_EQ(profile->guid(), s.ColumnString(0)); |
201 numbers.push_back(s.ColumnString16(2)); | 199 numbers.push_back(s.ColumnString16(2)); |
202 } | 200 } |
203 profile->SetMultiInfo(PHONE_HOME_WHOLE_NUMBER, numbers); | 201 profile->SetMultiInfo(PHONE_HOME_WHOLE_NUMBER, numbers); |
204 return true; | 202 return true; |
205 } | 203 } |
206 | 204 |
207 bool AddAutofillProfileNames(const AutofillProfile& profile, | 205 bool AddAutofillProfileNames(const AutofillProfile& profile, |
208 sql::Connection* db) { | 206 sql::Connection* db) { |
209 std::vector<string16> first_names; | 207 std::vector<string16> first_names; |
210 profile.GetMultiInfo(NAME_FIRST, &first_names); | 208 profile.GetMultiInfo(NAME_FIRST, &first_names); |
211 std::vector<string16> middle_names; | 209 std::vector<string16> middle_names; |
212 profile.GetMultiInfo(NAME_MIDDLE, &middle_names); | 210 profile.GetMultiInfo(NAME_MIDDLE, &middle_names); |
213 std::vector<string16> last_names; | 211 std::vector<string16> last_names; |
214 profile.GetMultiInfo(NAME_LAST, &last_names); | 212 profile.GetMultiInfo(NAME_LAST, &last_names); |
215 DCHECK_EQ(first_names.size(), middle_names.size()); | 213 DCHECK_EQ(first_names.size(), middle_names.size()); |
216 DCHECK_EQ(middle_names.size(), last_names.size()); | 214 DCHECK_EQ(middle_names.size(), last_names.size()); |
217 | 215 |
218 for (size_t i = 0; i < first_names.size(); ++i) { | 216 for (size_t i = 0; i < first_names.size(); ++i) { |
219 // Add the new name. | 217 // Add the new name. |
220 sql::Statement s(db->GetUniqueStatement( | 218 sql::Statement s(db->GetUniqueStatement( |
221 "INSERT INTO autofill_profile_names" | 219 "INSERT INTO autofill_profile_names" |
222 " (guid, first_name, middle_name, last_name) " | 220 " (guid, first_name, middle_name, last_name) " |
223 "VALUES (?,?,?,?)")); | 221 "VALUES (?,?,?,?)")); |
224 if (!s) { | |
225 NOTREACHED(); | |
226 return false; | |
227 } | |
228 s.BindString(0, profile.guid()); | 222 s.BindString(0, profile.guid()); |
229 s.BindString16(1, first_names[i]); | 223 s.BindString16(1, first_names[i]); |
230 s.BindString16(2, middle_names[i]); | 224 s.BindString16(2, middle_names[i]); |
231 s.BindString16(3, last_names[i]); | 225 s.BindString16(3, last_names[i]); |
232 | 226 |
233 if (!s.Run()) { | 227 if (!s.Run()) |
234 NOTREACHED(); | |
235 return false; | 228 return false; |
236 } | |
237 } | 229 } |
238 return true; | 230 return true; |
239 } | 231 } |
240 | 232 |
241 bool AddAutofillProfileEmails(const AutofillProfile& profile, | 233 bool AddAutofillProfileEmails(const AutofillProfile& profile, |
242 sql::Connection* db) { | 234 sql::Connection* db) { |
243 std::vector<string16> emails; | 235 std::vector<string16> emails; |
244 profile.GetMultiInfo(EMAIL_ADDRESS, &emails); | 236 profile.GetMultiInfo(EMAIL_ADDRESS, &emails); |
245 | 237 |
246 for (size_t i = 0; i < emails.size(); ++i) { | 238 for (size_t i = 0; i < emails.size(); ++i) { |
247 // Add the new email. | 239 // Add the new email. |
248 sql::Statement s(db->GetUniqueStatement( | 240 sql::Statement s(db->GetUniqueStatement( |
249 "INSERT INTO autofill_profile_emails" | 241 "INSERT INTO autofill_profile_emails" |
250 " (guid, email) " | 242 " (guid, email) " |
251 "VALUES (?,?)")); | 243 "VALUES (?,?)")); |
252 if (!s) { | |
253 NOTREACHED(); | |
254 return false; | |
255 } | |
256 s.BindString(0, profile.guid()); | 244 s.BindString(0, profile.guid()); |
257 s.BindString16(1, emails[i]); | 245 s.BindString16(1, emails[i]); |
258 | 246 |
259 if (!s.Run()) { | 247 if (!s.Run()) |
260 NOTREACHED(); | |
261 return false; | 248 return false; |
262 } | |
263 } | 249 } |
250 | |
264 return true; | 251 return true; |
265 } | 252 } |
266 | 253 |
267 bool AddAutofillProfilePhones(const AutofillProfile& profile, | 254 bool AddAutofillProfilePhones(const AutofillProfile& profile, |
268 sql::Connection* db) { | 255 sql::Connection* db) { |
269 std::vector<string16> numbers; | 256 std::vector<string16> numbers; |
270 profile.GetMultiInfo(PHONE_HOME_WHOLE_NUMBER, &numbers); | 257 profile.GetMultiInfo(PHONE_HOME_WHOLE_NUMBER, &numbers); |
271 | 258 |
272 for (size_t i = 0; i < numbers.size(); ++i) { | 259 for (size_t i = 0; i < numbers.size(); ++i) { |
273 // Add the new number. | 260 // Add the new number. |
274 sql::Statement s(db->GetUniqueStatement( | 261 sql::Statement s(db->GetUniqueStatement( |
275 "INSERT INTO autofill_profile_phones" | 262 "INSERT INTO autofill_profile_phones" |
276 " (guid, type, number) " | 263 " (guid, type, number) " |
277 "VALUES (?,?,?)")); | 264 "VALUES (?,?,?)")); |
278 if (!s) { | |
279 NOTREACHED(); | |
280 return false; | |
281 } | |
282 s.BindString(0, profile.guid()); | 265 s.BindString(0, profile.guid()); |
283 // Value used to be either [(0, phone), (1, fax)] but fax has been removed. | 266 // Value used to be either [(0, phone), (1, fax)] but fax has been removed. |
284 s.BindInt(1, 0); | 267 s.BindInt(1, 0); |
285 s.BindString16(2, numbers[i]); | 268 s.BindString16(2, numbers[i]); |
286 | 269 |
287 if (!s.Run()) { | 270 if (!s.Run()) |
288 NOTREACHED(); | |
289 return false; | 271 return false; |
290 } | |
291 } | 272 } |
292 | 273 |
293 return true; | 274 return true; |
294 } | 275 } |
295 | 276 |
296 bool AddAutofillProfilePieces(const AutofillProfile& profile, | 277 bool AddAutofillProfilePieces(const AutofillProfile& profile, |
297 sql::Connection* db) { | 278 sql::Connection* db) { |
298 if (!AddAutofillProfileNames(profile, db)) | 279 if (!AddAutofillProfileNames(profile, db)) |
299 return false; | 280 return false; |
300 | 281 |
301 if (!AddAutofillProfileEmails(profile, db)) | 282 if (!AddAutofillProfileEmails(profile, db)) |
302 return false; | 283 return false; |
303 | 284 |
304 if (!AddAutofillProfilePhones(profile, db)) | 285 if (!AddAutofillProfilePhones(profile, db)) |
305 return false; | 286 return false; |
306 | 287 |
307 return true; | 288 return true; |
308 } | 289 } |
309 | 290 |
310 bool RemoveAutofillProfilePieces(const std::string& guid, sql::Connection* db) { | 291 bool RemoveAutofillProfilePieces(const std::string& guid, sql::Connection* db) { |
311 sql::Statement s1(db->GetUniqueStatement( | 292 sql::Statement s1(db->GetUniqueStatement( |
312 "DELETE FROM autofill_profile_names WHERE guid = ?")); | 293 "DELETE FROM autofill_profile_names WHERE guid = ?")); |
313 if (!s1) { | 294 s1.BindString(0, guid); |
314 NOTREACHED() << "Statement prepare failed"; | |
315 return false; | |
316 } | |
317 | 295 |
318 s1.BindString(0, guid); | |
319 if (!s1.Run()) | 296 if (!s1.Run()) |
320 return false; | 297 return false; |
321 | 298 |
322 sql::Statement s2(db->GetUniqueStatement( | 299 sql::Statement s2(db->GetUniqueStatement( |
323 "DELETE FROM autofill_profile_emails WHERE guid = ?")); | 300 "DELETE FROM autofill_profile_emails WHERE guid = ?")); |
324 if (!s2) { | 301 s2.BindString(0, guid); |
325 NOTREACHED() << "Statement prepare failed"; | |
326 return false; | |
327 } | |
328 | 302 |
329 s2.BindString(0, guid); | |
330 if (!s2.Run()) | 303 if (!s2.Run()) |
331 return false; | 304 return false; |
332 | 305 |
333 sql::Statement s3(db->GetUniqueStatement( | 306 sql::Statement s3(db->GetUniqueStatement( |
334 "DELETE FROM autofill_profile_phones WHERE guid = ?")); | 307 "DELETE FROM autofill_profile_phones WHERE guid = ?")); |
335 if (!s3) { | 308 s3.BindString(0, guid); |
336 NOTREACHED() << "Statement prepare failed"; | |
337 return false; | |
338 } | |
339 | 309 |
340 s3.BindString(0, guid); | |
341 return s3.Run(); | 310 return s3.Run(); |
342 } | 311 } |
343 | 312 |
344 } // namespace | 313 } // namespace |
345 | 314 |
346 // The maximum length allowed for form data. | 315 // The maximum length allowed for form data. |
347 const size_t AutofillTable::kMaxDataLength = 1024; | 316 const size_t AutofillTable::kMaxDataLength = 1024; |
348 | 317 |
349 AutofillTable::AutofillTable(sql::Connection* db, sql::MetaTable* meta_table) | 318 AutofillTable::AutofillTable(sql::Connection* db, sql::MetaTable* meta_table) |
350 : WebDatabaseTable(db, meta_table) { | 319 : WebDatabaseTable(db, meta_table) { |
(...skipping 29 matching lines...) Expand all Loading... | |
380 int limit) { | 349 int limit) { |
381 DCHECK(values); | 350 DCHECK(values); |
382 sql::Statement s; | 351 sql::Statement s; |
383 | 352 |
384 if (prefix.empty()) { | 353 if (prefix.empty()) { |
385 s.Assign(db_->GetUniqueStatement( | 354 s.Assign(db_->GetUniqueStatement( |
386 "SELECT value FROM autofill " | 355 "SELECT value FROM autofill " |
387 "WHERE name = ? " | 356 "WHERE name = ? " |
388 "ORDER BY count DESC " | 357 "ORDER BY count DESC " |
389 "LIMIT ?")); | 358 "LIMIT ?")); |
390 if (!s) { | |
391 NOTREACHED() << "Statement prepare failed"; | |
392 return false; | |
393 } | |
394 | |
395 s.BindString16(0, name); | 359 s.BindString16(0, name); |
396 s.BindInt(1, limit); | 360 s.BindInt(1, limit); |
397 } else { | 361 } else { |
398 string16 prefix_lower = base::i18n::ToLower(prefix); | 362 string16 prefix_lower = base::i18n::ToLower(prefix); |
399 string16 next_prefix = prefix_lower; | 363 string16 next_prefix = prefix_lower; |
400 next_prefix[next_prefix.length() - 1]++; | 364 next_prefix[next_prefix.length() - 1]++; |
401 | 365 |
402 s.Assign(db_->GetUniqueStatement( | 366 s.Assign(db_->GetUniqueStatement( |
403 "SELECT value FROM autofill " | 367 "SELECT value FROM autofill " |
404 "WHERE name = ? AND " | 368 "WHERE name = ? AND " |
405 "value_lower >= ? AND " | 369 "value_lower >= ? AND " |
406 "value_lower < ? " | 370 "value_lower < ? " |
407 "ORDER BY count DESC " | 371 "ORDER BY count DESC " |
408 "LIMIT ?")); | 372 "LIMIT ?")); |
409 if (!s) { | |
410 NOTREACHED() << "Statement prepare failed"; | |
411 return false; | |
412 } | |
413 | |
414 s.BindString16(0, name); | 373 s.BindString16(0, name); |
415 s.BindString16(1, prefix_lower); | 374 s.BindString16(1, prefix_lower); |
416 s.BindString16(2, next_prefix); | 375 s.BindString16(2, next_prefix); |
417 s.BindInt(3, limit); | 376 s.BindInt(3, limit); |
418 } | 377 } |
419 | 378 |
420 values->clear(); | 379 values->clear(); |
421 while (s.Step()) | 380 while (s.Step()) |
422 values->push_back(s.ColumnString16(0)); | 381 values->push_back(s.ColumnString16(0)); |
423 return s.Succeeded(); | 382 return s.Succeeded(); |
424 } | 383 } |
425 | 384 |
426 bool AutofillTable::RemoveFormElementsAddedBetween( | 385 bool AutofillTable::RemoveFormElementsAddedBetween( |
427 const Time& delete_begin, | 386 const Time& delete_begin, |
428 const Time& delete_end, | 387 const Time& delete_end, |
429 std::vector<AutofillChange>* changes) { | 388 std::vector<AutofillChange>* changes) { |
430 DCHECK(changes); | 389 DCHECK(changes); |
431 // Query for the pair_id, name, and value of all form elements that | 390 // Query for the pair_id, name, and value of all form elements that |
432 // were used between the given times. | 391 // were used between the given times. |
433 sql::Statement s(db_->GetUniqueStatement( | 392 sql::Statement s(db_->GetUniqueStatement( |
434 "SELECT DISTINCT a.pair_id, a.name, a.value " | 393 "SELECT DISTINCT a.pair_id, a.name, a.value " |
435 "FROM autofill_dates ad JOIN autofill a ON ad.pair_id = a.pair_id " | 394 "FROM autofill_dates ad JOIN autofill a ON ad.pair_id = a.pair_id " |
436 "WHERE ad.date_created >= ? AND ad.date_created < ?")); | 395 "WHERE ad.date_created >= ? AND ad.date_created < ?")); |
437 if (!s) { | |
438 NOTREACHED() << "Statement 1 prepare failed"; | |
439 return false; | |
440 } | |
441 s.BindInt64(0, delete_begin.ToTimeT()); | 396 s.BindInt64(0, delete_begin.ToTimeT()); |
442 s.BindInt64(1, | 397 s.BindInt64(1, |
443 delete_end.is_null() ? | 398 delete_end.is_null() ? |
444 std::numeric_limits<int64>::max() : | 399 std::numeric_limits<int64>::max() : |
445 delete_end.ToTimeT()); | 400 delete_end.ToTimeT()); |
446 | 401 |
447 AutofillElementList elements; | 402 AutofillElementList elements; |
448 while (s.Step()) { | 403 while (s.Step()) { |
449 elements.push_back(MakeTuple(s.ColumnInt64(0), | 404 elements.push_back(MakeTuple(s.ColumnInt64(0), |
450 s.ColumnString16(1), | 405 s.ColumnString16(1), |
451 s.ColumnString16(2))); | 406 s.ColumnString16(2))); |
452 } | 407 } |
453 | 408 |
454 if (!s.Succeeded()) { | 409 if (!s.Succeeded()) |
455 NOTREACHED(); | |
456 return false; | 410 return false; |
457 } | |
458 | 411 |
459 for (AutofillElementList::iterator itr = elements.begin(); | 412 for (AutofillElementList::iterator itr = elements.begin(); |
460 itr != elements.end(); itr++) { | 413 itr != elements.end(); itr++) { |
461 int how_many = 0; | 414 int how_many = 0; |
462 if (!RemoveFormElementForTimeRange(itr->a, delete_begin, delete_end, | 415 if (!RemoveFormElementForTimeRange(itr->a, delete_begin, delete_end, |
463 &how_many)) { | 416 &how_many)) { |
464 return false; | 417 return false; |
465 } | 418 } |
466 bool was_removed = false; | 419 bool was_removed = false; |
467 if (!AddToCountOfFormElement(itr->a, -how_many, &was_removed)) | 420 if (!AddToCountOfFormElement(itr->a, -how_many, &was_removed)) |
468 return false; | 421 return false; |
469 AutofillChange::Type change_type = | 422 AutofillChange::Type change_type = |
470 was_removed ? AutofillChange::REMOVE : AutofillChange::UPDATE; | 423 was_removed ? AutofillChange::REMOVE : AutofillChange::UPDATE; |
471 changes->push_back(AutofillChange(change_type, | 424 changes->push_back(AutofillChange(change_type, |
472 AutofillKey(itr->b, itr->c))); | 425 AutofillKey(itr->b, itr->c))); |
473 } | 426 } |
474 | 427 |
475 return true; | 428 return true; |
476 } | 429 } |
477 | 430 |
478 bool AutofillTable::RemoveFormElementForTimeRange(int64 pair_id, | 431 bool AutofillTable::RemoveFormElementForTimeRange(int64 pair_id, |
479 const Time& delete_begin, | 432 const Time& delete_begin, |
480 const Time& delete_end, | 433 const Time& delete_end, |
481 int* how_many) { | 434 int* how_many) { |
482 sql::Statement s(db_->GetUniqueStatement( | 435 sql::Statement s(db_->GetUniqueStatement( |
483 "DELETE FROM autofill_dates WHERE pair_id = ? AND " | 436 "DELETE FROM autofill_dates WHERE pair_id = ? AND " |
484 "date_created >= ? AND date_created < ?")); | 437 "date_created >= ? AND date_created < ?")); |
485 if (!s) { | |
486 NOTREACHED() << "Statement 1 prepare failed"; | |
487 return false; | |
488 } | |
489 s.BindInt64(0, pair_id); | 438 s.BindInt64(0, pair_id); |
490 s.BindInt64(1, delete_begin.is_null() ? 0 : delete_begin.ToTimeT()); | 439 s.BindInt64(1, delete_begin.is_null() ? 0 : delete_begin.ToTimeT()); |
491 s.BindInt64(2, delete_end.is_null() ? std::numeric_limits<int64>::max() : | 440 s.BindInt64(2, delete_end.is_null() ? std::numeric_limits<int64>::max() : |
492 delete_end.ToTimeT()); | 441 delete_end.ToTimeT()); |
493 | 442 |
494 bool result = s.Run(); | 443 bool result = s.Run(); |
495 if (how_many) | 444 if (how_many) |
496 *how_many = db_->GetLastChangeCount(); | 445 *how_many = db_->GetLastChangeCount(); |
497 | 446 |
498 return result; | 447 return result; |
(...skipping 17 matching lines...) Expand all Loading... | |
516 if (!SetCountOfFormElement(pair_id, count + delta)) | 465 if (!SetCountOfFormElement(pair_id, count + delta)) |
517 return false; | 466 return false; |
518 } | 467 } |
519 return true; | 468 return true; |
520 } | 469 } |
521 | 470 |
522 bool AutofillTable::GetIDAndCountOfFormElement( | 471 bool AutofillTable::GetIDAndCountOfFormElement( |
523 const FormField& element, | 472 const FormField& element, |
524 int64* pair_id, | 473 int64* pair_id, |
525 int* count) { | 474 int* count) { |
475 DCHECK(pair_id); | |
476 DCHECK(count); | |
477 | |
526 sql::Statement s(db_->GetUniqueStatement( | 478 sql::Statement s(db_->GetUniqueStatement( |
527 "SELECT pair_id, count FROM autofill " | 479 "SELECT pair_id, count FROM autofill " |
528 "WHERE name = ? AND value = ?")); | 480 "WHERE name = ? AND value = ?")); |
529 if (!s) { | |
530 NOTREACHED() << "Statement prepare failed"; | |
531 return false; | |
532 } | |
533 | |
534 s.BindString16(0, element.name); | 481 s.BindString16(0, element.name); |
535 s.BindString16(1, element.value); | 482 s.BindString16(1, element.value); |
536 | 483 |
484 if (!s.is_valid()) | |
485 return false; | |
486 | |
537 *pair_id = 0; | 487 *pair_id = 0; |
538 *count = 0; | 488 *count = 0; |
539 | 489 |
540 if (s.Step()) { | 490 if (s.Step()) { |
541 *pair_id = s.ColumnInt64(0); | 491 *pair_id = s.ColumnInt64(0); |
542 *count = s.ColumnInt(1); | 492 *count = s.ColumnInt(1); |
543 } | 493 } |
544 | 494 |
545 return true; | 495 return true; |
546 } | 496 } |
547 | 497 |
548 bool AutofillTable::GetCountOfFormElement(int64 pair_id, int* count) { | 498 bool AutofillTable::GetCountOfFormElement(int64 pair_id, int* count) { |
499 DCHECK(count); | |
549 sql::Statement s(db_->GetUniqueStatement( | 500 sql::Statement s(db_->GetUniqueStatement( |
550 "SELECT count FROM autofill WHERE pair_id = ?")); | 501 "SELECT count FROM autofill WHERE pair_id = ?")); |
551 if (!s) { | |
552 NOTREACHED() << "Statement prepare failed"; | |
553 return false; | |
554 } | |
555 | |
556 s.BindInt64(0, pair_id); | 502 s.BindInt64(0, pair_id); |
557 | 503 |
558 if (s.Step()) { | 504 if (s.Step()) { |
559 *count = s.ColumnInt(0); | 505 *count = s.ColumnInt(0); |
560 return true; | 506 return true; |
561 } | 507 } |
562 return false; | 508 return false; |
563 } | 509 } |
564 | 510 |
565 bool AutofillTable::SetCountOfFormElement(int64 pair_id, int count) { | 511 bool AutofillTable::SetCountOfFormElement(int64 pair_id, int count) { |
566 sql::Statement s(db_->GetUniqueStatement( | 512 sql::Statement s(db_->GetUniqueStatement( |
567 "UPDATE autofill SET count = ? WHERE pair_id = ?")); | 513 "UPDATE autofill SET count = ? WHERE pair_id = ?")); |
568 if (!s) { | |
569 NOTREACHED() << "Statement prepare failed"; | |
570 return false; | |
571 } | |
572 | |
573 s.BindInt(0, count); | 514 s.BindInt(0, count); |
574 s.BindInt64(1, pair_id); | 515 s.BindInt64(1, pair_id); |
575 if (!s.Run()) { | |
576 NOTREACHED(); | |
577 return false; | |
578 } | |
579 | 516 |
580 return true; | 517 return s.Run(); |
581 } | 518 } |
582 | 519 |
583 bool AutofillTable::InsertFormElement(const FormField& element, | 520 bool AutofillTable::InsertFormElement(const FormField& element, |
584 int64* pair_id) { | 521 int64* pair_id) { |
522 DCHECK(pair_id); | |
585 sql::Statement s(db_->GetUniqueStatement( | 523 sql::Statement s(db_->GetUniqueStatement( |
586 "INSERT INTO autofill (name, value, value_lower) VALUES (?,?,?)")); | 524 "INSERT INTO autofill (name, value, value_lower) VALUES (?,?,?)")); |
587 if (!s) { | |
588 NOTREACHED() << "Statement prepare failed"; | |
589 return false; | |
590 } | |
591 | |
592 s.BindString16(0, element.name); | 525 s.BindString16(0, element.name); |
593 s.BindString16(1, element.value); | 526 s.BindString16(1, element.value); |
594 s.BindString16(2, base::i18n::ToLower(element.value)); | 527 s.BindString16(2, base::i18n::ToLower(element.value)); |
595 | 528 |
596 if (!s.Run()) { | 529 if (!s.Run()) |
597 NOTREACHED(); | |
598 return false; | 530 return false; |
599 } | |
600 | 531 |
601 *pair_id = db_->GetLastInsertRowId(); | 532 *pair_id = db_->GetLastInsertRowId(); |
602 return true; | 533 return true; |
603 } | 534 } |
604 | 535 |
605 bool AutofillTable::InsertPairIDAndDate(int64 pair_id, | 536 bool AutofillTable::InsertPairIDAndDate(int64 pair_id, |
606 const Time& date_created) { | 537 const Time& date_created) { |
607 sql::Statement s(db_->GetUniqueStatement( | 538 sql::Statement s(db_->GetUniqueStatement( |
608 "INSERT INTO autofill_dates " | 539 "INSERT INTO autofill_dates " |
609 "(pair_id, date_created) VALUES (?, ?)")); | 540 "(pair_id, date_created) VALUES (?, ?)")); |
610 if (!s) { | |
611 NOTREACHED() << "Statement prepare failed"; | |
612 return false; | |
613 } | |
614 | |
615 s.BindInt64(0, pair_id); | 541 s.BindInt64(0, pair_id); |
616 s.BindInt64(1, date_created.ToTimeT()); | 542 s.BindInt64(1, date_created.ToTimeT()); |
617 | 543 |
618 if (!s.Run()) { | 544 return s.Run(); |
619 NOTREACHED(); | |
620 return false; | |
621 } | |
622 | |
623 return true; | |
624 } | 545 } |
625 | 546 |
626 bool AutofillTable::AddFormFieldValuesTime( | 547 bool AutofillTable::AddFormFieldValuesTime( |
627 const std::vector<FormField>& elements, | 548 const std::vector<FormField>& elements, |
628 std::vector<AutofillChange>* changes, | 549 std::vector<AutofillChange>* changes, |
629 Time time) { | 550 Time time) { |
630 // Only add one new entry for each unique element name. Use |seen_names| to | 551 // Only add one new entry for each unique element name. Use |seen_names| to |
631 // track this. Add up to |kMaximumUniqueNames| unique entries per form. | 552 // track this. Add up to |kMaximumUniqueNames| unique entries per form. |
632 const size_t kMaximumUniqueNames = 256; | 553 const size_t kMaximumUniqueNames = 256; |
633 std::set<string16> seen_names; | 554 std::set<string16> seen_names; |
634 bool result = true; | 555 bool result = true; |
635 for (std::vector<FormField>::const_iterator | 556 for (std::vector<FormField>::const_iterator |
636 itr = elements.begin(); | 557 itr = elements.begin(); |
637 itr != elements.end(); | 558 itr != elements.end(); |
638 itr++) { | 559 itr++) { |
639 if (seen_names.size() >= kMaximumUniqueNames) | 560 if (seen_names.size() >= kMaximumUniqueNames) |
640 break; | 561 break; |
641 if (seen_names.find(itr->name) != seen_names.end()) | 562 if (seen_names.find(itr->name) != seen_names.end()) |
642 continue; | 563 continue; |
643 result = result && AddFormFieldValueTime(*itr, changes, time); | 564 result = result && AddFormFieldValueTime(*itr, changes, time); |
644 seen_names.insert(itr->name); | 565 seen_names.insert(itr->name); |
645 } | 566 } |
646 return result; | 567 return result; |
647 } | 568 } |
648 | 569 |
649 bool AutofillTable::ClearAutofillEmptyValueElements() { | 570 bool AutofillTable::ClearAutofillEmptyValueElements() { |
650 sql::Statement s(db_->GetUniqueStatement( | 571 sql::Statement s(db_->GetUniqueStatement( |
651 "SELECT pair_id FROM autofill WHERE TRIM(value)= \"\"")); | 572 "SELECT pair_id FROM autofill WHERE TRIM(value)= \"\"")); |
652 if (!s) { | 573 if (!s.is_valid()) |
653 NOTREACHED() << "Statement prepare failed"; | |
654 return false; | 574 return false; |
655 } | |
656 | 575 |
657 std::set<int64> ids; | 576 std::set<int64> ids; |
658 while (s.Step()) | 577 while (s.Step()) |
659 ids.insert(s.ColumnInt64(0)); | 578 ids.insert(s.ColumnInt64(0)); |
660 | 579 |
661 bool success = true; | 580 bool success = true; |
662 for (std::set<int64>::const_iterator iter = ids.begin(); iter != ids.end(); | 581 for (std::set<int64>::const_iterator iter = ids.begin(); iter != ids.end(); |
663 ++iter) { | 582 ++iter) { |
664 if (!RemoveFormElementForID(*iter)) | 583 if (!RemoveFormElementForID(*iter)) |
665 success = false; | 584 success = false; |
666 } | 585 } |
667 | 586 |
668 return success; | 587 return success; |
669 } | 588 } |
670 | 589 |
671 bool AutofillTable::GetAllAutofillEntries(std::vector<AutofillEntry>* entries) { | 590 bool AutofillTable::GetAllAutofillEntries(std::vector<AutofillEntry>* entries) { |
672 DCHECK(entries); | 591 DCHECK(entries); |
673 sql::Statement s(db_->GetUniqueStatement( | 592 sql::Statement s(db_->GetUniqueStatement( |
674 "SELECT name, value, date_created FROM autofill a JOIN " | 593 "SELECT name, value, date_created FROM autofill a JOIN " |
675 "autofill_dates ad ON a.pair_id=ad.pair_id")); | 594 "autofill_dates ad ON a.pair_id=ad.pair_id")); |
676 | 595 |
677 if (!s) { | |
678 NOTREACHED() << "Statement prepare failed"; | |
679 return false; | |
680 } | |
681 | |
682 bool first_entry = true; | 596 bool first_entry = true; |
683 AutofillKey* current_key_ptr = NULL; | 597 AutofillKey* current_key_ptr = NULL; |
684 std::vector<Time>* timestamps_ptr = NULL; | 598 std::vector<Time>* timestamps_ptr = NULL; |
685 string16 name, value; | 599 string16 name, value; |
686 Time time; | 600 Time time; |
687 while (s.Step()) { | 601 while (s.Step()) { |
688 name = s.ColumnString16(0); | 602 name = s.ColumnString16(0); |
689 value = s.ColumnString16(1); | 603 value = s.ColumnString16(1); |
690 time = Time::FromTimeT(s.ColumnInt64(2)); | 604 time = Time::FromTimeT(s.ColumnInt64(2)); |
691 | 605 |
(...skipping 13 matching lines...) Expand all Loading... | |
705 | 619 |
706 delete current_key_ptr; | 620 delete current_key_ptr; |
707 delete timestamps_ptr; | 621 delete timestamps_ptr; |
708 | 622 |
709 current_key_ptr = new AutofillKey(name, value); | 623 current_key_ptr = new AutofillKey(name, value); |
710 timestamps_ptr = new std::vector<Time>; | 624 timestamps_ptr = new std::vector<Time>; |
711 } | 625 } |
712 timestamps_ptr->push_back(time); | 626 timestamps_ptr->push_back(time); |
713 } | 627 } |
714 } | 628 } |
629 | |
630 if (!s.is_valid()) | |
631 return false; | |
632 | |
715 // If there is at least one result returned, first_entry will be false. | 633 // If there is at least one result returned, first_entry will be false. |
716 // For this case we need to do a final cleanup step. | 634 // For this case we need to do a final cleanup step. |
717 if (!first_entry) { | 635 if (!first_entry) { |
718 AutofillEntry entry(*current_key_ptr, *timestamps_ptr); | 636 AutofillEntry entry(*current_key_ptr, *timestamps_ptr); |
719 entries->push_back(entry); | 637 entries->push_back(entry); |
720 delete current_key_ptr; | 638 delete current_key_ptr; |
721 delete timestamps_ptr; | 639 delete timestamps_ptr; |
722 } | 640 } |
723 | 641 |
724 return s.Succeeded(); | 642 return s.Succeeded(); |
725 } | 643 } |
726 | 644 |
727 bool AutofillTable::GetAutofillTimestamps(const string16& name, | 645 bool AutofillTable::GetAutofillTimestamps(const string16& name, |
728 const string16& value, | 646 const string16& value, |
729 std::vector<Time>* timestamps) { | 647 std::vector<Time>* timestamps) { |
730 DCHECK(timestamps); | 648 DCHECK(timestamps); |
731 sql::Statement s(db_->GetUniqueStatement( | 649 sql::Statement s(db_->GetUniqueStatement( |
732 "SELECT date_created FROM autofill a JOIN " | 650 "SELECT date_created FROM autofill a JOIN " |
733 "autofill_dates ad ON a.pair_id=ad.pair_id " | 651 "autofill_dates ad ON a.pair_id=ad.pair_id " |
734 "WHERE a.name = ? AND a.value = ?")); | 652 "WHERE a.name = ? AND a.value = ?")); |
735 | |
736 if (!s) { | |
737 NOTREACHED() << "Statement prepare failed"; | |
738 return false; | |
739 } | |
740 | |
741 s.BindString16(0, name); | 653 s.BindString16(0, name); |
742 s.BindString16(1, value); | 654 s.BindString16(1, value); |
655 | |
743 while (s.Step()) | 656 while (s.Step()) |
744 timestamps->push_back(Time::FromTimeT(s.ColumnInt64(0))); | 657 timestamps->push_back(Time::FromTimeT(s.ColumnInt64(0))); |
745 | 658 |
746 return s.Succeeded(); | 659 return s.Succeeded(); |
747 } | 660 } |
748 | 661 |
749 bool AutofillTable::UpdateAutofillEntries( | 662 bool AutofillTable::UpdateAutofillEntries( |
750 const std::vector<AutofillEntry>& entries) { | 663 const std::vector<AutofillEntry>& entries) { |
751 if (!entries.size()) | 664 if (!entries.size()) |
752 return true; | 665 return true; |
753 | 666 |
754 // Remove all existing entries. | 667 // Remove all existing entries. |
755 for (size_t i = 0; i < entries.size(); i++) { | 668 for (size_t i = 0; i < entries.size(); i++) { |
756 std::string sql = "SELECT pair_id FROM autofill " | 669 std::string sql = "SELECT pair_id FROM autofill " |
757 "WHERE name = ? AND value = ?"; | 670 "WHERE name = ? AND value = ?"; |
758 sql::Statement s(db_->GetUniqueStatement(sql.c_str())); | 671 sql::Statement s(db_->GetUniqueStatement(sql.c_str())); |
759 if (!s.is_valid()) { | |
760 NOTREACHED() << "Statement prepare failed"; | |
761 return false; | |
762 } | |
763 | |
764 s.BindString16(0, entries[i].key().name()); | 672 s.BindString16(0, entries[i].key().name()); |
765 s.BindString16(1, entries[i].key().value()); | 673 s.BindString16(1, entries[i].key().value()); |
674 | |
675 if (!s.is_valid()) | |
676 return false; | |
677 | |
766 if (s.Step()) { | 678 if (s.Step()) { |
767 if (!RemoveFormElementForID(s.ColumnInt64(0))) | 679 if (!RemoveFormElementForID(s.ColumnInt64(0))) |
768 return false; | 680 return false; |
769 } | 681 } |
770 } | 682 } |
771 | 683 |
772 // Insert all the supplied autofill entries. | 684 // Insert all the supplied autofill entries. |
773 for (size_t i = 0; i < entries.size(); i++) { | 685 for (size_t i = 0; i < entries.size(); i++) { |
774 if (!InsertAutofillEntry(entries[i])) | 686 if (!InsertAutofillEntry(entries[i])) |
775 return false; | 687 return false; |
776 } | 688 } |
777 | 689 |
778 return true; | 690 return true; |
779 } | 691 } |
780 | 692 |
781 bool AutofillTable::InsertAutofillEntry(const AutofillEntry& entry) { | 693 bool AutofillTable::InsertAutofillEntry(const AutofillEntry& entry) { |
782 std::string sql = "INSERT INTO autofill (name, value, value_lower, count) " | 694 std::string sql = "INSERT INTO autofill (name, value, value_lower, count) " |
783 "VALUES (?, ?, ?, ?)"; | 695 "VALUES (?, ?, ?, ?)"; |
784 sql::Statement s(db_->GetUniqueStatement(sql.c_str())); | 696 sql::Statement s(db_->GetUniqueStatement(sql.c_str())); |
785 if (!s.is_valid()) { | |
786 NOTREACHED() << "Statement prepare failed"; | |
787 return false; | |
788 } | |
789 | |
790 s.BindString16(0, entry.key().name()); | 697 s.BindString16(0, entry.key().name()); |
791 s.BindString16(1, entry.key().value()); | 698 s.BindString16(1, entry.key().value()); |
792 s.BindString16(2, base::i18n::ToLower(entry.key().value())); | 699 s.BindString16(2, base::i18n::ToLower(entry.key().value())); |
793 s.BindInt(3, entry.timestamps().size()); | 700 s.BindInt(3, entry.timestamps().size()); |
794 | 701 |
795 if (!s.Run()) { | 702 if (!s.Run()) |
796 NOTREACHED(); | |
797 return false; | 703 return false; |
798 } | |
799 | 704 |
800 int64 pair_id = db_->GetLastInsertRowId(); | 705 int64 pair_id = db_->GetLastInsertRowId(); |
801 for (size_t i = 0; i < entry.timestamps().size(); i++) { | 706 for (size_t i = 0; i < entry.timestamps().size(); i++) { |
802 if (!InsertPairIDAndDate(pair_id, entry.timestamps()[i])) | 707 if (!InsertPairIDAndDate(pair_id, entry.timestamps()[i])) |
803 return false; | 708 return false; |
804 } | 709 } |
805 | 710 |
806 return true; | 711 return true; |
807 } | 712 } |
808 | 713 |
(...skipping 22 matching lines...) Expand all Loading... | |
831 AutofillKey(element.name, element.value))); | 736 AutofillKey(element.name, element.value))); |
832 return true; | 737 return true; |
833 } | 738 } |
834 | 739 |
835 | 740 |
836 bool AutofillTable::RemoveFormElement(const string16& name, | 741 bool AutofillTable::RemoveFormElement(const string16& name, |
837 const string16& value) { | 742 const string16& value) { |
838 // Find the id for that pair. | 743 // Find the id for that pair. |
839 sql::Statement s(db_->GetUniqueStatement( | 744 sql::Statement s(db_->GetUniqueStatement( |
840 "SELECT pair_id FROM autofill WHERE name = ? AND value= ?")); | 745 "SELECT pair_id FROM autofill WHERE name = ? AND value= ?")); |
841 if (!s) { | |
842 NOTREACHED() << "Statement 1 prepare failed"; | |
843 return false; | |
844 } | |
845 s.BindString16(0, name); | 746 s.BindString16(0, name); |
846 s.BindString16(1, value); | 747 s.BindString16(1, value); |
847 | 748 |
848 if (s.Step()) | 749 if (s.Step()) |
849 return RemoveFormElementForID(s.ColumnInt64(0)); | 750 return RemoveFormElementForID(s.ColumnInt64(0)); |
850 return false; | 751 return false; |
851 } | 752 } |
852 | 753 |
853 bool AutofillTable::AddAutofillProfile(const AutofillProfile& profile) { | 754 bool AutofillTable::AddAutofillProfile(const AutofillProfile& profile) { |
854 if (IsAutofillGUIDInTrash(profile.guid())) | 755 if (IsAutofillGUIDInTrash(profile.guid())) |
855 return true; | 756 return true; |
856 | 757 |
857 sql::Statement s(db_->GetUniqueStatement( | 758 sql::Statement s(db_->GetUniqueStatement( |
858 "INSERT INTO autofill_profiles" | 759 "INSERT INTO autofill_profiles" |
859 "(guid, company_name, address_line_1, address_line_2, city, state," | 760 "(guid, company_name, address_line_1, address_line_2, city, state," |
860 " zipcode, country, country_code, date_modified)" | 761 " zipcode, country, country_code, date_modified)" |
861 "VALUES (?,?,?,?,?,?,?,?,?,?)")); | 762 "VALUES (?,?,?,?,?,?,?,?,?,?)")); |
862 if (!s) { | |
863 NOTREACHED() << "Statement prepare failed"; | |
864 return false; | |
865 } | |
866 | |
867 BindAutofillProfileToStatement(profile, &s); | 763 BindAutofillProfileToStatement(profile, &s); |
868 | 764 |
869 if (!s.Run()) { | 765 if (!s.Run()) |
870 NOTREACHED(); | |
871 return false; | |
872 } | |
873 | |
874 if (!s.Succeeded()) | |
875 return false; | 766 return false; |
876 | 767 |
877 return AddAutofillProfilePieces(profile, db_); | 768 return AddAutofillProfilePieces(profile, db_); |
878 } | 769 } |
879 | 770 |
880 bool AutofillTable::GetAutofillProfile(const std::string& guid, | 771 bool AutofillTable::GetAutofillProfile(const std::string& guid, |
881 AutofillProfile** profile) { | 772 AutofillProfile** profile) { |
882 DCHECK(guid::IsValidGUID(guid)); | 773 DCHECK(guid::IsValidGUID(guid)); |
883 DCHECK(profile); | 774 DCHECK(profile); |
884 sql::Statement s(db_->GetUniqueStatement( | 775 sql::Statement s(db_->GetUniqueStatement( |
885 "SELECT guid, company_name, address_line_1, address_line_2, city, state," | 776 "SELECT guid, company_name, address_line_1, address_line_2, city, state," |
886 " zipcode, country, country_code, date_modified " | 777 " zipcode, country, country_code, date_modified " |
887 "FROM autofill_profiles " | 778 "FROM autofill_profiles " |
888 "WHERE guid=?")); | 779 "WHERE guid=?")); |
889 if (!s) { | 780 s.BindString(0, guid); |
890 NOTREACHED() << "Statement prepare failed"; | |
891 return false; | |
892 } | |
893 | 781 |
894 s.BindString(0, guid); | |
895 if (!s.Step()) | 782 if (!s.Step()) |
896 return false; | 783 return false; |
897 | 784 |
898 if (!s.Succeeded()) | |
899 return false; | |
900 | |
901 scoped_ptr<AutofillProfile> p(AutofillProfileFromStatement(s)); | 785 scoped_ptr<AutofillProfile> p(AutofillProfileFromStatement(s)); |
902 | 786 |
903 // Get associated name info. | 787 // Get associated name info. |
904 AddAutofillProfileNamesToProfile(db_, p.get()); | 788 AddAutofillProfileNamesToProfile(db_, p.get()); |
905 | 789 |
906 // Get associated email info. | 790 // Get associated email info. |
907 AddAutofillProfileEmailsToProfile(db_, p.get()); | 791 AddAutofillProfileEmailsToProfile(db_, p.get()); |
908 | 792 |
909 // Get associated phone info. | 793 // Get associated phone info. |
910 AddAutofillProfilePhonesToProfile(db_, p.get()); | 794 AddAutofillProfilePhonesToProfile(db_, p.get()); |
911 | 795 |
912 *profile = p.release(); | 796 *profile = p.release(); |
913 return true; | 797 return true; |
914 } | 798 } |
915 | 799 |
916 bool AutofillTable::GetAutofillProfiles( | 800 bool AutofillTable::GetAutofillProfiles( |
917 std::vector<AutofillProfile*>* profiles) { | 801 std::vector<AutofillProfile*>* profiles) { |
918 DCHECK(profiles); | 802 DCHECK(profiles); |
919 profiles->clear(); | 803 profiles->clear(); |
920 | 804 |
921 sql::Statement s(db_->GetUniqueStatement( | 805 sql::Statement s(db_->GetUniqueStatement( |
922 "SELECT guid " | 806 "SELECT guid " |
923 "FROM autofill_profiles")); | 807 "FROM autofill_profiles")); |
924 if (!s) { | |
925 NOTREACHED() << "Statement prepare failed"; | |
926 return false; | |
927 } | |
928 | 808 |
929 while (s.Step()) { | 809 while (s.Step()) { |
930 std::string guid = s.ColumnString(0); | 810 std::string guid = s.ColumnString(0); |
931 AutofillProfile* profile = NULL; | 811 AutofillProfile* profile = NULL; |
932 if (!GetAutofillProfile(guid, &profile)) | 812 if (!GetAutofillProfile(guid, &profile)) |
933 return false; | 813 return false; |
934 profiles->push_back(profile); | 814 profiles->push_back(profile); |
935 } | 815 } |
936 | 816 |
937 return s.Succeeded(); | 817 return s.Succeeded(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
988 scoped_ptr<AutofillProfile> old_profile(tmp_profile); | 868 scoped_ptr<AutofillProfile> old_profile(tmp_profile); |
989 if (old_profile->CompareMulti(profile) == 0) | 869 if (old_profile->CompareMulti(profile) == 0) |
990 return true; | 870 return true; |
991 | 871 |
992 sql::Statement s(db_->GetUniqueStatement( | 872 sql::Statement s(db_->GetUniqueStatement( |
993 "UPDATE autofill_profiles " | 873 "UPDATE autofill_profiles " |
994 "SET guid=?, company_name=?, address_line_1=?, address_line_2=?, " | 874 "SET guid=?, company_name=?, address_line_1=?, address_line_2=?, " |
995 " city=?, state=?, zipcode=?, country=?, country_code=?, " | 875 " city=?, state=?, zipcode=?, country=?, country_code=?, " |
996 " date_modified=? " | 876 " date_modified=? " |
997 "WHERE guid=?")); | 877 "WHERE guid=?")); |
998 if (!s) { | |
999 NOTREACHED() << "Statement prepare failed"; | |
1000 return false; | |
1001 } | |
1002 | |
1003 BindAutofillProfileToStatement(profile, &s); | 878 BindAutofillProfileToStatement(profile, &s); |
1004 s.BindString(10, profile.guid()); | 879 s.BindString(10, profile.guid()); |
880 | |
1005 bool result = s.Run(); | 881 bool result = s.Run(); |
1006 DCHECK_GT(db_->GetLastChangeCount(), 0); | 882 DCHECK_GT(db_->GetLastChangeCount(), 0); |
1007 if (!result) | 883 if (!result) |
1008 return result; | 884 return result; |
1009 | 885 |
1010 // Remove the old names, emails, and phone numbers. | 886 // Remove the old names, emails, and phone numbers. |
1011 if (!RemoveAutofillProfilePieces(profile.guid(), db_)) | 887 if (!RemoveAutofillProfilePieces(profile.guid(), db_)) |
1012 return false; | 888 return false; |
1013 | 889 |
1014 return AddAutofillProfilePieces(profile, db_); | 890 return AddAutofillProfilePieces(profile, db_); |
1015 } | 891 } |
1016 | 892 |
1017 bool AutofillTable::RemoveAutofillProfile(const std::string& guid) { | 893 bool AutofillTable::RemoveAutofillProfile(const std::string& guid) { |
1018 DCHECK(guid::IsValidGUID(guid)); | 894 DCHECK(guid::IsValidGUID(guid)); |
1019 | 895 |
1020 if (IsAutofillGUIDInTrash(guid)) { | 896 if (IsAutofillGUIDInTrash(guid)) { |
1021 sql::Statement s_trash(db_->GetUniqueStatement( | 897 sql::Statement s_trash(db_->GetUniqueStatement( |
1022 "DELETE FROM autofill_profiles_trash WHERE guid = ?")); | 898 "DELETE FROM autofill_profiles_trash WHERE guid = ?")); |
1023 if (!s_trash) { | |
1024 NOTREACHED() << "Statement prepare failed"; | |
1025 return false; | |
1026 } | |
1027 s_trash.BindString(0, guid); | 899 s_trash.BindString(0, guid); |
1028 if (!s_trash.Run()) { | |
1029 NOTREACHED() << "Expected item in trash."; | |
Scott Hess - ex-Googler
2011/12/15 23:02:57
This looks like they might have originally meant D
Greg Billock
2011/12/16 17:26:58
Added. I think you're right.
| |
1030 return false; | |
1031 } | |
1032 | 900 |
1033 return true; | 901 return s_trash.Run(); |
1034 } | 902 } |
1035 | 903 |
1036 sql::Statement s(db_->GetUniqueStatement( | 904 sql::Statement s(db_->GetUniqueStatement( |
1037 "DELETE FROM autofill_profiles WHERE guid = ?")); | 905 "DELETE FROM autofill_profiles WHERE guid = ?")); |
1038 if (!s) { | 906 s.BindString(0, guid); |
1039 NOTREACHED() << "Statement prepare failed"; | |
1040 return false; | |
1041 } | |
1042 | 907 |
1043 s.BindString(0, guid); | |
1044 if (!s.Run()) | 908 if (!s.Run()) |
1045 return false; | 909 return false; |
1046 | 910 |
1047 return RemoveAutofillProfilePieces(guid, db_); | 911 return RemoveAutofillProfilePieces(guid, db_); |
1048 } | 912 } |
1049 | 913 |
1050 bool AutofillTable::ClearAutofillProfiles() { | 914 bool AutofillTable::ClearAutofillProfiles() { |
1051 sql::Statement s1(db_->GetUniqueStatement( | 915 sql::Statement s1(db_->GetUniqueStatement( |
1052 "DELETE FROM autofill_profiles")); | 916 "DELETE FROM autofill_profiles")); |
1053 if (!s1) { | |
1054 NOTREACHED() << "Statement prepare failed"; | |
1055 return false; | |
1056 } | |
1057 | 917 |
1058 if (!s1.Run()) | 918 if (!s1.Run()) |
1059 return false; | 919 return false; |
1060 | 920 |
1061 sql::Statement s2(db_->GetUniqueStatement( | 921 sql::Statement s2(db_->GetUniqueStatement( |
1062 "DELETE FROM autofill_profile_names")); | 922 "DELETE FROM autofill_profile_names")); |
1063 if (!s2) { | |
1064 NOTREACHED() << "Statement prepare failed"; | |
1065 return false; | |
1066 } | |
1067 | 923 |
1068 if (!s2.Run()) | 924 if (!s2.Run()) |
1069 return false; | 925 return false; |
1070 | 926 |
1071 sql::Statement s3(db_->GetUniqueStatement( | 927 sql::Statement s3(db_->GetUniqueStatement( |
1072 "DELETE FROM autofill_profile_emails")); | 928 "DELETE FROM autofill_profile_emails")); |
1073 if (!s3) { | |
1074 NOTREACHED() << "Statement prepare failed"; | |
1075 return false; | |
1076 } | |
1077 | 929 |
1078 if (!s3.Run()) | 930 if (!s3.Run()) |
1079 return false; | 931 return false; |
1080 | 932 |
1081 sql::Statement s4(db_->GetUniqueStatement( | 933 sql::Statement s4(db_->GetUniqueStatement( |
1082 "DELETE FROM autofill_profile_phones")); | 934 "DELETE FROM autofill_profile_phones")); |
1083 if (!s4) { | |
1084 NOTREACHED() << "Statement prepare failed"; | |
1085 return false; | |
1086 } | |
1087 | 935 |
1088 if (!s4.Run()) | 936 return s4.Run(); |
1089 return false; | |
1090 | |
1091 return true; | |
1092 } | 937 } |
1093 | 938 |
1094 bool AutofillTable::AddCreditCard(const CreditCard& credit_card) { | 939 bool AutofillTable::AddCreditCard(const CreditCard& credit_card) { |
1095 sql::Statement s(db_->GetUniqueStatement( | 940 sql::Statement s(db_->GetUniqueStatement( |
1096 "INSERT INTO credit_cards" | 941 "INSERT INTO credit_cards" |
1097 "(guid, name_on_card, expiration_month, expiration_year, " | 942 "(guid, name_on_card, expiration_month, expiration_year, " |
1098 "card_number_encrypted, date_modified)" | 943 "card_number_encrypted, date_modified)" |
1099 "VALUES (?,?,?,?,?,?)")); | 944 "VALUES (?,?,?,?,?,?)")); |
1100 if (!s) { | |
1101 NOTREACHED() << "Statement prepare failed"; | |
1102 return false; | |
1103 } | |
1104 | |
1105 BindCreditCardToStatement(credit_card, &s); | 945 BindCreditCardToStatement(credit_card, &s); |
1106 | 946 |
1107 if (!s.Run()) { | 947 if (!s.Run()) |
1108 NOTREACHED(); | |
1109 return false; | 948 return false; |
1110 } | |
1111 | 949 |
1112 DCHECK_GT(db_->GetLastChangeCount(), 0); | 950 DCHECK_GT(db_->GetLastChangeCount(), 0); |
1113 return s.Succeeded(); | 951 return true; |
1114 } | 952 } |
1115 | 953 |
1116 bool AutofillTable::GetCreditCard(const std::string& guid, | 954 bool AutofillTable::GetCreditCard(const std::string& guid, |
1117 CreditCard** credit_card) { | 955 CreditCard** credit_card) { |
1118 DCHECK(guid::IsValidGUID(guid)); | 956 DCHECK(guid::IsValidGUID(guid)); |
1119 sql::Statement s(db_->GetUniqueStatement( | 957 sql::Statement s(db_->GetUniqueStatement( |
1120 "SELECT guid, name_on_card, expiration_month, expiration_year, " | 958 "SELECT guid, name_on_card, expiration_month, expiration_year, " |
1121 "card_number_encrypted, date_modified " | 959 "card_number_encrypted, date_modified " |
1122 "FROM credit_cards " | 960 "FROM credit_cards " |
1123 "WHERE guid = ?")); | 961 "WHERE guid = ?")); |
1124 if (!s) { | 962 s.BindString(0, guid); |
1125 NOTREACHED() << "Statement prepare failed"; | |
1126 return false; | |
1127 } | |
1128 | 963 |
1129 s.BindString(0, guid); | |
1130 if (!s.Step()) | 964 if (!s.Step()) |
1131 return false; | 965 return false; |
1132 | 966 |
1133 *credit_card = CreditCardFromStatement(s); | 967 *credit_card = CreditCardFromStatement(s); |
1134 | 968 return true; |
1135 return s.Succeeded(); | |
1136 } | 969 } |
1137 | 970 |
1138 bool AutofillTable::GetCreditCards( | 971 bool AutofillTable::GetCreditCards( |
1139 std::vector<CreditCard*>* credit_cards) { | 972 std::vector<CreditCard*>* credit_cards) { |
1140 DCHECK(credit_cards); | 973 DCHECK(credit_cards); |
1141 credit_cards->clear(); | 974 credit_cards->clear(); |
1142 | 975 |
1143 sql::Statement s(db_->GetUniqueStatement( | 976 sql::Statement s(db_->GetUniqueStatement( |
1144 "SELECT guid " | 977 "SELECT guid " |
1145 "FROM credit_cards")); | 978 "FROM credit_cards")); |
1146 if (!s) { | |
1147 NOTREACHED() << "Statement prepare failed"; | |
1148 return false; | |
1149 } | |
1150 | 979 |
1151 while (s.Step()) { | 980 while (s.Step()) { |
1152 std::string guid = s.ColumnString(0); | 981 std::string guid = s.ColumnString(0); |
1153 CreditCard* credit_card = NULL; | 982 CreditCard* credit_card = NULL; |
1154 if (!GetCreditCard(guid, &credit_card)) | 983 if (!GetCreditCard(guid, &credit_card)) |
1155 return false; | 984 return false; |
1156 credit_cards->push_back(credit_card); | 985 credit_cards->push_back(credit_card); |
1157 } | 986 } |
1158 | 987 |
1159 return s.Succeeded(); | 988 return s.Succeeded(); |
1160 } | 989 } |
1161 | 990 |
1162 bool AutofillTable::UpdateCreditCard(const CreditCard& credit_card) { | 991 bool AutofillTable::UpdateCreditCard(const CreditCard& credit_card) { |
1163 DCHECK(guid::IsValidGUID(credit_card.guid())); | 992 DCHECK(guid::IsValidGUID(credit_card.guid())); |
1164 | 993 |
1165 CreditCard* tmp_credit_card = NULL; | 994 CreditCard* tmp_credit_card = NULL; |
1166 if (!GetCreditCard(credit_card.guid(), &tmp_credit_card)) | 995 if (!GetCreditCard(credit_card.guid(), &tmp_credit_card)) |
1167 return false; | 996 return false; |
1168 | 997 |
1169 // Preserve appropriate modification dates by not updating unchanged cards. | 998 // Preserve appropriate modification dates by not updating unchanged cards. |
1170 scoped_ptr<CreditCard> old_credit_card(tmp_credit_card); | 999 scoped_ptr<CreditCard> old_credit_card(tmp_credit_card); |
1171 if (*old_credit_card == credit_card) | 1000 if (*old_credit_card == credit_card) |
1172 return true; | 1001 return true; |
1173 | 1002 |
1174 sql::Statement s(db_->GetUniqueStatement( | 1003 sql::Statement s(db_->GetUniqueStatement( |
1175 "UPDATE credit_cards " | 1004 "UPDATE credit_cards " |
1176 "SET guid=?, name_on_card=?, expiration_month=?, " | 1005 "SET guid=?, name_on_card=?, expiration_month=?, " |
1177 " expiration_year=?, card_number_encrypted=?, date_modified=? " | 1006 " expiration_year=?, card_number_encrypted=?, date_modified=? " |
1178 "WHERE guid=?")); | 1007 "WHERE guid=?")); |
1179 if (!s) { | |
1180 NOTREACHED() << "Statement prepare failed"; | |
1181 return false; | |
1182 } | |
1183 | |
1184 BindCreditCardToStatement(credit_card, &s); | 1008 BindCreditCardToStatement(credit_card, &s); |
1185 s.BindString(6, credit_card.guid()); | 1009 s.BindString(6, credit_card.guid()); |
1010 | |
1186 bool result = s.Run(); | 1011 bool result = s.Run(); |
1187 DCHECK_GT(db_->GetLastChangeCount(), 0); | 1012 DCHECK_GT(db_->GetLastChangeCount(), 0); |
1188 return result; | 1013 return result; |
1189 } | 1014 } |
1190 | 1015 |
1191 bool AutofillTable::RemoveCreditCard(const std::string& guid) { | 1016 bool AutofillTable::RemoveCreditCard(const std::string& guid) { |
1192 DCHECK(guid::IsValidGUID(guid)); | 1017 DCHECK(guid::IsValidGUID(guid)); |
1193 sql::Statement s(db_->GetUniqueStatement( | 1018 sql::Statement s(db_->GetUniqueStatement( |
1194 "DELETE FROM credit_cards WHERE guid = ?")); | 1019 "DELETE FROM credit_cards WHERE guid = ?")); |
1195 if (!s) { | 1020 s.BindString(0, guid); |
1196 NOTREACHED() << "Statement prepare failed"; | |
1197 return false; | |
1198 } | |
1199 | 1021 |
1200 s.BindString(0, guid); | |
1201 return s.Run(); | 1022 return s.Run(); |
1202 } | 1023 } |
1203 | 1024 |
1204 bool AutofillTable::RemoveAutofillProfilesAndCreditCardsModifiedBetween( | 1025 bool AutofillTable::RemoveAutofillProfilesAndCreditCardsModifiedBetween( |
1205 const Time& delete_begin, | 1026 const Time& delete_begin, |
1206 const Time& delete_end, | 1027 const Time& delete_end, |
1207 std::vector<std::string>* profile_guids, | 1028 std::vector<std::string>* profile_guids, |
1208 std::vector<std::string>* credit_card_guids) { | 1029 std::vector<std::string>* credit_card_guids) { |
1209 DCHECK(delete_end.is_null() || delete_begin < delete_end); | 1030 DCHECK(delete_end.is_null() || delete_begin < delete_end); |
1210 | 1031 |
1211 time_t delete_begin_t = delete_begin.ToTimeT(); | 1032 time_t delete_begin_t = delete_begin.ToTimeT(); |
1212 time_t delete_end_t = delete_end.is_null() ? | 1033 time_t delete_end_t = delete_end.is_null() ? |
1213 std::numeric_limits<time_t>::max() : | 1034 std::numeric_limits<time_t>::max() : |
1214 delete_end.ToTimeT(); | 1035 delete_end.ToTimeT(); |
1215 | 1036 |
1216 // Remember Autofill profiles in the time range. | 1037 // Remember Autofill profiles in the time range. |
1217 sql::Statement s_profiles_get(db_->GetUniqueStatement( | 1038 sql::Statement s_profiles_get(db_->GetUniqueStatement( |
1218 "SELECT guid FROM autofill_profiles " | 1039 "SELECT guid FROM autofill_profiles " |
1219 "WHERE date_modified >= ? AND date_modified < ?")); | 1040 "WHERE date_modified >= ? AND date_modified < ?")); |
1220 if (!s_profiles_get) { | |
1221 NOTREACHED() << "Autofill profiles statement prepare failed"; | |
1222 return false; | |
1223 } | |
1224 | |
1225 s_profiles_get.BindInt64(0, delete_begin_t); | 1041 s_profiles_get.BindInt64(0, delete_begin_t); |
1226 s_profiles_get.BindInt64(1, delete_end_t); | 1042 s_profiles_get.BindInt64(1, delete_end_t); |
1043 | |
1044 if (!s_profiles_get.is_valid()) | |
1045 return false; | |
1046 | |
1227 profile_guids->clear(); | 1047 profile_guids->clear(); |
1228 while (s_profiles_get.Step()) { | 1048 while (s_profiles_get.Step()) { |
1229 std::string guid = s_profiles_get.ColumnString(0); | 1049 std::string guid = s_profiles_get.ColumnString(0); |
1230 profile_guids->push_back(guid); | 1050 profile_guids->push_back(guid); |
1231 } | 1051 } |
1232 | 1052 |
1233 // Remove Autofill profiles in the time range. | 1053 // Remove Autofill profiles in the time range. |
1234 sql::Statement s_profiles(db_->GetUniqueStatement( | 1054 sql::Statement s_profiles(db_->GetUniqueStatement( |
1235 "DELETE FROM autofill_profiles " | 1055 "DELETE FROM autofill_profiles " |
1236 "WHERE date_modified >= ? AND date_modified < ?")); | 1056 "WHERE date_modified >= ? AND date_modified < ?")); |
1237 if (!s_profiles) { | |
1238 NOTREACHED() << "Autofill profiles statement prepare failed"; | |
1239 return false; | |
1240 } | |
1241 | |
1242 s_profiles.BindInt64(0, delete_begin_t); | 1057 s_profiles.BindInt64(0, delete_begin_t); |
1243 s_profiles.BindInt64(1, delete_end_t); | 1058 s_profiles.BindInt64(1, delete_end_t); |
1059 | |
1060 if (!s_profiles.is_valid()) | |
1061 return false; | |
1062 | |
1244 s_profiles.Run(); | 1063 s_profiles.Run(); |
1245 | 1064 if (!s_profiles.Succeeded()) |
1246 if (!s_profiles.Succeeded()) { | |
1247 NOTREACHED(); | |
1248 return false; | 1065 return false; |
1249 } | |
1250 | 1066 |
1251 // Remember Autofill credit cards in the time range. | 1067 // Remember Autofill credit cards in the time range. |
1252 sql::Statement s_credit_cards_get(db_->GetUniqueStatement( | 1068 sql::Statement s_credit_cards_get(db_->GetUniqueStatement( |
1253 "SELECT guid FROM credit_cards " | 1069 "SELECT guid FROM credit_cards " |
1254 "WHERE date_modified >= ? AND date_modified < ?")); | 1070 "WHERE date_modified >= ? AND date_modified < ?")); |
1255 if (!s_credit_cards_get) { | |
1256 NOTREACHED() << "Autofill profiles statement prepare failed"; | |
1257 return false; | |
1258 } | |
1259 | |
1260 s_credit_cards_get.BindInt64(0, delete_begin_t); | 1071 s_credit_cards_get.BindInt64(0, delete_begin_t); |
1261 s_credit_cards_get.BindInt64(1, delete_end_t); | 1072 s_credit_cards_get.BindInt64(1, delete_end_t); |
1073 | |
1074 if (!s_credit_cards_get.is_valid()) | |
1075 return false; | |
1076 | |
1262 credit_card_guids->clear(); | 1077 credit_card_guids->clear(); |
1263 while (s_credit_cards_get.Step()) { | 1078 while (s_credit_cards_get.Step()) { |
1264 std::string guid = s_credit_cards_get.ColumnString(0); | 1079 std::string guid = s_credit_cards_get.ColumnString(0); |
1265 credit_card_guids->push_back(guid); | 1080 credit_card_guids->push_back(guid); |
1266 } | 1081 } |
1267 | 1082 |
1268 // Remove Autofill credit cards in the time range. | 1083 // Remove Autofill credit cards in the time range. |
1269 sql::Statement s_credit_cards(db_->GetUniqueStatement( | 1084 sql::Statement s_credit_cards(db_->GetUniqueStatement( |
1270 "DELETE FROM credit_cards " | 1085 "DELETE FROM credit_cards " |
1271 "WHERE date_modified >= ? AND date_modified < ?")); | 1086 "WHERE date_modified >= ? AND date_modified < ?")); |
1272 if (!s_credit_cards) { | |
1273 NOTREACHED() << "Autofill credit cards statement prepare failed"; | |
1274 return false; | |
1275 } | |
1276 | |
1277 s_credit_cards.BindInt64(0, delete_begin_t); | 1087 s_credit_cards.BindInt64(0, delete_begin_t); |
1278 s_credit_cards.BindInt64(1, delete_end_t); | 1088 s_credit_cards.BindInt64(1, delete_end_t); |
1089 | |
1090 if (!s_credit_cards.is_valid()) | |
1091 return false; | |
1092 | |
1279 s_credit_cards.Run(); | 1093 s_credit_cards.Run(); |
1280 | 1094 return s_credit_cards.Succeeded(); |
1281 if (!s_credit_cards.Succeeded()) { | |
1282 NOTREACHED(); | |
1283 return false; | |
1284 } | |
1285 | |
1286 return true; | |
1287 } | 1095 } |
1288 | 1096 |
1289 bool AutofillTable::GetAutofillProfilesInTrash( | 1097 bool AutofillTable::GetAutofillProfilesInTrash( |
1290 std::vector<std::string>* guids) { | 1098 std::vector<std::string>* guids) { |
1291 guids->clear(); | 1099 guids->clear(); |
1292 | 1100 |
1293 sql::Statement s(db_->GetUniqueStatement( | 1101 sql::Statement s(db_->GetUniqueStatement( |
1294 "SELECT guid " | 1102 "SELECT guid " |
1295 "FROM autofill_profiles_trash")); | 1103 "FROM autofill_profiles_trash")); |
1296 if (!s) { | |
1297 NOTREACHED() << "Statement prepare failed"; | |
1298 return false; | |
1299 } | |
1300 | 1104 |
1301 while (s.Step()) { | 1105 while (s.Step()) { |
1302 std::string guid = s.ColumnString(0); | 1106 std::string guid = s.ColumnString(0); |
1303 guids->push_back(guid); | 1107 guids->push_back(guid); |
1304 } | 1108 } |
1305 | 1109 |
1306 return s.Succeeded(); | 1110 return s.Succeeded(); |
1307 } | 1111 } |
1308 | 1112 |
1309 bool AutofillTable::EmptyAutofillProfilesTrash() { | 1113 bool AutofillTable::EmptyAutofillProfilesTrash() { |
1310 sql::Statement s(db_->GetUniqueStatement( | 1114 sql::Statement s(db_->GetUniqueStatement( |
1311 "DELETE FROM autofill_profiles_trash")); | 1115 "DELETE FROM autofill_profiles_trash")); |
1312 if (!s) { | |
1313 NOTREACHED() << "Statement prepare failed"; | |
1314 return false; | |
1315 } | |
1316 | 1116 |
1317 return s.Run(); | 1117 return s.Run(); |
1318 } | 1118 } |
1319 | 1119 |
1320 | 1120 |
1321 bool AutofillTable::RemoveFormElementForID(int64 pair_id) { | 1121 bool AutofillTable::RemoveFormElementForID(int64 pair_id) { |
1322 sql::Statement s(db_->GetUniqueStatement( | 1122 sql::Statement s(db_->GetUniqueStatement( |
1323 "DELETE FROM autofill WHERE pair_id = ?")); | 1123 "DELETE FROM autofill WHERE pair_id = ?")); |
1324 if (!s) { | |
1325 NOTREACHED() << "Statement prepare failed"; | |
1326 return false; | |
1327 } | |
1328 s.BindInt64(0, pair_id); | 1124 s.BindInt64(0, pair_id); |
1125 | |
1329 if (s.Run()) | 1126 if (s.Run()) |
1330 return RemoveFormElementForTimeRange(pair_id, Time(), Time(), NULL); | 1127 return RemoveFormElementForTimeRange(pair_id, Time(), Time(), NULL); |
1331 | 1128 |
1332 return false; | 1129 return false; |
1333 } | 1130 } |
1334 | 1131 |
1335 bool AutofillTable::AddAutofillGUIDToTrash(const std::string& guid) { | 1132 bool AutofillTable::AddAutofillGUIDToTrash(const std::string& guid) { |
1336 sql::Statement s(db_->GetUniqueStatement( | 1133 sql::Statement s(db_->GetUniqueStatement( |
1337 "INSERT INTO autofill_profiles_trash" | 1134 "INSERT INTO autofill_profiles_trash" |
1338 " (guid) " | 1135 " (guid) " |
1339 "VALUES (?)")); | 1136 "VALUES (?)")); |
1340 if (!s) { | 1137 s.BindString(0, guid); |
1341 NOTREACHED(); | |
1342 return sql::INIT_FAILURE; | |
Scott Hess - ex-Googler
2011/12/15 23:02:57
I wish this hadn't compiled in the first place ...
| |
1343 } | |
1344 | 1138 |
1345 s.BindString(0, guid); | 1139 return s.Run(); |
1346 if (!s.Run()) { | |
1347 NOTREACHED(); | |
1348 return false; | |
1349 } | |
1350 return true; | |
1351 } | 1140 } |
1352 | 1141 |
1353 bool AutofillTable::IsAutofillProfilesTrashEmpty() { | 1142 bool AutofillTable::IsAutofillProfilesTrashEmpty() { |
1354 sql::Statement s(db_->GetUniqueStatement( | 1143 sql::Statement s(db_->GetUniqueStatement( |
1355 "SELECT guid " | 1144 "SELECT guid " |
1356 "FROM autofill_profiles_trash")); | 1145 "FROM autofill_profiles_trash")); |
1357 if (!s) { | |
1358 NOTREACHED() << "Statement prepare failed"; | |
1359 return false; | |
1360 } | |
1361 | 1146 |
1362 return !s.Step(); | 1147 return !s.Step(); |
1363 } | 1148 } |
1364 | 1149 |
1365 bool AutofillTable::IsAutofillGUIDInTrash(const std::string& guid) { | 1150 bool AutofillTable::IsAutofillGUIDInTrash(const std::string& guid) { |
1366 sql::Statement s(db_->GetUniqueStatement( | 1151 sql::Statement s(db_->GetUniqueStatement( |
1367 "SELECT guid " | 1152 "SELECT guid " |
1368 "FROM autofill_profiles_trash " | 1153 "FROM autofill_profiles_trash " |
1369 "WHERE guid = ?")); | 1154 "WHERE guid = ?")); |
1370 if (!s) { | 1155 s.BindString(0, guid); |
1371 NOTREACHED() << "Statement prepare failed"; | |
1372 return false; | |
1373 } | |
1374 | 1156 |
1375 s.BindString(0, guid); | |
1376 return s.Step(); | 1157 return s.Step(); |
1377 } | 1158 } |
1378 | 1159 |
1379 bool AutofillTable::InitMainTable() { | 1160 bool AutofillTable::InitMainTable() { |
1380 if (!db_->DoesTableExist("autofill")) { | 1161 if (!db_->DoesTableExist("autofill")) { |
1381 if (!db_->Execute("CREATE TABLE autofill (" | 1162 if (!db_->Execute("CREATE TABLE autofill (" |
1382 "name VARCHAR, " | 1163 "name VARCHAR, " |
1383 "value VARCHAR, " | 1164 "value VARCHAR, " |
1384 "value_lower VARCHAR, " | 1165 "value_lower VARCHAR, " |
1385 "pair_id INTEGER PRIMARY KEY, " | 1166 "pair_id INTEGER PRIMARY KEY, " |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1628 db_->DoesColumnExist("credit_cards", "billing_address") && | 1409 db_->DoesColumnExist("credit_cards", "billing_address") && |
1629 db_->DoesColumnExist("autofill_profiles", "unique_id"))) { | 1410 db_->DoesColumnExist("autofill_profiles", "unique_id"))) { |
1630 return true; | 1411 return true; |
1631 } | 1412 } |
1632 | 1413 |
1633 std::string stmt = | 1414 std::string stmt = |
1634 "SELECT credit_cards.unique_id, autofill_profiles.unique_id " | 1415 "SELECT credit_cards.unique_id, autofill_profiles.unique_id " |
1635 "FROM autofill_profiles, credit_cards " | 1416 "FROM autofill_profiles, credit_cards " |
1636 "WHERE credit_cards.billing_address = autofill_profiles.label"; | 1417 "WHERE credit_cards.billing_address = autofill_profiles.label"; |
1637 sql::Statement s(db_->GetUniqueStatement(stmt.c_str())); | 1418 sql::Statement s(db_->GetUniqueStatement(stmt.c_str())); |
1638 if (!s) | 1419 if (!s.is_valid()) |
1639 return false; | 1420 return false; |
1640 | 1421 |
1641 std::map<int, int> cc_billing_map; | 1422 std::map<int, int> cc_billing_map; |
1642 while (s.Step()) | 1423 while (s.Step()) |
1643 cc_billing_map[s.ColumnInt(0)] = s.ColumnInt(1); | 1424 cc_billing_map[s.ColumnInt(0)] = s.ColumnInt(1); |
1644 | 1425 |
1645 // Windows already stores the IDs as strings in |billing_address|. Try | 1426 // Windows already stores the IDs as strings in |billing_address|. Try |
1646 // to convert those. | 1427 // to convert those. |
1647 if (cc_billing_map.empty()) { | 1428 if (cc_billing_map.empty()) { |
1648 std::string stmt = "SELECT unique_id,billing_address FROM credit_cards"; | 1429 std::string stmt = "SELECT unique_id,billing_address FROM credit_cards"; |
1649 sql::Statement s(db_->GetUniqueStatement(stmt.c_str())); | 1430 sql::Statement s(db_->GetUniqueStatement(stmt.c_str())); |
1650 if (!s) | 1431 if (!s.is_valid()) |
1651 return false; | 1432 return false; |
1652 | 1433 |
1653 while (s.Step()) { | 1434 while (s.Step()) { |
1654 int id = 0; | 1435 int id = 0; |
1655 if (base::StringToInt(s.ColumnString(1), &id)) | 1436 if (base::StringToInt(s.ColumnString(1), &id)) |
1656 cc_billing_map[s.ColumnInt(0)] = id; | 1437 cc_billing_map[s.ColumnInt(0)] = id; |
1657 } | 1438 } |
1658 } | 1439 } |
1659 | 1440 |
1660 if (!db_->Execute("CREATE TABLE credit_cards_temp ( " | 1441 if (!db_->Execute("CREATE TABLE credit_cards_temp ( " |
(...skipping 25 matching lines...) Expand all Loading... | |
1686 return false; | 1467 return false; |
1687 | 1468 |
1688 if (!db_->Execute("ALTER TABLE credit_cards_temp RENAME TO credit_cards")) | 1469 if (!db_->Execute("ALTER TABLE credit_cards_temp RENAME TO credit_cards")) |
1689 return false; | 1470 return false; |
1690 | 1471 |
1691 for (std::map<int, int>::const_iterator iter = cc_billing_map.begin(); | 1472 for (std::map<int, int>::const_iterator iter = cc_billing_map.begin(); |
1692 iter != cc_billing_map.end(); ++iter) { | 1473 iter != cc_billing_map.end(); ++iter) { |
1693 sql::Statement s(db_->GetCachedStatement( | 1474 sql::Statement s(db_->GetCachedStatement( |
1694 SQL_FROM_HERE, | 1475 SQL_FROM_HERE, |
1695 "UPDATE credit_cards SET billing_address=? WHERE unique_id=?")); | 1476 "UPDATE credit_cards SET billing_address=? WHERE unique_id=?")); |
1696 if (!s) | |
1697 return false; | |
1698 | |
1699 s.BindInt(0, (*iter).second); | 1477 s.BindInt(0, (*iter).second); |
1700 s.BindInt(1, (*iter).first); | 1478 s.BindInt(1, (*iter).first); |
1701 | 1479 |
1702 if (!s.Run()) | 1480 if (!s.Run()) |
1703 return false; | 1481 return false; |
1704 } | 1482 } |
1705 | 1483 |
1706 return true; | 1484 return true; |
1707 } | 1485 } |
1708 | 1486 |
1709 bool AutofillTable::MigrateToVersion30AddDateModifed() { | 1487 bool AutofillTable::MigrateToVersion30AddDateModifed() { |
1710 // Add date_modified to autofill_profiles. | 1488 // Add date_modified to autofill_profiles. |
1711 if (!db_->DoesColumnExist("autofill_profiles", "date_modified")) { | 1489 if (!db_->DoesColumnExist("autofill_profiles", "date_modified")) { |
1712 if (!db_->Execute("ALTER TABLE autofill_profiles ADD COLUMN " | 1490 if (!db_->Execute("ALTER TABLE autofill_profiles ADD COLUMN " |
1713 "date_modified INTEGER NON NULL DEFAULT 0")) { | 1491 "date_modified INTEGER NON NULL DEFAULT 0")) { |
1714 return false; | 1492 return false; |
1715 } | 1493 } |
1716 | 1494 |
1717 sql::Statement s(db_->GetUniqueStatement( | 1495 sql::Statement s(db_->GetUniqueStatement( |
1718 "UPDATE autofill_profiles SET date_modified=?")); | 1496 "UPDATE autofill_profiles SET date_modified=?")); |
1719 if (!s) | |
1720 return false; | |
1721 | |
1722 s.BindInt64(0, Time::Now().ToTimeT()); | 1497 s.BindInt64(0, Time::Now().ToTimeT()); |
1723 | 1498 |
1724 if (!s.Run()) | 1499 if (!s.Run()) |
1725 return false; | 1500 return false; |
1726 } | 1501 } |
1727 | 1502 |
1728 // Add date_modified to credit_cards. | 1503 // Add date_modified to credit_cards. |
1729 if (!db_->DoesColumnExist("credit_cards", "date_modified")) { | 1504 if (!db_->DoesColumnExist("credit_cards", "date_modified")) { |
1730 if (!db_->Execute("ALTER TABLE credit_cards ADD COLUMN " | 1505 if (!db_->Execute("ALTER TABLE credit_cards ADD COLUMN " |
1731 "date_modified INTEGER NON NULL DEFAULT 0")) { | 1506 "date_modified INTEGER NON NULL DEFAULT 0")) { |
1732 return false; | 1507 return false; |
1733 } | 1508 } |
1734 | 1509 |
1735 sql::Statement s(db_->GetUniqueStatement( | 1510 sql::Statement s(db_->GetUniqueStatement( |
1736 "UPDATE credit_cards SET date_modified=?")); | 1511 "UPDATE credit_cards SET date_modified=?")); |
1737 if (!s) | |
1738 return false; | |
1739 | |
1740 s.BindInt64(0, Time::Now().ToTimeT()); | 1512 s.BindInt64(0, Time::Now().ToTimeT()); |
1741 | 1513 |
1742 if (!s.Run()) | 1514 if (!s.Run()) |
1743 return false; | 1515 return false; |
1744 } | 1516 } |
1745 | 1517 |
1746 return true; | 1518 return true; |
1747 } | 1519 } |
1748 | 1520 |
1749 bool AutofillTable::MigrateToVersion31AddGUIDToCreditCardsAndProfiles() { | 1521 bool AutofillTable::MigrateToVersion31AddGUIDToCreditCardsAndProfiles() { |
1750 // Note that we need to check for the guid column's existence due to the | 1522 // Note that we need to check for the guid column's existence due to the |
1751 // fact that for a version 22 database the |autofill_profiles| table | 1523 // fact that for a version 22 database the |autofill_profiles| table |
1752 // gets created fresh with |InitAutofillProfilesTable|. | 1524 // gets created fresh with |InitAutofillProfilesTable|. |
1753 if (!db_->DoesColumnExist("autofill_profiles", "guid")) { | 1525 if (!db_->DoesColumnExist("autofill_profiles", "guid")) { |
1754 if (!db_->Execute("ALTER TABLE autofill_profiles ADD COLUMN " | 1526 if (!db_->Execute("ALTER TABLE autofill_profiles ADD COLUMN " |
1755 "guid VARCHAR NOT NULL DEFAULT \"\"")) { | 1527 "guid VARCHAR NOT NULL DEFAULT \"\"")) { |
1756 return false; | 1528 return false; |
1757 } | 1529 } |
1758 | 1530 |
1759 // Set all the |guid| fields to valid values. | 1531 // Set all the |guid| fields to valid values. |
1760 | 1532 |
1761 sql::Statement s(db_->GetUniqueStatement("SELECT unique_id " | 1533 sql::Statement s(db_->GetUniqueStatement("SELECT unique_id " |
1762 "FROM autofill_profiles")); | 1534 "FROM autofill_profiles")); |
1763 if (!s) | 1535 if (!s.is_valid()) |
1764 return false; | 1536 return false; |
1765 | 1537 |
1766 while (s.Step()) { | 1538 while (s.Step()) { |
1767 sql::Statement update_s( | 1539 sql::Statement update_s( |
1768 db_->GetUniqueStatement("UPDATE autofill_profiles " | 1540 db_->GetUniqueStatement("UPDATE autofill_profiles " |
1769 "SET guid=? WHERE unique_id=?")); | 1541 "SET guid=? WHERE unique_id=?")); |
1770 if (!update_s) | |
1771 return false; | |
1772 update_s.BindString(0, guid::GenerateGUID()); | 1542 update_s.BindString(0, guid::GenerateGUID()); |
1773 update_s.BindInt(1, s.ColumnInt(0)); | 1543 update_s.BindInt(1, s.ColumnInt(0)); |
1774 | 1544 |
1775 if (!update_s.Run()) | 1545 if (!update_s.Run()) |
1776 return false; | 1546 return false; |
1777 } | 1547 } |
1778 } | 1548 } |
1779 | 1549 |
1780 // Note that we need to check for the guid column's existence due to the | 1550 // Note that we need to check for the guid column's existence due to the |
1781 // fact that for a version 22 database the |autofill_profiles| table | 1551 // fact that for a version 22 database the |autofill_profiles| table |
1782 // gets created fresh with |InitAutofillProfilesTable|. | 1552 // gets created fresh with |InitAutofillProfilesTable|. |
1783 if (!db_->DoesColumnExist("credit_cards", "guid")) { | 1553 if (!db_->DoesColumnExist("credit_cards", "guid")) { |
1784 if (!db_->Execute("ALTER TABLE credit_cards ADD COLUMN " | 1554 if (!db_->Execute("ALTER TABLE credit_cards ADD COLUMN " |
1785 "guid VARCHAR NOT NULL DEFAULT \"\"")) { | 1555 "guid VARCHAR NOT NULL DEFAULT \"\"")) { |
1786 return false; | 1556 return false; |
1787 } | 1557 } |
1788 | 1558 |
1789 // Set all the |guid| fields to valid values. | 1559 // Set all the |guid| fields to valid values. |
1790 | 1560 |
1791 sql::Statement s(db_->GetUniqueStatement("SELECT unique_id " | 1561 sql::Statement s(db_->GetUniqueStatement("SELECT unique_id " |
1792 "FROM credit_cards")); | 1562 "FROM credit_cards")); |
1793 if (!s) | 1563 if (!s.is_valid()) |
1794 return false; | 1564 return false; |
1795 | 1565 |
1796 while (s.Step()) { | 1566 while (s.Step()) { |
1797 sql::Statement update_s( | 1567 sql::Statement update_s( |
1798 db_->GetUniqueStatement("UPDATE credit_cards " | 1568 db_->GetUniqueStatement("UPDATE credit_cards " |
1799 "set guid=? WHERE unique_id=?")); | 1569 "set guid=? WHERE unique_id=?")); |
1800 if (!update_s) | 1570 if (!update_s.is_valid()) |
1801 return false; | 1571 return false; |
Scott Hess - ex-Googler
2011/12/15 23:02:57
Could be removed?
Greg Billock
2011/12/16 17:26:58
Done.
| |
1802 update_s.BindString(0, guid::GenerateGUID()); | 1572 update_s.BindString(0, guid::GenerateGUID()); |
1803 update_s.BindInt(1, s.ColumnInt(0)); | 1573 update_s.BindInt(1, s.ColumnInt(0)); |
1804 | 1574 |
1805 if (!update_s.Run()) | 1575 if (!update_s.Run()) |
1806 return false; | 1576 return false; |
1807 } | 1577 } |
1808 } | 1578 } |
1809 | 1579 |
1810 return true; | 1580 return true; |
1811 } | 1581 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1899 "date_modified INTEGER NOT NULL DEFAULT 0)")) { | 1669 "date_modified INTEGER NOT NULL DEFAULT 0)")) { |
1900 return false; | 1670 return false; |
1901 } | 1671 } |
1902 } | 1672 } |
1903 | 1673 |
1904 sql::Statement s(db_->GetUniqueStatement( | 1674 sql::Statement s(db_->GetUniqueStatement( |
1905 "SELECT guid, first_name, middle_name, last_name, email, " | 1675 "SELECT guid, first_name, middle_name, last_name, email, " |
1906 "company_name, address_line_1, address_line_2, city, state, " | 1676 "company_name, address_line_1, address_line_2, city, state, " |
1907 "zipcode, country, phone, date_modified " | 1677 "zipcode, country, phone, date_modified " |
1908 "FROM autofill_profiles")); | 1678 "FROM autofill_profiles")); |
1679 | |
1909 while (s.Step()) { | 1680 while (s.Step()) { |
1910 AutofillProfile profile; | 1681 AutofillProfile profile; |
1911 profile.set_guid(s.ColumnString(0)); | 1682 profile.set_guid(s.ColumnString(0)); |
1912 DCHECK(guid::IsValidGUID(profile.guid())); | 1683 DCHECK(guid::IsValidGUID(profile.guid())); |
1913 | 1684 |
1914 profile.SetInfo(NAME_FIRST, s.ColumnString16(1)); | 1685 profile.SetInfo(NAME_FIRST, s.ColumnString16(1)); |
1915 profile.SetInfo(NAME_MIDDLE, s.ColumnString16(2)); | 1686 profile.SetInfo(NAME_MIDDLE, s.ColumnString16(2)); |
1916 profile.SetInfo(NAME_LAST, s.ColumnString16(3)); | 1687 profile.SetInfo(NAME_LAST, s.ColumnString16(3)); |
1917 profile.SetInfo(EMAIL_ADDRESS, s.ColumnString16(4)); | 1688 profile.SetInfo(EMAIL_ADDRESS, s.ColumnString16(4)); |
1918 profile.SetInfo(COMPANY_NAME, s.ColumnString16(5)); | 1689 profile.SetInfo(COMPANY_NAME, s.ColumnString16(5)); |
1919 profile.SetInfo(ADDRESS_HOME_LINE1, s.ColumnString16(6)); | 1690 profile.SetInfo(ADDRESS_HOME_LINE1, s.ColumnString16(6)); |
1920 profile.SetInfo(ADDRESS_HOME_LINE2, s.ColumnString16(7)); | 1691 profile.SetInfo(ADDRESS_HOME_LINE2, s.ColumnString16(7)); |
1921 profile.SetInfo(ADDRESS_HOME_CITY, s.ColumnString16(8)); | 1692 profile.SetInfo(ADDRESS_HOME_CITY, s.ColumnString16(8)); |
1922 profile.SetInfo(ADDRESS_HOME_STATE, s.ColumnString16(9)); | 1693 profile.SetInfo(ADDRESS_HOME_STATE, s.ColumnString16(9)); |
1923 profile.SetInfo(ADDRESS_HOME_ZIP, s.ColumnString16(10)); | 1694 profile.SetInfo(ADDRESS_HOME_ZIP, s.ColumnString16(10)); |
1924 profile.SetInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(11)); | 1695 profile.SetInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(11)); |
1925 profile.SetInfo(PHONE_HOME_WHOLE_NUMBER, s.ColumnString16(12)); | 1696 profile.SetInfo(PHONE_HOME_WHOLE_NUMBER, s.ColumnString16(12)); |
1926 int64 date_modified = s.ColumnInt64(13); | 1697 int64 date_modified = s.ColumnInt64(13); |
1927 | 1698 |
1928 sql::Statement s_insert(db_->GetUniqueStatement( | 1699 sql::Statement s_insert(db_->GetUniqueStatement( |
1929 "INSERT INTO autofill_profiles_temp" | 1700 "INSERT INTO autofill_profiles_temp" |
1930 "(guid, company_name, address_line_1, address_line_2, city," | 1701 "(guid, company_name, address_line_1, address_line_2, city," |
1931 " state, zipcode, country, date_modified)" | 1702 " state, zipcode, country, date_modified)" |
1932 "VALUES (?,?,?,?,?,?,?,?,?)")); | 1703 "VALUES (?,?,?,?,?,?,?,?,?)")); |
1933 if (!s) | |
1934 return false; | |
1935 | |
1936 s_insert.BindString(0, profile.guid()); | 1704 s_insert.BindString(0, profile.guid()); |
1937 s_insert.BindString16(1, profile.GetInfo(COMPANY_NAME)); | 1705 s_insert.BindString16(1, profile.GetInfo(COMPANY_NAME)); |
1938 s_insert.BindString16(2, profile.GetInfo(ADDRESS_HOME_LINE1)); | 1706 s_insert.BindString16(2, profile.GetInfo(ADDRESS_HOME_LINE1)); |
1939 s_insert.BindString16(3, profile.GetInfo(ADDRESS_HOME_LINE2)); | 1707 s_insert.BindString16(3, profile.GetInfo(ADDRESS_HOME_LINE2)); |
1940 s_insert.BindString16(4, profile.GetInfo(ADDRESS_HOME_CITY)); | 1708 s_insert.BindString16(4, profile.GetInfo(ADDRESS_HOME_CITY)); |
1941 s_insert.BindString16(5, profile.GetInfo(ADDRESS_HOME_STATE)); | 1709 s_insert.BindString16(5, profile.GetInfo(ADDRESS_HOME_STATE)); |
1942 s_insert.BindString16(6, profile.GetInfo(ADDRESS_HOME_ZIP)); | 1710 s_insert.BindString16(6, profile.GetInfo(ADDRESS_HOME_ZIP)); |
1943 s_insert.BindString16(7, profile.GetInfo(ADDRESS_HOME_COUNTRY)); | 1711 s_insert.BindString16(7, profile.GetInfo(ADDRESS_HOME_COUNTRY)); |
1944 s_insert.BindInt64(8, date_modified); | 1712 s_insert.BindInt64(8, date_modified); |
1945 | 1713 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1998 if (!db_->DoesColumnExist("autofill_profiles", "country_code")) { | 1766 if (!db_->DoesColumnExist("autofill_profiles", "country_code")) { |
1999 if (!db_->Execute("ALTER TABLE autofill_profiles ADD COLUMN " | 1767 if (!db_->Execute("ALTER TABLE autofill_profiles ADD COLUMN " |
2000 "country_code VARCHAR")) { | 1768 "country_code VARCHAR")) { |
2001 return false; | 1769 return false; |
2002 } | 1770 } |
2003 | 1771 |
2004 // Set all the |country_code| fields to match existing |country| values. | 1772 // Set all the |country_code| fields to match existing |country| values. |
2005 sql::Statement s(db_->GetUniqueStatement("SELECT guid, country " | 1773 sql::Statement s(db_->GetUniqueStatement("SELECT guid, country " |
2006 "FROM autofill_profiles")); | 1774 "FROM autofill_profiles")); |
2007 | 1775 |
2008 if (!s) | 1776 if (!s.is_valid()) |
2009 return false; | 1777 return false; |
2010 | 1778 |
2011 while (s.Step()) { | 1779 while (s.Step()) { |
2012 sql::Statement update_s( | 1780 sql::Statement update_s( |
2013 db_->GetUniqueStatement("UPDATE autofill_profiles " | 1781 db_->GetUniqueStatement("UPDATE autofill_profiles " |
2014 "SET country_code=? WHERE guid=?")); | 1782 "SET country_code=? WHERE guid=?")); |
2015 if (!update_s) | |
2016 return false; | |
2017 | 1783 |
2018 string16 country = s.ColumnString16(1); | 1784 string16 country = s.ColumnString16(1); |
2019 std::string app_locale = AutofillCountry::ApplicationLocale(); | 1785 std::string app_locale = AutofillCountry::ApplicationLocale(); |
2020 update_s.BindString(0, AutofillCountry::GetCountryCode(country, | 1786 update_s.BindString(0, AutofillCountry::GetCountryCode(country, |
2021 app_locale)); | 1787 app_locale)); |
2022 update_s.BindString(1, s.ColumnString(0)); | 1788 update_s.BindString(1, s.ColumnString(0)); |
2023 | 1789 |
2024 if (!update_s.Run()) | 1790 if (!update_s.Run()) |
2025 return false; | 1791 return false; |
2026 } | 1792 } |
(...skipping 10 matching lines...) Expand all Loading... | |
2037 "UPDATE autofill_profiles SET country_code=\"GB\" " | 1803 "UPDATE autofill_profiles SET country_code=\"GB\" " |
2038 "WHERE country_code=\"UK\"")); | 1804 "WHERE country_code=\"UK\"")); |
2039 | 1805 |
2040 return s.Run(); | 1806 return s.Run(); |
2041 } | 1807 } |
2042 | 1808 |
2043 // Merge and cull older profiles where possible. | 1809 // Merge and cull older profiles where possible. |
2044 bool AutofillTable::MigrateToVersion37MergeAndCullOlderProfiles() { | 1810 bool AutofillTable::MigrateToVersion37MergeAndCullOlderProfiles() { |
2045 sql::Statement s(db_->GetUniqueStatement( | 1811 sql::Statement s(db_->GetUniqueStatement( |
2046 "SELECT guid, date_modified FROM autofill_profiles")); | 1812 "SELECT guid, date_modified FROM autofill_profiles")); |
2047 if (!s) | 1813 if (!s.is_valid()) |
2048 return false; | 1814 return false; |
2049 | 1815 |
2050 // Accumulate the good profiles. | 1816 // Accumulate the good profiles. |
2051 std::vector<AutofillProfile> accumulated_profiles; | 1817 std::vector<AutofillProfile> accumulated_profiles; |
2052 std::vector<AutofillProfile*> accumulated_profiles_p; | 1818 std::vector<AutofillProfile*> accumulated_profiles_p; |
2053 std::map<std::string, int64> modification_map; | 1819 std::map<std::string, int64> modification_map; |
2054 while (s.Step()) { | 1820 while (s.Step()) { |
2055 std::string guid = s.ColumnString(0); | 1821 std::string guid = s.ColumnString(0); |
2056 int64 date_modified = s.ColumnInt64(1); | 1822 int64 date_modified = s.ColumnInt64(1); |
2057 modification_map.insert( | 1823 modification_map.insert( |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2102 std::map<std::string, int64>::const_iterator date_item = | 1868 std::map<std::string, int64>::const_iterator date_item = |
2103 modification_map.find(iter->guid()); | 1869 modification_map.find(iter->guid()); |
2104 if (date_item == modification_map.end()) | 1870 if (date_item == modification_map.end()) |
2105 return false; | 1871 return false; |
2106 | 1872 |
2107 sql::Statement s_date(db_->GetUniqueStatement( | 1873 sql::Statement s_date(db_->GetUniqueStatement( |
2108 "UPDATE autofill_profiles SET date_modified=? " | 1874 "UPDATE autofill_profiles SET date_modified=? " |
2109 "WHERE guid=?")); | 1875 "WHERE guid=?")); |
2110 s_date.BindInt64(0, date_item->second); | 1876 s_date.BindInt64(0, date_item->second); |
2111 s_date.BindString(1, iter->guid()); | 1877 s_date.BindString(1, iter->guid()); |
1878 | |
2112 if (!s_date.Run()) | 1879 if (!s_date.Run()) |
2113 return false; | 1880 return false; |
2114 } | 1881 } |
2115 | 1882 |
2116 return true; | 1883 return true; |
2117 } | 1884 } |
OLD | NEW |