Steven Holte | 5c6dd63 | 2017-07-19 23:25:49 | [diff] [blame] | 1 | // 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 Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 8 | #include "base/memory/raw_ptr.h" |
Robert Kaplow | d45b620 | 2017-07-20 02:01:46 | [diff] [blame] | 9 | #include "base/strings/string_piece.h" |
Steven Holte | 5c6dd63 | 2017-07-19 23:25:49 | [diff] [blame] | 10 | #include "base/time/time.h" |
| 11 | #include "components/metrics/metrics_provider.h" |
Caitlin Fischer | d0cd0b9 | 2020-06-03 12:10:48 | [diff] [blame] | 12 | #include "third_party/metrics_proto/chrome_user_metrics_extension.pb.h" |
Steven Holte | 5c6dd63 | 2017-07-19 23:25:49 | [diff] [blame] | 13 | |
| 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 { |
| 18 | |
| 19 | class SyntheticTrialRegistry; |
| 20 | struct ActiveGroupId; |
| 21 | |
| 22 | class FieldTrialsProvider : public metrics::MetricsProvider { |
| 23 | public: |
| 24 | // |registry| must outlive this metrics provider. |
Robert Kaplow | d45b620 | 2017-07-20 02:01:46 | [diff] [blame] | 25 | FieldTrialsProvider(SyntheticTrialRegistry* registry, |
| 26 | base::StringPiece suffix); |
Peter Boström | 09c0182 | 2021-09-20 22:43:27 | [diff] [blame] | 27 | |
| 28 | FieldTrialsProvider(const FieldTrialsProvider&) = delete; |
| 29 | FieldTrialsProvider& operator=(const FieldTrialsProvider&) = delete; |
| 30 | |
Steven Holte | 5c6dd63 | 2017-07-19 23:25:49 | [diff] [blame] | 31 | ~FieldTrialsProvider() override; |
| 32 | |
| 33 | // metrics::MetricsProvider: |
Steven Holte | 5c6dd63 | 2017-07-19 23:25:49 | [diff] [blame] | 34 | void ProvideSystemProfileMetrics( |
| 35 | metrics::SystemProfileProto* system_profile_proto) override; |
Alexei Svitkine | 70c9502 | 2019-08-21 18:13:24 | [diff] [blame] | 36 | void ProvideSystemProfileMetricsWithLogCreationTime( |
| 37 | base::TimeTicks log_creation_time, |
| 38 | metrics::SystemProfileProto* system_profile_proto) override; |
Caitlin Fischer | d0cd0b9 | 2020-06-03 12:10:48 | [diff] [blame] | 39 | void ProvideCurrentSessionData( |
| 40 | metrics::ChromeUserMetricsExtension* uma_proto) override; |
| 41 | |
| 42 | // Sets |log_creation_time_| to |time|. |
| 43 | void SetLogCreationTimeForTesting(base::TimeTicks time); |
Steven Holte | 5c6dd63 | 2017-07-19 23:25:49 | [diff] [blame] | 44 | |
| 45 | private: |
Luc Nguyen | d28c202 | 2022-05-12 18:58:57 | [diff] [blame^] | 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; |
Steven Holte | 5c6dd63 | 2017-07-19 23:25:49 | [diff] [blame] | 49 | |
Caitlin Fischer | d0cd0b9 | 2020-06-03 12:10:48 | [diff] [blame] | 50 | // 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 Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 59 | raw_ptr<SyntheticTrialRegistry> registry_; |
Steven Holte | 5c6dd63 | 2017-07-19 23:25:49 | [diff] [blame] | 60 | |
Robert Kaplow | d45b620 | 2017-07-20 02:01:46 | [diff] [blame] | 61 | // Suffix used for the field trial names before they are hashed for uploads. |
| 62 | std::string suffix_; |
Steven Holte | 5c6dd63 | 2017-07-19 23:25:49 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | } // namespace variations |
| 66 | |
| 67 | #endif // COMPONENTS_METRICS_FIELD_TRIALS_PROVIDER_H_ |