Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(504)

Side by Side Diff: components/password_manager/core/browser/login_database.cc

Issue 335893002: Support to remove passwords by date_synced timestamp. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: vabr's comments Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/password_manager/core/browser/login_database.h" 5 #include "components/password_manager/core/browser/login_database.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 347
348 PasswordStoreChangeList LoginDatabase::UpdateLogin(const PasswordForm& form) { 348 PasswordStoreChangeList LoginDatabase::UpdateLogin(const PasswordForm& form) {
349 std::string encrypted_password; 349 std::string encrypted_password;
350 if (EncryptedString(form.password_value, &encrypted_password) != 350 if (EncryptedString(form.password_value, &encrypted_password) !=
351 ENCRYPTION_RESULT_SUCCESS) 351 ENCRYPTION_RESULT_SUCCESS)
352 return PasswordStoreChangeList(); 352 return PasswordStoreChangeList();
353 353
354 // Replacement is necessary to deal with updating imported credentials. See 354 // Replacement is necessary to deal with updating imported credentials. See
355 // crbug.com/349138 for details. 355 // crbug.com/349138 for details.
356 sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE, 356 sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE,
357 "UPDATE OR REPLACE logins SET " 357 "UPDATE OR REPLACE logins SET "
358 "action_url = ?, " 358 "action_url = ?, "
359 "password_value = ?, " 359 "password_value = ?, "
360 "ssl_valid = ?, " 360 "ssl_valid = ?, "
361 "preferred = ?, " 361 "preferred = ?, "
362 "possible_usernames = ?, " 362 "possible_usernames = ?, "
363 "times_used = ?, " 363 "times_used = ?, "
364 "submit_element = ? " 364 "submit_element = ?, "
365 "WHERE origin_url = ? AND " 365 "date_synced = ? "
366 "username_element = ? AND " 366 "WHERE origin_url = ? AND "
367 "username_value = ? AND " 367 "username_element = ? AND "
368 "password_element = ? AND " 368 "username_value = ? AND "
369 "signon_realm = ?")); 369 "password_element = ? AND "
370 "signon_realm = ?"));
370 s.BindString(0, form.action.spec()); 371 s.BindString(0, form.action.spec());
371 s.BindBlob(1, encrypted_password.data(), 372 s.BindBlob(1, encrypted_password.data(),
372 static_cast<int>(encrypted_password.length())); 373 static_cast<int>(encrypted_password.length()));
373 s.BindInt(2, form.ssl_valid); 374 s.BindInt(2, form.ssl_valid);
374 s.BindInt(3, form.preferred); 375 s.BindInt(3, form.preferred);
375 Pickle pickle = SerializeVector(form.other_possible_usernames); 376 Pickle pickle = SerializeVector(form.other_possible_usernames);
376 s.BindBlob(4, pickle.data(), pickle.size()); 377 s.BindBlob(4, pickle.data(), pickle.size());
377 s.BindInt(5, form.times_used); 378 s.BindInt(5, form.times_used);
378 s.BindString16(6, form.submit_element); 379 s.BindString16(6, form.submit_element);
380 s.BindInt64(7, form.date_synced.ToInternalValue());
379 381
380 s.BindString(7, form.origin.spec()); 382 s.BindString(8, form.origin.spec());
381 s.BindString16(8, form.username_element); 383 s.BindString16(9, form.username_element);
382 s.BindString16(9, form.username_value); 384 s.BindString16(10, form.username_value);
383 s.BindString16(10, form.password_element); 385 s.BindString16(11, form.password_element);
384 s.BindString(11, form.signon_realm); 386 s.BindString(12, form.signon_realm);
385 387
386 if (!s.Run()) 388 if (!s.Run())
387 return PasswordStoreChangeList(); 389 return PasswordStoreChangeList();
388 390
389 PasswordStoreChangeList list; 391 PasswordStoreChangeList list;
390 if (db_.GetLastChangeCount()) 392 if (db_.GetLastChangeCount())
391 list.push_back(PasswordStoreChange(PasswordStoreChange::UPDATE, form)); 393 list.push_back(PasswordStoreChange(PasswordStoreChange::UPDATE, form));
392 394
393 return list; 395 return list;
394 } 396 }
(...skipping 23 matching lines...) Expand all
418 sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE, 420 sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE,
419 "DELETE FROM logins WHERE " 421 "DELETE FROM logins WHERE "
420 "date_created >= ? AND date_created < ?")); 422 "date_created >= ? AND date_created < ?"));
421 s.BindInt64(0, delete_begin.ToTimeT()); 423 s.BindInt64(0, delete_begin.ToTimeT());
422 s.BindInt64(1, delete_end.is_null() ? std::numeric_limits<int64>::max() 424 s.BindInt64(1, delete_end.is_null() ? std::numeric_limits<int64>::max()
423 : delete_end.ToTimeT()); 425 : delete_end.ToTimeT());
424 426
425 return s.Run(); 427 return s.Run();
426 } 428 }
427 429
430 bool LoginDatabase::RemoveLoginsSyncedBetween(base::Time delete_begin,
431 base::Time delete_end) {
432 sql::Statement s(db_.GetCachedStatement(
433 SQL_FROM_HERE,
434 "DELETE FROM logins WHERE date_synced >= ? AND date_synced < ?"));
435 s.BindInt64(0, delete_begin.ToInternalValue());
436 s.BindInt64(1,
437 delete_end.is_null() ? base::Time::Max().ToInternalValue()
438 : delete_end.ToInternalValue());
439
440 return s.Run();
441 }
442
428 LoginDatabase::EncryptionResult LoginDatabase::InitPasswordFormFromStatement( 443 LoginDatabase::EncryptionResult LoginDatabase::InitPasswordFormFromStatement(
429 PasswordForm* form, 444 PasswordForm* form,
430 sql::Statement& s) const { 445 sql::Statement& s) const {
431 std::string encrypted_password; 446 std::string encrypted_password;
432 s.ColumnBlobAsString(COLUMN_PASSWORD_VALUE, &encrypted_password); 447 s.ColumnBlobAsString(COLUMN_PASSWORD_VALUE, &encrypted_password);
433 base::string16 decrypted_password; 448 base::string16 decrypted_password;
434 EncryptionResult encryption_result = 449 EncryptionResult encryption_result =
435 DecryptedString(encrypted_password, &decrypted_password); 450 DecryptedString(encrypted_password, &decrypted_password);
436 if (encryption_result != ENCRYPTION_RESULT_SUCCESS) 451 if (encryption_result != ENCRYPTION_RESULT_SUCCESS)
437 return encryption_result; 452 return encryption_result;
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 if (result == ENCRYPTION_RESULT_SERVICE_FAILURE) 611 if (result == ENCRYPTION_RESULT_SERVICE_FAILURE)
597 return false; 612 return false;
598 if (result == ENCRYPTION_RESULT_ITEM_FAILURE) 613 if (result == ENCRYPTION_RESULT_ITEM_FAILURE)
599 continue; 614 continue;
600 DCHECK(result == ENCRYPTION_RESULT_SUCCESS); 615 DCHECK(result == ENCRYPTION_RESULT_SUCCESS);
601 forms->push_back(new_form.release()); 616 forms->push_back(new_form.release());
602 } 617 }
603 return s.Succeeded(); 618 return s.Succeeded();
604 } 619 }
605 620
621 bool LoginDatabase::GetLoginsSyncedBetween(
622 const base::Time begin,
623 const base::Time end,
624 std::vector<autofill::PasswordForm*>* forms) const {
625 DCHECK(forms);
626 sql::Statement s(db_.GetCachedStatement(
627 SQL_FROM_HERE,
628 "SELECT origin_url, action_url, username_element, username_value, "
629 "password_element, password_value, submit_element, signon_realm, "
630 "ssl_valid, preferred, date_created, blacklisted_by_user, "
631 "scheme, password_type, possible_usernames, times_used, form_data, "
632 "use_additional_auth, date_synced FROM logins "
633 "WHERE date_synced >= ? AND date_synced < ?"
634 "ORDER BY origin_url"));
635 s.BindInt64(0, begin.ToInternalValue());
636 s.BindInt64(1,
637 end.is_null() ? base::Time::Max().ToInternalValue()
638 : end.ToInternalValue());
639
640 while (s.Step()) {
641 scoped_ptr<PasswordForm> new_form(new PasswordForm());
642 EncryptionResult result = InitPasswordFormFromStatement(new_form.get(), s);
643 if (result == ENCRYPTION_RESULT_SERVICE_FAILURE)
644 return false;
645 if (result == ENCRYPTION_RESULT_ITEM_FAILURE)
646 continue;
647 DCHECK(result == ENCRYPTION_RESULT_SUCCESS);
648 forms->push_back(new_form.release());
649 }
650 return s.Succeeded();
651 }
652
606 bool LoginDatabase::GetAutofillableLogins( 653 bool LoginDatabase::GetAutofillableLogins(
607 std::vector<PasswordForm*>* forms) const { 654 std::vector<PasswordForm*>* forms) const {
608 return GetAllLoginsWithBlacklistSetting(false, forms); 655 return GetAllLoginsWithBlacklistSetting(false, forms);
609 } 656 }
610 657
611 bool LoginDatabase::GetBlacklistLogins( 658 bool LoginDatabase::GetBlacklistLogins(
612 std::vector<PasswordForm*>* forms) const { 659 std::vector<PasswordForm*>* forms) const {
613 return GetAllLoginsWithBlacklistSetting(true, forms); 660 return GetAllLoginsWithBlacklistSetting(true, forms);
614 } 661 }
615 662
(...skipping 26 matching lines...) Expand all
642 689
643 bool LoginDatabase::DeleteAndRecreateDatabaseFile() { 690 bool LoginDatabase::DeleteAndRecreateDatabaseFile() {
644 DCHECK(db_.is_open()); 691 DCHECK(db_.is_open());
645 meta_table_.Reset(); 692 meta_table_.Reset();
646 db_.Close(); 693 db_.Close();
647 sql::Connection::Delete(db_path_); 694 sql::Connection::Delete(db_path_);
648 return Init(db_path_); 695 return Init(db_path_);
649 } 696 }
650 697
651 } // namespace password_manager 698 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698