OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/common/metrics/variations/variations_util.h" | 5 #include "chrome/common/metrics/variations/variations_util.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 const std::string group_name = | 138 const std::string group_name = |
139 base::FieldTrialList::FindFullName(trial_name); | 139 base::FieldTrialList::FindFullName(trial_name); |
140 const VariationKey key = VariationKey(trial_name, group_name); | 140 const VariationKey key = VariationKey(trial_name, group_name); |
141 if (!ContainsKey(variation_params_, key)) | 141 if (!ContainsKey(variation_params_, key)) |
142 return false; | 142 return false; |
143 | 143 |
144 *params = variation_params_[key]; | 144 *params = variation_params_[key]; |
145 return true; | 145 return true; |
146 } | 146 } |
147 | 147 |
148 void ClearAllParamsForTesting() { | |
Alexei Svitkine (slow)
2013/08/05 18:33:11
You will need to rebase this on top of http://crre
Mark P
2013/08/05 22:11:41
Done.
| |
149 base::AutoLock scoped_lock(lock_); | |
150 variation_params_.clear(); | |
151 } | |
152 | |
148 private: | 153 private: |
149 friend struct DefaultSingletonTraits<VariationsParamAssociator>; | 154 friend struct DefaultSingletonTraits<VariationsParamAssociator>; |
150 | 155 |
151 VariationsParamAssociator() {} | 156 VariationsParamAssociator() {} |
152 ~VariationsParamAssociator() {} | 157 ~VariationsParamAssociator() {} |
153 | 158 |
154 // Tests whether a field trial is active (i.e. group() has been called on it). | 159 // Tests whether a field trial is active (i.e. group() has been called on it). |
155 // TODO(asvitkine): Expose this as an API on base::FieldTrial. | 160 // TODO(asvitkine): Expose this as an API on base::FieldTrial. |
156 bool IsFieldTrialActive(const std::string& trial_name) { | 161 bool IsFieldTrialActive(const std::string& trial_name) { |
157 base::FieldTrial::ActiveGroups active_groups; | 162 base::FieldTrial::ActiveGroups active_groups; |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
371 } | 376 } |
372 | 377 |
373 // Functions below are exposed for testing explicitly behind this namespace. | 378 // Functions below are exposed for testing explicitly behind this namespace. |
374 // They simply wrap existing functions in this file. | 379 // They simply wrap existing functions in this file. |
375 namespace testing { | 380 namespace testing { |
376 | 381 |
377 void ClearAllVariationIDs() { | 382 void ClearAllVariationIDs() { |
378 GroupMapAccessor::GetInstance()->ClearAllMapsForTesting(); | 383 GroupMapAccessor::GetInstance()->ClearAllMapsForTesting(); |
379 } | 384 } |
380 | 385 |
386 void ClearAllVariationParams() { | |
387 VariationsParamAssociator::GetInstance()->ClearAllParamsForTesting(); | |
388 } | |
389 | |
381 void TestGetFieldTrialActiveGroupIds( | 390 void TestGetFieldTrialActiveGroupIds( |
382 const base::FieldTrial::ActiveGroups& active_groups, | 391 const base::FieldTrial::ActiveGroups& active_groups, |
383 std::vector<ActiveGroupId>* name_group_ids) { | 392 std::vector<ActiveGroupId>* name_group_ids) { |
384 GetFieldTrialActiveGroupIdsForActiveGroups(active_groups, | 393 GetFieldTrialActiveGroupIdsForActiveGroups(active_groups, |
385 name_group_ids); | 394 name_group_ids); |
386 } | 395 } |
387 | 396 |
388 } // namespace testing | 397 } // namespace testing |
389 | 398 |
390 } // namespace chrome_variations | 399 } // namespace chrome_variations |
391 | 400 |
OLD | NEW |