xref: /aosp_15_r20/external/cronet/base/metrics/field_trial_list_including_low_anonymity.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2023 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef BASE_METRICS_FIELD_TRIAL_LIST_INCLUDING_LOW_ANONYMITY_H_
6 #define BASE_METRICS_FIELD_TRIAL_LIST_INCLUDING_LOW_ANONYMITY_H_
7 
8 #include "base/gtest_prod_util.h"
9 #include "base/metrics/field_trial.h"
10 #include "base/values.h"
11 
12 class AndroidFieldTrialListLogActiveTrialsFriendHelper;
13 
14 namespace content {
15 class FieldTrialSynchronizer;
16 }
17 
18 namespace variations {
19 class ChildProcessFieldTrialSyncer;
20 class EntropyProviders;
21 class ProcessedStudy;
22 struct SeedSimulationResult;
23 class VariationsCrashKeys;
24 class VariationsLayers;
25 SeedSimulationResult ComputeDifferences(
26     const std::vector<ProcessedStudy>& processed_studies,
27     const VariationsLayers& layers,
28     const EntropyProviders& entropy_providers);
29 }  // namespace variations
30 
31 namespace version_ui {
32 base::Value::List GetVariationsList();
33 }
34 
35 namespace base {
36 
37 // Provides a way to restrict access to the full set of field trials, including
38 // trials with low anonymity, to explicitly allowed callers.
39 //
40 // See |FieldTrialList::FactoryGetFieldTrial()| for background.
41 class BASE_EXPORT FieldTrialListIncludingLowAnonymity {
42  public:
43   // Exposed publicly, to avoid test code needing to be explicitly friended.
GetActiveFieldTrialGroupsForTesting(FieldTrial::ActiveGroups * active_groups)44   static void GetActiveFieldTrialGroupsForTesting(
45       FieldTrial::ActiveGroups* active_groups) {
46     return GetActiveFieldTrialGroups(active_groups);
47   }
48 
49   // Classes / functions which are allowed full access to all field trials
50   // should be listed as friends here, with a comment explaining why this does
51   // not risk revealing identifiable information externally.
52 
53   // This is used only for local logging on Android.
54   friend class ::AndroidFieldTrialListLogActiveTrialsFriendHelper;
55 
56   // Used to synchronize field trial status between the browser and child
57   // processes.
58   // Access to these trials within each of these is then allowed only to the
59   // other friend classes / methods listed here.
60   friend class content::FieldTrialSynchronizer;
61   friend class variations::ChildProcessFieldTrialSyncer;
62 
63   // This is only used to simulate seed changes, not sent to Google servers.
64   friend variations::SeedSimulationResult variations::ComputeDifferences(
65       const std::vector<variations::ProcessedStudy>& processed_studies,
66       const variations::VariationsLayers& layers,
67       const variations::EntropyProviders& entropy_providers);
68 
69   // Include all active field trials in crash reports, so that crashes are
70   // reproducible: https://www.google.com/intl/en/chrome/privacy/.
71   friend class variations::VariationsCrashKeys;
72 
73   // This usage is to display field trials in chrome://version and other local
74   // internal UIs.
75   friend base::Value::List version_ui::GetVariationsList();
76 
77   // Required for tests.
78   friend class TestFieldTrialObserverIncludingLowAnonymity;
79   FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, ObserveIncludingLowAnonymity);
80 
81  private:
82   // The same as |FieldTrialList::GetActiveFieldTrialGroups| but gives access to
83   // low anonymity field trials too.
84   static void GetActiveFieldTrialGroups(
85       FieldTrial::ActiveGroups* active_groups);
86 
87   // Identical to |FieldTrialList::AddObserver| but also notifies of low
88   // anonymity trials.
89   static bool AddObserver(FieldTrialList::Observer* observer);
90 
91   // Identical to |FieldTrialList::RemoveObserver| but for observers registered
92   // through the AddObserver() function of this class.
93   static void RemoveObserver(FieldTrialList::Observer* observer);
94 };
95 
96 }  // namespace base
97 
98 #endif  // BASE_METRICS_FIELD_TRIAL_LIST_INCLUDING_LOW_ANONYMITY_H_
99