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

Unified Diff: components/password_manager/core/browser/form_fetcher_impl.cc

Issue 2263933002: Make FormFetcher a PasswordStoreConsumer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@621355_form_fetcher
Patch Set: Also operator= is now default Created 4 years 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 side-by-side diff with in-line comments
Download patch
Index: components/password_manager/core/browser/form_fetcher_impl.cc
diff --git a/components/password_manager/core/browser/form_fetcher_impl.cc b/components/password_manager/core/browser/form_fetcher_impl.cc
index 0266bd1966ff6976ce652040ef9f8c24141509fe..f40d40b833b5de4146c48c73e1245400d31d80f7 100644
--- a/components/password_manager/core/browser/form_fetcher_impl.cc
+++ b/components/password_manager/core/browser/form_fetcher_impl.cc
@@ -7,16 +7,21 @@
#include <algorithm>
#include <utility>
-#include "base/memory/ptr_util.h"
#include "build/build_config.h"
#include "components/autofill/core/common/password_form.h"
+#include "components/password_manager/core/browser/browser_save_password_progress_logger.h"
#include "components/password_manager/core/browser/credentials_filter.h"
#include "components/password_manager/core/browser/password_manager_client.h"
+#include "components/password_manager/core/browser/password_manager_util.h"
#include "components/password_manager/core/browser/password_store.h"
#include "components/password_manager/core/browser/statistics_table.h"
using autofill::PasswordForm;
+// Shorten the name to spare line breaks. The code provides enough context
+// already.
+using Logger = autofill::SavePasswordProgressLogger;
+
namespace password_manager {
namespace {
@@ -53,8 +58,9 @@ std::vector<const T*> MakeWeakCopies(
} // namespace
-FormFetcherImpl::FormFetcherImpl(const PasswordManagerClient* client)
- : client_(client) {}
+FormFetcherImpl::FormFetcherImpl(PasswordStore::FormDigest form_digest,
+ const PasswordManagerClient* client)
+ : form_digest_(std::move(form_digest)), client_(client) {}
FormFetcherImpl::~FormFetcherImpl() = default;
@@ -79,9 +85,25 @@ FormFetcherImpl::GetFederatedMatches() const {
return weak_federated_;
}
-void FormFetcherImpl::SetResults(
+void FormFetcherImpl::OnGetPasswordStoreResults(
std::vector<std::unique_ptr<autofill::PasswordForm>> results) {
DCHECK_EQ(State::WAITING, state_);
+ state_ = State::NOT_WAITING;
+
+ if (need_to_refetch_) {
+ // The received results are no longer up to date, need to re-request.
+ Fetch();
+ need_to_refetch_ = false;
+ return;
+ }
+
+ std::unique_ptr<BrowserSavePasswordProgressLogger> logger;
+ if (password_manager_util::IsLoggingActive(client_)) {
+ logger.reset(
+ new BrowserSavePasswordProgressLogger(client_->GetLogManager()));
+ logger->LogMessage(Logger::STRING_ON_GET_STORE_RESULTS_METHOD);
+ logger->LogNumber(Logger::STRING_NUMBER_RESULTS, results.size());
+ }
federated_ = SplitFederatedMatches(&results);
non_federated_ = std::move(results);
@@ -96,16 +118,51 @@ void FormFetcherImpl::SetResults(
weak_non_federated_ = MakeWeakCopies(non_federated_);
weak_federated_ = MakeWeakCopies(federated_);
- state_ = State::NOT_WAITING;
-
for (Consumer* consumer : consumers_)
consumer->ProcessMatches(weak_non_federated_, filtered_count_);
}
-void FormFetcherImpl::SetStats(
+void FormFetcherImpl::OnGetSiteStatistics(
std::vector<std::unique_ptr<InteractionsStats>> stats) {
+ // On Windows the password request may be resolved after the statistics due to
+ // importing from IE.
interactions_stats_ = std::move(stats);
weak_interactions_stats_ = MakeWeakCopies(interactions_stats_);
}
+void FormFetcherImpl::Fetch() {
+ std::unique_ptr<BrowserSavePasswordProgressLogger> logger;
+ if (password_manager_util::IsLoggingActive(client_)) {
+ logger.reset(
+ new BrowserSavePasswordProgressLogger(client_->GetLogManager()));
+ logger->LogMessage(Logger::STRING_FETCH_METHOD);
+ logger->LogNumber(Logger::STRING_FORM_FETCHER_STATE,
+ static_cast<int>(state_));
+ }
+
+ if (state_ == State::WAITING) {
+ // There is currently a password store query in progress, need to re-fetch
+ // store results later.
+ need_to_refetch_ = true;
+ return;
+ }
+
+ PasswordStore* password_store = client_->GetPasswordStore();
+ if (!password_store) {
+ if (logger)
+ logger->LogMessage(Logger::STRING_NO_STORE);
+ NOTREACHED();
+ return;
+ }
+ state_ = State::WAITING;
+ password_store->GetLogins(form_digest_, this);
+
+// The statistics isn't needed on mobile, only on desktop. Let's save some
+// processor cycles.
+#if !defined(OS_IOS) && !defined(OS_ANDROID)
+ // The statistics is needed for the "Save password?" bubble.
+ password_store->GetSiteStats(form_digest_.origin.GetOrigin(), this);
+#endif
+}
+
} // namespace password_manager

Powered by Google App Engine
This is Rietveld 408576698