Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/variations/active_field_trials.h" | |
| 6 | |
| 7 #include <vector> | |
| 8 | |
| 9 #include "base/strings/stringprintf.h" | |
| 10 #include "base/strings/utf_string_conversions.h" | |
| 11 #include "components/variations/metrics_util.h" | |
| 12 | |
| 13 namespace chrome_variations { | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 // Populates |name_group_ids| based on |active_groups|. | |
| 18 void GetFieldTrialActiveGroupIdsForActiveGroups( | |
| 19 const base::FieldTrial::ActiveGroups& active_groups, | |
| 20 std::vector<ActiveGroupId>* name_group_ids) { | |
| 21 DCHECK(name_group_ids->empty()); | |
| 22 for (base::FieldTrial::ActiveGroups::const_iterator it = | |
| 23 active_groups.begin(); it != active_groups.end(); ++it) { | |
| 24 name_group_ids->push_back(MakeActiveGroupId(it->trial_name, | |
| 25 it->group_name)); | |
| 26 } | |
| 27 } | |
| 28 | |
| 29 } // namespace | |
| 30 | |
| 31 ActiveGroupId MakeActiveGroupId(const std::string& trial_name, | |
| 32 const std::string& group_name) { | |
| 33 ActiveGroupId id; | |
| 34 id.name = metrics::HashName(trial_name); | |
| 35 id.group = metrics::HashName(group_name); | |
| 36 return id; | |
| 37 } | |
| 38 | |
| 39 void GetFieldTrialActiveGroupIds( | |
| 40 std::vector<ActiveGroupId>* name_group_ids) { | |
| 41 DCHECK(name_group_ids->empty()); | |
| 42 // A note on thread safety: Since GetActiveFieldTrialGroups() is thread | |
| 43 // safe, and we operate on a separate list of that data, this function is | |
| 44 // technically thread safe as well, with respect to the FieldTrialList data. | |
| 45 base::FieldTrial::ActiveGroups active_groups; | |
| 46 base::FieldTrialList::GetActiveFieldTrialGroups(&active_groups); | |
| 47 GetFieldTrialActiveGroupIdsForActiveGroups(active_groups, | |
| 48 name_group_ids); | |
| 49 } | |
| 50 | |
| 51 void GetFieldTrialActiveGroupIdsAsStrings( | |
| 52 std::vector<std::string>* output) { | |
|
Ilya Sherman
2014/05/19 12:29:42
nit: I think this fits on the previous line. Migh
Alexei Svitkine (slow)
2014/05/19 12:50:47
Done.
| |
| 53 DCHECK(output->empty()); | |
| 54 std::vector<ActiveGroupId> name_group_ids; | |
| 55 GetFieldTrialActiveGroupIds(&name_group_ids); | |
| 56 for (size_t i = 0; i < name_group_ids.size(); ++i) { | |
| 57 output->push_back(base::StringPrintf( | |
| 58 "%x-%x", name_group_ids[i].name, name_group_ids[i].group)); | |
| 59 } | |
| 60 } | |
| 61 | |
| 62 // Functions below are exposed for testing explicitly behind this namespace. | |
| 63 // They simply wrap existing functions in this file. | |
|
Ilya Sherman
2014/05/19 12:29:42
nit: Probably not necessary to duplicate this comm
Alexei Svitkine (slow)
2014/05/19 12:50:47
Done.
| |
| 64 namespace testing { | |
| 65 | |
| 66 void TestGetFieldTrialActiveGroupIds( | |
| 67 const base::FieldTrial::ActiveGroups& active_groups, | |
| 68 std::vector<ActiveGroupId>* name_group_ids) { | |
| 69 GetFieldTrialActiveGroupIdsForActiveGroups(active_groups, | |
| 70 name_group_ids); | |
| 71 } | |
| 72 | |
| 73 } // namespace testing | |
| 74 | |
| 75 | |
| 76 } // namespace chrome_variations | |
| OLD | NEW |