Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: components/variations/processed_study.cc

Issue 2614443002: Supporting study definitions without default groups and end_date filtering. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "components/variations/processed_study.h" 5 #include "components/variations/processed_study.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "base/version.h" 10 #include "base/version.h"
11 #include "components/variations/proto/study.pb.h" 11 #include "components/variations/proto/study.pb.h"
12 12
13 namespace variations { 13 namespace variations {
14 14
15 namespace { 15 namespace {
16 16
17 // Validates the sanity of |study| and computes the total probability and 17 // Validates the sanity of |study| and computes the total probability and
18 // whether all assignments are to a single group. 18 // whether all assignments are to a single group.
19 bool ValidateStudyAndComputeTotalProbability( 19 bool ValidateStudyAndComputeTotalProbability(
20 const Study& study, 20 const Study& study,
21 base::FieldTrial::Probability* total_probability, 21 base::FieldTrial::Probability* total_probability,
22 bool* all_assignments_to_one_group, 22 bool* all_assignments_to_one_group,
23 std::string* single_feature_name) { 23 std::string* single_feature_name) {
24 // At the moment, a missing default_experiment_name makes the study invalid.
25 if (study.default_experiment_name().empty()) {
26 DVLOG(1) << study.name() << " has no default experiment defined.";
27 return false;
28 }
29 if (study.filter().has_min_version() && 24 if (study.filter().has_min_version() &&
30 !base::Version::IsValidWildcardString(study.filter().min_version())) { 25 !base::Version::IsValidWildcardString(study.filter().min_version())) {
31 DVLOG(1) << study.name() << " has invalid min version: " 26 DVLOG(1) << study.name() << " has invalid min version: "
32 << study.filter().min_version(); 27 << study.filter().min_version();
33 return false; 28 return false;
34 } 29 }
35 if (study.filter().has_max_version() && 30 if (study.filter().has_max_version() &&
36 !base::Version::IsValidWildcardString(study.filter().max_version())) { 31 !base::Version::IsValidWildcardString(study.filter().max_version())) {
37 DVLOG(1) << study.name() << " has invalid max version: " 32 DVLOG(1) << study.name() << " has invalid max version: "
38 << study.filter().max_version(); 33 << study.filter().max_version();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 if (!experiment.has_forcing_flag() && experiment.probability_weight() > 0) { 80 if (!experiment.has_forcing_flag() && experiment.probability_weight() > 0) {
86 // If |divisor| is not 0, there was at least one prior non-zero group. 81 // If |divisor| is not 0, there was at least one prior non-zero group.
87 if (divisor != 0) 82 if (divisor != 0)
88 multiple_assigned_groups = true; 83 multiple_assigned_groups = true;
89 divisor += experiment.probability_weight(); 84 divisor += experiment.probability_weight();
90 } 85 }
91 if (study.experiment(i).name() == default_group_name) 86 if (study.experiment(i).name() == default_group_name)
92 found_default_group = true; 87 found_default_group = true;
93 } 88 }
94 89
95 if (!found_default_group) { 90 // Specifying a default experiment is optional, so finding it in the
91 // experiment list is only required when it is specified.
92 if (!study.default_experiment_name().empty() && !found_default_group) {
96 DVLOG(1) << study.name() << " is missing default experiment in its " 93 DVLOG(1) << study.name() << " is missing default experiment in its "
rkaplow 2017/01/04 15:58:25 optional, could add default_group_name to the DVLO
jwd 2017/01/04 21:10:22 Done.
97 << "experiment list"; 94 << "experiment list";
98 // The default group was not found in the list of groups. This study is not 95 // The default group was not found in the list of groups. This study is not
99 // valid. 96 // valid.
100 return false; 97 return false;
101 } 98 }
102 99
103 if (!has_multiple_features && !single_feature_name_seen.empty()) 100 if (!has_multiple_features && !single_feature_name_seen.empty())
104 single_feature_name->swap(single_feature_name_seen); 101 single_feature_name->swap(single_feature_name_seen);
105 else 102 else
106 single_feature_name->clear(); 103 single_feature_name->clear();
107 104
108 *total_probability = divisor; 105 *total_probability = divisor;
109 *all_assignments_to_one_group = !multiple_assigned_groups; 106 *all_assignments_to_one_group = !multiple_assigned_groups;
110 return true; 107 return true;
111 } 108 }
112 109
113 110
114 } // namespace 111 } // namespace
115 112
113 // static
114 const std::string ProcessedStudy::kGenericDefaultExperimentName =
115 "VariationsDefaultExperiment";
116
116 ProcessedStudy::ProcessedStudy() 117 ProcessedStudy::ProcessedStudy()
117 : study_(NULL), 118 : study_(NULL),
118 total_probability_(0), 119 total_probability_(0),
119 all_assignments_to_one_group_(false), 120 all_assignments_to_one_group_(false),
120 is_expired_(false) { 121 is_expired_(false) {
121 } 122 }
122 123
123 ProcessedStudy::~ProcessedStudy() { 124 ProcessedStudy::~ProcessedStudy() {
124 } 125 }
125 126
(...skipping 17 matching lines...) Expand all
143 144
144 int ProcessedStudy::GetExperimentIndexByName(const std::string& name) const { 145 int ProcessedStudy::GetExperimentIndexByName(const std::string& name) const {
145 for (int i = 0; i < study_->experiment_size(); ++i) { 146 for (int i = 0; i < study_->experiment_size(); ++i) {
146 if (study_->experiment(i).name() == name) 147 if (study_->experiment(i).name() == name)
147 return i; 148 return i;
148 } 149 }
149 150
150 return -1; 151 return -1;
151 } 152 }
152 153
154 const std::string& ProcessedStudy::GetDefaultExperimentName() const {
155 if (study_->default_experiment_name().empty())
156 return kGenericDefaultExperimentName;
157
158 return study_->default_experiment_name();
159 }
160
153 // static 161 // static
154 bool ProcessedStudy::ValidateAndAppendStudy( 162 bool ProcessedStudy::ValidateAndAppendStudy(
155 const Study* study, 163 const Study* study,
156 bool is_expired, 164 bool is_expired,
157 std::vector<ProcessedStudy>* processed_studies) { 165 std::vector<ProcessedStudy>* processed_studies) {
158 ProcessedStudy processed_study; 166 ProcessedStudy processed_study;
159 if (processed_study.Init(study, is_expired)) { 167 if (processed_study.Init(study, is_expired)) {
160 processed_studies->push_back(processed_study); 168 processed_studies->push_back(processed_study);
161 return true; 169 return true;
162 } 170 }
163 return false; 171 return false;
164 } 172 }
165 173
166 } // namespace variations 174 } // namespace variations
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698