File: README.md

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 (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(~)`.