| 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/password_manager/password_store_mac.h" | 5 #include "chrome/browser/password_manager/password_store_mac.h" |
| 6 #include "chrome/browser/password_manager/password_store_mac_internal.h" | 6 #include "chrome/browser/password_manager/password_store_mac_internal.h" |
| 7 | 7 |
| 8 #include <CoreServices/CoreServices.h> | 8 #include <CoreServices/CoreServices.h> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/mac/mac_util.h" | 14 #include "base/mac/mac_util.h" |
| 15 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
| 16 #include "base/stl_util-inl.h" | 16 #include "base/stl_util-inl.h" |
| 17 #include "base/string_util.h" | 17 #include "base/string_util.h" |
| 18 #include "base/task.h" | 18 #include "base/task.h" |
| 19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
| 20 #include "chrome/browser/keychain_mac.h" | 20 #include "chrome/browser/keychain_mac.h" |
| 21 #include "chrome/browser/password_manager/login_database.h" | 21 #include "chrome/browser/password_manager/login_database.h" |
| 22 #include "chrome/browser/password_manager/password_store_change.h" | 22 #include "chrome/browser/password_manager/password_store_change.h" |
| 23 #include "chrome/common/chrome_notification_types.h" |
| 23 #include "content/common/notification_service.h" | 24 #include "content/common/notification_service.h" |
| 24 | 25 |
| 25 using webkit_glue::PasswordForm; | 26 using webkit_glue::PasswordForm; |
| 26 | 27 |
| 27 // Utility class to handle the details of constructing and running a keychain | 28 // Utility class to handle the details of constructing and running a keychain |
| 28 // search from a set of attributes. | 29 // search from a set of attributes. |
| 29 class KeychainSearch { | 30 class KeychainSearch { |
| 30 public: | 31 public: |
| 31 explicit KeychainSearch(const MacKeychain& keychain); | 32 explicit KeychainSearch(const MacKeychain& keychain); |
| 32 ~KeychainSearch(); | 33 ~KeychainSearch(); |
| (...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 void PasswordStoreMac::ReportMetricsImpl() { | 764 void PasswordStoreMac::ReportMetricsImpl() { |
| 764 login_metadata_db_->ReportMetrics(); | 765 login_metadata_db_->ReportMetrics(); |
| 765 } | 766 } |
| 766 | 767 |
| 767 void PasswordStoreMac::AddLoginImpl(const PasswordForm& form) { | 768 void PasswordStoreMac::AddLoginImpl(const PasswordForm& form) { |
| 768 if (AddToKeychainIfNecessary(form)) { | 769 if (AddToKeychainIfNecessary(form)) { |
| 769 if (login_metadata_db_->AddLogin(form)) { | 770 if (login_metadata_db_->AddLogin(form)) { |
| 770 PasswordStoreChangeList changes; | 771 PasswordStoreChangeList changes; |
| 771 changes.push_back(PasswordStoreChange(PasswordStoreChange::ADD, form)); | 772 changes.push_back(PasswordStoreChange(PasswordStoreChange::ADD, form)); |
| 772 NotificationService::current()->Notify( | 773 NotificationService::current()->Notify( |
| 773 NotificationType::LOGINS_CHANGED, | 774 chrome::NOTIFICATION_LOGINS_CHANGED, |
| 774 Source<PasswordStore>(this), | 775 Source<PasswordStore>(this), |
| 775 Details<PasswordStoreChangeList>(&changes)); | 776 Details<PasswordStoreChangeList>(&changes)); |
| 776 } | 777 } |
| 777 } | 778 } |
| 778 } | 779 } |
| 779 | 780 |
| 780 void PasswordStoreMac::UpdateLoginImpl(const PasswordForm& form) { | 781 void PasswordStoreMac::UpdateLoginImpl(const PasswordForm& form) { |
| 781 int update_count = 0; | 782 int update_count = 0; |
| 782 if (!login_metadata_db_->UpdateLogin(form, &update_count)) | 783 if (!login_metadata_db_->UpdateLogin(form, &update_count)) |
| 783 return; | 784 return; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 798 if (login_metadata_db_->AddLogin(form)) { | 799 if (login_metadata_db_->AddLogin(form)) { |
| 799 changes.push_back(PasswordStoreChange(PasswordStoreChange::ADD, | 800 changes.push_back(PasswordStoreChange(PasswordStoreChange::ADD, |
| 800 form)); | 801 form)); |
| 801 } | 802 } |
| 802 } else { | 803 } else { |
| 803 changes.push_back(PasswordStoreChange(PasswordStoreChange::UPDATE, | 804 changes.push_back(PasswordStoreChange(PasswordStoreChange::UPDATE, |
| 804 form)); | 805 form)); |
| 805 } | 806 } |
| 806 if (!changes.empty()) { | 807 if (!changes.empty()) { |
| 807 NotificationService::current()->Notify( | 808 NotificationService::current()->Notify( |
| 808 NotificationType::LOGINS_CHANGED, | 809 chrome::NOTIFICATION_LOGINS_CHANGED, |
| 809 Source<PasswordStore>(this), | 810 Source<PasswordStore>(this), |
| 810 Details<PasswordStoreChangeList>(&changes)); | 811 Details<PasswordStoreChangeList>(&changes)); |
| 811 } | 812 } |
| 812 } | 813 } |
| 813 } | 814 } |
| 814 | 815 |
| 815 void PasswordStoreMac::RemoveLoginImpl(const PasswordForm& form) { | 816 void PasswordStoreMac::RemoveLoginImpl(const PasswordForm& form) { |
| 816 if (login_metadata_db_->RemoveLogin(form)) { | 817 if (login_metadata_db_->RemoveLogin(form)) { |
| 817 // See if we own a Keychain item associated with this item. We can do an | 818 // See if we own a Keychain item associated with this item. We can do an |
| 818 // exact search rather than messing around with trying to do fuzzy matching | 819 // exact search rather than messing around with trying to do fuzzy matching |
| (...skipping 10 matching lines...) Expand all Loading... |
| 829 // If we don't have other forms using it (i.e., a form differing only by | 830 // If we don't have other forms using it (i.e., a form differing only by |
| 830 // the names of the form elements), delete the keychain entry. | 831 // the names of the form elements), delete the keychain entry. |
| 831 if (!DatabaseHasFormMatchingKeychainForm(form)) { | 832 if (!DatabaseHasFormMatchingKeychainForm(form)) { |
| 832 owned_keychain_adapter.RemovePassword(form); | 833 owned_keychain_adapter.RemovePassword(form); |
| 833 } | 834 } |
| 834 } | 835 } |
| 835 | 836 |
| 836 PasswordStoreChangeList changes; | 837 PasswordStoreChangeList changes; |
| 837 changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, form)); | 838 changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, form)); |
| 838 NotificationService::current()->Notify( | 839 NotificationService::current()->Notify( |
| 839 NotificationType::LOGINS_CHANGED, | 840 chrome::NOTIFICATION_LOGINS_CHANGED, |
| 840 Source<PasswordStore>(this), | 841 Source<PasswordStore>(this), |
| 841 Details<PasswordStoreChangeList>(&changes)); | 842 Details<PasswordStoreChangeList>(&changes)); |
| 842 } | 843 } |
| 843 } | 844 } |
| 844 | 845 |
| 845 void PasswordStoreMac::RemoveLoginsCreatedBetweenImpl( | 846 void PasswordStoreMac::RemoveLoginsCreatedBetweenImpl( |
| 846 const base::Time& delete_begin, const base::Time& delete_end) { | 847 const base::Time& delete_begin, const base::Time& delete_end) { |
| 847 std::vector<PasswordForm*> forms; | 848 std::vector<PasswordForm*> forms; |
| 848 if (login_metadata_db_->GetLoginsCreatedBetween(delete_begin, delete_end, | 849 if (login_metadata_db_->GetLoginsCreatedBetween(delete_begin, delete_end, |
| 849 &forms)) { | 850 &forms)) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 863 RemoveKeychainForms(orphan_keychain_forms); | 864 RemoveKeychainForms(orphan_keychain_forms); |
| 864 STLDeleteElements(&orphan_keychain_forms); | 865 STLDeleteElements(&orphan_keychain_forms); |
| 865 | 866 |
| 866 PasswordStoreChangeList changes; | 867 PasswordStoreChangeList changes; |
| 867 for (std::vector<PasswordForm*>::const_iterator it = forms.begin(); | 868 for (std::vector<PasswordForm*>::const_iterator it = forms.begin(); |
| 868 it != forms.end(); ++it) { | 869 it != forms.end(); ++it) { |
| 869 changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, | 870 changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, |
| 870 **it)); | 871 **it)); |
| 871 } | 872 } |
| 872 NotificationService::current()->Notify( | 873 NotificationService::current()->Notify( |
| 873 NotificationType::LOGINS_CHANGED, | 874 chrome::NOTIFICATION_LOGINS_CHANGED, |
| 874 Source<PasswordStore>(this), | 875 Source<PasswordStore>(this), |
| 875 Details<PasswordStoreChangeList>(&changes)); | 876 Details<PasswordStoreChangeList>(&changes)); |
| 876 } | 877 } |
| 877 } | 878 } |
| 878 } | 879 } |
| 879 | 880 |
| 880 void PasswordStoreMac::GetLoginsImpl(GetLoginsRequest* request, | 881 void PasswordStoreMac::GetLoginsImpl(GetLoginsRequest* request, |
| 881 const webkit_glue::PasswordForm& form) { | 882 const webkit_glue::PasswordForm& form) { |
| 882 MacKeychainPasswordFormAdapter keychain_adapter(keychain_.get()); | 883 MacKeychainPasswordFormAdapter keychain_adapter(keychain_.get()); |
| 883 std::vector<PasswordForm*> keychain_forms = | 884 std::vector<PasswordForm*> keychain_forms = |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1002 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); | 1003 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); |
| 1003 for (std::vector<PasswordForm*>::const_iterator i = forms.begin(); | 1004 for (std::vector<PasswordForm*>::const_iterator i = forms.begin(); |
| 1004 i != forms.end(); ++i) { | 1005 i != forms.end(); ++i) { |
| 1005 owned_keychain_adapter.RemovePassword(**i); | 1006 owned_keychain_adapter.RemovePassword(**i); |
| 1006 } | 1007 } |
| 1007 } | 1008 } |
| 1008 | 1009 |
| 1009 void PasswordStoreMac::CreateNotificationService() { | 1010 void PasswordStoreMac::CreateNotificationService() { |
| 1010 notification_service_.reset(new NotificationService); | 1011 notification_service_.reset(new NotificationService); |
| 1011 } | 1012 } |
| OLD | NEW |