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

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

Issue 2754043002: Introduce FormFetcher::Clone (Closed)
Patch Set: Fix stats test Created 3 years, 9 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 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 a869f2bfcb4df3ac4ee16b6181171d7cad09b10c..91b29c708e0e436d4c1a5017a29db134e2c4694c 100644
--- a/components/password_manager/core/browser/form_fetcher_impl.cc
+++ b/components/password_manager/core/browser/form_fetcher_impl.cc
@@ -7,6 +7,7 @@
#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"
@@ -56,6 +57,18 @@ std::vector<const PasswordForm*> MakeWeakCopies(
return result;
}
+// Create a vector of unique_ptr<PasswordForm> from another such vector by
+// copying the pointed-to forms.
+std::vector<std::unique_ptr<PasswordForm>> MakeCopies(
+ const std::vector<std::unique_ptr<PasswordForm>>& source) {
+ std::vector<std::unique_ptr<PasswordForm>> result(source.size());
+ std::transform(source.begin(), source.end(), result.begin(),
+ [](const std::unique_ptr<PasswordForm>& ptr) {
+ return base::MakeUnique<PasswordForm>(*ptr);
+ });
+ return result;
+}
+
} // namespace
FormFetcherImpl::FormFetcherImpl(PasswordStore::FormDigest form_digest,
@@ -165,6 +178,28 @@ void FormFetcherImpl::Fetch() {
#endif
}
+std::unique_ptr<FormFetcher> FormFetcherImpl::Clone() {
+ DCHECK_EQ(State::NOT_WAITING, state_);
+
+ // Create the copy without the "HTTPS migration" activated. If it was needed,
+ // then it was done by |this| already.
+ auto result = base::MakeUnique<FormFetcherImpl>(form_digest_, client_, false);
+
+ result->non_federated_ = MakeCopies(this->non_federated_);
+ result->federated_ = MakeCopies(this->federated_);
+ result->interactions_stats_ = this->interactions_stats_;
+
+ result->weak_non_federated_ = MakeWeakCopies(result->non_federated_);
+ result->weak_federated_ = MakeWeakCopies(result->federated_);
+
+ result->filtered_count_ = this->filtered_count_;
+ result->state_ = this->state_;
+ result->need_to_refetch_ = this->need_to_refetch_;
+
+ // Move needed for upcasting.
+ return std::move(result);
+}
+
void FormFetcherImpl::ProcessPasswordStoreResults(
std::vector<std::unique_ptr<autofill::PasswordForm>> results) {
DCHECK_EQ(State::WAITING, state_);

Powered by Google App Engine
This is Rietveld 408576698