[email protected] | d4f8485 | 2013-11-08 01:05:35 | [diff] [blame] | 1 | // 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 | |||||
[email protected] | e24fff36 | 2014-07-22 01:19:02 | [diff] [blame] | 8 | #include <string> |
[email protected] | 70fbd005 | 2013-11-20 02:22:06 | [diff] [blame] | 9 | #include <vector> |
10 | |||||
[email protected] | d4f8485 | 2013-11-08 01:05:35 | [diff] [blame] | 11 | #include "base/metrics/field_trial.h" |
12 | |||||
[email protected] | 59b6f67 | 2014-07-26 18:35:47 | [diff] [blame] | 13 | namespace variations { |
[email protected] | d4f8485 | 2013-11-08 01:05:35 | [diff] [blame] | 14 | |
15 | class 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. | ||||
[email protected] | 70fbd005 | 2013-11-20 02:22:06 | [diff] [blame] | 19 | class ProcessedStudy { |
20 | public: | ||||
jwd | 5ff5410 | 2017-01-06 18:09:34 | [diff] [blame] | 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 | |||||
[email protected] | 70fbd005 | 2013-11-20 02:22:06 | [diff] [blame] | 25 | ProcessedStudy(); |
Alexei Svitkine | 5bbc915 | 2018-02-27 16:02:30 | [diff] [blame] | 26 | ProcessedStudy(const ProcessedStudy& other); |
[email protected] | d4f8485 | 2013-11-08 01:05:35 | [diff] [blame] | 27 | ~ProcessedStudy(); |
28 | |||||
[email protected] | 70fbd005 | 2013-11-20 02:22:06 | [diff] [blame] | 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 | |||||
asvitkine | 30ac0913 | 2015-02-20 19:50:10 | [diff] [blame] | 37 | bool all_assignments_to_one_group() const { |
38 | return all_assignments_to_one_group_; | ||||
39 | } | ||||
40 | |||||
[email protected] | 70fbd005 | 2013-11-20 02:22:06 | [diff] [blame] | 41 | bool is_expired() const { return is_expired_; } |
42 | |||||
Alexei Svitkine | 5bbc915 | 2018-02-27 16:02:30 | [diff] [blame] | 43 | const std::vector<std::string>& associated_features() const { |
44 | return associated_features_; | ||||
asvitkine | 64e9e11 | 2016-03-17 17:32:00 | [diff] [blame] | 45 | } |
46 | |||||
[email protected] | e24fff36 | 2014-07-22 01:19:02 | [diff] [blame] | 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 | |||||
jwd | 5ff5410 | 2017-01-06 18:09:34 | [diff] [blame] | 51 | // Gets the default experiment name for the study, or a generic one if none is |
52 | // specified. | ||||
53 | const char* GetDefaultExperimentName() const; | ||||
54 | |||||
[email protected] | 70fbd005 | 2013-11-20 02:22:06 | [diff] [blame] | 55 | static bool ValidateAndAppendStudy( |
56 | const Study* study, | ||||
57 | bool is_expired, | ||||
58 | std::vector<ProcessedStudy>* processed_studies); | ||||
59 | |||||
60 | private: | ||||
[email protected] | d4f8485 | 2013-11-08 01:05:35 | [diff] [blame] | 61 | // Corresponding Study object. Weak reference. |
Alexei Svitkine | 5bbc915 | 2018-02-27 16:02:30 | [diff] [blame] | 62 | const Study* study_ = nullptr; |
[email protected] | d4f8485 | 2013-11-08 01:05:35 | [diff] [blame] | 63 | |
64 | // Computed total group probability for the study. | ||||
Alexei Svitkine | 5bbc915 | 2018-02-27 16:02:30 | [diff] [blame] | 65 | base::FieldTrial::Probability total_probability_ = 0; |
[email protected] | d4f8485 | 2013-11-08 01:05:35 | [diff] [blame] | 66 | |
asvitkine | 30ac0913 | 2015-02-20 19:50:10 | [diff] [blame] | 67 | // Whether all assignments are to a single group. |
Alexei Svitkine | 5bbc915 | 2018-02-27 16:02:30 | [diff] [blame] | 68 | bool all_assignments_to_one_group_ = false; |
asvitkine | 30ac0913 | 2015-02-20 19:50:10 | [diff] [blame] | 69 | |
[email protected] | d4f8485 | 2013-11-08 01:05:35 | [diff] [blame] | 70 | // Whether the study is expired. |
Alexei Svitkine | 5bbc915 | 2018-02-27 16:02:30 | [diff] [blame] | 71 | bool is_expired_ = false; |
asvitkine | 64e9e11 | 2016-03-17 17:32:00 | [diff] [blame] | 72 | |
Alexei Svitkine | 5bbc915 | 2018-02-27 16:02:30 | [diff] [blame] | 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_; | ||||
[email protected] | d4f8485 | 2013-11-08 01:05:35 | [diff] [blame] | 78 | }; |
79 | |||||
[email protected] | 59b6f67 | 2014-07-26 18:35:47 | [diff] [blame] | 80 | } // namespace variations |
[email protected] | d4f8485 | 2013-11-08 01:05:35 | [diff] [blame] | 81 | |
82 | #endif // COMPONENTS_VARIATIONS_PROCESSED_STUDY_H_ |