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/native_backend_gnome_x.h" | 5 #include "chrome/browser/password_manager/native_backend_gnome_x.h" |
6 | 6 |
7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
8 #include <gnome-keyring.h> | 8 #include <gnome-keyring.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 form, app_string_.c_str())); | 527 form, app_string_.c_str())); |
528 GnomeKeyringResult result = method.WaitResult(); | 528 GnomeKeyringResult result = method.WaitResult(); |
529 if (result != GNOME_KEYRING_RESULT_OK) { | 529 if (result != GNOME_KEYRING_RESULT_OK) { |
530 LOG(ERROR) << "Keyring save failed: " | 530 LOG(ERROR) << "Keyring save failed: " |
531 << gnome_keyring_result_to_message(result); | 531 << gnome_keyring_result_to_message(result); |
532 return false; | 532 return false; |
533 } | 533 } |
534 return true; | 534 return true; |
535 } | 535 } |
536 | 536 |
537 bool NativeBackendGnome::AddLogin(const PasswordForm& form) { | 537 password_manager::PasswordStoreChangeList NativeBackendGnome::AddLogin( |
| 538 const PasswordForm& form) { |
538 // Based on LoginDatabase::AddLogin(), we search for an existing match based | 539 // Based on LoginDatabase::AddLogin(), we search for an existing match based |
539 // on origin_url, username_element, username_value, password_element, submit | 540 // on origin_url, username_element, username_value, password_element, submit |
540 // element, and signon_realm first, remove that, and then add the new entry. | 541 // element, and signon_realm first, remove that, and then add the new entry. |
541 // We'd add the new one first, and then delete the original, but then the | 542 // We'd add the new one first, and then delete the original, but then the |
542 // delete might actually delete the newly-added entry! | 543 // delete might actually delete the newly-added entry! |
543 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 544 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
544 GKRMethod method; | 545 GKRMethod method; |
545 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 546 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
546 base::Bind(&GKRMethod::AddLoginSearch, | 547 base::Bind(&GKRMethod::AddLoginSearch, |
547 base::Unretained(&method), | 548 base::Unretained(&method), |
548 form, app_string_.c_str())); | 549 form, app_string_.c_str())); |
549 PasswordFormList forms; | 550 ScopedVector<autofill::PasswordForm> forms; |
550 GnomeKeyringResult result = method.WaitResult(&forms); | 551 GnomeKeyringResult result = method.WaitResult(&forms.get()); |
551 if (result != GNOME_KEYRING_RESULT_OK && | 552 if (result != GNOME_KEYRING_RESULT_OK && |
552 result != GNOME_KEYRING_RESULT_NO_MATCH) { | 553 result != GNOME_KEYRING_RESULT_NO_MATCH) { |
553 LOG(ERROR) << "Keyring find failed: " | 554 LOG(ERROR) << "Keyring find failed: " |
554 << gnome_keyring_result_to_message(result); | 555 << gnome_keyring_result_to_message(result); |
555 return false; | 556 return password_manager::PasswordStoreChangeList(); |
556 } | 557 } |
| 558 password_manager::PasswordStoreChangeList changes; |
557 if (forms.size() > 0) { | 559 if (forms.size() > 0) { |
558 if (forms.size() > 1) { | 560 if (forms.size() > 1) { |
559 LOG(WARNING) << "Adding login when there are " << forms.size() | 561 LOG(WARNING) << "Adding login when there are " << forms.size() |
560 << " matching logins already! Will replace only the first."; | 562 << " matching logins already! Will replace only the first."; |
561 } | 563 } |
562 | 564 |
563 RemoveLogin(*forms[0]); | 565 if (RemoveLogin(*forms[0])) { |
564 for (size_t i = 0; i < forms.size(); ++i) | 566 changes.push_back(password_manager::PasswordStoreChange( |
565 delete forms[i]; | 567 password_manager::PasswordStoreChange::REMOVE, *forms[0])); |
| 568 } |
566 } | 569 } |
567 return RawAddLogin(form); | 570 if (RawAddLogin(form)) { |
| 571 changes.push_back(password_manager::PasswordStoreChange( |
| 572 password_manager::PasswordStoreChange::ADD, form)); |
| 573 } |
| 574 return changes; |
568 } | 575 } |
569 | 576 |
570 bool NativeBackendGnome::UpdateLogin(const PasswordForm& form) { | 577 bool NativeBackendGnome::UpdateLogin(const PasswordForm& form) { |
571 // Based on LoginDatabase::UpdateLogin(), we search for forms to update by | 578 // Based on LoginDatabase::UpdateLogin(), we search for forms to update by |
572 // origin_url, username_element, username_value, password_element, and | 579 // origin_url, username_element, username_value, password_element, and |
573 // signon_realm. We then compare the result to the updated form. If they | 580 // signon_realm. We then compare the result to the updated form. If they |
574 // differ in any of the mutable fields, then we remove the original, and | 581 // differ in any of the mutable fields, then we remove the original, and |
575 // then add the new entry. We'd add the new one first, and then delete the | 582 // then add the new entry. We'd add the new one first, and then delete the |
576 // original, but then the delete might actually delete the newly-added entry! | 583 // original, but then the delete might actually delete the newly-added entry! |
577 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 584 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 } | 745 } |
739 return true; | 746 return true; |
740 } | 747 } |
741 | 748 |
742 std::string NativeBackendGnome::GetProfileSpecificAppString() const { | 749 std::string NativeBackendGnome::GetProfileSpecificAppString() const { |
743 // Originally, the application string was always just "chrome" and used only | 750 // Originally, the application string was always just "chrome" and used only |
744 // so that we had *something* to search for since GNOME Keyring won't search | 751 // so that we had *something* to search for since GNOME Keyring won't search |
745 // for nothing. Now we use it to distinguish passwords for different profiles. | 752 // for nothing. Now we use it to distinguish passwords for different profiles. |
746 return base::StringPrintf("%s-%d", kGnomeKeyringAppString, profile_id_); | 753 return base::StringPrintf("%s-%d", kGnomeKeyringAppString, profile_id_); |
747 } | 754 } |
OLD | NEW |