1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/autofill/core/common/password_generation_util.h"
7 #include "base/command_line.h"
8 #include "base/metrics/field_trial.h"
9 #include "base/metrics/histogram_macros.h"
10 #include "components/autofill/core/common/autofill_switches.h"
13 namespace password_generation
{
15 PasswordGenerationActions::PasswordGenerationActions()
16 : learn_more_visited(false),
17 password_accepted(false),
18 password_edited(false),
19 password_regenerated(false) {
22 PasswordGenerationActions::~PasswordGenerationActions() {
25 void LogUserActions(PasswordGenerationActions actions
) {
26 UserAction action
= IGNORE_FEATURE
;
27 if (actions
.password_accepted
) {
28 if (actions
.password_edited
)
29 action
= ACCEPT_AFTER_EDITING
;
31 action
= ACCEPT_ORIGINAL_PASSWORD
;
32 } else if (actions
.learn_more_visited
) {
35 UMA_HISTOGRAM_ENUMERATION("PasswordGeneration.UserActions",
36 action
, ACTION_ENUM_COUNT
);
39 void LogPasswordGenerationEvent(PasswordGenerationEvent event
) {
40 UMA_HISTOGRAM_ENUMERATION("PasswordGeneration.Event",
41 event
, EVENT_ENUM_COUNT
);
44 bool IsPasswordGenerationEnabled() {
45 // Always fetch the field trial group to ensure it is reported correctly.
46 // The command line flags will be associated with a group that is reported
47 // so long as trial is actually queried.
48 std::string group_name
=
49 base::FieldTrialList::FindFullName("PasswordGeneration");
51 base::CommandLine
* command_line
= base::CommandLine::ForCurrentProcess();
52 if (command_line
->HasSwitch(switches::kDisablePasswordGeneration
))
55 if (command_line
->HasSwitch(switches::kEnablePasswordGeneration
))
58 return group_name
!= "Disabled";
61 } // namespace password_generation
62 } // namespace autofill