| 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/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 <utility> | 11 #include <utility> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/mac/mac_logging.h" | 16 #include "base/mac/mac_logging.h" |
| 17 #include "base/mac/mac_util.h" | 17 #include "base/mac/mac_util.h" |
| 18 #include "base/memory/scoped_vector.h" |
| 18 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
| 19 #include "base/stl_util.h" | 20 #include "base/stl_util.h" |
| 20 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
| 21 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 22 #include "chrome/browser/mac/security_wrappers.h" | 23 #include "chrome/browser/mac/security_wrappers.h" |
| 23 #include "components/password_manager/core/browser/login_database.h" | 24 #include "components/password_manager/core/browser/login_database.h" |
| 24 #include "components/password_manager/core/browser/password_store_change.h" | 25 #include "components/password_manager/core/browser/password_store_change.h" |
| 25 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 26 #include "crypto/apple_keychain.h" | 27 #include "crypto/apple_keychain.h" |
| 27 | 28 |
| (...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 952 | 953 |
| 953 changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, form)); | 954 changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, form)); |
| 954 } | 955 } |
| 955 return changes; | 956 return changes; |
| 956 } | 957 } |
| 957 | 958 |
| 958 PasswordStoreChangeList PasswordStoreMac::RemoveLoginsCreatedBetweenImpl( | 959 PasswordStoreChangeList PasswordStoreMac::RemoveLoginsCreatedBetweenImpl( |
| 959 base::Time delete_begin, | 960 base::Time delete_begin, |
| 960 base::Time delete_end) { | 961 base::Time delete_end) { |
| 961 PasswordStoreChangeList changes; | 962 PasswordStoreChangeList changes; |
| 962 std::vector<PasswordForm*> forms; | 963 ScopedVector<PasswordForm> forms; |
| 963 if (login_metadata_db_->GetLoginsCreatedBetween(delete_begin, delete_end, | 964 if (login_metadata_db_->GetLoginsCreatedBetween(delete_begin, delete_end, |
| 964 &forms)) { | 965 &forms.get())) { |
| 965 if (login_metadata_db_->RemoveLoginsCreatedBetween(delete_begin, | 966 if (login_metadata_db_->RemoveLoginsCreatedBetween(delete_begin, |
| 966 delete_end)) { | 967 delete_end)) { |
| 967 // We can't delete from the Keychain by date because we may be sharing | 968 RemoveKeychainForms(forms.get()); |
| 968 // items with database entries that weren't in the delete range. Instead, | |
| 969 // we find all the Keychain items we own but aren't using any more and | |
| 970 // delete those. | |
| 971 std::vector<PasswordForm*> orphan_keychain_forms = | |
| 972 GetUnusedKeychainForms(); | |
| 973 // This is inefficient, since we have to re-look-up each keychain item | |
| 974 // one at a time to delete it even though the search step already had a | |
| 975 // list of Keychain item references. If this turns out to be noticeably | |
| 976 // slow we'll need to rearchitect to allow the search and deletion steps | |
| 977 // to share. | |
| 978 RemoveKeychainForms(orphan_keychain_forms); | |
| 979 STLDeleteElements(&orphan_keychain_forms); | |
| 980 | 969 |
| 981 for (std::vector<PasswordForm*>::const_iterator it = forms.begin(); | 970 for (std::vector<PasswordForm*>::const_iterator it = forms.begin(); |
| 982 it != forms.end(); ++it) { | 971 it != forms.end(); ++it) { |
| 983 changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, | 972 changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, |
| 984 **it)); | 973 **it)); |
| 985 } | 974 } |
| 986 LogStatsForBulkDeletion(changes.size()); | 975 LogStatsForBulkDeletion(changes.size()); |
| 987 } | 976 } |
| 988 } | 977 } |
| 989 return changes; | 978 return changes; |
| 990 } | 979 } |
| 991 | 980 |
| 992 PasswordStoreChangeList PasswordStoreMac::RemoveLoginsSyncedBetweenImpl( | 981 PasswordStoreChangeList PasswordStoreMac::RemoveLoginsSyncedBetweenImpl( |
| 993 base::Time delete_begin, | 982 base::Time delete_begin, |
| 994 base::Time delete_end) { | 983 base::Time delete_end) { |
| 995 PasswordStoreChangeList changes; | 984 PasswordStoreChangeList changes; |
| 996 std::vector<PasswordForm*> forms; | 985 ScopedVector<PasswordForm> forms; |
| 997 if (login_metadata_db_->GetLoginsSyncedBetween( | 986 if (login_metadata_db_->GetLoginsSyncedBetween( |
| 998 delete_begin, delete_end, &forms)) { | 987 delete_begin, delete_end, &forms.get())) { |
| 999 if (login_metadata_db_->RemoveLoginsSyncedBetween(delete_begin, | 988 if (login_metadata_db_->RemoveLoginsSyncedBetween(delete_begin, |
| 1000 delete_end)) { | 989 delete_end)) { |
| 1001 // We can't delete from the Keychain by date because we may be sharing | 990 RemoveKeychainForms(forms.get()); |
| 1002 // items with database entries that weren't in the delete range. Instead, | |
| 1003 // we find all the Keychain items we own but aren't using any more and | |
| 1004 // delete those. | |
| 1005 std::vector<PasswordForm*> orphan_keychain_forms = | |
| 1006 GetUnusedKeychainForms(); | |
| 1007 // This is inefficient, since we have to re-look-up each keychain item | |
| 1008 // one at a time to delete it even though the search step already had a | |
| 1009 // list of Keychain item references. If this turns out to be noticeably | |
| 1010 // slow we'll need to rearchitect to allow the search and deletion steps | |
| 1011 // to share. | |
| 1012 RemoveKeychainForms(orphan_keychain_forms); | |
| 1013 STLDeleteElements(&orphan_keychain_forms); | |
| 1014 | 991 |
| 1015 for (std::vector<PasswordForm*>::const_iterator it = forms.begin(); | 992 for (std::vector<PasswordForm*>::const_iterator it = forms.begin(); |
| 1016 it != forms.end(); | 993 it != forms.end(); |
| 1017 ++it) { | 994 ++it) { |
| 1018 changes.push_back( | 995 changes.push_back( |
| 1019 PasswordStoreChange(PasswordStoreChange::REMOVE, **it)); | 996 PasswordStoreChange(PasswordStoreChange::REMOVE, **it)); |
| 1020 } | 997 } |
| 1021 } | 998 } |
| 1022 } | 999 } |
| 1023 return changes; | 1000 return changes; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1139 form, **i, internal_keychain_helpers::STRICT_FORM_MATCH) && | 1116 form, **i, internal_keychain_helpers::STRICT_FORM_MATCH) && |
| 1140 (*i)->origin == form.origin) { | 1117 (*i)->origin == form.origin) { |
| 1141 has_match = true; | 1118 has_match = true; |
| 1142 break; | 1119 break; |
| 1143 } | 1120 } |
| 1144 } | 1121 } |
| 1145 STLDeleteElements(&database_forms); | 1122 STLDeleteElements(&database_forms); |
| 1146 return has_match; | 1123 return has_match; |
| 1147 } | 1124 } |
| 1148 | 1125 |
| 1149 std::vector<PasswordForm*> PasswordStoreMac::GetUnusedKeychainForms() { | |
| 1150 std::vector<PasswordForm*> database_forms; | |
| 1151 login_metadata_db_->GetAutofillableLogins(&database_forms); | |
| 1152 | |
| 1153 MacKeychainPasswordFormAdapter owned_keychain_adapter(keychain_.get()); | |
| 1154 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); | |
| 1155 std::vector<PasswordForm*> owned_keychain_forms = | |
| 1156 owned_keychain_adapter.GetAllPasswordFormPasswords(); | |
| 1157 | |
| 1158 // Run a merge; anything left in owned_keychain_forms when we are done no | |
| 1159 // longer has a matching database entry. | |
| 1160 std::vector<PasswordForm*> merged_forms; | |
| 1161 internal_keychain_helpers::MergePasswordForms(&owned_keychain_forms, | |
| 1162 &database_forms, | |
| 1163 &merged_forms); | |
| 1164 STLDeleteElements(&merged_forms); | |
| 1165 STLDeleteElements(&database_forms); | |
| 1166 | |
| 1167 return owned_keychain_forms; | |
| 1168 } | |
| 1169 | |
| 1170 void PasswordStoreMac::RemoveDatabaseForms( | 1126 void PasswordStoreMac::RemoveDatabaseForms( |
| 1171 const std::vector<PasswordForm*>& forms) { | 1127 const std::vector<PasswordForm*>& forms) { |
| 1172 for (std::vector<PasswordForm*>::const_iterator i = forms.begin(); | 1128 for (std::vector<PasswordForm*>::const_iterator i = forms.begin(); |
| 1173 i != forms.end(); ++i) { | 1129 i != forms.end(); ++i) { |
| 1174 login_metadata_db_->RemoveLogin(**i); | 1130 login_metadata_db_->RemoveLogin(**i); |
| 1175 } | 1131 } |
| 1176 } | 1132 } |
| 1177 | 1133 |
| 1178 void PasswordStoreMac::RemoveKeychainForms( | 1134 void PasswordStoreMac::RemoveKeychainForms( |
| 1179 const std::vector<PasswordForm*>& forms) { | 1135 const std::vector<PasswordForm*>& forms) { |
| 1180 MacKeychainPasswordFormAdapter owned_keychain_adapter(keychain_.get()); | 1136 MacKeychainPasswordFormAdapter owned_keychain_adapter(keychain_.get()); |
| 1181 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); | 1137 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); |
| 1182 for (std::vector<PasswordForm*>::const_iterator i = forms.begin(); | 1138 for (std::vector<PasswordForm*>::const_iterator i = forms.begin(); |
| 1183 i != forms.end(); ++i) { | 1139 i != forms.end(); ++i) { |
| 1184 owned_keychain_adapter.RemovePassword(**i); | 1140 owned_keychain_adapter.RemovePassword(**i); |
| 1185 } | 1141 } |
| 1186 } | 1142 } |
| OLD | NEW |