Commit b42590ac authored by Mohamed Amir Yosef's avatar Mohamed Amir Yosef Committed by Commit Bot

[Passwords] Introduce FormFetcherImpl::SplitResults()

This CL simplifies the implementation for further reuse in the
MultiStoreFormFetcher

Change-Id: Id0cc669b3bde5bcd3666727170da075e9cba0d64
Bug: 1002000
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1796354Reviewed-by: default avatarVadym Doroshenko <dvadym@chromium.org>
Commit-Queue: Mohamed Amir Yosef <mamir@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695645}
parent 34d71b12
...@@ -29,39 +29,6 @@ namespace password_manager { ...@@ -29,39 +29,6 @@ namespace password_manager {
namespace { namespace {
struct SplitMatches {
std::vector<std::unique_ptr<PasswordForm>> non_federated;
std::vector<std::unique_ptr<PasswordForm>> federated;
std::vector<std::unique_ptr<PasswordForm>> blacklisted;
};
// Partitions |results| into |-- non federated -|- federated -|- blacklisted --|
// and returns result.
SplitMatches SplitResults(std::vector<std::unique_ptr<PasswordForm>> results) {
const auto first_blacklisted = std::partition(
results.begin(), results.end(),
[](const auto& form) { return !form->blacklisted_by_user; });
const auto first_federated =
std::partition(results.begin(), first_blacklisted, [](const auto& form) {
return form->federation_origin.opaque(); // False means federated.
});
// Ignore PSL matches for blacklisted entries.
const auto first_blacklisted_psl = std::partition(
first_blacklisted, results.end(),
[](const auto& form) { return !form->is_public_suffix_match; });
SplitMatches matches;
matches.non_federated.assign(std::make_move_iterator(results.begin()),
std::make_move_iterator(first_federated));
matches.federated.assign(std::make_move_iterator(first_federated),
std::make_move_iterator(first_blacklisted));
matches.blacklisted.assign(std::make_move_iterator(first_blacklisted),
std::make_move_iterator(first_blacklisted_psl));
return matches;
}
// Create a vector of const PasswordForm from a vector of // Create a vector of const PasswordForm from a vector of
// unique_ptr<PasswordForm> by applying get() item-wise. // unique_ptr<PasswordForm> by applying get() item-wise.
std::vector<const PasswordForm*> MakeWeakCopies( std::vector<const PasswordForm*> MakeWeakCopies(
...@@ -252,10 +219,7 @@ void FormFetcherImpl::ProcessPasswordStoreResults( ...@@ -252,10 +219,7 @@ void FormFetcherImpl::ProcessPasswordStoreResults(
std::vector<std::unique_ptr<PasswordForm>> results) { std::vector<std::unique_ptr<PasswordForm>> results) {
DCHECK_EQ(State::WAITING, state_); DCHECK_EQ(State::WAITING, state_);
state_ = State::NOT_WAITING; state_ = State::NOT_WAITING;
SplitMatches matches = SplitResults(std::move(results)); SplitResults(std::move(results));
federated_ = std::move(matches.federated);
non_federated_ = std::move(matches.non_federated);
blacklisted_ = std::move(matches.blacklisted);
password_manager_util::FindBestMatches( password_manager_util::FindBestMatches(
MakeWeakCopies(non_federated_), form_digest_.scheme, MakeWeakCopies(non_federated_), form_digest_.scheme,
...@@ -265,4 +229,23 @@ void FormFetcherImpl::ProcessPasswordStoreResults( ...@@ -265,4 +229,23 @@ void FormFetcherImpl::ProcessPasswordStoreResults(
consumer->OnFetchCompleted(); consumer->OnFetchCompleted();
} }
void FormFetcherImpl::SplitResults(
std::vector<std::unique_ptr<PasswordForm>> forms) {
blacklisted_.clear();
non_federated_.clear();
federated_.clear();
for (auto& form : forms) {
if (form->blacklisted_by_user) {
// Ignore PSL matches for blacklisted entries.
if (!form->is_public_suffix_match) {
blacklisted_.push_back(std::move(form));
}
} else if (form->IsFederatedCredential()) {
federated_.push_back(std::move(form));
} else {
non_federated_.push_back(std::move(form));
}
}
}
} // namespace password_manager } // namespace password_manager
...@@ -68,6 +68,10 @@ class FormFetcherImpl : public FormFetcher, ...@@ -68,6 +68,10 @@ class FormFetcherImpl : public FormFetcher,
std::vector<std::unique_ptr<autofill::PasswordForm>> forms) override; std::vector<std::unique_ptr<autofill::PasswordForm>> forms) override;
private: private:
// Splits |results| into |federated_|, |non_federated_| and |blacklisted_|.
void SplitResults(
std::vector<std::unique_ptr<autofill::PasswordForm>> results);
// Processes password form results and forwards them to the |consumers_|. // Processes password form results and forwards them to the |consumers_|.
void ProcessPasswordStoreResults( void ProcessPasswordStoreResults(
std::vector<std::unique_ptr<autofill::PasswordForm>> results); std::vector<std::unique_ptr<autofill::PasswordForm>> results);
......
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