Commit 95541d1e authored by Jan Wilken Dörrie's avatar Jan Wilken Dörrie Committed by Commit Bot

[Passwords] Shorten name of UsernameDetectionMethod in Form Parser

The name of the `username_detection_method` variable in form_parser.cc
is unnecessarily long for the scope it is defined in and results in
unnecessary line breaks (see also go/longnamesarelong). This change
fixes this, and also performs a small clean-up on the histogram logging
code.

Bug: None
Change-Id: I72164f113efbdfbd24d42234bd145cc01582d84d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2214544
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Commit-Queue: Friedrich [CET] <fhorschig@chromium.org>
Auto-Submit: Jan Wilken Dörrie <jdoerrie@chromium.org>
Reviewed-by: default avatarFriedrich [CET] <fhorschig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771562}
parent a86933f3
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_functions.h"
#include "base/no_destructor.h" #include "base/no_destructor.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
...@@ -1027,27 +1027,23 @@ std::unique_ptr<PasswordForm> FormDataParser::Parse(const FormData& form_data, ...@@ -1027,27 +1027,23 @@ std::unique_ptr<PasswordForm> FormDataParser::Parse(const FormData& form_data,
return nullptr; return nullptr;
SignificantFields significant_fields; SignificantFields significant_fields;
UsernameDetectionMethod username_detection_method = UsernameDetectionMethod method = UsernameDetectionMethod::kNoUsernameDetected;
UsernameDetectionMethod::kNoUsernameDetected;
// (1) First, try to parse with server predictions. // (1) First, try to parse with server predictions.
if (predictions_) { if (predictions_) {
ParseUsingPredictions(&processed_fields, *predictions_, mode, ParseUsingPredictions(&processed_fields, *predictions_, mode,
&significant_fields); &significant_fields);
if (significant_fields.username) { if (significant_fields.username) {
username_detection_method = method = UsernameDetectionMethod::kServerSidePrediction;
UsernameDetectionMethod::kServerSidePrediction;
} }
} }
// (2) If that failed, try to parse with autocomplete attributes. // (2) If that failed, try to parse with autocomplete attributes.
if (!significant_fields.is_single_username) { if (!significant_fields.is_single_username) {
ParseUsingAutocomplete(processed_fields, &significant_fields); ParseUsingAutocomplete(processed_fields, &significant_fields);
if (username_detection_method == if (method == UsernameDetectionMethod::kNoUsernameDetected &&
UsernameDetectionMethod::kNoUsernameDetected &&
significant_fields.username) { significant_fields.username) {
username_detection_method = method = UsernameDetectionMethod::kAutocompleteAttribute;
UsernameDetectionMethod::kAutocompleteAttribute;
} }
} }
...@@ -1067,10 +1063,9 @@ std::unique_ptr<PasswordForm> FormDataParser::Parse(const FormData& form_data, ...@@ -1067,10 +1063,9 @@ std::unique_ptr<PasswordForm> FormDataParser::Parse(const FormData& form_data,
Interactability username_max = Interactability::kUnlikely; Interactability username_max = Interactability::kUnlikely;
ParseUsingBaseHeuristics(processed_fields, mode, &significant_fields, ParseUsingBaseHeuristics(processed_fields, mode, &significant_fields,
&username_max, &readonly_status_); &username_max, &readonly_status_);
if (username_detection_method == if (method == UsernameDetectionMethod::kNoUsernameDetected &&
UsernameDetectionMethod::kNoUsernameDetected &&
significant_fields.username) { significant_fields.username) {
username_detection_method = UsernameDetectionMethod::kBaseHeuristic; method = UsernameDetectionMethod::kBaseHeuristic;
} }
// Additionally, and based on the best interactability computed by base // Additionally, and based on the best interactability computed by base
...@@ -1085,20 +1080,16 @@ std::unique_ptr<PasswordForm> FormDataParser::Parse(const FormData& form_data, ...@@ -1085,20 +1080,16 @@ std::unique_ptr<PasswordForm> FormDataParser::Parse(const FormData& form_data,
!(mode == FormDataParser::Mode::kSaving && !(mode == FormDataParser::Mode::kSaving &&
username_field_by_context->value.empty())) { username_field_by_context->value.empty())) {
significant_fields.username = username_field_by_context; significant_fields.username = username_field_by_context;
if (username_detection_method == if (method == UsernameDetectionMethod::kNoUsernameDetected ||
UsernameDetectionMethod::kNoUsernameDetected || method == UsernameDetectionMethod::kBaseHeuristic) {
username_detection_method == method = UsernameDetectionMethod::kHtmlBasedClassifier;
UsernameDetectionMethod::kBaseHeuristic) {
username_detection_method =
UsernameDetectionMethod::kHtmlBasedClassifier;
} }
} }
} }
} }
UMA_HISTOGRAM_ENUMERATION("PasswordManager.UsernameDetectionMethod", base::UmaHistogramEnumeration("PasswordManager.UsernameDetectionMethod",
username_detection_method, method);
UsernameDetectionMethod::kCount);
return AssemblePasswordForm(form_data, significant_fields, return AssemblePasswordForm(form_data, significant_fields,
std::move(all_possible_passwords), std::move(all_possible_passwords),
......
...@@ -39,7 +39,7 @@ class FormDataParser { ...@@ -39,7 +39,7 @@ class FormDataParser {
kHtmlBasedClassifier = 2, kHtmlBasedClassifier = 2,
kAutocompleteAttribute = 3, kAutocompleteAttribute = 3,
kServerSidePrediction = 4, kServerSidePrediction = 4,
kCount kMaxValue = kServerSidePrediction,
}; };
// Records whether password fields with a "readonly" attribute were ignored // Records whether password fields with a "readonly" attribute were ignored
......
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