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 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 password_manager::PasswordStoreChange::REMOVE, *forms[0])); | 567 password_manager::PasswordStoreChange::REMOVE, *forms[0])); |
568 } | 568 } |
569 } | 569 } |
570 if (RawAddLogin(form)) { | 570 if (RawAddLogin(form)) { |
571 changes.push_back(password_manager::PasswordStoreChange( | 571 changes.push_back(password_manager::PasswordStoreChange( |
572 password_manager::PasswordStoreChange::ADD, form)); | 572 password_manager::PasswordStoreChange::ADD, form)); |
573 } | 573 } |
574 return changes; | 574 return changes; |
575 } | 575 } |
576 | 576 |
577 bool NativeBackendGnome::UpdateLogin(const PasswordForm& form) { | 577 bool NativeBackendGnome::UpdateLogin( |
| 578 const PasswordForm& form, |
| 579 password_manager::PasswordStoreChangeList* changes) { |
578 // Based on LoginDatabase::UpdateLogin(), we search for forms to update by | 580 // Based on LoginDatabase::UpdateLogin(), we search for forms to update by |
579 // origin_url, username_element, username_value, password_element, and | 581 // origin_url, username_element, username_value, password_element, and |
580 // signon_realm. We then compare the result to the updated form. If they | 582 // signon_realm. We then compare the result to the updated form. If they |
581 // differ in any of the mutable fields, then we remove the original, and | 583 // differ in any of the mutable fields, then we remove the original, and |
582 // then add the new entry. We'd add the new one first, and then delete the | 584 // then add the new entry. We'd add the new one first, and then delete the |
583 // original, but then the delete might actually delete the newly-added entry! | 585 // original, but then the delete might actually delete the newly-added entry! |
584 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 586 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 587 DCHECK(changes); |
| 588 changes->clear(); |
585 GKRMethod method; | 589 GKRMethod method; |
586 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 590 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
587 base::Bind(&GKRMethod::UpdateLoginSearch, | 591 base::Bind(&GKRMethod::UpdateLoginSearch, |
588 base::Unretained(&method), | 592 base::Unretained(&method), |
589 form, app_string_.c_str())); | 593 form, app_string_.c_str())); |
590 PasswordFormList forms; | 594 ScopedVector<autofill::PasswordForm> forms; |
591 GnomeKeyringResult result = method.WaitResult(&forms); | 595 GnomeKeyringResult result = method.WaitResult(&forms.get()); |
592 if (result != GNOME_KEYRING_RESULT_OK) { | 596 if (result != GNOME_KEYRING_RESULT_OK) { |
593 LOG(ERROR) << "Keyring find failed: " | 597 LOG(ERROR) << "Keyring find failed: " |
594 << gnome_keyring_result_to_message(result); | 598 << gnome_keyring_result_to_message(result); |
595 return false; | 599 return false; |
596 } | 600 } |
597 | 601 |
598 bool ok = true; | 602 bool removed = false; |
599 for (size_t i = 0; i < forms.size(); ++i) { | 603 for (size_t i = 0; i < forms.size(); ++i) { |
600 if (forms[i]->action != form.action || | 604 if (*forms[i] != form) { |
601 forms[i]->password_value != form.password_value || | |
602 forms[i]->ssl_valid != form.ssl_valid || | |
603 forms[i]->preferred != form.preferred || | |
604 forms[i]->times_used != form.times_used) { | |
605 RemoveLogin(*forms[i]); | 605 RemoveLogin(*forms[i]); |
| 606 removed = true; |
| 607 } |
| 608 } |
| 609 if (!removed) |
| 610 return true; |
606 | 611 |
607 forms[i]->action = form.action; | 612 if (RawAddLogin(form)) { |
608 forms[i]->password_value = form.password_value; | 613 password_manager::PasswordStoreChange change( |
609 forms[i]->ssl_valid = form.ssl_valid; | 614 password_manager::PasswordStoreChange::UPDATE, form); |
610 forms[i]->preferred = form.preferred; | 615 changes->push_back(change); |
611 forms[i]->times_used = form.times_used; | 616 return true; |
612 if (!RawAddLogin(*forms[i])) | |
613 ok = false; | |
614 } | |
615 delete forms[i]; | |
616 } | 617 } |
617 return ok; | 618 return false; |
618 } | 619 } |
619 | 620 |
620 bool NativeBackendGnome::RemoveLogin(const PasswordForm& form) { | 621 bool NativeBackendGnome::RemoveLogin(const PasswordForm& form) { |
621 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 622 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
622 GKRMethod method; | 623 GKRMethod method; |
623 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 624 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
624 base::Bind(&GKRMethod::RemoveLogin, | 625 base::Bind(&GKRMethod::RemoveLogin, |
625 base::Unretained(&method), | 626 base::Unretained(&method), |
626 form, app_string_.c_str())); | 627 form, app_string_.c_str())); |
627 GnomeKeyringResult result = method.WaitResult(); | 628 GnomeKeyringResult result = method.WaitResult(); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 } | 746 } |
746 return true; | 747 return true; |
747 } | 748 } |
748 | 749 |
749 std::string NativeBackendGnome::GetProfileSpecificAppString() const { | 750 std::string NativeBackendGnome::GetProfileSpecificAppString() const { |
750 // Originally, the application string was always just "chrome" and used only | 751 // Originally, the application string was always just "chrome" and used only |
751 // so that we had *something* to search for since GNOME Keyring won't search | 752 // so that we had *something* to search for since GNOME Keyring won't search |
752 // for nothing. Now we use it to distinguish passwords for different profiles. | 753 // for nothing. Now we use it to distinguish passwords for different profiles. |
753 return base::StringPrintf("%s-%d", kGnomeKeyringAppString, profile_id_); | 754 return base::StringPrintf("%s-%d", kGnomeKeyringAppString, profile_id_); |
754 } | 755 } |
OLD | NEW |