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

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

Issue 299443002: Password Login Database: report correct changes from UpdateLogin(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Respect primary key in the UpdateLogin() Created 6 years, 7 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
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/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
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 ok = true;
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 606
607 forms[i]->action = form.action; 607 if (RawAddLogin(form)) {
Garrett Casto 2014/05/21 19:14:20 Now that we completely overwrite the saved form, i
vasilii 2014/05/22 11:38:14 Done.
608 forms[i]->password_value = form.password_value; 608 password_manager::PasswordStoreChange change(
609 forms[i]->ssl_valid = form.ssl_valid; 609 password_manager::PasswordStoreChange::UPDATE, form);
610 forms[i]->preferred = form.preferred; 610 changes->assign(&change, &change + 1);
611 forms[i]->times_used = form.times_used; 611 } else {
612 if (!RawAddLogin(*forms[i]))
613 ok = false; 612 ok = false;
613 }
614 } 614 }
615 delete forms[i];
616 } 615 }
617 return ok; 616 return ok;
618 } 617 }
619 618
620 bool NativeBackendGnome::RemoveLogin(const PasswordForm& form) { 619 bool NativeBackendGnome::RemoveLogin(const PasswordForm& form) {
621 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 620 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
622 GKRMethod method; 621 GKRMethod method;
623 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 622 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
624 base::Bind(&GKRMethod::RemoveLogin, 623 base::Bind(&GKRMethod::RemoveLogin,
625 base::Unretained(&method), 624 base::Unretained(&method),
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 } 744 }
746 return true; 745 return true;
747 } 746 }
748 747
749 std::string NativeBackendGnome::GetProfileSpecificAppString() const { 748 std::string NativeBackendGnome::GetProfileSpecificAppString() const {
750 // Originally, the application string was always just "chrome" and used only 749 // 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 750 // 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. 751 // for nothing. Now we use it to distinguish passwords for different profiles.
753 return base::StringPrintf("%s-%d", kGnomeKeyringAppString, profile_id_); 752 return base::StringPrintf("%s-%d", kGnomeKeyringAppString, profile_id_);
754 } 753 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698