blob: 504b5f4ddc20812f281dfcbef505f6afb3895455 [file] [log] [blame]
Kaido Kert788710a2023-06-05 07:50:22 -07001// Copyright 2013 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_VARIATIONS_PROCESSED_STUDY_H_
6#define COMPONENTS_VARIATIONS_PROCESSED_STUDY_H_
7
8#include <string>
9#include <vector>
10
11#include "base/metrics/field_trial.h"
12
13namespace variations {
14
15class Study;
16
17// Wrapper over Study with extra information computed during pre-processing,
18// such as whether the study is expired and its total probability.
19class ProcessedStudy {
20 public:
21 // The default group used when a study doesn't specify one. This is needed
22 // because the field trial api requires a default group name.
23 static const char kGenericDefaultExperimentName[];
24
25 ProcessedStudy();
26 ProcessedStudy(const ProcessedStudy& other);
27 ~ProcessedStudy();
28
29 bool Init(const Study* study, bool is_expired);
30
31 const Study* study() const { return study_; }
32
33 base::FieldTrial::Probability total_probability() const {
34 return total_probability_;
35 }
36
37 bool all_assignments_to_one_group() const {
38 return all_assignments_to_one_group_;
39 }
40
41 bool is_expired() const { return is_expired_; }
42
43 const std::vector<std::string>& associated_features() const {
44 return associated_features_;
45 }
46
47 // Gets the index of the experiment with the given |name|. Returns -1 if no
48 // experiment is found.
49 int GetExperimentIndexByName(const std::string& name) const;
50
51 // Gets the default experiment name for the study, or a generic one if none is
52 // specified.
53 const char* GetDefaultExperimentName() const;
54
55 static bool ValidateAndAppendStudy(
56 const Study* study,
57 bool is_expired,
58 std::vector<ProcessedStudy>* processed_studies);
59
60 private:
61 // Corresponding Study object. Weak reference.
62 const Study* study_ = nullptr;
63
64 // Computed total group probability for the study.
65 base::FieldTrial::Probability total_probability_ = 0;
66
67 // Whether all assignments are to a single group.
68 bool all_assignments_to_one_group_ = false;
69
70 // Whether the study is expired.
71 bool is_expired_ = false;
72
73 // A list of feature names associated with this study by default. Studies
74 // might have groups that do not specify any feature associations – this is
75 // often the case for a default group, for example. The features listed here
76 // will be associated with all such groups.
77 std::vector<std::string> associated_features_;
78};
79
80} // namespace variations
81
82#endif // COMPONENTS_VARIATIONS_PROCESSED_STUDY_H_