1 // Copyright 2017 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.
5 #ifndef COMPONENTS_METRICS_FIELD_TRIALS_PROVIDER_H_
6 #define COMPONENTS_METRICS_FIELD_TRIALS_PROVIDER_H_
8 #include "base/memory/raw_ptr.h"
9 #include "base/strings/string_piece.h"
10 #include "base/time/time.h"
11 #include "components/metrics/metrics_provider.h"
12 #include "third_party/metrics_proto/chrome_user_metrics_extension.pb.h"
14 // TODO(crbug/507665): Once MetricsProvider/SystemProfileProto are moved into
15 // //services/metrics, then //components/variations can depend on them, and
16 // this should be moved there.
17 namespace variations {
19 class SyntheticTrialRegistry;
22 class FieldTrialsProvider : public metrics::MetricsProvider {
24 // |registry| must outlive this metrics provider.
25 FieldTrialsProvider(SyntheticTrialRegistry* registry,
26 base::StringPiece suffix);
28 FieldTrialsProvider(const FieldTrialsProvider&) = delete;
29 FieldTrialsProvider& operator=(const FieldTrialsProvider&) = delete;
31 ~FieldTrialsProvider() override;
33 // metrics::MetricsProvider:
34 void ProvideSystemProfileMetrics(
35 metrics::SystemProfileProto* system_profile_proto) override;
36 void ProvideSystemProfileMetricsWithLogCreationTime(
37 base::TimeTicks log_creation_time,
38 metrics::SystemProfileProto* system_profile_proto) override;
39 void ProvideCurrentSessionData(
40 metrics::ChromeUserMetricsExtension* uma_proto) override;
42 // Sets |log_creation_time_| to |time|.
43 void SetLogCreationTimeForTesting(base::TimeTicks time);
46 // Populates |field_trial_ids| with currently active field trials groups. The
47 // trial and group names are suffixed with |suffix_| before being hashed.
48 void GetFieldTrialIds(std::vector<ActiveGroupId>* field_trial_ids) const;
50 // Gets active FieldTrials and SyntheticFieldTrials and populates
51 // |system_profile_proto| with them.
52 void GetAndWriteFieldTrials(
53 metrics::SystemProfileProto* system_profile_proto) const;
55 // The most recent time passed to
56 // ProvideSystemProfileMetricsWithLogCreationTime().
57 base::TimeTicks log_creation_time_;
59 raw_ptr<SyntheticTrialRegistry> registry_;
61 // Suffix used for the field trial names before they are hashed for uploads.
65 } // namespace variations
67 #endif // COMPONENTS_METRICS_FIELD_TRIALS_PROVIDER_H_