| OLD | NEW |
| 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 Loading... |
| 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(base::Time delete_begin, | 645 bool NativeBackendGnome::RemoveLoginsCreatedBetween( |
| 646 base::Time delete_end) { | 646 base::Time delete_begin, |
| 647 base::Time delete_end, |
| 648 password_manager::PasswordStoreChangeList* changes) { |
| 647 return RemoveLoginsBetween( | 649 return RemoveLoginsBetween( |
| 648 delete_begin, delete_end, CREATION_TIMESTAMP, NULL); | 650 delete_begin, delete_end, CREATION_TIMESTAMP, changes); |
| 649 } | 651 } |
| 650 | 652 |
| 651 bool NativeBackendGnome::RemoveLoginsSyncedBetween( | 653 bool NativeBackendGnome::RemoveLoginsSyncedBetween( |
| 652 base::Time delete_begin, | 654 base::Time delete_begin, |
| 653 base::Time delete_end, | 655 base::Time delete_end, |
| 654 password_manager::PasswordStoreChangeList* changes) { | 656 password_manager::PasswordStoreChangeList* changes) { |
| 655 return RemoveLoginsBetween(delete_begin, delete_end, SYNC_TIMESTAMP, changes); | 657 return RemoveLoginsBetween(delete_begin, delete_end, SYNC_TIMESTAMP, changes); |
| 656 } | 658 } |
| 657 | 659 |
| 658 bool NativeBackendGnome::GetLogins(const PasswordForm& form, | 660 bool NativeBackendGnome::GetLogins(const PasswordForm& form, |
| 659 PasswordFormList* forms) { | 661 PasswordFormList* forms) { |
| 660 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 662 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 661 GKRMethod method; | 663 GKRMethod method; |
| 662 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 664 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 663 base::Bind(&GKRMethod::GetLogins, | 665 base::Bind(&GKRMethod::GetLogins, |
| 664 base::Unretained(&method), | 666 base::Unretained(&method), |
| 665 form, app_string_.c_str())); | 667 form, app_string_.c_str())); |
| 666 GnomeKeyringResult result = method.WaitResult(forms); | 668 GnomeKeyringResult result = method.WaitResult(forms); |
| 667 if (result == GNOME_KEYRING_RESULT_NO_MATCH) | 669 if (result == GNOME_KEYRING_RESULT_NO_MATCH) |
| 668 return true; | 670 return true; |
| 669 if (result != GNOME_KEYRING_RESULT_OK) { | 671 if (result != GNOME_KEYRING_RESULT_OK) { |
| 670 LOG(ERROR) << "Keyring find failed: " | 672 LOG(ERROR) << "Keyring find failed: " |
| 671 << gnome_keyring_result_to_message(result); | 673 << gnome_keyring_result_to_message(result); |
| 672 return false; | 674 return false; |
| 673 } | 675 } |
| 674 return true; | 676 return true; |
| 675 } | 677 } |
| 676 | 678 |
| 677 bool NativeBackendGnome::GetLoginsCreatedBetween(base::Time get_begin, | |
| 678 base::Time get_end, | |
| 679 PasswordFormList* forms) { | |
| 680 return GetLoginsBetween(get_begin, get_end, CREATION_TIMESTAMP, forms); | |
| 681 } | |
| 682 | |
| 683 bool NativeBackendGnome::GetAutofillableLogins(PasswordFormList* forms) { | 679 bool NativeBackendGnome::GetAutofillableLogins(PasswordFormList* forms) { |
| 684 return GetLoginsList(forms, true); | 680 return GetLoginsList(forms, true); |
| 685 } | 681 } |
| 686 | 682 |
| 687 bool NativeBackendGnome::GetBlacklistLogins(PasswordFormList* forms) { | 683 bool NativeBackendGnome::GetBlacklistLogins(PasswordFormList* forms) { |
| 688 return GetLoginsList(forms, false); | 684 return GetLoginsList(forms, false); |
| 689 } | 685 } |
| 690 | 686 |
| 691 bool NativeBackendGnome::GetLoginsList(PasswordFormList* forms, | 687 bool NativeBackendGnome::GetLoginsList(PasswordFormList* forms, |
| 692 bool autofillable) { | 688 bool autofillable) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 | 749 |
| 754 return true; | 750 return true; |
| 755 } | 751 } |
| 756 | 752 |
| 757 bool NativeBackendGnome::RemoveLoginsBetween( | 753 bool NativeBackendGnome::RemoveLoginsBetween( |
| 758 base::Time get_begin, | 754 base::Time get_begin, |
| 759 base::Time get_end, | 755 base::Time get_end, |
| 760 TimestampToCompare date_to_compare, | 756 TimestampToCompare date_to_compare, |
| 761 password_manager::PasswordStoreChangeList* changes) { | 757 password_manager::PasswordStoreChangeList* changes) { |
| 762 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 758 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 763 if (changes) | 759 DCHECK(changes); |
| 764 changes->clear(); | 760 changes->clear(); |
| 765 // We could walk the list and delete items as we find them, but it is much | 761 // 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. | 762 // easier to build the list and use RemoveLogin() to delete them. |
| 767 ScopedVector<autofill::PasswordForm> forms; | 763 ScopedVector<autofill::PasswordForm> forms; |
| 768 if (!GetLoginsBetween(get_begin, get_end, date_to_compare, &forms.get())) | 764 if (!GetLoginsBetween(get_begin, get_end, date_to_compare, &forms.get())) |
| 769 return false; | 765 return false; |
| 770 | 766 |
| 771 bool ok = true; | 767 bool ok = true; |
| 772 for (size_t i = 0; i < forms.size(); ++i) { | 768 for (size_t i = 0; i < forms.size(); ++i) { |
| 773 if (RemoveLogin(*forms[i])) { | 769 if (RemoveLogin(*forms[i])) { |
| 774 if (changes) { | 770 changes->push_back(password_manager::PasswordStoreChange( |
| 775 changes->push_back(password_manager::PasswordStoreChange( | 771 password_manager::PasswordStoreChange::REMOVE, *forms[i])); |
| 776 password_manager::PasswordStoreChange::REMOVE, *forms[i])); | |
| 777 } | |
| 778 } else { | 772 } else { |
| 779 ok = false; | 773 ok = false; |
| 780 } | 774 } |
| 781 } | 775 } |
| 782 return ok; | 776 return ok; |
| 783 } | 777 } |
| 784 | 778 |
| 785 std::string NativeBackendGnome::GetProfileSpecificAppString() const { | 779 std::string NativeBackendGnome::GetProfileSpecificAppString() const { |
| 786 // Originally, the application string was always just "chrome" and used only | 780 // Originally, the application string was always just "chrome" and used only |
| 787 // so that we had *something* to search for since GNOME Keyring won't search | 781 // so that we had *something* to search for since GNOME Keyring won't search |
| 788 // for nothing. Now we use it to distinguish passwords for different profiles. | 782 // for nothing. Now we use it to distinguish passwords for different profiles. |
| 789 return base::StringPrintf("%s-%d", kGnomeKeyringAppString, profile_id_); | 783 return base::StringPrintf("%s-%d", kGnomeKeyringAppString, profile_id_); |
| 790 } | 784 } |
| OLD | NEW |