cluster_metrics_utils.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 COMPONENTS_HISTORY_CLUSTERS_CORE_CLUSTER_METRICS_UTILS_H_
  5. #define COMPONENTS_HISTORY_CLUSTERS_CORE_CLUSTER_METRICS_UTILS_H_
  6. #include "base/metrics/histogram_functions.h"
  7. namespace history_clusters {
  8. // A helper object for recording metrics about whether a cluster was filtered
  9. // for a specified reason. The metric is emitted when the object falls out of
  10. // scope.
  11. class ScopedFilterClusterMetricsRecorder {
  12. public:
  13. explicit ScopedFilterClusterMetricsRecorder(
  14. const std::string& filtered_reason)
  15. : filtered_reason_(filtered_reason) {}
  16. ~ScopedFilterClusterMetricsRecorder() {
  17. base::UmaHistogramBoolean(
  18. "History.Clusters.Backend.WasClusterFiltered." + filtered_reason_,
  19. was_filtered_);
  20. }
  21. void set_was_filtered(bool was_filtered) { was_filtered_ = was_filtered; }
  22. private:
  23. // Whether the cluster associated with this metrics recordered was filtered or
  24. // not.
  25. bool was_filtered_ = false;
  26. // The reason for why the cluster was filtered. Most be one of the items
  27. // specified in the patterned histogram in
  28. // tools/metrics/histograms/metadata/history/histograms.xml.
  29. const std::string filtered_reason_;
  30. };
  31. /**
  32. * The following enums must be kept in sync with their respective variants in
  33. * //tools/metrics/histograms/metadata/history/histograms.xml and
  34. * //ui/webui/resources/cr_components/history_clusters/history_clusters.mojom
  35. */
  36. // Actions that can be performed on clusters.
  37. enum class ClusterAction {
  38. kDeleted = 0,
  39. kOpenedInTabGroup = 1,
  40. kRelatedSearchClicked = 2,
  41. kRelatedVisitsVisibilityToggled = 3,
  42. kVisitClicked = 4,
  43. };
  44. // Actions that can be performed on related search items.
  45. enum class RelatedSearchAction {
  46. kClicked = 0,
  47. };
  48. // Actions that can be performed on visits.
  49. enum class VisitAction {
  50. kClicked = 0,
  51. kDeleted = 1,
  52. };
  53. // Types of visits that can be shown and acted on.
  54. enum class VisitType {
  55. kSRP = 0,
  56. kNonSRP = 1,
  57. };
  58. // Returns the string representation of each enum class used for
  59. // logging/histograms.
  60. std::string ClusterActionToString(ClusterAction action);
  61. std::string VisitActionToString(VisitAction action);
  62. std::string VisitTypeToString(VisitType action);
  63. std::string RelatedSearchActionToString(RelatedSearchAction action);
  64. } // namespace history_clusters
  65. #endif // COMPONENTS_HISTORY_CLUSTERS_CORE_CLUSTER_METRICS_UTILS_H_