File: README.md

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (100 lines) | stat: -rw-r--r-- 2,885 bytes parent folder | download | duplicates (9)
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
94
95
96
97
98
99
100
## Adding metrics for a new feature?

Please do **not** add your metrics in `autofill_metrics.*`! Instead, help
support code clarity and organization by adding a pair of files **per feature**.

### The old way

Originally, when making metrics for a new feature, everything was thrown into
the `autofill_metrics.*` files:

*autofill_metrics.h*:

```c++ {.bad}
class AutofillMetrics {

  enum class CoolFeatureInteractionMetric {
    // User accepted the cool feature.
    kAccepted = 0,
    // User explicitly denied the feature.
    kCancelled = 1,
    // User left the page without interacting with the feature.
    kIgnored = 2,
    kMaxValue = kIgnored,
  };

  // ...Roughly 1500 lines of other enums and functions...

  static void LogCoolFeatureInteraction(CoolFeatureInteractionMetric metric);
}
```

*autofill_metrics.cc*:

```c++ {.bad}
  // ...In the middle of 3000 lines of similar code...

  // static
  void AutofillMetrics::LogCoolFeatureInteraction(
      CoolFeatureInteractionMetric metric) {
    base::UmaHistogramEnumeration("Autofill.CoolFeatureInteraction", metric);
  }
```

The calling code of this function would be
`AutofillMetrics::LogCoolFeatureInteraction(~)`.

The biggest downside to this approach was not just how large the two files
became, but also how far apart enums/metrics related to the same feature were
located, as well as how hard it was to find **all** metrics for a given feature.

### The new way

**Don't** use a class, but **do** use the `autofill::autofill_metrics` namespace. Then,
combine all metrics that are part of a single feature together, so they're not
intertwined with the rest of Autofill's metrics.

*cool_feature_metrics.h*:

(Put this header file under components/autofill/core/browser/metrics/[optional_sub_directory])
```c++ {.good}
// [Copyright notice and include guards]

namespace autofill::autofill_metrics {

enum class CoolFeatureInteractionMetric {
  // User accepted the cool feature.
  kAccepted = 0,
  // User explicitly denied the feature.
  kCancelled = 1,
  // User left the page without interacting with the feature.
  kIgnored = 2,
  kMaxValue = kIgnored,
};

void LogCoolFeatureInteraction(CoolFeatureInteractionMetric metric);

}  // namespace autofill::autofill_metrics
```

*cool_feature_metrics.cc*:

```c++ {.good}
// [Copyright notice]

#include "components/autofill/core/browser/metrics/[optional_sub_directory]/cool_feature_metrics.h"

namespace autofill::autofill_metrics {

void LogCoolFeatureInteraction(CoolFeatureInteractionMetric metric) {
  base::UmaHistogramEnumeration("Autofill.CoolFeatureInteraction", metric);
}

// If there are other metrics related to this feature, they'd go here, and it
// would be very obvious they're related!

}  // namespace autofill::autofill_metrics
```

The calling code of this function would be
`autofill::autofill_metrics::LogCoolFeatureInteraction(~)`.