Commit c455f43c authored by Vaclav Brozek's avatar Vaclav Brozek Committed by Commit Bot

No static destructors in IsCreditCardVerificationPasswordField

Currently, IsCreditCardVerificationPasswordField creates a static
string16 object. That involves a static destructor, which is forbidden
by the style guide:
https://google.github.io/styleguide/cppguide.html#Static_and_Global_Variables

This CL fixes that by using base::NoDestructor. It also restructures the
function slightly.

There should be no visible change caused by this CL.

Bug: 833838
Change-Id: Id879c5595113aae295e858bebf6cacc7f211b373
Reviewed-on: https://chromium-review.googlesource.com/1028272
Commit-Queue: Vaclav Brozek <vabr@chromium.org>
Reviewed-by: default avatarSebastien Seguin-Gagnon <sebsg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553797}
parent 68832129
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.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"
#include "base/strings/string_split.h" #include "base/strings/string_split.h"
...@@ -456,6 +457,13 @@ bool ScriptModifiedUsernameAcceptable( ...@@ -456,6 +457,13 @@ bool ScriptModifiedUsernameAcceptable(
return false; return false;
} }
bool StringMatchesCVC(const base::string16& str) {
static const base::NoDestructor<base::string16> kCardCvcReCached(
base::UTF8ToUTF16(kCardCvcRe));
return MatchesPattern(str, *kCardCvcReCached);
}
// Get information about a login form encapsulated in a PasswordForm struct. // Get information about a login form encapsulated in a PasswordForm struct.
// If an element of |form| has an entry in |nonscript_modified_values|, the // If an element of |form| has an entry in |nonscript_modified_values|, the
// associated string is used instead of the element's value to create // associated string is used instead of the element's value to create
...@@ -974,11 +982,8 @@ bool IsCreditCardVerificationPasswordField( ...@@ -974,11 +982,8 @@ bool IsCreditCardVerificationPasswordField(
const blink::WebInputElement& field) { const blink::WebInputElement& field) {
if (!field.IsPasswordFieldForAutofill()) if (!field.IsPasswordFieldForAutofill())
return false; return false;
return StringMatchesCVC(field.GetAttribute("id").Utf16()) ||
static const base::string16 kCardCvcReCached = base::UTF8ToUTF16(kCardCvcRe); StringMatchesCVC(field.GetAttribute("name").Utf16());
return MatchesPattern(field.GetAttribute("id").Utf16(), kCardCvcReCached) ||
MatchesPattern(field.GetAttribute("name").Utf16(), kCardCvcReCached);
} }
std::string GetSignOnRealm(const GURL& origin) { std::string GetSignOnRealm(const GURL& origin) {
......
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