Commit 155761f5 authored by vabr's avatar vabr Committed by Commit bot

PasswordStore: Use ScopedVector to express ownership of forms

This is a clean-up, getting rid of many manual deletes and comments about who owns forms passed around in vectors.

BUG=451018

Review URL: https://codereview.chromium.org/825773003

Cr-Commit-Position: refs/heads/master@{#313539}
parent f1ccb4dd
......@@ -147,17 +147,17 @@ scoped_ptr<PasswordForm> FormFromAttributes(GnomeKeyringAttributeList* attrs) {
return form.Pass();
}
// Parse all the results from the given GList into a PasswordFormList, and free
// the GList. PasswordForms are allocated on the heap, and should be deleted by
// the consumer. If not NULL, |lookup_form| is used to filter out results --
// only credentials with signon realms passing the PSL matching against
// |lookup_form->signon_realm| will be kept. PSL matched results get their
// signon_realm, origin, and action rewritten to those of |lookup_form_|, with
// the original signon_realm saved into the result's original_signon_realm data
// member.
// Parse all the results from the given GList into a
// ScopedVector<autofill::PasswordForm>, and free the GList. PasswordForms are
// allocated on the heap, and should be deleted by the consumer. If not NULL,
// |lookup_form| is used to filter out results -- only credentials with signon
// realms passing the PSL matching against |lookup_form->signon_realm| will be
// kept. PSL matched results get their signon_realm, origin, and action
// rewritten to those of |lookup_form_|, with the original signon_realm saved
// into the result's original_signon_realm data member.
void ConvertFormList(GList* found,
const PasswordForm* lookup_form,
NativeBackendGnome::PasswordFormList* forms) {
ScopedVector<autofill::PasswordForm>* forms) {
password_manager::PSLDomainMatchMetric psl_domain_match_metric =
password_manager::PSL_DOMAIN_MATCH_NONE;
for (GList* element = g_list_first(found); element != NULL;
......@@ -255,8 +255,6 @@ const GnomeKeyringPasswordSchema kGnomeSchema = {
// be used in parallel.
class GKRMethod : public GnomeKeyringLoader {
public:
typedef NativeBackendGnome::PasswordFormList PasswordFormList;
GKRMethod() : event_(false, false), result_(GNOME_KEYRING_RESULT_CANCELLED) {}
// Action methods. These call gnome_keyring_* functions. Call from UI thread.
......@@ -274,7 +272,7 @@ class GKRMethod : public GnomeKeyringLoader {
// Use after AddLoginSearch, UpdateLoginSearch, GetLogins, GetLoginsList,
// GetAllLogins.
GnomeKeyringResult WaitResult(PasswordFormList* forms);
GnomeKeyringResult WaitResult(ScopedVector<autofill::PasswordForm>* forms);
private:
struct GnomeKeyringAttributeListFreeDeleter {
......@@ -306,7 +304,7 @@ class GKRMethod : public GnomeKeyringLoader {
base::WaitableEvent event_;
GnomeKeyringResult result_;
NativeBackendGnome::PasswordFormList forms_;
ScopedVector<autofill::PasswordForm> forms_;
// If the credential search is specified by a single form and needs to use PSL
// matching, then the specifying form is stored in |lookup_form_|. If PSL
// matching is used to find a result, then the results signon realm, origin
......@@ -466,7 +464,8 @@ GnomeKeyringResult GKRMethod::WaitResult() {
return result_;
}
GnomeKeyringResult GKRMethod::WaitResult(PasswordFormList* forms) {
GnomeKeyringResult GKRMethod::WaitResult(
ScopedVector<autofill::PasswordForm>* forms) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
event_.Wait();
if (forms->empty()) {
......@@ -475,7 +474,7 @@ GnomeKeyringResult GKRMethod::WaitResult(PasswordFormList* forms) {
} else {
// Rare case. Append forms_ to *forms.
forms->insert(forms->end(), forms_.begin(), forms_.end());
forms_.clear();
forms_.weak_clear();
}
return result_;
}
......@@ -564,7 +563,7 @@ password_manager::PasswordStoreChangeList NativeBackendGnome::AddLogin(
base::Unretained(&method),
form, app_string_.c_str()));
ScopedVector<autofill::PasswordForm> forms;
GnomeKeyringResult result = method.WaitResult(&forms.get());
GnomeKeyringResult result = method.WaitResult(&forms);
if (result != GNOME_KEYRING_RESULT_OK &&
result != GNOME_KEYRING_RESULT_NO_MATCH) {
LOG(ERROR) << "Keyring find failed: "
......@@ -608,7 +607,7 @@ bool NativeBackendGnome::UpdateLogin(
base::Unretained(&method),
form, app_string_.c_str()));
ScopedVector<autofill::PasswordForm> forms;
GnomeKeyringResult result = method.WaitResult(&forms.get());
GnomeKeyringResult result = method.WaitResult(&forms);
if (result != GNOME_KEYRING_RESULT_OK) {
LOG(ERROR) << "Keyring find failed: "
<< gnome_keyring_result_to_message(result);
......@@ -667,8 +666,9 @@ bool NativeBackendGnome::RemoveLoginsSyncedBetween(
return RemoveLoginsBetween(delete_begin, delete_end, SYNC_TIMESTAMP, changes);
}
bool NativeBackendGnome::GetLogins(const PasswordForm& form,
PasswordFormList* forms) {
bool NativeBackendGnome::GetLogins(
const PasswordForm& form,
ScopedVector<autofill::PasswordForm>* forms) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
GKRMethod method;
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
......@@ -686,16 +686,19 @@ bool NativeBackendGnome::GetLogins(const PasswordForm& form,
return true;
}
bool NativeBackendGnome::GetAutofillableLogins(PasswordFormList* forms) {
return GetLoginsList(forms, true);
bool NativeBackendGnome::GetAutofillableLogins(
ScopedVector<autofill::PasswordForm>* forms) {
return GetLoginsList(true, forms);
}
bool NativeBackendGnome::GetBlacklistLogins(PasswordFormList* forms) {
return GetLoginsList(forms, false);
bool NativeBackendGnome::GetBlacklistLogins(
ScopedVector<autofill::PasswordForm>* forms) {
return GetLoginsList(false, forms);
}
bool NativeBackendGnome::GetLoginsList(PasswordFormList* forms,
bool autofillable) {
bool NativeBackendGnome::GetLoginsList(
bool autofillable,
ScopedVector<autofill::PasswordForm>* forms) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
uint32_t blacklisted_by_user = !autofillable;
......@@ -716,7 +719,8 @@ bool NativeBackendGnome::GetLoginsList(PasswordFormList* forms,
return true;
}
bool NativeBackendGnome::GetAllLogins(PasswordFormList* forms) {
bool NativeBackendGnome::GetAllLogins(
ScopedVector<autofill::PasswordForm>* forms) {
GKRMethod method;
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
base::Bind(&GKRMethod::GetAllLogins,
......@@ -733,14 +737,15 @@ bool NativeBackendGnome::GetAllLogins(PasswordFormList* forms) {
return true;
}
bool NativeBackendGnome::GetLoginsBetween(base::Time get_begin,
base::Time get_end,
TimestampToCompare date_to_compare,
PasswordFormList* forms) {
bool NativeBackendGnome::GetLoginsBetween(
base::Time get_begin,
base::Time get_end,
TimestampToCompare date_to_compare,
ScopedVector<autofill::PasswordForm>* forms) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
// We could walk the list and add items as we find them, but it is much
// easier to build the list and then filter the results.
PasswordFormList all_forms;
ScopedVector<autofill::PasswordForm> all_forms;
if (!GetAllLogins(&all_forms))
return false;
......@@ -748,12 +753,11 @@ bool NativeBackendGnome::GetLoginsBetween(base::Time get_begin,
date_to_compare == CREATION_TIMESTAMP
? &autofill::PasswordForm::date_created
: &autofill::PasswordForm::date_synced;
for (size_t i = 0; i < all_forms.size(); ++i) {
if (get_begin <= all_forms[i]->*date_member &&
(get_end.is_null() || all_forms[i]->*date_member < get_end)) {
forms->push_back(all_forms[i]);
} else {
delete all_forms[i];
for (auto& saved_form : all_forms) {
if (get_begin <= saved_form->*date_member &&
(get_end.is_null() || saved_form->*date_member < get_end)) {
forms->push_back(saved_form);
saved_form = nullptr;
}
}
......@@ -771,7 +775,7 @@ bool NativeBackendGnome::RemoveLoginsBetween(
// We could walk the list and delete items as we find them, but it is much
// easier to build the list and use RemoveLogin() to delete them.
ScopedVector<autofill::PasswordForm> forms;
if (!GetLoginsBetween(get_begin, get_end, date_to_compare, &forms.get()))
if (!GetLoginsBetween(get_begin, get_end, date_to_compare, &forms))
return false;
bool ok = true;
......
......@@ -20,6 +20,7 @@
#include <string>
#include "base/basictypes.h"
#include "base/memory/scoped_vector.h"
#include "base/time/time.h"
#include "chrome/browser/password_manager/password_store_factory.h"
#include "chrome/browser/password_manager/password_store_x.h"
......@@ -105,9 +106,10 @@ class NativeBackendGnome : public PasswordStoreX::NativeBackend,
base::Time delete_end,
password_manager::PasswordStoreChangeList* changes) override;
bool GetLogins(const autofill::PasswordForm& form,
PasswordFormList* forms) override;
bool GetAutofillableLogins(PasswordFormList* forms) override;
bool GetBlacklistLogins(PasswordFormList* forms) override;
ScopedVector<autofill::PasswordForm>* forms) override;
bool GetAutofillableLogins(
ScopedVector<autofill::PasswordForm>* forms) override;
bool GetBlacklistLogins(ScopedVector<autofill::PasswordForm>* forms) override;
private:
enum TimestampToCompare {
......@@ -119,17 +121,18 @@ class NativeBackendGnome : public PasswordStoreX::NativeBackend,
bool RawAddLogin(const autofill::PasswordForm& form);
// Reads PasswordForms from the keyring with the given autofillability state.
bool GetLoginsList(PasswordFormList* forms, bool autofillable);
bool GetLoginsList(bool autofillable,
ScopedVector<autofill::PasswordForm>* forms);
// Helper for GetLoginsCreatedBetween().
bool GetAllLogins(PasswordFormList* forms);
bool GetAllLogins(ScopedVector<autofill::PasswordForm>* forms);
// Retrieves password created/synced in the time interval. Returns |true| if
// the operation succeeded.
bool GetLoginsBetween(base::Time get_begin,
base::Time get_end,
TimestampToCompare date_to_compare,
PasswordFormList* forms);
ScopedVector<autofill::PasswordForm>* forms);
// Removes password created/synced in the time interval. Returns |true| if the
// operation succeeded. |changes| will contain the changes applied.
......
......@@ -6,7 +6,6 @@
#include "base/basictypes.h"
#include "base/prefs/pref_service.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
......@@ -502,7 +501,7 @@ class NativeBackendGnomeTest : public testing::Test {
target_form.signon_realm.append("Realm");
target_form.scheme = scheme;
}
std::vector<PasswordForm*> form_list;
ScopedVector<autofill::PasswordForm> form_list;
BrowserThread::PostTask(
BrowserThread::DB,
FROM_HERE,
......@@ -523,7 +522,6 @@ class NativeBackendGnomeTest : public testing::Test {
EXPECT_EQ(1u, form_list.size());
if (result)
*result = *form_list[0];
STLDeleteElements(&form_list);
return true;
}
......@@ -549,7 +547,7 @@ class NativeBackendGnomeTest : public testing::Test {
PasswordForm m_facebook_lookup;
m_facebook_lookup.origin = kMobileURL;
m_facebook_lookup.signon_realm = kMobileURL.spec();
std::vector<PasswordForm*> form_list;
ScopedVector<autofill::PasswordForm> form_list;
BrowserThread::PostTask(
BrowserThread::DB,
FROM_HERE,
......@@ -561,7 +559,7 @@ class NativeBackendGnomeTest : public testing::Test {
EXPECT_EQ(1u, mock_keyring_items.size());
EXPECT_EQ(1u, form_list.size());
PasswordForm m_facebook = *form_list[0];
STLDeleteElements(&form_list);
form_list.clear();
EXPECT_EQ(kMobileURL, m_facebook.origin);
EXPECT_EQ(kMobileURL.spec(), m_facebook.signon_realm);
......@@ -621,7 +619,7 @@ class NativeBackendGnomeTest : public testing::Test {
EXPECT_EQ(kMobileURL, form_list[index_non_psl]->origin);
EXPECT_EQ(kMobileURL.spec(), form_list[index_non_psl]->signon_realm);
EXPECT_EQ(kOldPassword, form_list[index_non_psl]->password_value);
STLDeleteElements(&form_list);
form_list.clear();
// Check that www.facebook.com login was modified by the update.
BrowserThread::PostTask(
......@@ -641,7 +639,6 @@ class NativeBackendGnomeTest : public testing::Test {
EXPECT_EQ(form_facebook_.signon_realm,
form_list[index_non_psl]->signon_realm);
EXPECT_EQ(kNewPassword, form_list[index_non_psl]->password_value);
STLDeleteElements(&form_list);
}
void CheckMatchingWithScheme(const PasswordForm::Scheme& scheme) {
......@@ -775,7 +772,7 @@ TEST_F(NativeBackendGnomeTest, BasicListLogins) {
base::Bind(base::IgnoreResult( &NativeBackendGnome::AddLogin),
base::Unretained(&backend), form_google_));
std::vector<PasswordForm*> form_list;
ScopedVector<autofill::PasswordForm> form_list;
BrowserThread::PostTask(
BrowserThread::DB, FROM_HERE,
base::Bind(
......@@ -786,7 +783,6 @@ TEST_F(NativeBackendGnomeTest, BasicListLogins) {
// Quick check that we got something back.
EXPECT_EQ(1u, form_list.size());
STLDeleteElements(&form_list);
EXPECT_EQ(1u, mock_keyring_items.size());
if (mock_keyring_items.size() > 0)
......@@ -952,7 +948,7 @@ TEST_F(NativeBackendGnomeTest, RemoveNonexistentLogin) {
base::Unretained(&backend), form_isc_));
// Make sure we can still get the first form back.
std::vector<PasswordForm*> form_list;
ScopedVector<autofill::PasswordForm> form_list;
BrowserThread::PostTask(
BrowserThread::DB, FROM_HERE,
base::Bind(
......@@ -963,7 +959,6 @@ TEST_F(NativeBackendGnomeTest, RemoveNonexistentLogin) {
// Quick check that we got something back.
EXPECT_EQ(1u, form_list.size());
STLDeleteElements(&form_list);
EXPECT_EQ(1u, mock_keyring_items.size());
if (mock_keyring_items.size() > 0)
......@@ -1046,7 +1041,7 @@ TEST_F(NativeBackendGnomeTest, ListLoginsAppends) {
base::Unretained(&backend), form_google_));
// Send the same request twice with the same list both times.
std::vector<PasswordForm*> form_list;
ScopedVector<autofill::PasswordForm> form_list;
BrowserThread::PostTask(
BrowserThread::DB, FROM_HERE,
base::Bind(
......@@ -1062,7 +1057,6 @@ TEST_F(NativeBackendGnomeTest, ListLoginsAppends) {
// Quick check that we got two results back.
EXPECT_EQ(2u, form_list.size());
STLDeleteElements(&form_list);
EXPECT_EQ(1u, mock_keyring_items.size());
if (mock_keyring_items.size() > 0)
......
......@@ -9,6 +9,7 @@
#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_vector.h"
#include "base/time/time.h"
#include "chrome/browser/password_manager/password_store_factory.h"
#include "chrome/browser/password_manager/password_store_x.h"
......@@ -54,9 +55,10 @@ class NativeBackendKWallet : public PasswordStoreX::NativeBackend {
base::Time delete_end,
password_manager::PasswordStoreChangeList* changes) override;
bool GetLogins(const autofill::PasswordForm& form,
PasswordFormList* forms) override;
bool GetAutofillableLogins(PasswordFormList* forms) override;
bool GetBlacklistLogins(PasswordFormList* forms) override;
ScopedVector<autofill::PasswordForm>* forms) override;
bool GetAutofillableLogins(
ScopedVector<autofill::PasswordForm>* forms) override;
bool GetBlacklistLogins(ScopedVector<autofill::PasswordForm>* forms) override;
protected:
// Invalid handle returned by WalletHandle().
......@@ -68,7 +70,7 @@ class NativeBackendKWallet : public PasswordStoreX::NativeBackend {
// Deserializes a list of PasswordForms from the wallet.
static void DeserializeValue(const std::string& signon_realm,
const Pickle& pickle,
PasswordFormList* forms);
ScopedVector<autofill::PasswordForm>* forms);
private:
enum InitResult {
......@@ -90,22 +92,23 @@ class NativeBackendKWallet : public PasswordStoreX::NativeBackend {
bool* success);
// Reads PasswordForms from the wallet that match the given signon_realm.
bool GetLoginsList(PasswordFormList* forms,
const std::string& signon_realm,
int wallet_handle);
bool GetLoginsList(const std::string& signon_realm,
int wallet_handle,
ScopedVector<autofill::PasswordForm>* forms);
// Reads PasswordForms from the wallet with the given autofillability state.
bool GetLoginsList(PasswordFormList* forms,
bool autofillable,
int wallet_handle);
bool GetLoginsList(bool autofillable,
int wallet_handle,
ScopedVector<autofill::PasswordForm>* forms);
// Helper for some of the above GetLoginsList() methods.
bool GetAllLogins(PasswordFormList* forms, int wallet_handle);
bool GetAllLogins(int wallet_handle,
ScopedVector<autofill::PasswordForm>* forms);
// Writes a list of PasswordForms to the wallet with the given signon_realm.
// Overwrites any existing list for this signon_realm. Removes the entry if
// |forms| is empty. Returns true on success.
bool SetLoginsList(const PasswordFormList& forms,
bool SetLoginsList(const std::vector<autofill::PasswordForm*>& forms,
const std::string& signon_realm,
int wallet_handle);
......@@ -121,7 +124,8 @@ class NativeBackendKWallet : public PasswordStoreX::NativeBackend {
int WalletHandle();
// Serializes a list of PasswordForms to be stored in the wallet.
static void SerializeValue(const PasswordFormList& forms, Pickle* pickle);
static void SerializeValue(const std::vector<autofill::PasswordForm*>& forms,
Pickle* pickle);
// Deserializes a list of PasswordForms from the wallet.
// |size_32| controls reading the size field within the pickle as 32 bits.
......@@ -131,8 +135,10 @@ class NativeBackendKWallet : public PasswordStoreX::NativeBackend {
// when reading old pickles that fail to deserialize using the native size.
static bool DeserializeValueSize(const std::string& signon_realm,
const PickleIterator& iter,
int version, bool size_32, bool warn_only,
PasswordFormList* forms);
int version,
bool size_32,
bool warn_only,
ScopedVector<autofill::PasswordForm>* forms);
// In case the fields in the pickle ever change, version them so we can try to
// read old pickles. (Note: do not eat old pickles past the expiration date.)
......
......@@ -124,7 +124,7 @@ class TestKWallet {
// value is false.
void CheckGetAutofillableLoginsFails(
PasswordStoreX::NativeBackend* backend,
PasswordStoreX::NativeBackend::PasswordFormList* forms) {
ScopedVector<autofill::PasswordForm>* forms) {
EXPECT_FALSE(backend->GetAutofillableLogins(forms));
}
......@@ -599,13 +599,12 @@ void NativeBackendKWalletTest::CheckPasswordForms(
TestKWallet::Blob value;
EXPECT_TRUE(wallet_.readEntry(folder, entries[i], &value));
Pickle pickle(reinterpret_cast<const char*>(value.data()), value.size());
std::vector<PasswordForm*> forms;
ScopedVector<autofill::PasswordForm> forms;
NativeBackendKWalletStub::DeserializeValue(entries[i], pickle, &forms);
const std::vector<const PasswordForm*>& expect = sorted_expected[i].second;
EXPECT_EQ(expect.size(), forms.size());
for (size_t j = 0; j < forms.size() && j < expect.size(); ++j)
CheckPasswordForm(*expect[j], *forms[j]);
STLDeleteElements(&forms);
}
}
......@@ -710,7 +709,7 @@ TEST_F(NativeBackendKWalletTest, BasicListLogins) {
base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin),
base::Unretained(&backend), form_google_));
std::vector<PasswordForm*> form_list;
ScopedVector<autofill::PasswordForm> form_list;
BrowserThread::PostTask(
BrowserThread::DB, FROM_HERE,
base::Bind(
......@@ -721,7 +720,6 @@ TEST_F(NativeBackendKWalletTest, BasicListLogins) {
// Quick check that we got something back.
EXPECT_EQ(1u, form_list.size());
STLDeleteElements(&form_list);
EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data"));
......@@ -822,7 +820,7 @@ TEST_F(NativeBackendKWalletTest, RemoveNonexistentLogin) {
base::Unretained(&backend), form_isc_));
// Make sure we can still get the first form back.
std::vector<PasswordForm*> form_list;
ScopedVector<autofill::PasswordForm> form_list;
BrowserThread::PostTask(
BrowserThread::DB, FROM_HERE,
base::Bind(
......@@ -833,7 +831,6 @@ TEST_F(NativeBackendKWalletTest, RemoveNonexistentLogin) {
// Quick check that we got something back.
EXPECT_EQ(1u, form_list.size());
STLDeleteElements(&form_list);
CheckPasswordForms("Chrome Form Data (42)", expected);
}
......@@ -887,7 +884,7 @@ TEST_F(NativeBackendKWalletTest, ListLoginsAppends) {
base::Unretained(&backend), form_google_));
// Send the same request twice with the same list both times.
std::vector<PasswordForm*> form_list;
ScopedVector<autofill::PasswordForm> form_list;
BrowserThread::PostTask(
BrowserThread::DB, FROM_HERE,
base::Bind(
......@@ -903,7 +900,6 @@ TEST_F(NativeBackendKWalletTest, ListLoginsAppends) {
// Quick check that we got two results back.
EXPECT_EQ(2u, form_list.size());
STLDeleteElements(&form_list);
EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data"));
......@@ -1004,8 +1000,8 @@ void NativeBackendKWalletPickleTest::CheckVersion3Pickle() {
CreateVersion3Pickle(form, &pickle);
ScopedVector<PasswordForm> form_list;
NativeBackendKWalletStub::DeserializeValue(form.signon_realm,
pickle, &form_list.get());
NativeBackendKWalletStub::DeserializeValue(form.signon_realm, pickle,
&form_list);
EXPECT_EQ(1u, form_list.size());
if (form_list.size() > 0)
......@@ -1021,8 +1017,8 @@ void NativeBackendKWalletPickleTest::CheckVersion2Pickle() {
CreateVersion2Pickle(form, &pickle);
ScopedVector<PasswordForm> form_list;
NativeBackendKWalletStub::DeserializeValue(form.signon_realm,
pickle, &form_list.get());
NativeBackendKWalletStub::DeserializeValue(form.signon_realm, pickle,
&form_list);
EXPECT_EQ(1u, form_list.size());
if (form_list.size() > 0)
......@@ -1035,7 +1031,7 @@ void NativeBackendKWalletPickleTest::CheckVersion1Pickle() {
PasswordForm form = form_google_;
CreateVersion1Pickle(form, &pickle);
std::vector<PasswordForm*> form_list;
ScopedVector<autofill::PasswordForm> form_list;
NativeBackendKWalletStub::DeserializeValue(form.signon_realm,
pickle, &form_list);
......@@ -1044,7 +1040,6 @@ void NativeBackendKWalletPickleTest::CheckVersion1Pickle() {
EXPECT_EQ(1u, form_list.size());
if (form_list.size() > 0)
CheckPasswordForm(old_form_google_, *form_list[0]);
STLDeleteElements(&form_list);
}
void NativeBackendKWalletPickleTest::CheckVersion0Pickle(
......@@ -1053,13 +1048,12 @@ void NativeBackendKWalletPickleTest::CheckVersion0Pickle(
PasswordForm form = old_form_google_;
form.scheme = scheme;
CreateVersion0Pickle(size_32, form, &pickle);
std::vector<PasswordForm*> form_list;
ScopedVector<autofill::PasswordForm> form_list;
NativeBackendKWalletStub::DeserializeValue(form.signon_realm,
pickle, &form_list);
EXPECT_EQ(1u, form_list.size());
if (form_list.size() > 0)
CheckPasswordForm(form, *form_list[0]);
STLDeleteElements(&form_list);
}
// Check that if KWallet fails to respond, the backend propagates the error.
......@@ -1076,7 +1070,7 @@ TEST_F(NativeBackendKWalletTest, GetAllLoginsErrorHandling) {
base::Unretained(&backend), form_google_));
// Verify that nothing is in fact returned, because KWallet fails to respond.
std::vector<PasswordForm*> form_list;
ScopedVector<autofill::PasswordForm> form_list;
BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
base::Bind(&CheckGetAutofillableLoginsFails,
base::Unretained(&backend), &form_list));
......
......@@ -264,7 +264,7 @@ password_manager::PasswordStoreChangeList NativeBackendLibsecret::AddLogin(
// We'd add the new one first, and then delete the original, but then the
// delete might actually delete the newly-added entry!
ScopedVector<autofill::PasswordForm> forms;
AddUpdateLoginSearch(form, &forms.get(), SEARCH_USE_SUBMIT);
AddUpdateLoginSearch(form, SEARCH_USE_SUBMIT, &forms);
password_manager::PasswordStoreChangeList changes;
if (forms.size() > 0) {
if (forms.size() > 1) {
......@@ -297,7 +297,7 @@ bool NativeBackendLibsecret::UpdateLogin(
changes->clear();
ScopedVector<autofill::PasswordForm> forms;
AddUpdateLoginSearch(form, &forms.get(), SEARCH_IGNORE_SUBMIT);
AddUpdateLoginSearch(form, SEARCH_IGNORE_SUBMIT, &forms);
bool removed = false;
for (size_t i = 0; i < forms.size(); ++i) {
......@@ -352,15 +352,16 @@ bool NativeBackendLibsecret::RemoveLoginsSyncedBetween(
return RemoveLoginsBetween(delete_begin, delete_end, SYNC_TIMESTAMP, changes);
}
bool NativeBackendLibsecret::GetLogins(const PasswordForm& form,
PasswordFormList* forms) {
return GetLoginsList(forms, &form, ALL_LOGINS);
bool NativeBackendLibsecret::GetLogins(
const PasswordForm& form,
ScopedVector<autofill::PasswordForm>* forms) {
return GetLoginsList(&form, ALL_LOGINS, forms);
}
void NativeBackendLibsecret::AddUpdateLoginSearch(
const autofill::PasswordForm& lookup_form,
PasswordFormList* forms,
AddUpdateLoginSearchOptions options) {
AddUpdateLoginSearchOptions options,
ScopedVector<autofill::PasswordForm>* forms) {
LibsecretAttributesBuilder attrs;
attrs.Append("origin_url", lookup_form.origin.spec());
attrs.Append("username_element", UTF16ToUTF8(lookup_form.username_element));
......@@ -426,17 +427,20 @@ bool NativeBackendLibsecret::RawAddLogin(const PasswordForm& form) {
return true;
}
bool NativeBackendLibsecret::GetAutofillableLogins(PasswordFormList* forms) {
return GetLoginsList(forms, nullptr, AUTOFILLABLE_LOGINS);
bool NativeBackendLibsecret::GetAutofillableLogins(
ScopedVector<autofill::PasswordForm>* forms) {
return GetLoginsList(nullptr, AUTOFILLABLE_LOGINS, forms);
}
bool NativeBackendLibsecret::GetBlacklistLogins(PasswordFormList* forms) {
return GetLoginsList(forms, nullptr, BLACKLISTED_LOGINS);
bool NativeBackendLibsecret::GetBlacklistLogins(
ScopedVector<autofill::PasswordForm>* forms) {
return GetLoginsList(nullptr, BLACKLISTED_LOGINS, forms);
}
bool NativeBackendLibsecret::GetLoginsList(PasswordFormList* forms,
const PasswordForm* lookup_form,
GetLoginsListOptions options) {
bool NativeBackendLibsecret::GetLoginsList(
const PasswordForm* lookup_form,
GetLoginsListOptions options,
ScopedVector<autofill::PasswordForm>* forms) {
LibsecretAttributesBuilder attrs;
attrs.Append("application", app_string_);
if (options != ALL_LOGINS)
......@@ -464,16 +468,17 @@ bool NativeBackendLibsecret::GetLoginsList(PasswordFormList* forms,
return ConvertFormList(found, lookup_form, forms);
}
bool NativeBackendLibsecret::GetAllLogins(PasswordFormList* forms) {
return GetLoginsList(forms, nullptr, ALL_LOGINS);
bool NativeBackendLibsecret::GetAllLogins(
ScopedVector<autofill::PasswordForm>* forms) {
return GetLoginsList(nullptr, ALL_LOGINS, forms);
}
bool NativeBackendLibsecret::GetLoginsBetween(
base::Time get_begin,
base::Time get_end,
TimestampToCompare date_to_compare,
PasswordFormList* forms) {
PasswordFormList all_forms;
ScopedVector<autofill::PasswordForm>* forms) {
ScopedVector<autofill::PasswordForm> all_forms;
if (!GetAllLogins(&all_forms))
return false;
......@@ -481,12 +486,11 @@ bool NativeBackendLibsecret::GetLoginsBetween(
date_to_compare == CREATION_TIMESTAMP
? &autofill::PasswordForm::date_created
: &autofill::PasswordForm::date_synced;
for (size_t i = 0; i < all_forms.size(); ++i) {
if (get_begin <= all_forms[i]->*date_member &&
(get_end.is_null() || all_forms[i]->*date_member < get_end)) {
forms->push_back(all_forms[i]);
} else {
delete all_forms[i];
for (auto& saved_form : all_forms) {
if (get_begin <= saved_form->*date_member &&
(get_end.is_null() || saved_form->*date_member < get_end)) {
forms->push_back(saved_form);
saved_form = nullptr;
}
}
......@@ -501,7 +505,7 @@ bool NativeBackendLibsecret::RemoveLoginsBetween(
DCHECK(changes);
changes->clear();
ScopedVector<autofill::PasswordForm> forms;
if (!GetLoginsBetween(get_begin, get_end, date_to_compare, &forms.get()))
if (!GetLoginsBetween(get_begin, get_end, date_to_compare, &forms))
return false;
bool ok = true;
......@@ -519,7 +523,7 @@ bool NativeBackendLibsecret::RemoveLoginsBetween(
bool NativeBackendLibsecret::ConvertFormList(
GList* found,
const PasswordForm* lookup_form,
NativeBackendLibsecret::PasswordFormList* forms) {
ScopedVector<autofill::PasswordForm>* forms) {
password_manager::PSLDomainMatchMetric psl_domain_match_metric =
password_manager::PSL_DOMAIN_MATCH_NONE;
GError* error = nullptr;
......
......@@ -10,6 +10,7 @@
#include <string>
#include "base/basictypes.h"
#include "base/memory/scoped_vector.h"
#include "base/time/time.h"
#include "chrome/browser/password_manager/password_store_factory.h"
#include "chrome/browser/password_manager/password_store_x.h"
......@@ -69,9 +70,10 @@ class NativeBackendLibsecret : public PasswordStoreX::NativeBackend,
base::Time delete_end,
password_manager::PasswordStoreChangeList* changes) override;
bool GetLogins(const autofill::PasswordForm& form,
PasswordFormList* forms) override;
bool GetAutofillableLogins(PasswordFormList* forms) override;
bool GetBlacklistLogins(PasswordFormList* forms) override;
ScopedVector<autofill::PasswordForm>* forms) override;
bool GetAutofillableLogins(
ScopedVector<autofill::PasswordForm>* forms) override;
bool GetBlacklistLogins(ScopedVector<autofill::PasswordForm>* forms) override;
private:
enum TimestampToCompare {
......@@ -86,8 +88,8 @@ class NativeBackendLibsecret : public PasswordStoreX::NativeBackend,
// Search that is used in AddLogin and UpdateLogin methods
void AddUpdateLoginSearch(const autofill::PasswordForm& lookup_form,
PasswordFormList* forms,
AddUpdateLoginSearchOptions options);
AddUpdateLoginSearchOptions options,
ScopedVector<autofill::PasswordForm>* forms);
// Adds a login form without checking for one to replace first.
bool RawAddLogin(const autofill::PasswordForm& form);
......@@ -99,19 +101,19 @@ class NativeBackendLibsecret : public PasswordStoreX::NativeBackend,
};
// Reads PasswordForms from the keyring with the given autofillability state.
bool GetLoginsList(PasswordFormList* forms,
const autofill::PasswordForm* lookup_form,
GetLoginsListOptions options);
bool GetLoginsList(const autofill::PasswordForm* lookup_form,
GetLoginsListOptions options,
ScopedVector<autofill::PasswordForm>* forms);
// Helper for GetLoginsCreatedBetween().
bool GetAllLogins(PasswordFormList* forms);
bool GetAllLogins(ScopedVector<autofill::PasswordForm>* forms);
// Retrieves password created/synced in the time interval. Returns |true| if
// the operation succeeded.
bool GetLoginsBetween(base::Time get_begin,
base::Time get_end,
TimestampToCompare date_to_compare,
PasswordFormList* forms);
ScopedVector<autofill::PasswordForm>* forms);
// Removes password created/synced in the time interval. Returns |true| if the
// operation succeeded. |changes| will contain the changes applied.
......@@ -123,7 +125,7 @@ class NativeBackendLibsecret : public PasswordStoreX::NativeBackend,
// convert data get from Libsecret to Passwordform
bool ConvertFormList(GList* found,
const autofill::PasswordForm* lookup_form,
NativeBackendLibsecret::PasswordFormList* forms);
ScopedVector<autofill::PasswordForm>* forms);
// Generates a profile-specific app string based on profile_id_.
static std::string GetProfileSpecificAppString(LocalProfileId id);
......
......@@ -410,7 +410,7 @@ class NativeBackendLibsecretTest : public testing::Test {
target_form.signon_realm.append("Realm");
target_form.scheme = scheme;
}
std::vector<PasswordForm*> form_list;
ScopedVector<autofill::PasswordForm> form_list;
backend.GetLogins(target_form, &form_list);
EXPECT_EQ(1u, global_mock_libsecret_items.size());
......@@ -424,7 +424,6 @@ class NativeBackendLibsecretTest : public testing::Test {
EXPECT_EQ(1u, form_list.size());
if (result)
*result = *form_list[0];
STLDeleteElements(&form_list);
return true;
}
......@@ -443,13 +442,13 @@ class NativeBackendLibsecretTest : public testing::Test {
PasswordForm m_facebook_lookup;
m_facebook_lookup.origin = kMobileURL;
m_facebook_lookup.signon_realm = kMobileURL.spec();
std::vector<PasswordForm*> form_list;
ScopedVector<autofill::PasswordForm> form_list;
backend.GetLogins(m_facebook_lookup, &form_list);
EXPECT_EQ(1u, global_mock_libsecret_items.size());
EXPECT_EQ(1u, form_list.size());
PasswordForm m_facebook = *form_list[0];
STLDeleteElements(&form_list);
form_list.clear();
EXPECT_EQ(kMobileURL, m_facebook.origin);
EXPECT_EQ(kMobileURL.spec(), m_facebook.signon_realm);
......@@ -486,7 +485,7 @@ class NativeBackendLibsecretTest : public testing::Test {
EXPECT_EQ(kMobileURL, form_list[index_non_psl]->origin);
EXPECT_EQ(kMobileURL.spec(), form_list[index_non_psl]->signon_realm);
EXPECT_EQ(kOldPassword, form_list[index_non_psl]->password_value);
STLDeleteElements(&form_list);
form_list.clear();
// Check that www.facebook.com login was modified by the update.
backend.GetLogins(form_facebook_, &form_list);
......@@ -499,7 +498,7 @@ class NativeBackendLibsecretTest : public testing::Test {
EXPECT_EQ(form_facebook_.signon_realm,
form_list[index_non_psl]->signon_realm);
EXPECT_EQ(kNewPassword, form_list[index_non_psl]->password_value);
STLDeleteElements(&form_list);
form_list.clear();
}
// Checks various types of matching for forms with a non-HTML |scheme|.
......@@ -600,12 +599,12 @@ TEST_F(NativeBackendLibsecretTest, BasicListLogins) {
backend.AddLogin(form_google_);
std::vector<PasswordForm*> form_list;
ScopedVector<autofill::PasswordForm> form_list;
backend.GetAutofillableLogins(&form_list);
// Quick check that we got something back.
EXPECT_EQ(1u, form_list.size());
STLDeleteElements(&form_list);
form_list.clear();
EXPECT_EQ(1u, global_mock_libsecret_items.size());
if (global_mock_libsecret_items.size() > 0)
......@@ -731,12 +730,12 @@ TEST_F(NativeBackendLibsecretTest, RemoveNonexistentLogin) {
backend.RemoveLogin(form_isc_);
// Make sure we can still get the first form back.
std::vector<PasswordForm*> form_list;
ScopedVector<autofill::PasswordForm> form_list;
backend.GetAutofillableLogins(&form_list);
// Quick check that we got something back.
EXPECT_EQ(1u, form_list.size());
STLDeleteElements(&form_list);
form_list.clear();
EXPECT_EQ(1u, global_mock_libsecret_items.size());
if (global_mock_libsecret_items.size() > 0)
......@@ -797,13 +796,13 @@ TEST_F(NativeBackendLibsecretTest, ListLoginsAppends) {
backend.AddLogin(form_google_);
// Send the same request twice with the same list both times.
std::vector<PasswordForm*> form_list;
ScopedVector<autofill::PasswordForm> form_list;
backend.GetAutofillableLogins(&form_list);
backend.GetAutofillableLogins(&form_list);
// Quick check that we got two results back.
EXPECT_EQ(2u, form_list.size());
STLDeleteElements(&form_list);
form_list.clear();
EXPECT_EQ(1u, global_mock_libsecret_items.size());
if (global_mock_libsecret_items.size() > 0)
......
......@@ -9,6 +9,7 @@
#include "base/callback_forward.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "base/threading/thread.h"
#include "components/password_manager/core/browser/login_database.h"
#include "components/password_manager/core/browser/password_store.h"
......@@ -80,9 +81,9 @@ class PasswordStoreMac : public password_manager::PasswordStore {
void GetAutofillableLoginsImpl(GetLoginsRequest* request) override;
void GetBlacklistLoginsImpl(GetLoginsRequest* request) override;
bool FillAutofillableLogins(
std::vector<autofill::PasswordForm*>* forms) override;
ScopedVector<autofill::PasswordForm>* forms) override;
bool FillBlacklistLogins(
std::vector<autofill::PasswordForm*>* forms) override;
ScopedVector<autofill::PasswordForm>* forms) override;
// Adds the given form to the Keychain if it's something we want to store
// there (i.e., not a blacklist entry). Returns true if the operation
......@@ -103,9 +104,9 @@ class PasswordStoreMac : public password_manager::PasswordStore {
const std::vector<autofill::PasswordForm*>& forms);
// Searches the database for forms without a corresponding entry in the
// keychain. Removes those forms from the database, and returns them in
// |forms|. Ownership of |forms| is passed to the caller.
void CleanOrphanedForms(std::vector<autofill::PasswordForm*>* forms);
// keychain. Removes those forms from the database, and adds them to
// |orphaned_forms|.
void CleanOrphanedForms(ScopedVector<autofill::PasswordForm>* orphaned_forms);
scoped_ptr<crypto::AppleKeychain> keychain_;
......
......@@ -10,6 +10,7 @@
#include <string>
#include <vector>
#include "base/memory/scoped_vector.h"
#include "components/autofill/core/common/password_form.h"
#include "crypto/apple_keychain.h"
......@@ -24,9 +25,8 @@ class MacKeychainPasswordFormAdapter {
// created object.
explicit MacKeychainPasswordFormAdapter(const AppleKeychain* keychain);
// Returns PasswordForms for each keychain entry that could be used to fill
// |form|. Caller is responsible for deleting the returned forms.
std::vector<autofill::PasswordForm*> PasswordsFillingForm(
// Returns all keychain entries matching |signon_realm| and |scheme|.
ScopedVector<autofill::PasswordForm> PasswordsFillingForm(
const std::string& signon_realm,
autofill::PasswordForm::Scheme scheme);
......@@ -45,9 +45,9 @@ class MacKeychainPasswordFormAdapter {
// Returns all keychain items of types corresponding to password forms.
std::vector<SecKeychainItemRef> GetAllPasswordFormKeychainItems();
// Returns password data from all keychain items of types corresponding to
// password forms. Caller is responsible for deleting the returned forms.
std::vector<autofill::PasswordForm*> GetAllPasswordFormPasswords();
// Returns all keychain entries corresponding to password forms.
// TODO(vabr): This is only used in tests, should be moved there.
ScopedVector<autofill::PasswordForm> GetAllPasswordFormPasswords();
// Creates a new keychain entry from |form|, or updates the password of an
// existing keychain entry if there is a collision. Returns true if a keychain
......@@ -63,10 +63,9 @@ class MacKeychainPasswordFormAdapter {
void SetFindsOnlyOwnedItems(bool finds_only_owned);
private:
// Returns PasswordForms constructed from the given Keychain items, calling
// AppleKeychain::Free on all of the keychain items and clearing the vector.
// Caller is responsible for deleting the returned forms.
std::vector<autofill::PasswordForm*> ConvertKeychainItemsToForms(
// Returns PasswordForm instances transformed from |items|. Also calls
// AppleKeychain::Free on all of the keychain items and clears |items|.
ScopedVector<autofill::PasswordForm> ConvertKeychainItemsToForms(
std::vector<SecKeychainItemRef>* items);
// Searches |keychain| for the specific keychain entry that corresponds to the
......@@ -165,17 +164,16 @@ bool FormsMatchForMerge(const autofill::PasswordForm& form_a,
// password can be found (and which aren't blacklist entries), and for
// keychain_forms its entries that weren't merged into at least one database
// form.
void MergePasswordForms(
std::vector<autofill::PasswordForm*>* keychain_forms,
std::vector<autofill::PasswordForm*>* database_forms,
std::vector<autofill::PasswordForm*>* merged_forms);
// Fills in the passwords for as many of the forms in |database_forms| as
// possible using entries from |keychain| and returns them. On return,
// |database_forms| will contain only the forms for which no password was found.
std::vector<autofill::PasswordForm*> GetPasswordsForForms(
const AppleKeychain& keychain,
std::vector<autofill::PasswordForm*>* database_forms);
void MergePasswordForms(ScopedVector<autofill::PasswordForm>* keychain_forms,
ScopedVector<autofill::PasswordForm>* database_forms,
ScopedVector<autofill::PasswordForm>* merged_forms);
// For every form in |database_forms|, if such a form has a corresponding entry
// in |keychain|, this adds the password from the entry and moves that form from
// |database_forms| into |passwords|.
void GetPasswordsForForms(const AppleKeychain& keychain,
ScopedVector<autofill::PasswordForm>* database_forms,
ScopedVector<autofill::PasswordForm>* passwords);
// Loads all items in the system keychain into |keychain_items|, creates for
// each keychain item a corresponding PasswordForm that doesn't contain any
......@@ -206,10 +204,9 @@ bool ExtractSignonRealmComponents(const std::string& signon_realm,
bool FormIsValidAndMatchesOtherForm(const autofill::PasswordForm& query_form,
const autofill::PasswordForm& other_form);
// Returns PasswordForms populated with password data for each keychain entry
// in |item_form_pairs| that could be merged with |query_form|.
// Caller is responsible for deleting the returned forms.
std::vector<autofill::PasswordForm*> ExtractPasswordsMergeableWithForm(
// Returns PasswordForm instances populated with password data for each keychain
// entry in |item_form_pairs| that could be merged with |query_form|.
ScopedVector<autofill::PasswordForm> ExtractPasswordsMergeableWithForm(
const AppleKeychain& keychain,
const std::vector<ItemFormPair>& item_form_pairs,
const autofill::PasswordForm& query_form);
......
......@@ -54,7 +54,7 @@ class PasswordStoreWin::DBHandler : public WebDataServiceConsumer {
// Gets logins from IE7 if no others are found. Also copies them into
// Chrome's WebDatabase so we don't need to look next time.
std::vector<autofill::PasswordForm*> GetIE7Results(
ScopedVector<autofill::PasswordForm> GetIE7Results(
const WDTypedResult* result,
const PasswordForm& form);
......@@ -97,12 +97,11 @@ void PasswordStoreWin::DBHandler::GetIE7Login(
RequestInfo(new PasswordForm(form), callback_runner);
}
std::vector<PasswordForm*> PasswordStoreWin::DBHandler::GetIE7Results(
const WDTypedResult *result,
ScopedVector<autofill::PasswordForm> PasswordStoreWin::DBHandler::GetIE7Results(
const WDTypedResult* result,
const PasswordForm& form) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
std::vector<PasswordForm*> matching_forms;
ScopedVector<autofill::PasswordForm> matched_forms;
const WDResult<IE7PasswordInfo>* r =
static_cast<const WDResult<IE7PasswordInfo>*>(result);
IE7PasswordInfo info = r->GetValue();
......@@ -127,14 +126,14 @@ std::vector<PasswordForm*> PasswordStoreWin::DBHandler::GetIE7Results(
autofill->ssl_valid = form.origin.SchemeIsSecure();
autofill->date_created = info.date_created;
matching_forms.push_back(autofill);
matched_forms.push_back(autofill);
// Add this PasswordForm to the saved password table. We're on the DB
// thread already, so we use AddLoginImpl.
password_store_->AddLoginImpl(*autofill);
}
}
}
return matching_forms;
return matched_forms.Pass();
}
void PasswordStoreWin::DBHandler::OnWebDataServiceRequestDone(
......@@ -153,15 +152,12 @@ void PasswordStoreWin::DBHandler::OnWebDataServiceRequestDone(
if (!result) {
// The WDS returns NULL if it is shutting down. Run callback with empty
// result.
callback_runner.Run(std::vector<autofill::PasswordForm*>());
callback_runner.Run(ScopedVector<autofill::PasswordForm>());
return;
}
DCHECK_EQ(PASSWORD_IE7_RESULT, result->GetType());
std::vector<autofill::PasswordForm*> matched_forms =
GetIE7Results(result, *form);
callback_runner.Run(matched_forms);
callback_runner.Run(GetIE7Results(result, *form));
}
PasswordStoreWin::PasswordStoreWin(
......@@ -193,13 +189,13 @@ void PasswordStoreWin::Shutdown() {
void PasswordStoreWin::GetIE7LoginIfNecessary(
const PasswordForm& form,
const ConsumerCallbackRunner& callback_runner,
const std::vector<autofill::PasswordForm*>& matched_forms) {
ScopedVector<autofill::PasswordForm> matched_forms) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
if (matched_forms.empty() && db_handler_.get()) {
if (matched_forms.empty() && db_handler_) {
db_handler_->GetIE7Login(form, callback_runner);
} else {
// No need to get IE7 login.
callback_runner.Run(matched_forms);
callback_runner.Run(matched_forms.Pass());
}
}
......
......@@ -6,6 +6,7 @@
#define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_WIN_H_
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "components/password_manager/core/browser/password_store_default.h"
class PasswordWebDataService;
......@@ -48,9 +49,9 @@ class PasswordStoreWin : public password_manager::PasswordStoreDefault {
const ConsumerCallbackRunner& callback_runner) override;
void GetIE7LoginIfNecessary(
const autofill::PasswordForm& form,
const ConsumerCallbackRunner& callback_runner,
const std::vector<autofill::PasswordForm*>& matched_forms);
const autofill::PasswordForm& form,
const ConsumerCallbackRunner& callback_runner,
ScopedVector<autofill::PasswordForm> matched_forms);
scoped_ptr<DBHandler> db_handler_;
......
......@@ -24,7 +24,6 @@ using content::BrowserThread;
using password_manager::PasswordStoreChange;
using password_manager::PasswordStoreChangeList;
using password_manager::PasswordStoreDefault;
using std::vector;
namespace {
......@@ -130,7 +129,8 @@ struct LoginLessThan {
};
} // anonymous namespace
void PasswordStoreX::SortLoginsByOrigin(NativeBackend::PasswordFormList* list) {
void PasswordStoreX::SortLoginsByOrigin(
std::vector<autofill::PasswordForm*>* list) {
// In login_database.cc, the query has ORDER BY origin_url. Simulate that.
std::sort(list->begin(), list->end(), LoginLessThan());
}
......@@ -140,9 +140,9 @@ void PasswordStoreX::GetLoginsImpl(
AuthorizationPromptPolicy prompt_policy,
const ConsumerCallbackRunner& callback_runner) {
CheckMigration();
std::vector<autofill::PasswordForm*> matched_forms;
ScopedVector<autofill::PasswordForm> matched_forms;
if (use_native_backend() && backend_->GetLogins(form, &matched_forms)) {
SortLoginsByOrigin(&matched_forms);
SortLoginsByOrigin(&matched_forms.get());
// The native backend may succeed and return no data even while locked, if
// the query did not match anything stored. So we continue to allow fallback
// until we perform a write operation, or until a read returns actual data.
......@@ -154,13 +154,15 @@ void PasswordStoreX::GetLoginsImpl(
return;
}
// The consumer will be left hanging unless we reply.
callback_runner.Run(matched_forms);
callback_runner.Run(matched_forms.Pass());
}
void PasswordStoreX::GetAutofillableLoginsImpl(GetLoginsRequest* request) {
CheckMigration();
ScopedVector<autofill::PasswordForm> obtained_forms;
if (use_native_backend() &&
backend_->GetAutofillableLogins(request->result())) {
backend_->GetAutofillableLogins(&obtained_forms)) {
request->result()->swap(obtained_forms.get());
SortLoginsByOrigin(request->result());
// See GetLoginsImpl() for why we disallow fallback conditionally here.
if (request->result()->size() > 0)
......@@ -175,8 +177,9 @@ void PasswordStoreX::GetAutofillableLoginsImpl(GetLoginsRequest* request) {
void PasswordStoreX::GetBlacklistLoginsImpl(GetLoginsRequest* request) {
CheckMigration();
if (use_native_backend() &&
backend_->GetBlacklistLogins(request->result())) {
ScopedVector<autofill::PasswordForm> obtained_forms;
if (use_native_backend() && backend_->GetBlacklistLogins(&obtained_forms)) {
request->result()->swap(obtained_forms.get());
SortLoginsByOrigin(request->result());
// See GetLoginsImpl() for why we disallow fallback conditionally here.
if (request->result()->size() > 0)
......@@ -189,7 +192,8 @@ void PasswordStoreX::GetBlacklistLoginsImpl(GetLoginsRequest* request) {
ForwardLoginsResult(request);
}
bool PasswordStoreX::FillAutofillableLogins(vector<PasswordForm*>* forms) {
bool PasswordStoreX::FillAutofillableLogins(
ScopedVector<autofill::PasswordForm>* forms) {
CheckMigration();
if (use_native_backend() && backend_->GetAutofillableLogins(forms)) {
// See GetLoginsImpl() for why we disallow fallback conditionally here.
......@@ -202,7 +206,8 @@ bool PasswordStoreX::FillAutofillableLogins(vector<PasswordForm*>* forms) {
return false;
}
bool PasswordStoreX::FillBlacklistLogins(vector<PasswordForm*>* forms) {
bool PasswordStoreX::FillBlacklistLogins(
ScopedVector<autofill::PasswordForm>* forms) {
CheckMigration();
if (use_native_backend() && backend_->GetBlacklistLogins(forms)) {
// See GetLoginsImpl() for why we disallow fallback conditionally here.
......@@ -250,7 +255,7 @@ bool PasswordStoreX::allow_default_store() {
ssize_t PasswordStoreX::MigrateLogins() {
DCHECK(backend_.get());
vector<PasswordForm*> forms;
ScopedVector<autofill::PasswordForm> forms;
bool ok = PasswordStoreDefault::FillAutofillableLogins(&forms) &&
PasswordStoreDefault::FillBlacklistLogins(&forms);
if (ok) {
......@@ -283,6 +288,5 @@ ssize_t PasswordStoreX::MigrateLogins() {
}
}
ssize_t result = ok ? forms.size() : -1;
STLDeleteElements(&forms);
return result;
}
......@@ -8,6 +8,7 @@
#include <vector>
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "base/time/time.h"
#include "components/password_manager/core/browser/password_store_default.h"
......@@ -34,8 +35,6 @@ class PasswordStoreX : public password_manager::PasswordStoreDefault {
// with return values rather than implicit consumer notification.
class NativeBackend {
public:
typedef std::vector<autofill::PasswordForm*> PasswordFormList;
virtual ~NativeBackend() {}
virtual bool Init() = 0;
......@@ -60,9 +59,11 @@ class PasswordStoreX : public password_manager::PasswordStoreDefault {
password_manager::PasswordStoreChangeList* changes) = 0;
virtual bool GetLogins(const autofill::PasswordForm& form,
PasswordFormList* forms) = 0;
virtual bool GetAutofillableLogins(PasswordFormList* forms) = 0;
virtual bool GetBlacklistLogins(PasswordFormList* forms) = 0;
ScopedVector<autofill::PasswordForm>* forms) = 0;
virtual bool GetAutofillableLogins(
ScopedVector<autofill::PasswordForm>* forms) = 0;
virtual bool GetBlacklistLogins(
ScopedVector<autofill::PasswordForm>* forms) = 0;
};
// Takes ownership of |login_db| and |backend|. |backend| may be NULL in which
......@@ -96,12 +97,12 @@ class PasswordStoreX : public password_manager::PasswordStoreDefault {
void GetAutofillableLoginsImpl(GetLoginsRequest* request) override;
void GetBlacklistLoginsImpl(GetLoginsRequest* request) override;
bool FillAutofillableLogins(
std::vector<autofill::PasswordForm*>* forms) override;
ScopedVector<autofill::PasswordForm>* forms) override;
bool FillBlacklistLogins(
std::vector<autofill::PasswordForm*>* forms) override;
ScopedVector<autofill::PasswordForm>* forms) override;
// Sort logins by origin, like the ORDER BY clause in login_database.cc.
void SortLoginsByOrigin(NativeBackend::PasswordFormList* list);
void SortLoginsByOrigin(std::vector<autofill::PasswordForm*>* list);
// Check to see whether migration is necessary, and perform it if so.
void CheckMigration();
......
......@@ -33,8 +33,6 @@ using testing::_;
using testing::ElementsAreArray;
using testing::WithArg;
typedef std::vector<PasswordForm*> VectorOfForms;
namespace {
class MockPasswordStoreConsumer
......@@ -78,12 +76,19 @@ class FailingBackend : public PasswordStoreX::NativeBackend {
return false;
}
bool GetLogins(const PasswordForm& form, PasswordFormList* forms) override {
bool GetLogins(const PasswordForm& form,
ScopedVector<autofill::PasswordForm>* forms) override {
return false;
}
bool GetAutofillableLogins(PasswordFormList* forms) override { return false; }
bool GetBlacklistLogins(PasswordFormList* forms) override { return false; }
bool GetAutofillableLogins(
ScopedVector<autofill::PasswordForm>* forms) override {
return false;
}
bool GetBlacklistLogins(
ScopedVector<autofill::PasswordForm>* forms) override {
return false;
}
};
class MockBackend : public PasswordStoreX::NativeBackend {
......@@ -142,21 +147,24 @@ class MockBackend : public PasswordStoreX::NativeBackend {
return true;
}
bool GetLogins(const PasswordForm& form, PasswordFormList* forms) override {
bool GetLogins(const PasswordForm& form,
ScopedVector<autofill::PasswordForm>* forms) override {
for (size_t i = 0; i < all_forms_.size(); ++i)
if (all_forms_[i].signon_realm == form.signon_realm)
forms->push_back(new PasswordForm(all_forms_[i]));
return true;
}
bool GetAutofillableLogins(PasswordFormList* forms) override {
bool GetAutofillableLogins(
ScopedVector<autofill::PasswordForm>* forms) override {
for (size_t i = 0; i < all_forms_.size(); ++i)
if (!all_forms_[i].blacklisted_by_user)
forms->push_back(new PasswordForm(all_forms_[i]));
return true;
}
bool GetBlacklistLogins(PasswordFormList* forms) override {
bool GetBlacklistLogins(
ScopedVector<autofill::PasswordForm>* forms) override {
for (size_t i = 0; i < all_forms_.size(); ++i)
if (all_forms_[i].blacklisted_by_user)
forms->push_back(new PasswordForm(all_forms_[i]));
......@@ -193,16 +201,18 @@ class MockLoginDatabaseReturn {
void LoginDatabaseQueryCallback(password_manager::LoginDatabase* login_db,
bool autofillable,
MockLoginDatabaseReturn* mock_return) {
std::vector<PasswordForm*> forms;
ScopedVector<autofill::PasswordForm> forms;
if (autofillable)
login_db->GetAutofillableLogins(&forms);
else
login_db->GetBlacklistLogins(&forms);
mock_return->OnLoginDatabaseQueryDone(forms);
mock_return->OnLoginDatabaseQueryDone(forms.get());
}
// Generate |count| expected logins, either auto-fillable or blacklisted.
void InitExpectedForms(bool autofillable, size_t count, VectorOfForms* forms) {
void InitExpectedForms(bool autofillable,
size_t count,
ScopedVector<autofill::PasswordForm>* forms) {
const char* domain = autofillable ? "example" : "blacklisted";
for (size_t i = 0; i < count; ++i) {
std::string realm = base::StringPrintf("http://%zu.%s.com", i, domain);
......@@ -339,10 +349,10 @@ TEST_P(PasswordStoreXTest, Notifications) {
}
TEST_P(PasswordStoreXTest, NativeMigration) {
VectorOfForms expected_autofillable;
ScopedVector<autofill::PasswordForm> expected_autofillable;
InitExpectedForms(true, 50, &expected_autofillable);
VectorOfForms expected_blacklisted;
ScopedVector<autofill::PasswordForm> expected_blacklisted;
InitExpectedForms(false, 50, &expected_blacklisted);
const base::FilePath login_db_file = test_login_db_file_path();
......@@ -356,13 +366,11 @@ TEST_P(PasswordStoreXTest, NativeMigration) {
ASSERT_TRUE(base::GetFileInfo(login_db_file, &db_file_start_info));
// Populate the login DB with logins that should be migrated.
for (VectorOfForms::iterator it = expected_autofillable.begin();
it != expected_autofillable.end(); ++it) {
login_db->AddLogin(**it);
for (const auto* form : expected_autofillable) {
login_db->AddLogin(*form);
}
for (VectorOfForms::iterator it = expected_blacklisted.begin();
it != expected_blacklisted.end(); ++it) {
login_db->AddLogin(**it);
for (const auto* form : expected_blacklisted) {
login_db->AddLogin(*form);
}
// Get the new size of the login DB file. We expect it to be larger.
......@@ -380,35 +388,32 @@ TEST_P(PasswordStoreXTest, NativeMigration) {
MockPasswordStoreConsumer consumer;
// The autofillable forms should have been migrated to the native backend.
EXPECT_CALL(consumer,
OnGetPasswordStoreResults(
ContainsAllPasswordForms(expected_autofillable)))
EXPECT_CALL(consumer, OnGetPasswordStoreResults(ContainsAllPasswordForms(
expected_autofillable.get())))
.WillOnce(WithArg<0>(STLDeleteElements0()));
store->GetAutofillableLogins(&consumer);
base::RunLoop().RunUntilIdle();
// The blacklisted forms should have been migrated to the native backend.
EXPECT_CALL(consumer,
OnGetPasswordStoreResults(ContainsAllPasswordForms(expected_blacklisted)))
EXPECT_CALL(consumer, OnGetPasswordStoreResults(ContainsAllPasswordForms(
expected_blacklisted.get())))
.WillOnce(WithArg<0>(STLDeleteElements0()));
store->GetBlacklistLogins(&consumer);
base::RunLoop().RunUntilIdle();
VectorOfForms empty;
ScopedVector<autofill::PasswordForm> empty;
MockLoginDatabaseReturn ld_return;
if (GetParam() == WORKING_BACKEND) {
// No autofillable logins should be left in the login DB.
EXPECT_CALL(ld_return,
OnLoginDatabaseQueryDone(ContainsAllPasswordForms(empty)));
EXPECT_CALL(ld_return, OnLoginDatabaseQueryDone(
ContainsAllPasswordForms(empty.get())));
} else {
// The autofillable logins should still be in the login DB.
EXPECT_CALL(ld_return,
OnLoginDatabaseQueryDone(
ContainsAllPasswordForms(expected_autofillable)))
.WillOnce(WithArg<0>(STLDeleteElements0()));
EXPECT_CALL(ld_return, OnLoginDatabaseQueryDone(ContainsAllPasswordForms(
expected_autofillable.get())));
}
LoginDatabaseQueryCallback(store->login_db(), true, &ld_return);
......@@ -418,14 +423,12 @@ TEST_P(PasswordStoreXTest, NativeMigration) {
if (GetParam() == WORKING_BACKEND) {
// Likewise, no blacklisted logins should be left in the login DB.
EXPECT_CALL(ld_return,
OnLoginDatabaseQueryDone(ContainsAllPasswordForms(empty)));
EXPECT_CALL(ld_return, OnLoginDatabaseQueryDone(
ContainsAllPasswordForms(empty.get())));
} else {
// The blacklisted logins should still be in the login DB.
EXPECT_CALL(ld_return,
OnLoginDatabaseQueryDone(
ContainsAllPasswordForms(expected_blacklisted)))
.WillOnce(WithArg<0>(STLDeleteElements0()));
EXPECT_CALL(ld_return, OnLoginDatabaseQueryDone(ContainsAllPasswordForms(
expected_blacklisted.get())));
}
LoginDatabaseQueryCallback(store->login_db(), false, &ld_return);
......@@ -444,9 +447,6 @@ TEST_P(PasswordStoreXTest, NativeMigration) {
EXPECT_EQ(db_file_start_info.size, db_file_end_info.size);
}
STLDeleteElements(&expected_autofillable);
STLDeleteElements(&expected_blacklisted);
store->Shutdown();
}
......
......@@ -676,8 +676,9 @@ LoginDatabase::EncryptionResult LoginDatabase::InitPasswordFormFromStatement(
return ENCRYPTION_RESULT_SUCCESS;
}
bool LoginDatabase::GetLogins(const PasswordForm& form,
std::vector<PasswordForm*>* forms) const {
bool LoginDatabase::GetLogins(
const PasswordForm& form,
ScopedVector<autofill::PasswordForm>* forms) const {
DCHECK(forms);
// You *must* change LoginTableColumns if this query changes.
const std::string sql_query =
......@@ -774,7 +775,7 @@ bool LoginDatabase::GetLogins(const PasswordForm& form,
bool LoginDatabase::GetLoginsCreatedBetween(
const base::Time begin,
const base::Time end,
std::vector<autofill::PasswordForm*>* forms) const {
ScopedVector<autofill::PasswordForm>* forms) const {
DCHECK(forms);
sql::Statement s(db_.GetCachedStatement(
SQL_FROM_HERE,
......@@ -807,7 +808,7 @@ bool LoginDatabase::GetLoginsCreatedBetween(
bool LoginDatabase::GetLoginsSyncedBetween(
const base::Time begin,
const base::Time end,
std::vector<autofill::PasswordForm*>* forms) const {
ScopedVector<autofill::PasswordForm>* forms) const {
DCHECK(forms);
sql::Statement s(db_.GetCachedStatement(
SQL_FROM_HERE,
......@@ -838,18 +839,18 @@ bool LoginDatabase::GetLoginsSyncedBetween(
}
bool LoginDatabase::GetAutofillableLogins(
std::vector<PasswordForm*>* forms) const {
ScopedVector<autofill::PasswordForm>* forms) const {
return GetAllLoginsWithBlacklistSetting(false, forms);
}
bool LoginDatabase::GetBlacklistLogins(
std::vector<PasswordForm*>* forms) const {
ScopedVector<autofill::PasswordForm>* forms) const {
return GetAllLoginsWithBlacklistSetting(true, forms);
}
bool LoginDatabase::GetAllLoginsWithBlacklistSetting(
bool blacklisted,
std::vector<PasswordForm*>* forms) const {
ScopedVector<autofill::PasswordForm>* forms) const {
DCHECK(forms);
// You *must* change LoginTableColumns if this query changes.
sql::Statement s(db_.GetCachedStatement(
......
......@@ -9,8 +9,10 @@
#include <vector>
#include "base/files/file_path.h"
#include "base/memory/scoped_vector.h"
#include "base/pickle.h"
#include "base/strings/string16.h"
#include "components/password_manager/core/browser/password_store.h"
#include "components/password_manager/core/browser/password_store_change.h"
#include "components/password_manager/core/browser/psl_matching_helper.h"
#include "sql/connection.h"
......@@ -66,33 +68,32 @@ class LoginDatabase {
// Loads a list of matching password forms into the specified vector |forms|.
// The list will contain all possibly relevant entries to the observed |form|,
// including blacklisted matches. The caller owns |forms| after the call.
// including blacklisted matches.
bool GetLogins(const autofill::PasswordForm& form,
std::vector<autofill::PasswordForm*>* forms) const;
ScopedVector<autofill::PasswordForm>* forms) const;
// Loads all logins created from |begin| onwards (inclusive) and before |end|.
// You may use a null Time value to do an unbounded search in either
// direction. The caller owns |forms| after the call.
// direction.
bool GetLoginsCreatedBetween(
base::Time begin,
base::Time end,
std::vector<autofill::PasswordForm*>* forms) const;
ScopedVector<autofill::PasswordForm>* forms) const;
// Loads all logins synced from |begin| onwards (inclusive) and before |end|.
// You may use a null Time value to do an unbounded search in either
// direction. The caller owns |forms| after the call.
// direction.
bool GetLoginsSyncedBetween(
base::Time begin,
base::Time end,
std::vector<autofill::PasswordForm*>* forms) const;
ScopedVector<autofill::PasswordForm>* forms) const;
// Loads the complete list of autofillable password forms (i.e., not blacklist
// entries) into |forms|. The caller owns |forms| after the call.
bool GetAutofillableLogins(std::vector<autofill::PasswordForm*>* forms) const;
// entries) into |forms|.
bool GetAutofillableLogins(ScopedVector<autofill::PasswordForm>* forms) const;
// Loads the complete list of blacklist forms into |forms|. The caller owns
// |forms| after the call.
bool GetBlacklistLogins(std::vector<autofill::PasswordForm*>* forms) const;
// Loads the complete list of blacklist forms into |forms|.
bool GetBlacklistLogins(ScopedVector<autofill::PasswordForm>* forms) const;
// Deletes the login database file on disk, and creates a new, empty database.
// This can be used after migrating passwords to some other store, to ensure
......@@ -144,7 +145,7 @@ class LoginDatabase {
// |forms|.
bool GetAllLoginsWithBlacklistSetting(
bool blacklisted,
std::vector<autofill::PasswordForm*>* forms) const;
ScopedVector<autofill::PasswordForm>* forms) const;
base::FilePath db_path_;
mutable sql::Connection db_;
......
......@@ -41,9 +41,9 @@ class MockPasswordStore : public PasswordStore {
MOCK_METHOD1(GetAutofillableLoginsImpl, void(GetLoginsRequest*));
MOCK_METHOD1(GetBlacklistLoginsImpl, void(GetLoginsRequest*));
MOCK_METHOD1(FillAutofillableLogins,
bool(std::vector<autofill::PasswordForm*>*));
bool(ScopedVector<autofill::PasswordForm>*));
MOCK_METHOD1(FillBlacklistLogins,
bool(std::vector<autofill::PasswordForm*>*));
bool(ScopedVector<autofill::PasswordForm>*));
MOCK_METHOD1(NotifyLoginsChanged, void(const PasswordStoreChangeList&));
PasswordStoreSync* GetSyncInterface() { return this; }
......
......@@ -145,7 +145,7 @@ void PasswordStore::GetLogins(const PasswordForm& form,
request->set_ignore_logins_cutoff(ignore_logins_cutoff);
ConsumerCallbackRunner callback_runner = base::Bind(
&PasswordStore::CopyAndForwardLoginsResult, this, base::Owned(request));
&PasswordStore::CopyAndForwardLoginsResult, base::Owned(request));
ScheduleTask(base::Bind(&PasswordStore::GetLoginsImpl, this, form,
prompt_policy, callback_runner));
}
......@@ -207,17 +207,18 @@ PasswordStore::GetBackgroundTaskRunner() {
return db_thread_runner_;
}
// static
void PasswordStore::ForwardLoginsResult(GetLoginsRequest* request) {
request->ApplyIgnoreLoginsCutoff();
request->ForwardResult();
}
// static
void PasswordStore::CopyAndForwardLoginsResult(
PasswordStore::GetLoginsRequest* request,
const std::vector<PasswordForm*>& matched_forms) {
// Copy the contents of |matched_forms| into the request. The request takes
// ownership of the PasswordForm elements.
*(request->result()) = matched_forms;
ScopedVector<autofill::PasswordForm> matched_forms) {
// Move the contents of |matched_forms| into the request.
request->result()->swap(matched_forms.get());
ForwardLoginsResult(request);
}
......
......@@ -11,6 +11,7 @@
#include "base/gtest_prod_util.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "base/observer_list_threadsafe.h"
#include "base/threading/thread.h"
#include "base/threading/thread_checker.h"
......@@ -223,8 +224,8 @@ class PasswordStore : protected PasswordStoreSync,
base::Time delete_begin,
base::Time delete_end) = 0;
typedef base::Callback<void(const std::vector<autofill::PasswordForm*>&)>
ConsumerCallbackRunner; // Owns all PasswordForms in the vector.
typedef base::Callback<void(ScopedVector<autofill::PasswordForm>)>
ConsumerCallbackRunner;
// Should find all PasswordForms with the same signon_realm. The results
// will then be scored by the PasswordFormManager. Once they are found
......@@ -241,7 +242,7 @@ class PasswordStore : protected PasswordStoreSync,
// Dispatches the result to the PasswordStoreConsumer on the original caller's
// thread so the callback can be executed there. This should be the UI thread.
virtual void ForwardLoginsResult(GetLoginsRequest* request);
static void ForwardLoginsResult(GetLoginsRequest* request);
// Log UMA stats for number of bulk deletions.
void LogStatsForBulkDeletion(int num_deletions);
......@@ -289,9 +290,9 @@ class PasswordStore : protected PasswordStoreSync,
// |ForwardLoginsResult|. Temporarily used as an adapter between the API of
// |GetLoginsImpl| and |PasswordStoreConsumer|.
// TODO(dubroy): Get rid of this.
void CopyAndForwardLoginsResult(
static void CopyAndForwardLoginsResult(
PasswordStore::GetLoginsRequest* request,
const std::vector<autofill::PasswordForm*>& matched_forms);
ScopedVector<autofill::PasswordForm> matched_forms);
#if defined(PASSWORD_MANAGER_ENABLE_SYNC)
// Creates PasswordSyncableService instance on the background thread.
......
......@@ -78,40 +78,36 @@ PasswordStoreChangeList PasswordStoreDefault::RemoveLoginImpl(
PasswordStoreChangeList PasswordStoreDefault::RemoveLoginsCreatedBetweenImpl(
base::Time delete_begin,
base::Time delete_end) {
std::vector<PasswordForm*> forms;
ScopedVector<autofill::PasswordForm> forms;
PasswordStoreChangeList changes;
if (login_db_ &&
login_db_->GetLoginsCreatedBetween(delete_begin, delete_end, &forms)) {
if (login_db_->RemoveLoginsCreatedBetween(delete_begin, delete_end)) {
for (std::vector<PasswordForm*>::const_iterator it = forms.begin();
it != forms.end(); ++it) {
for (const auto* form : forms) {
changes.push_back(
PasswordStoreChange(PasswordStoreChange::REMOVE, **it));
PasswordStoreChange(PasswordStoreChange::REMOVE, *form));
}
LogStatsForBulkDeletion(changes.size());
}
}
STLDeleteElements(&forms);
return changes;
}
PasswordStoreChangeList PasswordStoreDefault::RemoveLoginsSyncedBetweenImpl(
base::Time delete_begin,
base::Time delete_end) {
std::vector<PasswordForm*> forms;
ScopedVector<autofill::PasswordForm> forms;
PasswordStoreChangeList changes;
if (login_db_ &&
login_db_->GetLoginsSyncedBetween(delete_begin, delete_end, &forms)) {
if (login_db_->RemoveLoginsSyncedBetween(delete_begin, delete_end)) {
for (std::vector<PasswordForm*>::const_iterator it = forms.begin();
it != forms.end(); ++it) {
for (const auto* form : forms) {
changes.push_back(
PasswordStoreChange(PasswordStoreChange::REMOVE, **it));
PasswordStoreChange(PasswordStoreChange::REMOVE, *form));
}
LogStatsForBulkDeletionDuringRollback(changes.size());
}
}
STLDeleteElements(&forms);
return changes;
}
......@@ -119,31 +115,41 @@ void PasswordStoreDefault::GetLoginsImpl(
const autofill::PasswordForm& form,
AuthorizationPromptPolicy prompt_policy,
const ConsumerCallbackRunner& callback_runner) {
std::vector<PasswordForm*> matched_forms;
ScopedVector<autofill::PasswordForm> matched_forms;
if (login_db_)
login_db_->GetLogins(form, &matched_forms);
callback_runner.Run(matched_forms);
callback_runner.Run(matched_forms.Pass());
}
void PasswordStoreDefault::GetAutofillableLoginsImpl(
GetLoginsRequest* request) {
FillAutofillableLogins(request->result());
// TODO(vabr) -- request should have a ScopedVector<autofill::PasswordForm>
// instead of using |logins| here.
DCHECK(request->result()->empty());
ScopedVector<autofill::PasswordForm> logins;
FillAutofillableLogins(&logins);
logins.swap(*request->result());
ForwardLoginsResult(request);
}
void PasswordStoreDefault::GetBlacklistLoginsImpl(GetLoginsRequest* request) {
FillBlacklistLogins(request->result());
// TODO(vabr) -- request should have a ScopedVector<autofill::PasswordForm>
// instead of using |logins| here.
DCHECK(request->result()->empty());
ScopedVector<autofill::PasswordForm> logins;
FillBlacklistLogins(&logins);
logins.swap(*request->result());
ForwardLoginsResult(request);
}
bool PasswordStoreDefault::FillAutofillableLogins(
std::vector<PasswordForm*>* forms) {
ScopedVector<autofill::PasswordForm>* forms) {
DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread());
return login_db_ && login_db_->GetAutofillableLogins(forms);
}
bool PasswordStoreDefault::FillBlacklistLogins(
std::vector<PasswordForm*>* forms) {
ScopedVector<autofill::PasswordForm>* forms) {
DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread());
return login_db_ && login_db_->GetBlacklistLogins(forms);
}
......
......@@ -56,9 +56,9 @@ class PasswordStoreDefault : public PasswordStore {
void GetAutofillableLoginsImpl(GetLoginsRequest* request) override;
void GetBlacklistLoginsImpl(GetLoginsRequest* request) override;
bool FillAutofillableLogins(
std::vector<autofill::PasswordForm*>* forms) override;
ScopedVector<autofill::PasswordForm>* forms) override;
bool FillBlacklistLogins(
std::vector<autofill::PasswordForm*>* forms) override;
ScopedVector<autofill::PasswordForm>* forms) override;
protected:
inline bool DeleteAndRecreateDatabaseFile() {
......
......@@ -5,8 +5,7 @@
#ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_SYNC_INTERFACE_H_
#define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_SYNC_INTERFACE_H_
#include <vector>
#include "base/memory/scoped_vector.h"
#include "components/password_manager/core/browser/password_store_change.h"
namespace password_manager {
......@@ -19,11 +18,11 @@ class PasswordStoreSync {
public:
// Finds all non-blacklist PasswordForms, and fills the vector.
virtual bool FillAutofillableLogins(
std::vector<autofill::PasswordForm*>* forms) = 0;
ScopedVector<autofill::PasswordForm>* forms) = 0;
// Finds all blacklist PasswordForms, and fills the vector.
virtual bool FillBlacklistLogins(
std::vector<autofill::PasswordForm*>* forms) = 0;
ScopedVector<autofill::PasswordForm>* forms) = 0;
// Synchronous implementation to add the given login.
virtual PasswordStoreChangeList AddLoginImpl(
......
......@@ -303,8 +303,8 @@ bool PasswordSyncableService::ReadFromPasswordStore(
ScopedVector<autofill::PasswordForm>* password_entries,
PasswordEntryMap* passwords_entry_map) const {
DCHECK(password_entries);
if (!password_store_->FillAutofillableLogins(&password_entries->get()) ||
!password_store_->FillBlacklistLogins(&password_entries->get())) {
if (!password_store_->FillAutofillableLogins(password_entries) ||
!password_store_->FillBlacklistLogins(password_entries)) {
// Password store often fails to load passwords. Track failures with UMA.
// (http://crbug.com/249000)
UMA_HISTOGRAM_ENUMERATION("Sync.LocalDataFailedToLoad",
......
......@@ -98,14 +98,13 @@ void TestPasswordStore::GetLoginsImpl(
const autofill::PasswordForm& form,
PasswordStore::AuthorizationPromptPolicy prompt_policy,
const PasswordStore::ConsumerCallbackRunner& runner) {
std::vector<autofill::PasswordForm*> matched_forms;
ScopedVector<autofill::PasswordForm> matched_forms;
std::vector<autofill::PasswordForm> forms =
stored_passwords_[form.signon_realm];
for (std::vector<autofill::PasswordForm>::iterator it = forms.begin();
it != forms.end(); ++it) {
matched_forms.push_back(new autofill::PasswordForm(*it));
for (const auto& stored_form : forms) {
matched_forms.push_back(new autofill::PasswordForm(stored_form));
}
runner.Run(matched_forms);
runner.Run(matched_forms.Pass());
}
PasswordStoreChangeList TestPasswordStore::RemoveLoginsCreatedBetweenImpl(
......@@ -123,12 +122,12 @@ PasswordStoreChangeList TestPasswordStore::RemoveLoginsSyncedBetweenImpl(
}
bool TestPasswordStore::FillAutofillableLogins(
std::vector<autofill::PasswordForm*>* forms) {
ScopedVector<autofill::PasswordForm>* forms) {
return true;
}
bool TestPasswordStore::FillBlacklistLogins(
std::vector<autofill::PasswordForm*>* forms) {
ScopedVector<autofill::PasswordForm>* forms) {
return true;
}
......
......@@ -65,9 +65,9 @@ class TestPasswordStore : public PasswordStore {
void GetBlacklistLoginsImpl(
PasswordStore::GetLoginsRequest* request) override {}
bool FillAutofillableLogins(
std::vector<autofill::PasswordForm*>* forms) override;
ScopedVector<autofill::PasswordForm>* forms) override;
bool FillBlacklistLogins(
std::vector<autofill::PasswordForm*>* forms) override;
ScopedVector<autofill::PasswordForm>* forms) override;
private:
PasswordMap stored_passwords_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment