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.h" | 16 #include "base/stl_util.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 "chrome/common/chrome_notification_types.h" |
24 #include "content/common/notification_service.h" | 24 #include "content/browser/notification_service_impl.h" |
25 | 25 |
26 using webkit_glue::PasswordForm; | 26 using webkit_glue::PasswordForm; |
27 | 27 |
28 // 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 |
29 // search from a set of attributes. | 29 // search from a set of attributes. |
30 class KeychainSearch { | 30 class KeychainSearch { |
31 public: | 31 public: |
32 explicit KeychainSearch(const MacKeychain& keychain); | 32 explicit KeychainSearch(const MacKeychain& keychain); |
33 ~KeychainSearch(); | 33 ~KeychainSearch(); |
34 | 34 |
(...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 | 768 |
769 void PasswordStoreMac::ReportMetricsImpl() { | 769 void PasswordStoreMac::ReportMetricsImpl() { |
770 login_metadata_db_->ReportMetrics(); | 770 login_metadata_db_->ReportMetrics(); |
771 } | 771 } |
772 | 772 |
773 void PasswordStoreMac::AddLoginImpl(const PasswordForm& form) { | 773 void PasswordStoreMac::AddLoginImpl(const PasswordForm& form) { |
774 if (AddToKeychainIfNecessary(form)) { | 774 if (AddToKeychainIfNecessary(form)) { |
775 if (login_metadata_db_->AddLogin(form)) { | 775 if (login_metadata_db_->AddLogin(form)) { |
776 PasswordStoreChangeList changes; | 776 PasswordStoreChangeList changes; |
777 changes.push_back(PasswordStoreChange(PasswordStoreChange::ADD, form)); | 777 changes.push_back(PasswordStoreChange(PasswordStoreChange::ADD, form)); |
778 NotificationService::current()->Notify( | 778 content::NotificationService::current()->Notify( |
779 chrome::NOTIFICATION_LOGINS_CHANGED, | 779 chrome::NOTIFICATION_LOGINS_CHANGED, |
780 content::Source<PasswordStore>(this), | 780 content::Source<PasswordStore>(this), |
781 content::Details<PasswordStoreChangeList>(&changes)); | 781 content::Details<PasswordStoreChangeList>(&changes)); |
782 } | 782 } |
783 } | 783 } |
784 } | 784 } |
785 | 785 |
786 void PasswordStoreMac::UpdateLoginImpl(const PasswordForm& form) { | 786 void PasswordStoreMac::UpdateLoginImpl(const PasswordForm& form) { |
787 int update_count = 0; | 787 int update_count = 0; |
788 if (!login_metadata_db_->UpdateLogin(form, &update_count)) | 788 if (!login_metadata_db_->UpdateLogin(form, &update_count)) |
(...skipping 14 matching lines...) Expand all Loading... |
803 if (update_count == 0) { | 803 if (update_count == 0) { |
804 if (login_metadata_db_->AddLogin(form)) { | 804 if (login_metadata_db_->AddLogin(form)) { |
805 changes.push_back(PasswordStoreChange(PasswordStoreChange::ADD, | 805 changes.push_back(PasswordStoreChange(PasswordStoreChange::ADD, |
806 form)); | 806 form)); |
807 } | 807 } |
808 } else { | 808 } else { |
809 changes.push_back(PasswordStoreChange(PasswordStoreChange::UPDATE, | 809 changes.push_back(PasswordStoreChange(PasswordStoreChange::UPDATE, |
810 form)); | 810 form)); |
811 } | 811 } |
812 if (!changes.empty()) { | 812 if (!changes.empty()) { |
813 NotificationService::current()->Notify( | 813 content::NotificationService::current()->Notify( |
814 chrome::NOTIFICATION_LOGINS_CHANGED, | 814 chrome::NOTIFICATION_LOGINS_CHANGED, |
815 content::Source<PasswordStore>(this), | 815 content::Source<PasswordStore>(this), |
816 content::Details<PasswordStoreChangeList>(&changes)); | 816 content::Details<PasswordStoreChangeList>(&changes)); |
817 } | 817 } |
818 } | 818 } |
819 } | 819 } |
820 | 820 |
821 void PasswordStoreMac::RemoveLoginImpl(const PasswordForm& form) { | 821 void PasswordStoreMac::RemoveLoginImpl(const PasswordForm& form) { |
822 if (login_metadata_db_->RemoveLogin(form)) { | 822 if (login_metadata_db_->RemoveLogin(form)) { |
823 // See if we own a Keychain item associated with this item. We can do an | 823 // See if we own a Keychain item associated with this item. We can do an |
(...skipping 10 matching lines...) Expand all Loading... |
834 if (owned_password_form) { | 834 if (owned_password_form) { |
835 // If we don't have other forms using it (i.e., a form differing only by | 835 // If we don't have other forms using it (i.e., a form differing only by |
836 // the names of the form elements), delete the keychain entry. | 836 // the names of the form elements), delete the keychain entry. |
837 if (!DatabaseHasFormMatchingKeychainForm(form)) { | 837 if (!DatabaseHasFormMatchingKeychainForm(form)) { |
838 owned_keychain_adapter.RemovePassword(form); | 838 owned_keychain_adapter.RemovePassword(form); |
839 } | 839 } |
840 } | 840 } |
841 | 841 |
842 PasswordStoreChangeList changes; | 842 PasswordStoreChangeList changes; |
843 changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, form)); | 843 changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, form)); |
844 NotificationService::current()->Notify( | 844 content::NotificationService::current()->Notify( |
845 chrome::NOTIFICATION_LOGINS_CHANGED, | 845 chrome::NOTIFICATION_LOGINS_CHANGED, |
846 content::Source<PasswordStore>(this), | 846 content::Source<PasswordStore>(this), |
847 content::Details<PasswordStoreChangeList>(&changes)); | 847 content::Details<PasswordStoreChangeList>(&changes)); |
848 } | 848 } |
849 } | 849 } |
850 | 850 |
851 void PasswordStoreMac::RemoveLoginsCreatedBetweenImpl( | 851 void PasswordStoreMac::RemoveLoginsCreatedBetweenImpl( |
852 const base::Time& delete_begin, const base::Time& delete_end) { | 852 const base::Time& delete_begin, const base::Time& delete_end) { |
853 std::vector<PasswordForm*> forms; | 853 std::vector<PasswordForm*> forms; |
854 if (login_metadata_db_->GetLoginsCreatedBetween(delete_begin, delete_end, | 854 if (login_metadata_db_->GetLoginsCreatedBetween(delete_begin, delete_end, |
(...skipping 13 matching lines...) Expand all Loading... |
868 // to share. | 868 // to share. |
869 RemoveKeychainForms(orphan_keychain_forms); | 869 RemoveKeychainForms(orphan_keychain_forms); |
870 STLDeleteElements(&orphan_keychain_forms); | 870 STLDeleteElements(&orphan_keychain_forms); |
871 | 871 |
872 PasswordStoreChangeList changes; | 872 PasswordStoreChangeList changes; |
873 for (std::vector<PasswordForm*>::const_iterator it = forms.begin(); | 873 for (std::vector<PasswordForm*>::const_iterator it = forms.begin(); |
874 it != forms.end(); ++it) { | 874 it != forms.end(); ++it) { |
875 changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, | 875 changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, |
876 **it)); | 876 **it)); |
877 } | 877 } |
878 NotificationService::current()->Notify( | 878 content::NotificationService::current()->Notify( |
879 chrome::NOTIFICATION_LOGINS_CHANGED, | 879 chrome::NOTIFICATION_LOGINS_CHANGED, |
880 content::Source<PasswordStore>(this), | 880 content::Source<PasswordStore>(this), |
881 content::Details<PasswordStoreChangeList>(&changes)); | 881 content::Details<PasswordStoreChangeList>(&changes)); |
882 } | 882 } |
883 } | 883 } |
884 } | 884 } |
885 | 885 |
886 void PasswordStoreMac::GetLoginsImpl(GetLoginsRequest* request, | 886 void PasswordStoreMac::GetLoginsImpl(GetLoginsRequest* request, |
887 const webkit_glue::PasswordForm& form) { | 887 const webkit_glue::PasswordForm& form) { |
888 MacKeychainPasswordFormAdapter keychain_adapter(keychain_.get()); | 888 MacKeychainPasswordFormAdapter keychain_adapter(keychain_.get()); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1006 const std::vector<PasswordForm*>& forms) { | 1006 const std::vector<PasswordForm*>& forms) { |
1007 MacKeychainPasswordFormAdapter owned_keychain_adapter(keychain_.get()); | 1007 MacKeychainPasswordFormAdapter owned_keychain_adapter(keychain_.get()); |
1008 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); | 1008 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); |
1009 for (std::vector<PasswordForm*>::const_iterator i = forms.begin(); | 1009 for (std::vector<PasswordForm*>::const_iterator i = forms.begin(); |
1010 i != forms.end(); ++i) { | 1010 i != forms.end(); ++i) { |
1011 owned_keychain_adapter.RemovePassword(**i); | 1011 owned_keychain_adapter.RemovePassword(**i); |
1012 } | 1012 } |
1013 } | 1013 } |
1014 | 1014 |
1015 void PasswordStoreMac::CreateNotificationService() { | 1015 void PasswordStoreMac::CreateNotificationService() { |
1016 notification_service_.reset(new NotificationService); | 1016 notification_service_.reset(new NotificationServiceImpl); |
1017 } | 1017 } |
OLD | NEW |