| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/passwords/password_bubble_experiment.h" | 5 #include "chrome/browser/ui/passwords/password_bubble_experiment.h" |
| 6 | 6 |
| 7 #include "base/metrics/field_trial.h" | 7 #include "base/metrics/field_trial.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
| 11 #include "components/pref_registry/pref_registry_syncable.h" | 11 #include "components/pref_registry/pref_registry_syncable.h" |
| 12 #include "components/variations/variations_associated_data.h" | 12 #include "components/variations/variations_associated_data.h" |
| 13 | 13 |
| 14 namespace password_bubble_experiment { | 14 namespace password_bubble_experiment { |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 // Return the number of consecutive times the user clicked "Not now" in the | 17 // Return the number of consecutive times the user clicked "Not now" in the |
| 18 // "Save password" bubble. | 18 // "Save password" bubble. |
| 19 int GetCurrentNopesCount(PrefService* prefs) { | 19 int GetCurrentNopesCount(PrefService* prefs) { |
| 20 return prefs->GetInteger(prefs::kPasswordBubbleNopesCount); | 20 return prefs->GetInteger(prefs::kPasswordBubbleNopesCount); |
| 21 } | 21 } |
| 22 | 22 |
| 23 } // namespace | 23 } // namespace |
| 24 | 24 |
| 25 const char kExperimentName[] = "PasswordBubbleAlgorithm"; | 25 const char kExperimentName[] = "PasswordBubbleAlgorithm"; |
| 26 const char kParamNopeThreshold[] = "consecutive_nope_threshold"; | 26 const char kParamNopeThreshold[] = "consecutive_nope_threshold"; |
| 27 | 27 |
| 28 void RegisterPrefs(user_prefs::PrefRegistrySyncable* registry) { | 28 void RegisterPrefs(user_prefs::PrefRegistrySyncable* registry) { |
| 29 registry->RegisterIntegerPref( | 29 registry->RegisterIntegerPref(prefs::kPasswordBubbleNopesCount, 0); |
| 30 prefs::kPasswordBubbleNopesCount, | |
| 31 0, | |
| 32 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 33 } | 30 } |
| 34 | 31 |
| 35 bool ShouldShowNeverForThisSiteDefault(PrefService* prefs) { | 32 bool ShouldShowNeverForThisSiteDefault(PrefService* prefs) { |
| 36 if (!base::FieldTrialList::TrialExists(kExperimentName)) | 33 if (!base::FieldTrialList::TrialExists(kExperimentName)) |
| 37 return false; | 34 return false; |
| 38 std::string param = | 35 std::string param = |
| 39 variations::GetVariationParamValue(kExperimentName, kParamNopeThreshold); | 36 variations::GetVariationParamValue(kExperimentName, kParamNopeThreshold); |
| 40 | 37 |
| 41 int threshold = 0; | 38 int threshold = 0; |
| 42 return base::StringToInt(param, &threshold) && | 39 return base::StringToInt(param, &threshold) && |
| 43 GetCurrentNopesCount(prefs) >= threshold; | 40 GetCurrentNopesCount(prefs) >= threshold; |
| 44 } | 41 } |
| 45 | 42 |
| 46 void RecordBubbleClosed( | 43 void RecordBubbleClosed( |
| 47 PrefService* prefs, | 44 PrefService* prefs, |
| 48 password_manager::metrics_util::UIDismissalReason reason) { | 45 password_manager::metrics_util::UIDismissalReason reason) { |
| 49 // Clicking "Never" doesn't change the experiment state. | 46 // Clicking "Never" doesn't change the experiment state. |
| 50 if (reason == password_manager::metrics_util::CLICKED_NEVER) | 47 if (reason == password_manager::metrics_util::CLICKED_NEVER) |
| 51 return; | 48 return; |
| 52 int nopes_count = GetCurrentNopesCount(prefs); | 49 int nopes_count = GetCurrentNopesCount(prefs); |
| 53 if (reason == password_manager::metrics_util::CLICKED_NOPE) | 50 if (reason == password_manager::metrics_util::CLICKED_NOPE) |
| 54 nopes_count++; | 51 nopes_count++; |
| 55 else | 52 else |
| 56 nopes_count = 0; | 53 nopes_count = 0; |
| 57 prefs->SetInteger(prefs::kPasswordBubbleNopesCount, nopes_count); | 54 prefs->SetInteger(prefs::kPasswordBubbleNopesCount, nopes_count); |
| 58 } | 55 } |
| 59 | 56 |
| 60 } // namespace password_bubble_experiment | 57 } // namespace password_bubble_experiment |
| OLD | NEW |