OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_VARIATIONS_PROCESSED_STUDY_H_ | 5 #ifndef COMPONENTS_VARIATIONS_PROCESSED_STUDY_H_ |
6 #define COMPONENTS_VARIATIONS_PROCESSED_STUDY_H_ | 6 #define COMPONENTS_VARIATIONS_PROCESSED_STUDY_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
12 | 12 |
13 namespace variations { | 13 namespace variations { |
14 | 14 |
15 class Study; | 15 class Study; |
16 | 16 |
17 // Wrapper over Study with extra information computed during pre-processing, | 17 // Wrapper over Study with extra information computed during pre-processing, |
18 // such as whether the study is expired and its total probability. | 18 // such as whether the study is expired and its total probability. |
19 class ProcessedStudy { | 19 class ProcessedStudy { |
20 public: | 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 std::string kGenericDefaultExperimentName; |
| 24 |
21 ProcessedStudy(); | 25 ProcessedStudy(); |
22 ~ProcessedStudy(); | 26 ~ProcessedStudy(); |
23 | 27 |
24 bool Init(const Study* study, bool is_expired); | 28 bool Init(const Study* study, bool is_expired); |
25 | 29 |
26 const Study* study() const { return study_; } | 30 const Study* study() const { return study_; } |
27 | 31 |
28 base::FieldTrial::Probability total_probability() const { | 32 base::FieldTrial::Probability total_probability() const { |
29 return total_probability_; | 33 return total_probability_; |
30 } | 34 } |
31 | 35 |
32 bool all_assignments_to_one_group() const { | 36 bool all_assignments_to_one_group() const { |
33 return all_assignments_to_one_group_; | 37 return all_assignments_to_one_group_; |
34 } | 38 } |
35 | 39 |
36 bool is_expired() const { return is_expired_; } | 40 bool is_expired() const { return is_expired_; } |
37 | 41 |
38 const std::string& single_feature_name() const { | 42 const std::string& single_feature_name() const { |
39 return single_feature_name_; | 43 return single_feature_name_; |
40 } | 44 } |
41 | 45 |
42 // Gets the index of the experiment with the given |name|. Returns -1 if no | 46 // Gets the index of the experiment with the given |name|. Returns -1 if no |
43 // experiment is found. | 47 // experiment is found. |
44 int GetExperimentIndexByName(const std::string& name) const; | 48 int GetExperimentIndexByName(const std::string& name) const; |
45 | 49 |
| 50 // Gets the default experiment name for the study, or a generic one if none is |
| 51 // specified. |
| 52 const std::string& GetDefaultExperimentName() const; |
| 53 |
46 static bool ValidateAndAppendStudy( | 54 static bool ValidateAndAppendStudy( |
47 const Study* study, | 55 const Study* study, |
48 bool is_expired, | 56 bool is_expired, |
49 std::vector<ProcessedStudy>* processed_studies); | 57 std::vector<ProcessedStudy>* processed_studies); |
50 | 58 |
51 private: | 59 private: |
52 // Corresponding Study object. Weak reference. | 60 // Corresponding Study object. Weak reference. |
53 const Study* study_; | 61 const Study* study_; |
54 | 62 |
55 // Computed total group probability for the study. | 63 // Computed total group probability for the study. |
56 base::FieldTrial::Probability total_probability_; | 64 base::FieldTrial::Probability total_probability_; |
57 | 65 |
58 // Whether all assignments are to a single group. | 66 // Whether all assignments are to a single group. |
59 bool all_assignments_to_one_group_; | 67 bool all_assignments_to_one_group_; |
60 | 68 |
61 // Whether the study is expired. | 69 // Whether the study is expired. |
62 bool is_expired_; | 70 bool is_expired_; |
63 | 71 |
64 // If the study has groups that enable/disable a single feature, the name of | 72 // If the study has groups that enable/disable a single feature, the name of |
65 // that feature. | 73 // that feature. |
66 std::string single_feature_name_; | 74 std::string single_feature_name_; |
67 }; | 75 }; |
68 | 76 |
69 } // namespace variations | 77 } // namespace variations |
70 | 78 |
71 #endif // COMPONENTS_VARIATIONS_PROCESSED_STUDY_H_ | 79 #endif // COMPONENTS_VARIATIONS_PROCESSED_STUDY_H_ |
OLD | NEW |