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

Side by Side Diff: chrome/browser/password_manager/password_store_mac.cc

Issue 454083002: Fix a memory leak in PasswordStoreMac (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: a nit Created 6 years, 4 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
« no previous file with comments | « no previous file | chrome/browser/password_manager/password_store_mac_internal.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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>
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 611
612 std::vector<PasswordForm*> MacKeychainPasswordFormAdapter::PasswordsFillingForm( 612 std::vector<PasswordForm*> MacKeychainPasswordFormAdapter::PasswordsFillingForm(
613 const std::string& signon_realm, 613 const std::string& signon_realm,
614 PasswordForm::Scheme scheme) { 614 PasswordForm::Scheme scheme) {
615 std::vector<SecKeychainItemRef> keychain_items = 615 std::vector<SecKeychainItemRef> keychain_items =
616 MatchingKeychainItems(signon_realm, scheme, NULL, NULL); 616 MatchingKeychainItems(signon_realm, scheme, NULL, NULL);
617 617
618 return ConvertKeychainItemsToForms(&keychain_items); 618 return ConvertKeychainItemsToForms(&keychain_items);
619 } 619 }
620 620
621 PasswordForm* MacKeychainPasswordFormAdapter::PasswordExactlyMatchingForm( 621 bool MacKeychainPasswordFormAdapter::HasPasswordExactlyMatchingForm(
622 const PasswordForm& query_form) { 622 const PasswordForm& query_form) {
623 SecKeychainItemRef keychain_item = KeychainItemForForm(query_form); 623 SecKeychainItemRef keychain_item = KeychainItemForForm(query_form);
624 if (keychain_item) { 624 if (keychain_item) {
625 PasswordForm* form = new PasswordForm();
626 internal_keychain_helpers::FillPasswordFormFromKeychainItem(*keychain_,
627 keychain_item,
628 form,
629 true);
630 keychain_->Free(keychain_item); 625 keychain_->Free(keychain_item);
631 return form; 626 return true;
632 } 627 }
633 return NULL; 628 return false;
634 } 629 }
635 630
636 bool MacKeychainPasswordFormAdapter::HasPasswordsMergeableWithForm( 631 bool MacKeychainPasswordFormAdapter::HasPasswordsMergeableWithForm(
637 const PasswordForm& query_form) { 632 const PasswordForm& query_form) {
638 std::string username = base::UTF16ToUTF8(query_form.username_value); 633 std::string username = base::UTF16ToUTF8(query_form.username_value);
639 std::vector<SecKeychainItemRef> matches = 634 std::vector<SecKeychainItemRef> matches =
640 MatchingKeychainItems(query_form.signon_realm, query_form.scheme, 635 MatchingKeychainItems(query_form.signon_realm, query_form.scheme,
641 NULL, username.c_str()); 636 NULL, username.c_str());
642 for (std::vector<SecKeychainItemRef>::iterator i = matches.begin(); 637 for (std::vector<SecKeychainItemRef>::iterator i = matches.begin();
643 i != matches.end(); ++i) { 638 i != matches.end(); ++i) {
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 if (login_metadata_db_->RemoveLogin(form)) { 930 if (login_metadata_db_->RemoveLogin(form)) {
936 // See if we own a Keychain item associated with this item. We can do an 931 // See if we own a Keychain item associated with this item. We can do an
937 // exact search rather than messing around with trying to do fuzzy matching 932 // exact search rather than messing around with trying to do fuzzy matching
938 // because passwords that we created will always have an exact-match 933 // because passwords that we created will always have an exact-match
939 // database entry. 934 // database entry.
940 // (If a user does lose their profile but not their keychain we'll treat the 935 // (If a user does lose their profile but not their keychain we'll treat the
941 // entries we find like other imported entries anyway, so it's reasonable to 936 // entries we find like other imported entries anyway, so it's reasonable to
942 // handle deletes on them the way we would for an imported item.) 937 // handle deletes on them the way we would for an imported item.)
943 MacKeychainPasswordFormAdapter owned_keychain_adapter(keychain_.get()); 938 MacKeychainPasswordFormAdapter owned_keychain_adapter(keychain_.get());
944 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); 939 owned_keychain_adapter.SetFindsOnlyOwnedItems(true);
945 PasswordForm* owned_password_form = 940 if (owned_keychain_adapter.HasPasswordExactlyMatchingForm(form)) {
946 owned_keychain_adapter.PasswordExactlyMatchingForm(form);
947 if (owned_password_form) {
948 // If we don't have other forms using it (i.e., a form differing only by 941 // If we don't have other forms using it (i.e., a form differing only by
949 // the names of the form elements), delete the keychain entry. 942 // the names of the form elements), delete the keychain entry.
950 if (!DatabaseHasFormMatchingKeychainForm(form)) { 943 if (!DatabaseHasFormMatchingKeychainForm(form)) {
951 owned_keychain_adapter.RemovePassword(form); 944 owned_keychain_adapter.RemovePassword(form);
952 } 945 }
953 } 946 }
954 947
955 changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, form)); 948 changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, form));
956 } 949 }
957 return changes; 950 return changes;
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 1146
1154 ScopedVector<PasswordForm> merged_forms; 1147 ScopedVector<PasswordForm> merged_forms;
1155 merged_forms.get() = internal_keychain_helpers::GetPasswordsForForms( 1148 merged_forms.get() = internal_keychain_helpers::GetPasswordsForForms(
1156 *keychain_, &database_forms); 1149 *keychain_, &database_forms);
1157 1150
1158 // Clean up any orphaned database entries. 1151 // Clean up any orphaned database entries.
1159 RemoveDatabaseForms(database_forms); 1152 RemoveDatabaseForms(database_forms);
1160 1153
1161 forms->insert(forms->end(), database_forms.begin(), database_forms.end()); 1154 forms->insert(forms->end(), database_forms.begin(), database_forms.end());
1162 } 1155 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/password_manager/password_store_mac_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698