Chromium Code Reviews| 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); |
|
Jialiu Lin
2017/03/07 18:07:12
how about IsExtendedReportingEnabled() function? M
lpz
2017/03/07 19:34:54
I'm not sure the False vs Null distinction is rele
| |
| 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: |
| 70 UMA_HISTOGRAM_BOOLEAN( | 89 UMA_HISTOGRAM_BOOLEAN( |
| 71 "SafeBrowsing.Pref.Scout.SetPref.SBER2Pref.ChromeSettings", | 90 "SafeBrowsing.Pref.Scout.SetPref.SBER2Pref.ChromeSettings", |
| 72 pref_value); | 91 pref_value); |
| 73 break; | 92 break; |
| 74 case safe_browsing::SBER_OPTIN_SITE_ANDROID_SETTINGS: | 93 case safe_browsing::SBER_OPTIN_SITE_ANDROID_SETTINGS: |
| 75 UMA_HISTOGRAM_BOOLEAN( | 94 UMA_HISTOGRAM_BOOLEAN( |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 void RecordExtendedReportingMetrics(const PrefService& prefs) { | 291 void RecordExtendedReportingMetrics(const PrefService& prefs) { |
| 273 // This metric tracks the extended browsing opt-in based on whichever setting | 292 // 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 | 293 // the user is currently seeing. It tells us whether extended reporting is |
| 275 // happening for this user. | 294 // happening for this user. |
| 276 UMA_HISTOGRAM_BOOLEAN("SafeBrowsing.Pref.Extended", | 295 UMA_HISTOGRAM_BOOLEAN("SafeBrowsing.Pref.Extended", |
| 277 IsExtendedReportingEnabled(prefs)); | 296 IsExtendedReportingEnabled(prefs)); |
| 278 | 297 |
| 279 // These metrics track the Scout transition. | 298 // These metrics track the Scout transition. |
| 280 if (prefs.GetBoolean(prefs::kSafeBrowsingScoutGroupSelected)) { | 299 if (prefs.GetBoolean(prefs::kSafeBrowsingScoutGroupSelected)) { |
| 281 // Users in the Scout group: currently seeing the Scout opt-in. | 300 // Users in the Scout group: currently seeing the Scout opt-in. |
| 282 UMA_HISTOGRAM_BOOLEAN( | 301 UMA_HISTOGRAM_ENUMERATION( |
| 283 "SafeBrowsing.Pref.Scout.ScoutGroup.SBER1Pref", | 302 "SafeBrowsing.Pref.Scout.ScoutGroup.SBER1Pref", |
| 284 prefs.GetBoolean(prefs::kSafeBrowsingExtendedReportingEnabled)); | 303 GetPrefValueOrNull(prefs, prefs::kSafeBrowsingExtendedReportingEnabled), |
| 285 UMA_HISTOGRAM_BOOLEAN( | 304 MAX_NULLABLE_BOOLEAN); |
| 305 UMA_HISTOGRAM_ENUMERATION( | |
| 286 "SafeBrowsing.Pref.Scout.ScoutGroup.SBER2Pref", | 306 "SafeBrowsing.Pref.Scout.ScoutGroup.SBER2Pref", |
| 287 prefs.GetBoolean(prefs::kSafeBrowsingScoutReportingEnabled)); | 307 GetPrefValueOrNull(prefs, prefs::kSafeBrowsingScoutReportingEnabled), |
| 308 MAX_NULLABLE_BOOLEAN); | |
| 288 } else { | 309 } else { |
| 289 // Users not in the Scout group: currently seeing the SBER opt-in. | 310 // Users not in the Scout group: currently seeing the SBER opt-in. |
| 290 UMA_HISTOGRAM_BOOLEAN( | 311 UMA_HISTOGRAM_ENUMERATION( |
| 291 "SafeBrowsing.Pref.Scout.NoScoutGroup.SBER1Pref", | 312 "SafeBrowsing.Pref.Scout.NoScoutGroup.SBER1Pref", |
| 292 prefs.GetBoolean(prefs::kSafeBrowsingExtendedReportingEnabled)); | 313 GetPrefValueOrNull(prefs, prefs::kSafeBrowsingExtendedReportingEnabled), |
| 314 MAX_NULLABLE_BOOLEAN); | |
| 293 // The following metric is a corner case. User was previously in the | 315 // 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 | 316 // 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). | 317 // removed from the Scout group (eg: by rolling back a Scout experiment). |
| 296 UMA_HISTOGRAM_BOOLEAN( | 318 UMA_HISTOGRAM_ENUMERATION( |
| 297 "SafeBrowsing.Pref.Scout.NoScoutGroup.SBER2Pref", | 319 "SafeBrowsing.Pref.Scout.NoScoutGroup.SBER2Pref", |
| 298 prefs.GetBoolean(prefs::kSafeBrowsingScoutReportingEnabled)); | 320 GetPrefValueOrNull(prefs, prefs::kSafeBrowsingScoutReportingEnabled), |
| 321 MAX_NULLABLE_BOOLEAN); | |
| 299 } | 322 } |
| 300 } | 323 } |
| 301 | 324 |
| 302 void SetExtendedReportingPrefAndMetric( | 325 void SetExtendedReportingPrefAndMetric( |
| 303 PrefService* prefs, | 326 PrefService* prefs, |
| 304 bool value, | 327 bool value, |
| 305 ExtendedReportingOptInLocation location) { | 328 ExtendedReportingOptInLocation location) { |
| 306 prefs->SetBoolean(GetExtendedReportingPrefName(*prefs), value); | 329 prefs->SetBoolean(GetExtendedReportingPrefName(*prefs), value); |
| 307 RecordExtendedReportingPrefChanged(*prefs, location); | 330 RecordExtendedReportingPrefChanged(*prefs, location); |
| 308 } | 331 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 380 if (base::FeatureList::IsEnabled(kCanShowScoutOptIn) && | 403 if (base::FeatureList::IsEnabled(kCanShowScoutOptIn) && |
| 381 !prefs->GetBoolean(prefs::kSafeBrowsingScoutGroupSelected)) { | 404 !prefs->GetBoolean(prefs::kSafeBrowsingScoutGroupSelected)) { |
| 382 prefs->SetBoolean(prefs::kSafeBrowsingScoutGroupSelected, true); | 405 prefs->SetBoolean(prefs::kSafeBrowsingScoutGroupSelected, true); |
| 383 UMA_HISTOGRAM_ENUMERATION(kScoutTransitionMetricName, | 406 UMA_HISTOGRAM_ENUMERATION(kScoutTransitionMetricName, |
| 384 CAN_SHOW_SCOUT_OPT_IN_SAW_FIRST_INTERSTITIAL, | 407 CAN_SHOW_SCOUT_OPT_IN_SAW_FIRST_INTERSTITIAL, |
| 385 MAX_REASONS); | 408 MAX_REASONS); |
| 386 } | 409 } |
| 387 } | 410 } |
| 388 | 411 |
| 389 } // namespace safe_browsing | 412 } // namespace safe_browsing |
| OLD | NEW |