1 // Copyright 2014 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 "chrome/browser/ui/passwords/password_bubble_experiment.h"
7 #include "base/metrics/field_trial.h"
8 #include "base/prefs/pref_service.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "chrome/common/pref_names.h"
11 #include "components/pref_registry/pref_registry_syncable.h"
12 #include "components/variations/variations_associated_data.h"
14 namespace password_bubble_experiment
{
17 // Return the number of consecutive times the user clicked "Not now" in the
18 // "Save password" bubble.
19 int GetCurrentNopesCount(PrefService
* prefs
) {
20 return prefs
->GetInteger(prefs::kPasswordBubbleNopesCount
);
25 const char kExperimentName
[] = "PasswordBubbleAlgorithm";
26 const char kParamNopeThreshold
[] = "consecutive_nope_threshold";
28 void RegisterPrefs(user_prefs::PrefRegistrySyncable
* registry
) {
29 registry
->RegisterIntegerPref(
30 prefs::kPasswordBubbleNopesCount
,
32 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
35 bool ShouldShowNeverForThisSiteDefault(PrefService
* prefs
) {
36 if (!base::FieldTrialList::TrialExists(kExperimentName
))
39 variations::GetVariationParamValue(kExperimentName
, kParamNopeThreshold
);
42 return base::StringToInt(param
, &threshold
) &&
43 GetCurrentNopesCount(prefs
) >= threshold
;
46 void RecordBubbleClosed(
48 password_manager::metrics_util::UIDismissalReason reason
) {
49 // Clicking "Never" doesn't change the experiment state.
50 if (reason
== password_manager::metrics_util::CLICKED_NEVER
)
52 int nopes_count
= GetCurrentNopesCount(prefs
);
53 if (reason
== password_manager::metrics_util::CLICKED_NOPE
)
57 prefs
->SetInteger(prefs::kPasswordBubbleNopesCount
, nopes_count
);
60 } // namespace password_bubble_experiment