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/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 Loading... |
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 Loading... |
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 kSafeBrowsingSawInterstitialSber1[] = |
| 148 "safebrowsing.saw_interstitial_sber1"; |
| 149 const char kSafeBrowsingSawInterstitialSber2[] = |
| 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 prefs->ClearPref(prefs::kSafeBrowsingExtendedReportingEnabled); | 273 prefs->ClearPref(prefs::kSafeBrowsingExtendedReportingEnabled); |
251 UMA_HISTOGRAM_ENUMERATION(kScoutTransitionMetricName, | 274 UMA_HISTOGRAM_ENUMERATION(kScoutTransitionMetricName, |
252 ROLLBACK_NO_SBER2_CLEAR_SBER1, MAX_REASONS); | 275 ROLLBACK_NO_SBER2_CLEAR_SBER1, MAX_REASONS); |
253 } | 276 } |
254 } | 277 } |
255 | 278 |
256 // Also clear both the Scout settings to start over from a clean state and | 279 // Also clear both the Scout settings to start over from a clean state and |
257 // avoid the above logic from triggering on next restart. | 280 // avoid the above logic from triggering on next restart. |
258 prefs->ClearPref(prefs::kSafeBrowsingScoutGroupSelected); | 281 prefs->ClearPref(prefs::kSafeBrowsingScoutGroupSelected); |
259 prefs->ClearPref(prefs::kSafeBrowsingScoutReportingEnabled); | 282 prefs->ClearPref(prefs::kSafeBrowsingScoutReportingEnabled); |
| 283 |
| 284 // Also forget that the user has seen any interstitials since they're |
| 285 // reverting back to a clean state. |
| 286 prefs->ClearPref(prefs::kSafeBrowsingSawInterstitialSber1); |
| 287 prefs->ClearPref(prefs::kSafeBrowsingSawInterstitialSber2); |
260 } | 288 } |
261 } | 289 } |
262 | 290 |
263 bool IsExtendedReportingEnabled(const PrefService& prefs) { | 291 bool IsExtendedReportingEnabled(const PrefService& prefs) { |
264 return prefs.GetBoolean(GetExtendedReportingPrefName(prefs)); | 292 return prefs.GetBoolean(GetExtendedReportingPrefName(prefs)); |
265 } | 293 } |
266 | 294 |
267 bool IsScout(const PrefService& prefs) { | 295 bool IsScout(const PrefService& prefs) { |
268 return GetExtendedReportingPrefName(prefs) == | 296 return GetExtendedReportingPrefName(prefs) == |
269 prefs::kSafeBrowsingScoutReportingEnabled; | 297 prefs::kSafeBrowsingScoutReportingEnabled; |
270 } | 298 } |
271 | 299 |
272 void RecordExtendedReportingMetrics(const PrefService& prefs) { | 300 void RecordExtendedReportingMetrics(const PrefService& prefs) { |
273 // This metric tracks the extended browsing opt-in based on whichever setting | 301 // 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 | 302 // the user is currently seeing. It tells us whether extended reporting is |
275 // happening for this user. | 303 // happening for this user. |
276 UMA_HISTOGRAM_BOOLEAN("SafeBrowsing.Pref.Extended", | 304 UMA_HISTOGRAM_BOOLEAN("SafeBrowsing.Pref.Extended", |
277 IsExtendedReportingEnabled(prefs)); | 305 IsExtendedReportingEnabled(prefs)); |
278 | 306 |
| 307 // Track whether this user has ever seen a security interstitial. |
| 308 UMA_HISTOGRAM_BOOLEAN( |
| 309 "SafeBrowsing.Pref.SawInterstitial.SBER1Pref", |
| 310 prefs.GetBoolean(prefs::kSafeBrowsingSawInterstitialSber1)); |
| 311 UMA_HISTOGRAM_BOOLEAN( |
| 312 "SafeBrowsing.Pref.SawInterstitial.SBER2Pref", |
| 313 prefs.GetBoolean(prefs::kSafeBrowsingSawInterstitialSber2)); |
| 314 |
279 // These metrics track the Scout transition. | 315 // These metrics track the Scout transition. |
280 if (prefs.GetBoolean(prefs::kSafeBrowsingScoutGroupSelected)) { | 316 if (prefs.GetBoolean(prefs::kSafeBrowsingScoutGroupSelected)) { |
281 // Users in the Scout group: currently seeing the Scout opt-in. | 317 // Users in the Scout group: currently seeing the Scout opt-in. |
282 UMA_HISTOGRAM_BOOLEAN( | 318 UMA_HISTOGRAM_ENUMERATION( |
283 "SafeBrowsing.Pref.Scout.ScoutGroup.SBER1Pref", | 319 "SafeBrowsing.Pref.Scout.ScoutGroup.SBER1Pref", |
284 prefs.GetBoolean(prefs::kSafeBrowsingExtendedReportingEnabled)); | 320 GetPrefValueOrNull(prefs, prefs::kSafeBrowsingExtendedReportingEnabled), |
285 UMA_HISTOGRAM_BOOLEAN( | 321 MAX_NULLABLE_BOOLEAN); |
| 322 UMA_HISTOGRAM_ENUMERATION( |
286 "SafeBrowsing.Pref.Scout.ScoutGroup.SBER2Pref", | 323 "SafeBrowsing.Pref.Scout.ScoutGroup.SBER2Pref", |
287 prefs.GetBoolean(prefs::kSafeBrowsingScoutReportingEnabled)); | 324 GetPrefValueOrNull(prefs, prefs::kSafeBrowsingScoutReportingEnabled), |
| 325 MAX_NULLABLE_BOOLEAN); |
288 } else { | 326 } else { |
289 // Users not in the Scout group: currently seeing the SBER opt-in. | 327 // Users not in the Scout group: currently seeing the SBER opt-in. |
290 UMA_HISTOGRAM_BOOLEAN( | 328 UMA_HISTOGRAM_ENUMERATION( |
291 "SafeBrowsing.Pref.Scout.NoScoutGroup.SBER1Pref", | 329 "SafeBrowsing.Pref.Scout.NoScoutGroup.SBER1Pref", |
292 prefs.GetBoolean(prefs::kSafeBrowsingExtendedReportingEnabled)); | 330 GetPrefValueOrNull(prefs, prefs::kSafeBrowsingExtendedReportingEnabled), |
| 331 MAX_NULLABLE_BOOLEAN); |
293 // The following metric is a corner case. User was previously in the | 332 // 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 | 333 // 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). | 334 // removed from the Scout group (eg: by rolling back a Scout experiment). |
296 UMA_HISTOGRAM_BOOLEAN( | 335 UMA_HISTOGRAM_ENUMERATION( |
297 "SafeBrowsing.Pref.Scout.NoScoutGroup.SBER2Pref", | 336 "SafeBrowsing.Pref.Scout.NoScoutGroup.SBER2Pref", |
298 prefs.GetBoolean(prefs::kSafeBrowsingScoutReportingEnabled)); | 337 GetPrefValueOrNull(prefs, prefs::kSafeBrowsingScoutReportingEnabled), |
| 338 MAX_NULLABLE_BOOLEAN); |
299 } | 339 } |
300 } | 340 } |
301 | 341 |
302 void SetExtendedReportingPrefAndMetric( | 342 void SetExtendedReportingPrefAndMetric( |
303 PrefService* prefs, | 343 PrefService* prefs, |
304 bool value, | 344 bool value, |
305 ExtendedReportingOptInLocation location) { | 345 ExtendedReportingOptInLocation location) { |
306 prefs->SetBoolean(GetExtendedReportingPrefName(*prefs), value); | 346 prefs->SetBoolean(GetExtendedReportingPrefName(*prefs), value); |
307 RecordExtendedReportingPrefChanged(*prefs, location); | 347 RecordExtendedReportingPrefChanged(*prefs, location); |
308 } | 348 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 void UpdatePrefsBeforeSecurityInterstitial(PrefService* prefs) { | 417 void UpdatePrefsBeforeSecurityInterstitial(PrefService* prefs) { |
378 // Move the user into the Scout Group if the CanShowScoutOptIn experiment is | 418 // Move the user into the Scout Group if the CanShowScoutOptIn experiment is |
379 // enabled and they're not in the group already. | 419 // enabled and they're not in the group already. |
380 if (base::FeatureList::IsEnabled(kCanShowScoutOptIn) && | 420 if (base::FeatureList::IsEnabled(kCanShowScoutOptIn) && |
381 !prefs->GetBoolean(prefs::kSafeBrowsingScoutGroupSelected)) { | 421 !prefs->GetBoolean(prefs::kSafeBrowsingScoutGroupSelected)) { |
382 prefs->SetBoolean(prefs::kSafeBrowsingScoutGroupSelected, true); | 422 prefs->SetBoolean(prefs::kSafeBrowsingScoutGroupSelected, true); |
383 UMA_HISTOGRAM_ENUMERATION(kScoutTransitionMetricName, | 423 UMA_HISTOGRAM_ENUMERATION(kScoutTransitionMetricName, |
384 CAN_SHOW_SCOUT_OPT_IN_SAW_FIRST_INTERSTITIAL, | 424 CAN_SHOW_SCOUT_OPT_IN_SAW_FIRST_INTERSTITIAL, |
385 MAX_REASONS); | 425 MAX_REASONS); |
386 } | 426 } |
| 427 |
| 428 // Remember that this user saw an interstitial with the current opt-in text. |
| 429 prefs->SetBoolean(IsScout(*prefs) ? prefs::kSafeBrowsingSawInterstitialSber2 |
| 430 : prefs::kSafeBrowsingSawInterstitialSber1, |
| 431 true); |
387 } | 432 } |
388 | 433 |
389 } // namespace safe_browsing | 434 } // namespace safe_browsing |
OLD | NEW |