Chromium Code Reviews| 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> |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 439 database_blacklist_forms.begin(), | 439 database_blacklist_forms.begin(), |
| 440 database_blacklist_forms.end()); | 440 database_blacklist_forms.end()); |
| 441 | 441 |
| 442 // Clear out all the Keychain entries we used. | 442 // Clear out all the Keychain entries we used. |
| 443 DeleteVectorElementsInSet(keychain_forms, used_keychain_forms); | 443 DeleteVectorElementsInSet(keychain_forms, used_keychain_forms); |
| 444 } | 444 } |
| 445 | 445 |
| 446 std::vector<PasswordForm*> GetPasswordsForForms( | 446 std::vector<PasswordForm*> GetPasswordsForForms( |
| 447 const AppleKeychain& keychain, | 447 const AppleKeychain& keychain, |
| 448 std::vector<PasswordForm*>* database_forms) { | 448 std::vector<PasswordForm*>* database_forms) { |
| 449 // We load all passwords added to the keychain by Chrome at the start, instead | |
|
stuartmorgan
2013/08/29 20:24:23
This comment is incorrect. You aren't loading all
Raghu Simha
2013/08/29 23:28:46
You are correct. I only stepped through one level
| |
| 450 // of individually searching through the keychain for passwords matching each | |
| 451 // form in |database_forms|. This will result in a significant performance | |
| 452 // gain, since we are replacing O(N) keychain search operations with a single | |
| 453 // operation that loads all of Chrome's passwords. See crbug.com/263685. | |
| 449 MacKeychainPasswordFormAdapter keychain_adapter(&keychain); | 454 MacKeychainPasswordFormAdapter keychain_adapter(&keychain); |
| 455 std::vector<PasswordForm*> keychain_forms = | |
| 456 keychain_adapter.GetAllPasswordFormPasswords(); | |
| 450 | 457 |
| 451 std::vector<PasswordForm*> merged_forms; | 458 std::vector<PasswordForm*> merged_forms; |
| 452 for (std::vector<PasswordForm*>::iterator i = database_forms->begin(); | 459 for (std::vector<PasswordForm*>::iterator i = database_forms->begin(); |
| 453 i != database_forms->end();) { | 460 i != database_forms->end();) { |
| 454 std::vector<PasswordForm*> db_form_container(1, *i); | 461 std::vector<PasswordForm*> db_form_container(1, *i); |
| 455 std::vector<PasswordForm*> keychain_matches = | 462 std::vector<PasswordForm*> keychain_matches; |
| 456 keychain_adapter.PasswordsMergeableWithForm(**i); | 463 for (std::vector<PasswordForm*>::iterator j = keychain_forms.begin(); |
| 464 j != keychain_forms.end(); ++j) { | |
| 465 if ((*i)->username_value == (*j)->username_value && | |
| 466 (*i)->scheme == (*j)->scheme && | |
| 467 GURL((*i)->signon_realm) == GURL((*j)->signon_realm)) { | |
| 468 // Create a new object, since the caller is responsible for deleting the | |
| 469 // returned forms. | |
| 470 PasswordForm* form = new PasswordForm(**j); | |
| 471 keychain_matches.push_back(form); | |
| 472 } | |
| 473 } | |
| 457 MergePasswordForms(&keychain_matches, &db_form_container, &merged_forms); | 474 MergePasswordForms(&keychain_matches, &db_form_container, &merged_forms); |
| 458 if (db_form_container.empty()) { | 475 if (db_form_container.empty()) { |
| 459 i = database_forms->erase(i); | 476 i = database_forms->erase(i); |
| 460 } else { | 477 } else { |
| 461 ++i; | 478 ++i; |
| 462 } | 479 } |
| 463 STLDeleteElements(&keychain_matches); | 480 STLDeleteElements(&keychain_matches); |
| 464 } | 481 } |
| 482 STLDeleteElements(&keychain_forms); | |
| 465 return merged_forms; | 483 return merged_forms; |
| 466 } | 484 } |
| 467 | 485 |
| 468 } // namespace internal_keychain_helpers | 486 } // namespace internal_keychain_helpers |
| 469 | 487 |
| 470 #pragma mark - | 488 #pragma mark - |
| 471 | 489 |
| 472 MacKeychainPasswordFormAdapter::MacKeychainPasswordFormAdapter( | 490 MacKeychainPasswordFormAdapter::MacKeychainPasswordFormAdapter( |
| 473 const AppleKeychain* keychain) | 491 const AppleKeychain* keychain) |
| 474 : keychain_(keychain), finds_only_owned_(false) { | 492 : keychain_(keychain), finds_only_owned_(false) { |
| (...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1018 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); | 1036 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); |
| 1019 for (std::vector<PasswordForm*>::const_iterator i = forms.begin(); | 1037 for (std::vector<PasswordForm*>::const_iterator i = forms.begin(); |
| 1020 i != forms.end(); ++i) { | 1038 i != forms.end(); ++i) { |
| 1021 owned_keychain_adapter.RemovePassword(**i); | 1039 owned_keychain_adapter.RemovePassword(**i); |
| 1022 } | 1040 } |
| 1023 } | 1041 } |
| 1024 | 1042 |
| 1025 void PasswordStoreMac::CreateNotificationService() { | 1043 void PasswordStoreMac::CreateNotificationService() { |
| 1026 notification_service_.reset(content::NotificationService::Create()); | 1044 notification_service_.reset(content::NotificationService::Create()); |
| 1027 } | 1045 } |
| OLD | NEW |