blob: 504b5f4ddc20812f281dfcbef505f6afb3895455 [file] [log] [blame]
[email protected]d4f84852013-11-08 01:05:351// 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]e24fff362014-07-22 01:19:028#include <string>
[email protected]70fbd0052013-11-20 02:22:069#include <vector>
10
[email protected]d4f84852013-11-08 01:05:3511#include "base/metrics/field_trial.h"
12
[email protected]59b6f672014-07-26 18:35:4713namespace variations {
[email protected]d4f84852013-11-08 01:05:3514
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.
[email protected]70fbd0052013-11-20 02:22:0619class ProcessedStudy {
20 public:
jwd5ff54102017-01-06 18:09:3421 // 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]70fbd0052013-11-20 02:22:0625 ProcessedStudy();
Alexei Svitkine5bbc9152018-02-27 16:02:3026 ProcessedStudy(const ProcessedStudy& other);
[email protected]d4f84852013-11-08 01:05:3527 ~ProcessedStudy();
28
[email protected]70fbd0052013-11-20 02:22:0629 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
asvitkine30ac09132015-02-20 19:50:1037 bool all_assignments_to_one_group() const {
38 return all_assignments_to_one_group_;
39 }
40
[email protected]70fbd0052013-11-20 02:22:0641 bool is_expired() const { return is_expired_; }
42
Alexei Svitkine5bbc9152018-02-27 16:02:3043 const std::vector<std::string>& associated_features() const {
44 return associated_features_;
asvitkine64e9e112016-03-17 17:32:0045 }
46
[email protected]e24fff362014-07-22 01:19:0247 // 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
jwd5ff54102017-01-06 18:09:3451 // 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]70fbd0052013-11-20 02:22:0655 static bool ValidateAndAppendStudy(
56 const Study* study,
57 bool is_expired,
58 std::vector<ProcessedStudy>* processed_studies);
59
60 private:
[email protected]d4f84852013-11-08 01:05:3561 // Corresponding Study object. Weak reference.
Alexei Svitkine5bbc9152018-02-27 16:02:3062 const Study* study_ = nullptr;
[email protected]d4f84852013-11-08 01:05:3563
64 // Computed total group probability for the study.
Alexei Svitkine5bbc9152018-02-27 16:02:3065 base::FieldTrial::Probability total_probability_ = 0;
[email protected]d4f84852013-11-08 01:05:3566
asvitkine30ac09132015-02-20 19:50:1067 // Whether all assignments are to a single group.
Alexei Svitkine5bbc9152018-02-27 16:02:3068 bool all_assignments_to_one_group_ = false;
asvitkine30ac09132015-02-20 19:50:1069
[email protected]d4f84852013-11-08 01:05:3570 // Whether the study is expired.
Alexei Svitkine5bbc9152018-02-27 16:02:3071 bool is_expired_ = false;
asvitkine64e9e112016-03-17 17:32:0072
Alexei Svitkine5bbc9152018-02-27 16:02:3073 // 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]d4f84852013-11-08 01:05:3578};
79
[email protected]59b6f672014-07-26 18:35:4780} // namespace variations
[email protected]d4f84852013-11-08 01:05:3581
82#endif // COMPONENTS_VARIATIONS_PROCESSED_STUDY_H_