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 #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 | 9 |
9 #include "base/version.h" | 10 #include "base/version.h" |
10 #include "components/variations/proto/study.pb.h" | 11 #include "components/variations/proto/study.pb.h" |
11 | 12 |
12 namespace chrome_variations { | 13 namespace chrome_variations { |
13 | 14 |
14 namespace { | 15 namespace { |
15 | 16 |
16 // Validates the sanity of |study| and computes the total probability. | 17 // Validates the sanity of |study| and computes the total probability. |
17 bool ValidateStudyAndComputeTotalProbability( | 18 bool ValidateStudyAndComputeTotalProbability( |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 base::FieldTrial::Probability total_probability = 0; | 85 base::FieldTrial::Probability total_probability = 0; |
85 if (!ValidateStudyAndComputeTotalProbability(*study, &total_probability)) | 86 if (!ValidateStudyAndComputeTotalProbability(*study, &total_probability)) |
86 return false; | 87 return false; |
87 | 88 |
88 study_ = study; | 89 study_ = study; |
89 is_expired_ = is_expired; | 90 is_expired_ = is_expired; |
90 total_probability_ = total_probability; | 91 total_probability_ = total_probability; |
91 return true; | 92 return true; |
92 } | 93 } |
93 | 94 |
| 95 int ProcessedStudy::GetExperimentIndexByName( |
| 96 const std::string& name) const { |
| 97 for (int i = 0; i < study_->experiment_size(); ++i) { |
| 98 if (study_->experiment(i).name() == name) |
| 99 return i; |
| 100 } |
| 101 |
| 102 return -1; |
| 103 } |
| 104 |
94 // static | 105 // static |
95 bool ProcessedStudy::ValidateAndAppendStudy( | 106 bool ProcessedStudy::ValidateAndAppendStudy( |
96 const Study* study, | 107 const Study* study, |
97 bool is_expired, | 108 bool is_expired, |
98 std::vector<ProcessedStudy>* processed_studies) { | 109 std::vector<ProcessedStudy>* processed_studies) { |
99 ProcessedStudy processed_study; | 110 ProcessedStudy processed_study; |
100 if (processed_study.Init(study, is_expired)) { | 111 if (processed_study.Init(study, is_expired)) { |
101 processed_studies->push_back(processed_study); | 112 processed_studies->push_back(processed_study); |
102 return true; | 113 return true; |
103 } | 114 } |
104 return false; | 115 return false; |
105 } | 116 } |
106 | 117 |
107 } // namespace chrome_variations | 118 } // namespace chrome_variations |
OLD | NEW |