Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / passwords / password_bubble_experiment.cc
blob8afabfcaee87a94f2ed4c0429427e1781844b48c
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 {
15 namespace {
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);
23 } // namespace
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))
37 return false;
38 std::string param =
39 variations::GetVariationParamValue(kExperimentName, kParamNopeThreshold);
41 int threshold = 0;
42 return base::StringToInt(param, &threshold) &&
43 GetCurrentNopesCount(prefs) >= threshold;
46 void RecordBubbleClosed(
47 PrefService* prefs,
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)
51 return;
52 int nopes_count = GetCurrentNopesCount(prefs);
53 if (reason == password_manager::metrics_util::CLICKED_NOPE)
54 nopes_count++;
55 else
56 nopes_count = 0;
57 prefs->SetInteger(prefs::kPasswordBubbleNopesCount, nopes_count);
60 } // namespace password_bubble_experiment