blob: 56f869aedb8f52389c98ccc858e78d36bd6f08de [file] [log] [blame]
Steven Holte5c6dd632017-07-19 23:25:491// Copyright 2017 The Chromium Authors. All rights reserved.
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 COMPONENTS_METRICS_FIELD_TRIALS_PROVIDER_H_
6#define COMPONENTS_METRICS_FIELD_TRIALS_PROVIDER_H_
7
Keishi Hattori0e45c022021-11-27 09:25:528#include "base/memory/raw_ptr.h"
Robert Kaplowd45b6202017-07-20 02:01:469#include "base/strings/string_piece.h"
Steven Holte5c6dd632017-07-19 23:25:4910#include "base/time/time.h"
11#include "components/metrics/metrics_provider.h"
Caitlin Fischerd0cd0b92020-06-03 12:10:4812#include "third_party/metrics_proto/chrome_user_metrics_extension.pb.h"
Steven Holte5c6dd632017-07-19 23:25:4913
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.
17namespace variations {
18
19class SyntheticTrialRegistry;
20struct ActiveGroupId;
21
22class FieldTrialsProvider : public metrics::MetricsProvider {
23 public:
24 // |registry| must outlive this metrics provider.
Robert Kaplowd45b6202017-07-20 02:01:4625 FieldTrialsProvider(SyntheticTrialRegistry* registry,
26 base::StringPiece suffix);
Peter Boström09c01822021-09-20 22:43:2727
28 FieldTrialsProvider(const FieldTrialsProvider&) = delete;
29 FieldTrialsProvider& operator=(const FieldTrialsProvider&) = delete;
30
Steven Holte5c6dd632017-07-19 23:25:4931 ~FieldTrialsProvider() override;
32
33 // metrics::MetricsProvider:
Steven Holte5c6dd632017-07-19 23:25:4934 void ProvideSystemProfileMetrics(
35 metrics::SystemProfileProto* system_profile_proto) override;
Alexei Svitkine70c95022019-08-21 18:13:2436 void ProvideSystemProfileMetricsWithLogCreationTime(
37 base::TimeTicks log_creation_time,
38 metrics::SystemProfileProto* system_profile_proto) override;
Caitlin Fischerd0cd0b92020-06-03 12:10:4839 void ProvideCurrentSessionData(
40 metrics::ChromeUserMetricsExtension* uma_proto) override;
41
42 // Sets |log_creation_time_| to |time|.
43 void SetLogCreationTimeForTesting(base::TimeTicks time);
Steven Holte5c6dd632017-07-19 23:25:4944
45 private:
46 // Overrideable for testing.
47 virtual void GetFieldTrialIds(
48 std::vector<ActiveGroupId>* field_trial_ids) const;
49
Caitlin Fischerd0cd0b92020-06-03 12:10:4850 // Gets active FieldTrials and SyntheticFieldTrials and populates
51 // |system_profile_proto| with them.
52 void GetAndWriteFieldTrials(
53 metrics::SystemProfileProto* system_profile_proto) const;
54
55 // The most recent time passed to
56 // ProvideSystemProfileMetricsWithLogCreationTime().
57 base::TimeTicks log_creation_time_;
58
Keishi Hattori0e45c022021-11-27 09:25:5259 raw_ptr<SyntheticTrialRegistry> registry_;
Steven Holte5c6dd632017-07-19 23:25:4960
Robert Kaplowd45b6202017-07-20 02:01:4661 // Suffix used for the field trial names before they are hashed for uploads.
62 std::string suffix_;
Steven Holte5c6dd632017-07-19 23:25:4963};
64
65} // namespace variations
66
67#endif // COMPONENTS_METRICS_FIELD_TRIALS_PROVIDER_H_