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

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: 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 (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(
648 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 648 delete_begin, delete_end, CREATION_TIMESTAMP, NULL);
649 bool ok = true; 649 }
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 650
656 for (size_t i = 0; i < forms.size(); ++i) { 651 bool NativeBackendGnome::RemoveLoginsSyncedBetween(
657 if (delete_begin <= forms[i]->date_created && 652 base::Time delete_begin,
658 (delete_end.is_null() || forms[i]->date_created < delete_end)) { 653 base::Time delete_end,
659 if (!RemoveLogin(*forms[i])) 654 password_manager::PasswordStoreChangeList* changes) {
660 ok = false; 655 return RemoveLoginsBetween(delete_begin, delete_end, SYNC_TIMESTAMP, changes);
661 }
662 delete forms[i];
663 }
664 return ok;
665 } 656 }
666 657
667 bool NativeBackendGnome::GetLogins(const PasswordForm& form, 658 bool NativeBackendGnome::GetLogins(const PasswordForm& form,
668 PasswordFormList* forms) { 659 PasswordFormList* forms) {
669 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 660 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
670 GKRMethod method; 661 GKRMethod method;
671 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 662 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
672 base::Bind(&GKRMethod::GetLogins, 663 base::Bind(&GKRMethod::GetLogins,
673 base::Unretained(&method), 664 base::Unretained(&method),
674 form, app_string_.c_str())); 665 form, app_string_.c_str()));
675 GnomeKeyringResult result = method.WaitResult(forms); 666 GnomeKeyringResult result = method.WaitResult(forms);
676 if (result == GNOME_KEYRING_RESULT_NO_MATCH) 667 if (result == GNOME_KEYRING_RESULT_NO_MATCH)
677 return true; 668 return true;
678 if (result != GNOME_KEYRING_RESULT_OK) { 669 if (result != GNOME_KEYRING_RESULT_OK) {
679 LOG(ERROR) << "Keyring find failed: " 670 LOG(ERROR) << "Keyring find failed: "
680 << gnome_keyring_result_to_message(result); 671 << gnome_keyring_result_to_message(result);
681 return false; 672 return false;
682 } 673 }
683 return true; 674 return true;
684 } 675 }
685 676
686 bool NativeBackendGnome::GetLoginsCreatedBetween(const base::Time& get_begin, 677 bool NativeBackendGnome::GetLoginsCreatedBetween(base::Time get_begin,
687 const base::Time& get_end, 678 base::Time get_end,
688 PasswordFormList* forms) { 679 PasswordFormList* forms) {
689 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 680 return GetLoginsBetween(get_begin, get_end, CREATION_TIMESTAMP, 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 } 681 }
708 682
709 bool NativeBackendGnome::GetAutofillableLogins(PasswordFormList* forms) { 683 bool NativeBackendGnome::GetAutofillableLogins(PasswordFormList* forms) {
710 return GetLoginsList(forms, true); 684 return GetLoginsList(forms, true);
711 } 685 }
712 686
713 bool NativeBackendGnome::GetBlacklistLogins(PasswordFormList* forms) { 687 bool NativeBackendGnome::GetBlacklistLogins(PasswordFormList* forms) {
714 return GetLoginsList(forms, false); 688 return GetLoginsList(forms, false);
715 } 689 }
716 690
(...skipping 29 matching lines...) Expand all
746 if (result == GNOME_KEYRING_RESULT_NO_MATCH) 720 if (result == GNOME_KEYRING_RESULT_NO_MATCH)
747 return true; 721 return true;
748 if (result != GNOME_KEYRING_RESULT_OK) { 722 if (result != GNOME_KEYRING_RESULT_OK) {
749 LOG(ERROR) << "Keyring find failed: " 723 LOG(ERROR) << "Keyring find failed: "
750 << gnome_keyring_result_to_message(result); 724 << gnome_keyring_result_to_message(result);
751 return false; 725 return false;
752 } 726 }
753 return true; 727 return true;
754 } 728 }
755 729
730 bool NativeBackendGnome::GetLoginsBetween(base::Time get_begin,
731 base::Time get_end,
732 TimestampToCompare date_to_compare,
733 PasswordFormList* forms) {
734 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
735 // We could walk the list and add items as we find them, but it is much
736 // easier to build the list and then filter the results.
737 PasswordFormList all_forms;
738 if (!GetAllLogins(&all_forms))
739 return false;
740
741 base::Time autofill::PasswordForm::*date_member =
742 date_to_compare == CREATION_TIMESTAMP
743 ? &autofill::PasswordForm::date_created
744 : &autofill::PasswordForm::date_synced;
745 for (size_t i = 0; i < all_forms.size(); ++i) {
746 if (get_begin <= all_forms[i]->*date_member &&
747 (get_end.is_null() || all_forms[i]->*date_member < get_end)) {
748 forms->push_back(all_forms[i]);
749 } else {
750 delete all_forms[i];
751 }
752 }
753
754 return true;
755 }
756
757 bool NativeBackendGnome::RemoveLoginsBetween(
758 base::Time get_begin,
759 base::Time get_end,
760 TimestampToCompare date_to_compare,
761 password_manager::PasswordStoreChangeList* changes) {
762 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
763 if (changes)
764 changes->clear();
765 // We could walk the list and delete items as we find them, but it is much
766 // easier to build the list and use RemoveLogin() to delete them.
767 ScopedVector<autofill::PasswordForm> forms;
768 if (!GetLoginsBetween(get_begin, get_end, date_to_compare, &forms.get()))
769 return false;
770
771 bool ok = true;
772 for (size_t i = 0; i < forms.size(); ++i) {
773 if (RemoveLogin(*forms[i])) {
774 if (changes) {
775 changes->push_back(password_manager::PasswordStoreChange(
776 password_manager::PasswordStoreChange::REMOVE, *forms[i]));
777 }
778 } else {
779 ok = false;
780 }
781 }
782 return ok;
783 }
784
756 std::string NativeBackendGnome::GetProfileSpecificAppString() const { 785 std::string NativeBackendGnome::GetProfileSpecificAppString() const {
757 // Originally, the application string was always just "chrome" and used only 786 // 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 787 // 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. 788 // for nothing. Now we use it to distinguish passwords for different profiles.
760 return base::StringPrintf("%s-%d", kGnomeKeyringAppString, profile_id_); 789 return base::StringPrintf("%s-%d", kGnomeKeyringAppString, profile_id_);
761 } 790 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698