feature_discovery_metric_util.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // Copyright 2022 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef ASH_PUBLIC_CPP_FEATURE_DISCOVERY_METRIC_UTIL_H_
  5. #define ASH_PUBLIC_CPP_FEATURE_DISCOVERY_METRIC_UTIL_H_
  6. #include <array>
  7. #include "ash/public/cpp/ash_public_export.h"
  8. namespace ash::feature_discovery {
  9. // The features supported by `FeatureDiscoveryDurationReporter`.
  10. // NOTE: `FeatureDiscoveryDurationReporter` users should add new enum types if
  11. // the features that users expect to track are not listed here. Also, when a new
  12. // enum type is added, make sure to update `kTrackableFeatureArray` as well.
  13. // Ensure that kMax is always the last one.
  14. enum class ASH_PUBLIC_EXPORT TrackableFeature {
  15. // A mock feature used for testing.
  16. kMockFeature = 0,
  17. // A mock feature whose discovery duration is reported with different
  18. // histograms under tablet and clamshell. Used for testing only.
  19. kModeSeparateMockFeature,
  20. // App list reorder after the reorder education nudge shows.
  21. // TODO(https://crbug.com/1316185): split this histogram into the one for
  22. // clamshell and another one for tablet.
  23. kAppListReorderAfterEducationNudge,
  24. // Similar to `kAppListReorderAfterEducationNudge`. The only difference
  25. // is that the collected data is separated by the tablet mode state under
  26. // which the reorder education nudge shows.
  27. kAppListReorderAfterEducationNudgePerTabletMode,
  28. // App list reorder after the user session activation.
  29. // TODO(https://crbug.com/1316185): split this histogram into the one for
  30. // clamshell and another one for tablet.
  31. kAppListReorderAfterSessionActivation,
  32. // Used to mark the end. It should always be the last one.
  33. kMax,
  34. };
  35. struct ASH_PUBLIC_EXPORT TrackableFeatureInfo {
  36. // This ctor should be used when the metric data collected from this feature
  37. // should be separated by the mode, i.e. clamshell or tablet, under which the
  38. // feature observation starts.
  39. // In detail, when reporting the metric data collected from a feature defined
  40. // by this ctor, there are the following two cases:
  41. // 1. If the observation on this feature starts in tablet mode,
  42. // `param_histogram_tablet` is used for reporting;
  43. // 2. If the observation on this feature starts in clamshell mode,
  44. // `param_histogram_clamshell` is used for reporting.
  45. // NOTE: if a feature is registered with this ctor, do not switch this feature
  46. // back to non-split. Otherwise, the data left in pref service may lead to
  47. // poorly defined behavior.
  48. constexpr TrackableFeatureInfo(TrackableFeature param_feature,
  49. const char* param_name,
  50. const char* param_histogram_clamshell,
  51. const char* param_histogram_tablet);
  52. // This ctor should be used when the metric data collected from this feature
  53. // should NOT be separated by tablet mode.
  54. // NOTE: if a feature is registered with this ctor, do not switch this feature
  55. // back to tablet-mode-split.
  56. constexpr TrackableFeatureInfo(TrackableFeature param_feature,
  57. const char* param_name,
  58. const char* param_histogram);
  59. TrackableFeatureInfo(const TrackableFeatureInfo&) = delete;
  60. TrackableFeatureInfo& operator=(const TrackableFeatureInfo&) = delete;
  61. ~TrackableFeatureInfo();
  62. // A trackable feature's enum type.
  63. const TrackableFeature feature;
  64. // A trackable feature's name.
  65. const char* const name;
  66. // The histogram that records the discovery duration of `feature`. Used only
  67. // when `split_by_tablet_mode` is false.
  68. const char* const histogram;
  69. // The histograms to record data under the specified mode (tablet or
  70. // clamshell). Used only when `split_by_tablet_mode` is true.
  71. const char* const histogram_clamshell;
  72. const char* const histogram_tablet;
  73. // Indicates whether the metric recordings should be split by modes (i.e.
  74. // tablet or clamshell).
  75. // Its value should not be set explicitly by `TrackableFeatureInfo`'s users.
  76. // Instead, the value is calculated by the ctor.
  77. const bool split_by_tablet_mode;
  78. };
  79. // A hardcoded array of trackable features' info.
  80. // NOTE: update `kTrackableFeatureArray` if a new trackable feature is added.
  81. ASH_PUBLIC_EXPORT extern const std::
  82. array<TrackableFeatureInfo, static_cast<int>(TrackableFeature::kMax)>
  83. kTrackableFeatureArray;
  84. } // namespace ash::feature_discovery
  85. #endif // ASH_PUBLIC_CPP_FEATURE_DISCOVERY_METRIC_UTIL_H_