| Index: components/password_manager/core/browser/obsolete_http_cleaner.cc
|
| diff --git a/components/password_manager/core/browser/obsolete_http_cleaner.cc b/components/password_manager/core/browser/obsolete_http_cleaner.cc
|
| index c1daec4eddddc9b794bf1e859228efb673f4d06d..06536ddccf849566dee382f4d4863c71172b22f4 100644
|
| --- a/components/password_manager/core/browser/obsolete_http_cleaner.cc
|
| +++ b/components/password_manager/core/browser/obsolete_http_cleaner.cc
|
| @@ -9,6 +9,7 @@
|
| #include <tuple>
|
|
|
| #include "base/logging.h"
|
| +#include "base/memory/ref_counted.h"
|
| #include "components/autofill/core/common/password_form.h"
|
| #include "components/password_manager/core/browser/password_manager_client.h"
|
| #include "components/password_manager/core/browser/password_store.h"
|
| @@ -31,6 +32,20 @@ std::vector<std::unique_ptr<PasswordForm>> SplitFormsFrom(
|
| return result;
|
| }
|
|
|
| +void RemoveLoginIfHSTS(const scoped_refptr<PasswordStore>& store,
|
| + const PasswordForm& form,
|
| + bool is_hsts) {
|
| + if (is_hsts)
|
| + store->RemoveLogin(form);
|
| +}
|
| +
|
| +void RemoveSiteStatsIfHSTS(const scoped_refptr<PasswordStore>& store,
|
| + const InteractionsStats& stats,
|
| + bool is_hsts) {
|
| + if (is_hsts)
|
| + store->RemoveSiteStats(stats.origin_domain);
|
| +}
|
| +
|
| } // namespace
|
|
|
| ObsoleteHttpCleaner::ObsoleteHttpCleaner(const PasswordManagerClient* client)
|
| @@ -68,25 +83,19 @@ void ObsoleteHttpCleaner::OnGetPasswordStoreResults(
|
| // Remove blacklisted HTTP forms from the password store when HSTS is active
|
| // for the given host.
|
| for (const auto& form : blacklisted_http_forms) {
|
| - if (client_->IsHSTSActiveForHost(form->origin))
|
| - client_->GetPasswordStore()->RemoveLogin(*form);
|
| + client_->PostHSTSQueryForHost(
|
| + form->origin,
|
| + base::Bind(RemoveLoginIfHSTS,
|
| + make_scoped_refptr(client_->GetPasswordStore()), *form));
|
| }
|
|
|
| // Return early if there are no non-blacklisted HTTP forms.
|
| if (results.empty())
|
| return;
|
|
|
| - // Ignore non HSTS forms.
|
| - https_forms.erase(
|
| - std::remove_if(std::begin(https_forms), std::end(https_forms),
|
| - [this](const std::unique_ptr<PasswordForm>& form) {
|
| - return !client_->IsHSTSActiveForHost(form->origin);
|
| - }),
|
| - std::end(https_forms));
|
| -
|
| - // Sort HSTS forms according to custom comparison function. Consider two forms
|
| - // equivalent if they have the same host, as well as the same username and
|
| - // password.
|
| + // Sort HTTPS forms according to custom comparison function. Consider two
|
| + // forms equivalent if they have the same host, as well as the same username
|
| + // and password.
|
| const auto form_cmp = [](const std::unique_ptr<PasswordForm>& lhs,
|
| const std::unique_ptr<PasswordForm>& rhs) {
|
| return std::forward_as_tuple(lhs->origin.host_piece(), lhs->username_value,
|
| @@ -98,20 +107,27 @@ void ObsoleteHttpCleaner::OnGetPasswordStoreResults(
|
| std::sort(std::begin(https_forms), std::end(https_forms), form_cmp);
|
|
|
| // Iterate through HTTP forms and remove them from the password store if there
|
| - // exists an equivalent HSTS form.
|
| + // exists an equivalent HTTPS form that has HSTS enabled.
|
| for (const auto& form : results) {
|
| if (std::binary_search(std::begin(https_forms), std::end(https_forms), form,
|
| - form_cmp))
|
| - client_->GetPasswordStore()->RemoveLogin(*form);
|
| + form_cmp)) {
|
| + client_->PostHSTSQueryForHost(
|
| + form->origin,
|
| + base::Bind(RemoveLoginIfHSTS,
|
| + make_scoped_refptr(client_->GetPasswordStore()), *form));
|
| + }
|
| }
|
| }
|
|
|
| void ObsoleteHttpCleaner::OnGetSiteStatistics(
|
| std::vector<InteractionsStats> stats) {
|
| for (const auto& stat : stats) {
|
| - if (stat.origin_domain.SchemeIs(url::kHttpScheme) &&
|
| - client_->IsHSTSActiveForHost(stat.origin_domain))
|
| - client_->GetPasswordStore()->RemoveSiteStats(stat.origin_domain);
|
| + if (stat.origin_domain.SchemeIs(url::kHttpScheme)) {
|
| + client_->PostHSTSQueryForHost(
|
| + stat.origin_domain,
|
| + base::Bind(RemoveSiteStatsIfHSTS,
|
| + make_scoped_refptr(client_->GetPasswordStore()), stat));
|
| + }
|
| }
|
| }
|
|
|
|
|