Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: components/safe_browsing_db/safe_browsing_prefs.cc

Issue 2739643003: Make Sber1/2 pref metrics into Nullable Booleans so we can track how often these prefs are unset. (Closed)
Patch Set: Fix test Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/logging.h" 6 #include "base/logging.h"
7 #include "base/metrics/histogram_macros.h" 7 #include "base/metrics/histogram_macros.h"
8 #include "components/prefs/pref_service.h" 8 #include "components/prefs/pref_service.h"
9 #include "components/safe_browsing_db/safe_browsing_prefs.h" 9 #include "components/safe_browsing_db/safe_browsing_prefs.h"
10 10
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 // The Extended Reporting pref that is currently active, used for UMA metrics. 50 // The Extended Reporting pref that is currently active, used for UMA metrics.
51 // These values are written to logs. New enum values can be added, but 51 // These values are written to logs. New enum values can be added, but
52 // existing enums must never be renumbered or deleted and reused. 52 // existing enums must never be renumbered or deleted and reused.
53 enum ActiveExtendedReportingPref { 53 enum ActiveExtendedReportingPref {
54 SBER1_PREF = 0, 54 SBER1_PREF = 0,
55 SBER2_PREF = 1, 55 SBER2_PREF = 1,
56 // New prefs must be added before MAX_SBER_PREF 56 // New prefs must be added before MAX_SBER_PREF
57 MAX_SBER_PREF 57 MAX_SBER_PREF
58 }; 58 };
59 59
60 // A histogram for tracking a nullable boolean, which can be false, true or
61 // null. These values are written to logs. New enum values can be added, but
62 // existing enums must never be renumbered or deleted and reused.
63 enum NullableBoolean {
64 NULLABLE_BOOLEAN_FALSE = 0,
65 NULLABLE_BOOLEAN_TRUE = 1,
66 NULLABLE_BOOLEAN_NULL = 2,
67 MAX_NULLABLE_BOOLEAN
68 };
69
70 NullableBoolean GetPrefValueOrNull(const PrefService& prefs,
71 const std::string& pref_name) {
72 if (!prefs.HasPrefPath(pref_name)) {
73 return NULLABLE_BOOLEAN_NULL;
74 }
75 return prefs.GetBoolean(pref_name) ? NULLABLE_BOOLEAN_TRUE
76 : NULLABLE_BOOLEAN_FALSE;
77 }
78
60 // Update the correct UMA metric based on which pref was changed and which UI 79 // Update the correct UMA metric based on which pref was changed and which UI
61 // the change was made on. 80 // the change was made on.
62 void RecordExtendedReportingPrefChanged( 81 void RecordExtendedReportingPrefChanged(
63 const PrefService& prefs, 82 const PrefService& prefs,
64 safe_browsing::ExtendedReportingOptInLocation location) { 83 safe_browsing::ExtendedReportingOptInLocation location) {
65 bool pref_value = safe_browsing::IsExtendedReportingEnabled(prefs); 84 bool pref_value = safe_browsing::IsExtendedReportingEnabled(prefs);
66 85
67 if (safe_browsing::IsScout(prefs)) { 86 if (safe_browsing::IsScout(prefs)) {
68 switch (location) { 87 switch (location) {
69 case safe_browsing::SBER_OPTIN_SITE_CHROME_SETTINGS: 88 case safe_browsing::SBER_OPTIN_SITE_CHROME_SETTINGS:
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 } 137 }
119 } // namespace 138 } // namespace
120 139
121 namespace prefs { 140 namespace prefs {
122 const char kSafeBrowsingExtendedReportingEnabled[] = 141 const char kSafeBrowsingExtendedReportingEnabled[] =
123 "safebrowsing.extended_reporting_enabled"; 142 "safebrowsing.extended_reporting_enabled";
124 const char kSafeBrowsingScoutReportingEnabled[] = 143 const char kSafeBrowsingScoutReportingEnabled[] =
125 "safebrowsing.scout_reporting_enabled"; 144 "safebrowsing.scout_reporting_enabled";
126 const char kSafeBrowsingScoutGroupSelected[] = 145 const char kSafeBrowsingScoutGroupSelected[] =
127 "safebrowsing.scout_group_selected"; 146 "safebrowsing.scout_group_selected";
147 const char kSafeBrowsingSawInterstitialExtendedReporting[] =
148 "safebrowsing.saw_interstitial_sber1";
149 const char kSafeBrowsingSawInterstitialScoutReporting[] =
150 "safebrowsing.saw_interstitial_sber2";
128 } // namespace prefs 151 } // namespace prefs
129 152
130 namespace safe_browsing { 153 namespace safe_browsing {
131 154
132 const char kSwitchForceScoutGroup[] = "force-scout-group"; 155 const char kSwitchForceScoutGroup[] = "force-scout-group";
133 156
134 const base::Feature kCanShowScoutOptIn{"CanShowScoutOptIn", 157 const base::Feature kCanShowScoutOptIn{"CanShowScoutOptIn",
135 base::FEATURE_DISABLED_BY_DEFAULT}; 158 base::FEATURE_DISABLED_BY_DEFAULT};
136 159
137 const base::Feature kOnlyShowScoutOptIn{"OnlyShowScoutOptIn", 160 const base::Feature kOnlyShowScoutOptIn{"OnlyShowScoutOptIn",
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 UMA_HISTOGRAM_ENUMERATION(kScoutTransitionMetricName, 240 UMA_HISTOGRAM_ENUMERATION(kScoutTransitionMetricName,
218 CAN_SHOW_SCOUT_OPT_IN_WAIT_FOR_INTERSTITIAL, 241 CAN_SHOW_SCOUT_OPT_IN_WAIT_FOR_INTERSTITIAL,
219 MAX_REASONS); 242 MAX_REASONS);
220 } 243 }
221 } else { 244 } else {
222 // Both experiment features are off, so this is the Control group. We must 245 // Both experiment features are off, so this is the Control group. We must
223 // handle the possibility that the user was previously in an experiment 246 // handle the possibility that the user was previously in an experiment
224 // group (above) that was reverted. We want to restore the user to a 247 // group (above) that was reverted. We want to restore the user to a
225 // reasonable state based on the ScoutGroup and ScoutReporting preferences. 248 // reasonable state based on the ScoutGroup and ScoutReporting preferences.
226 UMA_HISTOGRAM_ENUMERATION(kScoutTransitionMetricName, CONTROL, MAX_REASONS); 249 UMA_HISTOGRAM_ENUMERATION(kScoutTransitionMetricName, CONTROL, MAX_REASONS);
250 bool transitioned = false;
227 if (prefs->GetBoolean(prefs::kSafeBrowsingScoutReportingEnabled)) { 251 if (prefs->GetBoolean(prefs::kSafeBrowsingScoutReportingEnabled)) {
228 // User opted-in to Scout which is broader than legacy Extended Reporting. 252 // User opted-in to Scout which is broader than legacy Extended Reporting.
229 // Opt them in to Extended Reporting. 253 // Opt them in to Extended Reporting.
230 prefs->SetBoolean(prefs::kSafeBrowsingExtendedReportingEnabled, true); 254 prefs->SetBoolean(prefs::kSafeBrowsingExtendedReportingEnabled, true);
231 UMA_HISTOGRAM_ENUMERATION(kScoutTransitionMetricName, 255 UMA_HISTOGRAM_ENUMERATION(kScoutTransitionMetricName,
232 ROLLBACK_SBER2_IMPLIES_SBER1, MAX_REASONS); 256 ROLLBACK_SBER2_IMPLIES_SBER1, MAX_REASONS);
257 transitioned = true;
233 } else if (prefs->GetBoolean(prefs::kSafeBrowsingScoutGroupSelected)) { 258 } else if (prefs->GetBoolean(prefs::kSafeBrowsingScoutGroupSelected)) {
234 // User was in the Scout Group (ie: seeing the Scout opt-in text) but did 259 // User was in the Scout Group (ie: seeing the Scout opt-in text) but did
235 // NOT opt-in to Scout. Assume this was a conscious choice and remove 260 // NOT opt-in to Scout. Assume this was a conscious choice and remove
236 // their legacy Extended Reporting opt-in as well. The user will have a 261 // their legacy Extended Reporting opt-in as well. The user will have a
237 // chance to evaluate their choice next time they see the opt-in text. 262 // chance to evaluate their choice next time they see the opt-in text.
238 263
239 // We make the Extended Reporting pref mimic the state of the Scout 264 // We make the Extended Reporting pref mimic the state of the Scout
240 // Reporting pref. So we either Clear it or set it to False. 265 // Reporting pref. So we either Clear it or set it to False.
241 if (prefs->HasPrefPath(prefs::kSafeBrowsingScoutReportingEnabled)) { 266 if (prefs->HasPrefPath(prefs::kSafeBrowsingScoutReportingEnabled)) {
242 // Scout Reporting pref was explicitly set to false, so set the SBER 267 // Scout Reporting pref was explicitly set to false, so set the SBER
243 // pref to false. 268 // pref to false.
244 prefs->SetBoolean(prefs::kSafeBrowsingExtendedReportingEnabled, false); 269 prefs->SetBoolean(prefs::kSafeBrowsingExtendedReportingEnabled, false);
245 UMA_HISTOGRAM_ENUMERATION(kScoutTransitionMetricName, 270 UMA_HISTOGRAM_ENUMERATION(kScoutTransitionMetricName,
246 ROLLBACK_NO_SBER2_SET_SBER1_FALSE, 271 ROLLBACK_NO_SBER2_SET_SBER1_FALSE,
247 MAX_REASONS); 272 MAX_REASONS);
248 } else { 273 } else {
249 // Scout Reporting pref is unset, so clear the SBER pref. 274 // Scout Reporting pref is unset, so clear the SBER pref.
250 prefs->ClearPref(prefs::kSafeBrowsingExtendedReportingEnabled); 275 prefs->ClearPref(prefs::kSafeBrowsingExtendedReportingEnabled);
251 UMA_HISTOGRAM_ENUMERATION(kScoutTransitionMetricName, 276 UMA_HISTOGRAM_ENUMERATION(kScoutTransitionMetricName,
252 ROLLBACK_NO_SBER2_CLEAR_SBER1, MAX_REASONS); 277 ROLLBACK_NO_SBER2_CLEAR_SBER1, MAX_REASONS);
253 } 278 }
279 transitioned = true;
254 } 280 }
255 281
256 // Also clear both the Scout settings to start over from a clean state and 282 // Also clear both the Scout settings to start over from a clean state and
257 // avoid the above logic from triggering on next restart. 283 // avoid the above logic from triggering on next restart.
258 prefs->ClearPref(prefs::kSafeBrowsingScoutGroupSelected); 284 prefs->ClearPref(prefs::kSafeBrowsingScoutGroupSelected);
259 prefs->ClearPref(prefs::kSafeBrowsingScoutReportingEnabled); 285 prefs->ClearPref(prefs::kSafeBrowsingScoutReportingEnabled);
286
287 // Also forget that the user has seen any interstitials if they're
288 // reverting back to a clean state.
289 if (transitioned) {
290 prefs->ClearPref(prefs::kSafeBrowsingSawInterstitialExtendedReporting);
291 prefs->ClearPref(prefs::kSafeBrowsingSawInterstitialScoutReporting);
292 }
260 } 293 }
261 } 294 }
262 295
263 bool IsExtendedReportingEnabled(const PrefService& prefs) { 296 bool IsExtendedReportingEnabled(const PrefService& prefs) {
264 return prefs.GetBoolean(GetExtendedReportingPrefName(prefs)); 297 return prefs.GetBoolean(GetExtendedReportingPrefName(prefs));
265 } 298 }
266 299
267 bool IsScout(const PrefService& prefs) { 300 bool IsScout(const PrefService& prefs) {
268 return GetExtendedReportingPrefName(prefs) == 301 return GetExtendedReportingPrefName(prefs) ==
269 prefs::kSafeBrowsingScoutReportingEnabled; 302 prefs::kSafeBrowsingScoutReportingEnabled;
270 } 303 }
271 304
272 void RecordExtendedReportingMetrics(const PrefService& prefs) { 305 void RecordExtendedReportingMetrics(const PrefService& prefs) {
273 // This metric tracks the extended browsing opt-in based on whichever setting 306 // This metric tracks the extended browsing opt-in based on whichever setting
274 // the user is currently seeing. It tells us whether extended reporting is 307 // the user is currently seeing. It tells us whether extended reporting is
275 // happening for this user. 308 // happening for this user.
276 UMA_HISTOGRAM_BOOLEAN("SafeBrowsing.Pref.Extended", 309 UMA_HISTOGRAM_BOOLEAN("SafeBrowsing.Pref.Extended",
277 IsExtendedReportingEnabled(prefs)); 310 IsExtendedReportingEnabled(prefs));
278 311
312 // Track whether this user has ever seen a security interstitial.
313 UMA_HISTOGRAM_BOOLEAN(
314 "SafeBrowsing.Pref.SawInterstitial.SBER1Pref",
315 prefs.GetBoolean(prefs::kSafeBrowsingSawInterstitialExtendedReporting));
316 UMA_HISTOGRAM_BOOLEAN(
317 "SafeBrowsing.Pref.SawInterstitial.SBER2Pref",
318 prefs.GetBoolean(prefs::kSafeBrowsingSawInterstitialScoutReporting));
319
279 // These metrics track the Scout transition. 320 // These metrics track the Scout transition.
280 if (prefs.GetBoolean(prefs::kSafeBrowsingScoutGroupSelected)) { 321 if (prefs.GetBoolean(prefs::kSafeBrowsingScoutGroupSelected)) {
281 // Users in the Scout group: currently seeing the Scout opt-in. 322 // Users in the Scout group: currently seeing the Scout opt-in.
282 UMA_HISTOGRAM_BOOLEAN( 323 UMA_HISTOGRAM_ENUMERATION(
283 "SafeBrowsing.Pref.Scout.ScoutGroup.SBER1Pref", 324 "SafeBrowsing.Pref.Scout.ScoutGroup.SBER1Pref",
284 prefs.GetBoolean(prefs::kSafeBrowsingExtendedReportingEnabled)); 325 GetPrefValueOrNull(prefs, prefs::kSafeBrowsingExtendedReportingEnabled),
285 UMA_HISTOGRAM_BOOLEAN( 326 MAX_NULLABLE_BOOLEAN);
327 UMA_HISTOGRAM_ENUMERATION(
286 "SafeBrowsing.Pref.Scout.ScoutGroup.SBER2Pref", 328 "SafeBrowsing.Pref.Scout.ScoutGroup.SBER2Pref",
287 prefs.GetBoolean(prefs::kSafeBrowsingScoutReportingEnabled)); 329 GetPrefValueOrNull(prefs, prefs::kSafeBrowsingScoutReportingEnabled),
330 MAX_NULLABLE_BOOLEAN);
288 } else { 331 } else {
289 // Users not in the Scout group: currently seeing the SBER opt-in. 332 // Users not in the Scout group: currently seeing the SBER opt-in.
290 UMA_HISTOGRAM_BOOLEAN( 333 UMA_HISTOGRAM_ENUMERATION(
291 "SafeBrowsing.Pref.Scout.NoScoutGroup.SBER1Pref", 334 "SafeBrowsing.Pref.Scout.NoScoutGroup.SBER1Pref",
292 prefs.GetBoolean(prefs::kSafeBrowsingExtendedReportingEnabled)); 335 GetPrefValueOrNull(prefs, prefs::kSafeBrowsingExtendedReportingEnabled),
336 MAX_NULLABLE_BOOLEAN);
293 // The following metric is a corner case. User was previously in the 337 // The following metric is a corner case. User was previously in the
294 // Scout group and was able to opt-in to the Scout pref, but was since 338 // Scout group and was able to opt-in to the Scout pref, but was since
295 // removed from the Scout group (eg: by rolling back a Scout experiment). 339 // removed from the Scout group (eg: by rolling back a Scout experiment).
296 UMA_HISTOGRAM_BOOLEAN( 340 UMA_HISTOGRAM_ENUMERATION(
297 "SafeBrowsing.Pref.Scout.NoScoutGroup.SBER2Pref", 341 "SafeBrowsing.Pref.Scout.NoScoutGroup.SBER2Pref",
298 prefs.GetBoolean(prefs::kSafeBrowsingScoutReportingEnabled)); 342 GetPrefValueOrNull(prefs, prefs::kSafeBrowsingScoutReportingEnabled),
343 MAX_NULLABLE_BOOLEAN);
299 } 344 }
300 } 345 }
301 346
302 void SetExtendedReportingPrefAndMetric( 347 void SetExtendedReportingPrefAndMetric(
303 PrefService* prefs, 348 PrefService* prefs,
304 bool value, 349 bool value,
305 ExtendedReportingOptInLocation location) { 350 ExtendedReportingOptInLocation location) {
306 prefs->SetBoolean(GetExtendedReportingPrefName(*prefs), value); 351 prefs->SetBoolean(GetExtendedReportingPrefName(*prefs), value);
307 RecordExtendedReportingPrefChanged(*prefs, location); 352 RecordExtendedReportingPrefChanged(*prefs, location);
308 } 353 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 void UpdatePrefsBeforeSecurityInterstitial(PrefService* prefs) { 422 void UpdatePrefsBeforeSecurityInterstitial(PrefService* prefs) {
378 // Move the user into the Scout Group if the CanShowScoutOptIn experiment is 423 // Move the user into the Scout Group if the CanShowScoutOptIn experiment is
379 // enabled and they're not in the group already. 424 // enabled and they're not in the group already.
380 if (base::FeatureList::IsEnabled(kCanShowScoutOptIn) && 425 if (base::FeatureList::IsEnabled(kCanShowScoutOptIn) &&
381 !prefs->GetBoolean(prefs::kSafeBrowsingScoutGroupSelected)) { 426 !prefs->GetBoolean(prefs::kSafeBrowsingScoutGroupSelected)) {
382 prefs->SetBoolean(prefs::kSafeBrowsingScoutGroupSelected, true); 427 prefs->SetBoolean(prefs::kSafeBrowsingScoutGroupSelected, true);
383 UMA_HISTOGRAM_ENUMERATION(kScoutTransitionMetricName, 428 UMA_HISTOGRAM_ENUMERATION(kScoutTransitionMetricName,
384 CAN_SHOW_SCOUT_OPT_IN_SAW_FIRST_INTERSTITIAL, 429 CAN_SHOW_SCOUT_OPT_IN_SAW_FIRST_INTERSTITIAL,
385 MAX_REASONS); 430 MAX_REASONS);
386 } 431 }
432
433 // Remember that this user saw an interstitial with the current opt-in text.
434 prefs->SetBoolean(IsScout(*prefs)
435 ? prefs::kSafeBrowsingSawInterstitialScoutReporting
436 : prefs::kSafeBrowsingSawInterstitialExtendedReporting,
437 true);
387 } 438 }
388 439
389 } // namespace safe_browsing 440 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « components/safe_browsing_db/safe_browsing_prefs.h ('k') | components/safe_browsing_db/safe_browsing_prefs_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698