field_trials_provider.h 2.4 KB

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