Commit 95c315a2 authored by sczs's avatar sczs Committed by Commit Bot

Creates UpdatePasswordFormUsernameAndPassword util function.

- Creates an UpdatePasswordFormUsernameAndPassword util function
which updates the FormManager Username and password.
- It should be used when editing these values on the Bubble in
desktop and on the Modal Infobar on Mobile.

Bug: 945478
Change-Id: I990c5983a34e33a67c75a1db662226a2a7e3b10f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1560448Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#649892}
parent d228a5e6
......@@ -35,6 +35,7 @@
#include "components/password_manager/core/browser/password_bubble_experiment.h"
#include "components/password_manager/core/browser/password_form_manager_for_ui.h"
#include "components/password_manager/core/browser/password_manager_constants.h"
#include "components/password_manager/core/browser/password_ui_utils.h"
#include "components/password_manager/core/browser/statistics_table.h"
#include "components/password_manager/core/common/credential_manager_types.h"
#include "content/public/browser/navigation_handle.h"
......@@ -390,35 +391,9 @@ void ManagePasswordsUIController::OnPasswordsRevealed() {
void ManagePasswordsUIController::SavePassword(const base::string16& username,
const base::string16& password) {
const auto& pending_credentials =
passwords_data_.form_manager()->GetPendingCredentials();
bool username_edited = pending_credentials.username_value != username;
bool password_changed = pending_credentials.password_value != password;
if (username_edited) {
passwords_data_.form_manager()->UpdateUsername(username);
if (GetPasswordFormMetricsRecorder()) {
GetPasswordFormMetricsRecorder()->RecordDetailedUserAction(
password_manager::PasswordFormMetricsRecorder::DetailedUserAction::
kEditedUsernameInBubble);
}
}
if (password_changed) {
passwords_data_.form_manager()->UpdatePasswordValue(password);
if (GetPasswordFormMetricsRecorder()) {
GetPasswordFormMetricsRecorder()->RecordDetailedUserAction(
password_manager::PasswordFormMetricsRecorder::DetailedUserAction::
kSelectedDifferentPasswordInBubble);
}
}
UpdatePasswordFormUsernameAndPassword(username, password,
passwords_data_.form_manager());
// Values of this histogram are a bit mask. Only the lower two bits are used:
// 0001 to indicate that the user has edited the username in the password
// save bubble.
// 0010 to indicate that the user has changed the password in the password
// save bubble.
// The maximum possible value is defined by OR-ing these values.
UMA_HISTOGRAM_ENUMERATION("PasswordManager.EditsInSaveBubble",
username_edited + 2 * password_changed, 4);
UMA_HISTOGRAM_BOOLEAN("PasswordManager.PasswordSavedWithManualFallback",
BubbleIsManualFallbackForSaving());
if (GetPasswordFormMetricsRecorder() && BubbleIsManualFallbackForSaving()) {
......
......@@ -8,11 +8,14 @@
#include <string>
#include <vector>
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "components/autofill/core/common/password_form.h"
#include "components/password_manager/core/browser/android_affiliation/affiliation_utils.h"
#include "components/password_manager/core/browser/password_form_manager_for_ui.h"
#include "components/password_manager/core/browser/password_form_metrics_recorder.h"
#include "components/url_formatter/elide_url.h"
namespace password_manager {
......@@ -71,4 +74,38 @@ std::string GetShownOrigin(const GURL& origin) {
: original;
}
void UpdatePasswordFormUsernameAndPassword(
const base::string16& username,
const base::string16& password,
PasswordFormManagerForUI* form_manager) {
const auto& pending_credentials = form_manager->GetPendingCredentials();
bool username_edited = pending_credentials.username_value != username;
bool password_changed = pending_credentials.password_value != password;
if (username_edited) {
form_manager->UpdateUsername(username);
if (form_manager->GetMetricsRecorder()) {
form_manager->GetMetricsRecorder()->RecordDetailedUserAction(
password_manager::PasswordFormMetricsRecorder::DetailedUserAction::
kEditedUsernameInBubble);
}
}
if (password_changed) {
form_manager->UpdatePasswordValue(password);
if (form_manager->GetMetricsRecorder()) {
form_manager->GetMetricsRecorder()->RecordDetailedUserAction(
password_manager::PasswordFormMetricsRecorder::DetailedUserAction::
kSelectedDifferentPasswordInBubble);
}
}
// Values of this histogram are a bit mask. Only the lower two bits are used:
// 0001 to indicate that the user has edited the username in the password save
// bubble.
// 0010 to indicate that the user has changed the password in the
// password save bubble.
// The maximum possible value is defined by OR-ing these values.
UMA_HISTOGRAM_ENUMERATION("PasswordManager.EditsInSaveBubble",
username_edited + 2 * password_changed, 4);
}
} // namespace password_manager
......@@ -20,6 +20,8 @@ struct PasswordForm;
namespace password_manager {
class PasswordFormManagerForUI;
// Reverses order of labels in hostname.
std::string SplitByDotAndReverse(base::StringPiece host);
......@@ -41,6 +43,13 @@ std::pair<std::string, GURL> GetShownOriginAndLinkUrl(
// |password_form|) and without prefixes "m.", "mobile." or "www.".
std::string GetShownOrigin(const GURL& origin);
// Updates the |form_manager| pending credentials with |username| and
// |password|.
void UpdatePasswordFormUsernameAndPassword(
const base::string16& username,
const base::string16& password,
PasswordFormManagerForUI* form_manager);
} // namespace password_manager
#endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_UI_UTILS_H_
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