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

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

Issue 1366673002: Introduce a new FieldTrialList::IsTrialActive() API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address nit. Created 5 years, 2 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/variations_associated_data.h" 5 #include "components/variations/variations_associated_data.h"
6 6
7 #include <map> 7 #include <map>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 // Retrieve the singleton. 109 // Retrieve the singleton.
110 static VariationsParamAssociator* GetInstance() { 110 static VariationsParamAssociator* GetInstance() {
111 return base::Singleton<VariationsParamAssociator>::get(); 111 return base::Singleton<VariationsParamAssociator>::get();
112 } 112 }
113 113
114 bool AssociateVariationParams(const std::string& trial_name, 114 bool AssociateVariationParams(const std::string& trial_name,
115 const std::string& group_name, 115 const std::string& group_name,
116 const VariationParams& params) { 116 const VariationParams& params) {
117 base::AutoLock scoped_lock(lock_); 117 base::AutoLock scoped_lock(lock_);
118 118
119 if (IsFieldTrialActive(trial_name)) 119 if (base::FieldTrialList::IsTrialActive(trial_name))
120 return false; 120 return false;
121 121
122 const VariationKey key(trial_name, group_name); 122 const VariationKey key(trial_name, group_name);
123 if (ContainsKey(variation_params_, key)) 123 if (ContainsKey(variation_params_, key))
124 return false; 124 return false;
125 125
126 variation_params_[key] = params; 126 variation_params_[key] = params;
127 return true; 127 return true;
128 } 128 }
129 129
(...skipping 15 matching lines...) Expand all
145 base::AutoLock scoped_lock(lock_); 145 base::AutoLock scoped_lock(lock_);
146 variation_params_.clear(); 146 variation_params_.clear();
147 } 147 }
148 148
149 private: 149 private:
150 friend struct base::DefaultSingletonTraits<VariationsParamAssociator>; 150 friend struct base::DefaultSingletonTraits<VariationsParamAssociator>;
151 151
152 VariationsParamAssociator() {} 152 VariationsParamAssociator() {}
153 ~VariationsParamAssociator() {} 153 ~VariationsParamAssociator() {}
154 154
155 // Tests whether a field trial is active (i.e. group() has been called on it).
156 // TODO(asvitkine): Expose this as an API on base::FieldTrial.
157 bool IsFieldTrialActive(const std::string& trial_name) {
158 base::FieldTrial::ActiveGroups active_groups;
159 base::FieldTrialList::GetActiveFieldTrialGroups(&active_groups);
160 for (size_t i = 0; i < active_groups.size(); ++i) {
161 if (active_groups[i].trial_name == trial_name)
162 return true;
163 }
164 return false;
165 }
166
167 base::Lock lock_; 155 base::Lock lock_;
168 std::map<VariationKey, VariationParams> variation_params_; 156 std::map<VariationKey, VariationParams> variation_params_;
169 157
170 DISALLOW_COPY_AND_ASSIGN(VariationsParamAssociator); 158 DISALLOW_COPY_AND_ASSIGN(VariationsParamAssociator);
171 }; 159 };
172 160
173 } // namespace 161 } // namespace
174 162
175 void AssociateGoogleVariationID(IDCollectionKey key, 163 void AssociateGoogleVariationID(IDCollectionKey key,
176 const std::string& trial_name, 164 const std::string& trial_name,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 GroupMapAccessor::GetInstance()->ClearAllMapsForTesting(); 228 GroupMapAccessor::GetInstance()->ClearAllMapsForTesting();
241 } 229 }
242 230
243 void ClearAllVariationParams() { 231 void ClearAllVariationParams() {
244 VariationsParamAssociator::GetInstance()->ClearAllParamsForTesting(); 232 VariationsParamAssociator::GetInstance()->ClearAllParamsForTesting();
245 } 233 }
246 234
247 } // namespace testing 235 } // namespace testing
248 236
249 } // namespace variations 237 } // namespace variations
OLDNEW
« no previous file with comments | « base/metrics/field_trial.cc ('k') | components/variations/variations_associated_data_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698