File: redaction_tool_metrics_recorder.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (93 lines) | stat: -rw-r--r-- 3,385 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_FEEDBACK_REDACTION_TOOL_REDACTION_TOOL_METRICS_RECORDER_H_
#define COMPONENTS_FEEDBACK_REDACTION_TOOL_REDACTION_TOOL_METRICS_RECORDER_H_

#include <memory>
#include <string_view>

#include "base/time/time.h"
#include "components/feedback/redaction_tool/pii_types.h"

namespace redaction {

// These values are logged to UMA. Entries should not be renumbered and
// numeric values should never be reused. Please keep in sync with
// "CreditCardDetection" in //tools/metrics/histograms/enums.xml.
enum class CreditCardDetection {
  kRegexMatch = 1,
  kTimestamp = 2,
  kRepeatedChars = 3,
  kDoesntValidate = 4,
  kValidated = 5,
  kMaxValue = kValidated,
};

// These values are logged to UMA. Entries should not be renumbered and
// numeric values should never be reused. Please keep in sync with
// "RedactionToolCaller" in //tools/metrics/histograms/enums.xml.
enum class RedactionToolCaller {
  kSysLogUploader = 1,
  kSysLogFetcher = 2,
  kSupportTool = 3,
  kErrorReporting = 4,
  // Feedback Tool is deprecated and split into it's components.
  // kFeedbackTool = 5,
  // Browser system logs is deprecated since it's being called only
  // by the feedback tool.
  // kBrowserSystemLogs = 6,
  kUnitTest = 7,
  kUndetermined = 8,
  kUnknown = 9,
  kCrashTool = 10,
  kCrashToolJSErrors = 11,
  kFeedbackToolHotRod = 12,
  kFeedbackToolUserDescriptions = 13,
  kFeedbackToolLogs = 14,
  kMaxValue = kFeedbackToolLogs,
};

inline constexpr char kPIIRedactedHistogram[] = "Feedback.RedactionTool";
inline constexpr char kCreditCardRedactionHistogram[] =
    "Feedback.RedactionTool.CreditCardMatch";
inline constexpr char kRedactionToolCallerHistogram[] =
    "Feedback.RedactionTool.Caller";

// This class is the platform independent interface to record histograms using
// the platform specific libraries.
class RedactionToolMetricsRecorder {
 public:
  // Create a new instance of the platform default implementation.
  static std::unique_ptr<RedactionToolMetricsRecorder> Create();

  RedactionToolMetricsRecorder() = default;
  RedactionToolMetricsRecorder(const RedactionToolMetricsRecorder&) = delete;
  RedactionToolMetricsRecorder& operator=(const RedactionToolMetricsRecorder&) =
      delete;
  virtual ~RedactionToolMetricsRecorder() = default;

  // Record when a bit of PII of the type `pii_type` was redacted by the
  // redaction tool.
  virtual void RecordPIIRedactedHistogram(PIIType pii_type) = 0;

  // Records the `step` that was reached when validating a series of numbers
  // against credit card checks.
  virtual void RecordCreditCardRedactionHistogram(CreditCardDetection step) = 0;

  // Records the caller who initiated the call to the Redaction Tool.
  virtual void RecordRedactionToolCallerHistogram(RedactionToolCaller step) = 0;

  // Records the `time_spent` in milliseconds for redacting an input text.
  virtual void RecordTimeSpentRedactingHistogram(
      base::TimeDelta time_spent) = 0;

  // Returns the platform specific metric name used to measure how long it took
  // to redact the input.
  static std::string_view GetTimeSpentRedactingHistogramNameForTesting();
};

}  // namespace redaction

#endif  // COMPONENTS_FEEDBACK_REDACTION_TOOL_REDACTION_TOOL_METRICS_RECORDER_H_