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

Side by Side Diff: chrome/browser/password_manager/native_backend_gnome_x.cc

Issue 335893002: Support to remove passwords by date_synced timestamp. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync integration tests 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/password_manager/native_backend_gnome_x.h" 5 #include "chrome/browser/password_manager/native_backend_gnome_x.h"
6 6
7 #include <dlfcn.h> 7 #include <dlfcn.h>
8 #include <gnome-keyring.h> 8 #include <gnome-keyring.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 if (result != GNOME_KEYRING_RESULT_OK) { 635 if (result != GNOME_KEYRING_RESULT_OK) {
636 // Warning, not error, because this can sometimes happen due to the user 636 // Warning, not error, because this can sometimes happen due to the user
637 // racing with the daemon to delete the password a second time. 637 // racing with the daemon to delete the password a second time.
638 LOG(WARNING) << "Keyring delete failed: " 638 LOG(WARNING) << "Keyring delete failed: "
639 << gnome_keyring_result_to_message(result); 639 << gnome_keyring_result_to_message(result);
640 return false; 640 return false;
641 } 641 }
642 return true; 642 return true;
643 } 643 }
644 644
645 bool NativeBackendGnome::RemoveLoginsCreatedBetween( 645 bool NativeBackendGnome::RemoveLoginsCreatedBetween(base::Time delete_begin,
646 const base::Time& delete_begin, 646 base::Time delete_end) {
647 const base::Time& delete_end) { 647 return RemoveLoginsBetween(delete_begin, delete_end, true, NULL);
648 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 648 }
649 bool ok = true;
650 // We could walk the list and delete items as we find them, but it is much
651 // easier to build the list and use RemoveLogin() to delete them.
652 PasswordFormList forms;
653 if (!GetAllLogins(&forms))
654 return false;
655 649
656 for (size_t i = 0; i < forms.size(); ++i) { 650 bool NativeBackendGnome::RemoveLoginsSyncedBetween(
657 if (delete_begin <= forms[i]->date_created && 651 base::Time delete_begin,
658 (delete_end.is_null() || forms[i]->date_created < delete_end)) { 652 base::Time delete_end,
659 if (!RemoveLogin(*forms[i])) 653 password_manager::PasswordStoreChangeList* changes) {
660 ok = false; 654 return RemoveLoginsBetween(delete_begin, delete_end, false, changes);
661 }
662 delete forms[i];
663 }
664 return ok;
665 } 655 }
666 656
667 bool NativeBackendGnome::GetLogins(const PasswordForm& form, 657 bool NativeBackendGnome::GetLogins(const PasswordForm& form,
668 PasswordFormList* forms) { 658 PasswordFormList* forms) {
669 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 659 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
670 GKRMethod method; 660 GKRMethod method;
671 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 661 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
672 base::Bind(&GKRMethod::GetLogins, 662 base::Bind(&GKRMethod::GetLogins,
673 base::Unretained(&method), 663 base::Unretained(&method),
674 form, app_string_.c_str())); 664 form, app_string_.c_str()));
675 GnomeKeyringResult result = method.WaitResult(forms); 665 GnomeKeyringResult result = method.WaitResult(forms);
676 if (result == GNOME_KEYRING_RESULT_NO_MATCH) 666 if (result == GNOME_KEYRING_RESULT_NO_MATCH)
677 return true; 667 return true;
678 if (result != GNOME_KEYRING_RESULT_OK) { 668 if (result != GNOME_KEYRING_RESULT_OK) {
679 LOG(ERROR) << "Keyring find failed: " 669 LOG(ERROR) << "Keyring find failed: "
680 << gnome_keyring_result_to_message(result); 670 << gnome_keyring_result_to_message(result);
681 return false; 671 return false;
682 } 672 }
683 return true; 673 return true;
684 } 674 }
685 675
686 bool NativeBackendGnome::GetLoginsCreatedBetween(const base::Time& get_begin, 676 bool NativeBackendGnome::GetLoginsCreatedBetween(base::Time get_begin,
687 const base::Time& get_end, 677 base::Time get_end,
688 PasswordFormList* forms) { 678 PasswordFormList* forms) {
689 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 679 return GetLoginsBetween(get_begin, get_end, true, forms);
690 // We could walk the list and add items as we find them, but it is much
691 // easier to build the list and then filter the results.
692 PasswordFormList all_forms;
693 if (!GetAllLogins(&all_forms))
694 return false;
695
696 forms->reserve(forms->size() + all_forms.size());
697 for (size_t i = 0; i < all_forms.size(); ++i) {
698 if (get_begin <= all_forms[i]->date_created &&
699 (get_end.is_null() || all_forms[i]->date_created < get_end)) {
700 forms->push_back(all_forms[i]);
701 } else {
702 delete all_forms[i];
703 }
704 }
705
706 return true;
707 } 680 }
708 681
709 bool NativeBackendGnome::GetAutofillableLogins(PasswordFormList* forms) { 682 bool NativeBackendGnome::GetAutofillableLogins(PasswordFormList* forms) {
710 return GetLoginsList(forms, true); 683 return GetLoginsList(forms, true);
711 } 684 }
712 685
713 bool NativeBackendGnome::GetBlacklistLogins(PasswordFormList* forms) { 686 bool NativeBackendGnome::GetBlacklistLogins(PasswordFormList* forms) {
714 return GetLoginsList(forms, false); 687 return GetLoginsList(forms, false);
715 } 688 }
716 689
(...skipping 29 matching lines...) Expand all
746 if (result == GNOME_KEYRING_RESULT_NO_MATCH) 719 if (result == GNOME_KEYRING_RESULT_NO_MATCH)
747 return true; 720 return true;
748 if (result != GNOME_KEYRING_RESULT_OK) { 721 if (result != GNOME_KEYRING_RESULT_OK) {
749 LOG(ERROR) << "Keyring find failed: " 722 LOG(ERROR) << "Keyring find failed: "
750 << gnome_keyring_result_to_message(result); 723 << gnome_keyring_result_to_message(result);
751 return false; 724 return false;
752 } 725 }
753 return true; 726 return true;
754 } 727 }
755 728
729 bool NativeBackendGnome::GetLoginsBetween(base::Time get_begin,
730 base::Time get_end,
731 bool date_is_creation,
732 PasswordFormList* forms) {
733 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
734 // We could walk the list and add items as we find them, but it is much
735 // easier to build the list and then filter the results.
736 PasswordFormList all_forms;
737 if (!GetAllLogins(&all_forms))
738 return false;
739
740 base::Time autofill::PasswordForm::*date_member = date_is_creation ?
741 &autofill::PasswordForm::date_created :
742 &autofill::PasswordForm::date_synced;
743 forms->reserve(forms->size() + all_forms.size());
vabr (Chromium) 2014/06/17 15:28:40 What are the reasons for this speed optimisation?
vasilii 2014/06/17 17:24:14 Done. I copied it from GetLoginsCreatedBetween().
744 for (size_t i = 0; i < all_forms.size(); ++i) {
745 if (get_begin <= all_forms[i]->*date_member &&
746 (get_end.is_null() || all_forms[i]->*date_member < get_end)) {
747 forms->push_back(all_forms[i]);
748 } else {
749 delete all_forms[i];
750 }
751 }
752
753 return true;
754 }
755
756 bool NativeBackendGnome::RemoveLoginsBetween(
757 base::Time get_begin,
758 base::Time get_end,
759 bool date_is_creation,
760 password_manager::PasswordStoreChangeList* changes) {
761 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
762 if (changes)
763 changes->clear();
764 // We could walk the list and delete items as we find them, but it is much
765 // easier to build the list and use RemoveLogin() to delete them.
766 ScopedVector<autofill::PasswordForm> forms;
767 if (!GetLoginsBetween(get_begin, get_end, date_is_creation, &forms.get()))
768 return false;
769
770 bool ok = true;
771 for (size_t i = 0; i < forms.size(); ++i) {
772 if (RemoveLogin(*forms[i])) {
773 if (changes) {
774 changes->push_back(password_manager::PasswordStoreChange(
775 password_manager::PasswordStoreChange::REMOVE, *forms[i]));
776 }
777 } else {
778 ok = false;
779 }
780 }
781 return ok;
782 }
783
756 std::string NativeBackendGnome::GetProfileSpecificAppString() const { 784 std::string NativeBackendGnome::GetProfileSpecificAppString() const {
757 // Originally, the application string was always just "chrome" and used only 785 // Originally, the application string was always just "chrome" and used only
758 // so that we had *something* to search for since GNOME Keyring won't search 786 // so that we had *something* to search for since GNOME Keyring won't search
759 // for nothing. Now we use it to distinguish passwords for different profiles. 787 // for nothing. Now we use it to distinguish passwords for different profiles.
760 return base::StringPrintf("%s-%d", kGnomeKeyringAppString, profile_id_); 788 return base::StringPrintf("%s-%d", kGnomeKeyringAppString, profile_id_);
761 } 789 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698