| OLD | NEW |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/metrics/histogram_macros.h" | 6 #include "base/metrics/histogram_macros.h" |
| 7 #include "components/prefs/pref_service.h" | 7 #include "components/prefs/pref_service.h" |
| 8 #include "components/safe_browsing_db/safe_browsing_prefs.h" | 8 #include "components/safe_browsing_db/safe_browsing_prefs.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| 11 | 11 |
| 12 // Switch value which force the ScoutGroupSelected pref to true. | 12 // Switch value which force the ScoutGroupSelected pref to true. |
| 13 const char kForceScoutGroupValueTrue[] = "true"; | 13 const char kForceScoutGroupValueTrue[] = "true"; |
| 14 // Switch value which force the ScoutGroupSelected pref to false. | 14 // Switch value which force the ScoutGroupSelected pref to false. |
| 15 const char kForceScoutGroupValueFalse[] = "false"; | 15 const char kForceScoutGroupValueFalse[] = "false"; |
| 16 | 16 |
| 17 // Name of the Scout Transition UMA metric. |
| 18 const char kScoutTransitionMetricName[] = "SafeBrowsing.Pref.Scout.Transition"; |
| 19 |
| 20 // Reasons that a state transition for Scout was performed. |
| 21 // These values are written to logs. New enum values can be added, but |
| 22 // existing enums must never be renumbered or deleted and reused. |
| 23 enum ScoutTransitionReason { |
| 24 // Flag forced Scout Group to true |
| 25 FORCE_SCOUT_FLAG_TRUE = 0, |
| 26 // Flag forced Scout Group to false |
| 27 FORCE_SCOUT_FLAG_FALSE = 1, |
| 28 // User in OnlyShowScout group, enters Scout Group |
| 29 ONLY_SHOW_SCOUT_OPT_IN = 2, |
| 30 // User in CanShowScout group, enters Scout Group immediately |
| 31 CAN_SHOW_SCOUT_OPT_IN_SCOUT_GROUP_ON = 3, |
| 32 // User in CanShowScout group, waiting for interstitial to enter Scout Group |
| 33 CAN_SHOW_SCOUT_OPT_IN_WAIT_FOR_INTERSTITIAL = 4, |
| 34 // User in Control group |
| 35 CONTROL = 5, |
| 36 // Rollback: SBER2 on on implies SBER1 can turn on |
| 37 ROLLBACK_SBER2_IMPLIES_SBER1 = 6, |
| 38 // Rollback: SBER2 off so SBER1 must be turned off |
| 39 ROLLBACK_NO_SBER2_SET_SBER1_FALSE = 7, |
| 40 // Rollback: SBER2 absent so SBER1 must be cleared |
| 41 ROLLBACK_NO_SBER2_CLEAR_SBER1 = 8, |
| 42 // New reasons must be added BEFORE MAX_REASONS |
| 43 MAX_REASONS |
| 44 }; |
| 17 } // namespace | 45 } // namespace |
| 18 | 46 |
| 19 namespace prefs { | 47 namespace prefs { |
| 20 const char kSafeBrowsingExtendedReportingEnabled[] = | 48 const char kSafeBrowsingExtendedReportingEnabled[] = |
| 21 "safebrowsing.extended_reporting_enabled"; | 49 "safebrowsing.extended_reporting_enabled"; |
| 22 const char kSafeBrowsingScoutReportingEnabled[] = | 50 const char kSafeBrowsingScoutReportingEnabled[] = |
| 23 "safebrowsing.scout_reporting_enabled"; | 51 "safebrowsing.scout_reporting_enabled"; |
| 24 const char kSafeBrowsingScoutGroupSelected[] = | 52 const char kSafeBrowsingScoutGroupSelected[] = |
| 25 "safebrowsing.scout_group_selected"; | 53 "safebrowsing.scout_group_selected"; |
| 26 } // namespace prefs | 54 } // namespace prefs |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 | 104 |
| 77 void InitializeSafeBrowsingPrefs(PrefService* prefs) { | 105 void InitializeSafeBrowsingPrefs(PrefService* prefs) { |
| 78 // First handle forcing kSafeBrowsingScoutGroupSelected pref via cmd-line. | 106 // First handle forcing kSafeBrowsingScoutGroupSelected pref via cmd-line. |
| 79 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 107 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 80 kSwitchForceScoutGroup)) { | 108 kSwitchForceScoutGroup)) { |
| 81 std::string switch_value = | 109 std::string switch_value = |
| 82 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 110 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 83 kSwitchForceScoutGroup); | 111 kSwitchForceScoutGroup); |
| 84 if (switch_value == kForceScoutGroupValueTrue) { | 112 if (switch_value == kForceScoutGroupValueTrue) { |
| 85 prefs->SetBoolean(prefs::kSafeBrowsingScoutGroupSelected, true); | 113 prefs->SetBoolean(prefs::kSafeBrowsingScoutGroupSelected, true); |
| 114 UMA_HISTOGRAM_ENUMERATION(kScoutTransitionMetricName, |
| 115 FORCE_SCOUT_FLAG_TRUE, MAX_REASONS); |
| 86 } else if (switch_value == kForceScoutGroupValueFalse) { | 116 } else if (switch_value == kForceScoutGroupValueFalse) { |
| 87 prefs->SetBoolean(prefs::kSafeBrowsingScoutGroupSelected, false); | 117 prefs->SetBoolean(prefs::kSafeBrowsingScoutGroupSelected, false); |
| 118 UMA_HISTOGRAM_ENUMERATION(kScoutTransitionMetricName, |
| 119 FORCE_SCOUT_FLAG_FALSE, MAX_REASONS); |
| 88 } | 120 } |
| 89 | 121 |
| 90 // If the switch is used, don't process the experiment state. | 122 // If the switch is used, don't process the experiment state. |
| 91 return; | 123 return; |
| 92 } | 124 } |
| 93 | 125 |
| 94 // Handle the three possible experiment states. | 126 // Handle the three possible experiment states. |
| 95 if (base::FeatureList::IsEnabled(kOnlyShowScoutOptIn)) { | 127 if (base::FeatureList::IsEnabled(kOnlyShowScoutOptIn)) { |
| 96 // OnlyShowScoutOptIn immediately turns on ScoutGroupSelected pref. | 128 // OnlyShowScoutOptIn immediately turns on ScoutGroupSelected pref. |
| 97 prefs->SetBoolean(prefs::kSafeBrowsingScoutGroupSelected, true); | 129 prefs->SetBoolean(prefs::kSafeBrowsingScoutGroupSelected, true); |
| 130 UMA_HISTOGRAM_ENUMERATION(kScoutTransitionMetricName, |
| 131 ONLY_SHOW_SCOUT_OPT_IN, MAX_REASONS); |
| 98 } else if (base::FeatureList::IsEnabled(kCanShowScoutOptIn)) { | 132 } else if (base::FeatureList::IsEnabled(kCanShowScoutOptIn)) { |
| 99 // CanShowScoutOptIn will only turn on ScoutGroupSelected pref if the legacy | 133 // CanShowScoutOptIn will only turn on ScoutGroupSelected pref if the legacy |
| 100 // SBER pref is false. Otherwise the legacy SBER pref will stay on and | 134 // SBER pref is false. Otherwise the legacy SBER pref will stay on and |
| 101 // continue to be used until the next security incident, at which point | 135 // continue to be used until the next security incident, at which point |
| 102 // the Scout pref will become the active one. | 136 // the Scout pref will become the active one. |
| 103 if (!prefs->GetBoolean(prefs::kSafeBrowsingExtendedReportingEnabled)) { | 137 if (!prefs->GetBoolean(prefs::kSafeBrowsingExtendedReportingEnabled)) { |
| 104 prefs->SetBoolean(prefs::kSafeBrowsingScoutGroupSelected, true); | 138 prefs->SetBoolean(prefs::kSafeBrowsingScoutGroupSelected, true); |
| 139 UMA_HISTOGRAM_ENUMERATION(kScoutTransitionMetricName, |
| 140 CAN_SHOW_SCOUT_OPT_IN_SCOUT_GROUP_ON, |
| 141 MAX_REASONS); |
| 142 } else { |
| 143 UMA_HISTOGRAM_ENUMERATION(kScoutTransitionMetricName, |
| 144 CAN_SHOW_SCOUT_OPT_IN_WAIT_FOR_INTERSTITIAL, |
| 145 MAX_REASONS); |
| 105 } | 146 } |
| 106 } else { | 147 } else { |
| 107 // Both experiment features are off, so this is the Control group. We must | 148 // Both experiment features are off, so this is the Control group. We must |
| 108 // handle the possibility that the user was previously in an experiment | 149 // handle the possibility that the user was previously in an experiment |
| 109 // group (above) that was reverted. We want to restore the user to a | 150 // group (above) that was reverted. We want to restore the user to a |
| 110 // reasonable state based on the ScoutGroup and ScoutReporting preferences. | 151 // reasonable state based on the ScoutGroup and ScoutReporting preferences. |
| 152 UMA_HISTOGRAM_ENUMERATION(kScoutTransitionMetricName, CONTROL, MAX_REASONS); |
| 111 if (prefs->GetBoolean(prefs::kSafeBrowsingScoutReportingEnabled)) { | 153 if (prefs->GetBoolean(prefs::kSafeBrowsingScoutReportingEnabled)) { |
| 112 // User opted-in to Scout which is broader than legacy Extended Reporting. | 154 // User opted-in to Scout which is broader than legacy Extended Reporting. |
| 113 // Opt them in to Extended Reporting. | 155 // Opt them in to Extended Reporting. |
| 114 prefs->SetBoolean(prefs::kSafeBrowsingExtendedReportingEnabled, true); | 156 prefs->SetBoolean(prefs::kSafeBrowsingExtendedReportingEnabled, true); |
| 157 UMA_HISTOGRAM_ENUMERATION(kScoutTransitionMetricName, |
| 158 ROLLBACK_SBER2_IMPLIES_SBER1, MAX_REASONS); |
| 115 } else if (prefs->GetBoolean(prefs::kSafeBrowsingScoutGroupSelected)) { | 159 } else if (prefs->GetBoolean(prefs::kSafeBrowsingScoutGroupSelected)) { |
| 116 // User was in the Scout Group (ie: seeing the Scout opt-in text) but did | 160 // User was in the Scout Group (ie: seeing the Scout opt-in text) but did |
| 117 // NOT opt-in to Scout. Assume this was a conscious choice and remove | 161 // NOT opt-in to Scout. Assume this was a conscious choice and remove |
| 118 // their legacy Extended Reporting opt-in as well. The user will have a | 162 // their legacy Extended Reporting opt-in as well. The user will have a |
| 119 // chance to evaluate their choice next time they see the opt-in text. | 163 // chance to evaluate their choice next time they see the opt-in text. |
| 120 | 164 |
| 121 // We make the Extended Reporting pref mimic the state of the Scout | 165 // We make the Extended Reporting pref mimic the state of the Scout |
| 122 // Reporting pref. So we either Clear it or set it to False. | 166 // Reporting pref. So we either Clear it or set it to False. |
| 123 if (prefs->HasPrefPath(prefs::kSafeBrowsingScoutReportingEnabled)) { | 167 if (prefs->HasPrefPath(prefs::kSafeBrowsingScoutReportingEnabled)) { |
| 124 // Scout Reporting pref was explicitly set to false, so set the SBER | 168 // Scout Reporting pref was explicitly set to false, so set the SBER |
| 125 // pref to false. | 169 // pref to false. |
| 126 prefs->SetBoolean(prefs::kSafeBrowsingExtendedReportingEnabled, false); | 170 prefs->SetBoolean(prefs::kSafeBrowsingExtendedReportingEnabled, false); |
| 171 UMA_HISTOGRAM_ENUMERATION(kScoutTransitionMetricName, |
| 172 ROLLBACK_NO_SBER2_SET_SBER1_FALSE, |
| 173 MAX_REASONS); |
| 127 } else { | 174 } else { |
| 128 // Scout Reporting pref is unset, so clear the SBER pref. | 175 // Scout Reporting pref is unset, so clear the SBER pref. |
| 129 prefs->ClearPref(prefs::kSafeBrowsingExtendedReportingEnabled); | 176 prefs->ClearPref(prefs::kSafeBrowsingExtendedReportingEnabled); |
| 177 UMA_HISTOGRAM_ENUMERATION(kScoutTransitionMetricName, |
| 178 ROLLBACK_NO_SBER2_CLEAR_SBER1, MAX_REASONS); |
| 130 } | 179 } |
| 131 } | 180 } |
| 132 | 181 |
| 133 // Also clear both the Scout settings to start over from a clean state and | 182 // Also clear both the Scout settings to start over from a clean state and |
| 134 // avoid the above logic from triggering on next restart. | 183 // avoid the above logic from triggering on next restart. |
| 135 prefs->ClearPref(prefs::kSafeBrowsingScoutGroupSelected); | 184 prefs->ClearPref(prefs::kSafeBrowsingScoutGroupSelected); |
| 136 prefs->ClearPref(prefs::kSafeBrowsingScoutReportingEnabled); | 185 prefs->ClearPref(prefs::kSafeBrowsingScoutReportingEnabled); |
| 137 } | 186 } |
| 138 } | 187 } |
| 139 | 188 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 231 |
| 183 void UpdatePrefsBeforeSecurityInterstitial(PrefService* prefs) { | 232 void UpdatePrefsBeforeSecurityInterstitial(PrefService* prefs) { |
| 184 // Move the user into the Scout Group if the CanShowScoutOptIn experiment is | 233 // Move the user into the Scout Group if the CanShowScoutOptIn experiment is |
| 185 // enabled. | 234 // enabled. |
| 186 if (base::FeatureList::IsEnabled(kCanShowScoutOptIn)) { | 235 if (base::FeatureList::IsEnabled(kCanShowScoutOptIn)) { |
| 187 prefs->SetBoolean(prefs::kSafeBrowsingScoutGroupSelected, true); | 236 prefs->SetBoolean(prefs::kSafeBrowsingScoutGroupSelected, true); |
| 188 } | 237 } |
| 189 } | 238 } |
| 190 | 239 |
| 191 } // namespace safe_browsing | 240 } // namespace safe_browsing |
| OLD | NEW |