OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef COMPONENTS_VARIATIONS_ACTIVE_FIELD_TRIALS_H_ | 5 #ifndef COMPONENTS_VARIATIONS_ACTIVE_FIELD_TRIALS_H_ |
6 #define COMPONENTS_VARIATIONS_ACTIVE_FIELD_TRIALS_H_ | 6 #define COMPONENTS_VARIATIONS_ACTIVE_FIELD_TRIALS_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/metrics/field_trial.h" | 12 #include "base/metrics/field_trial.h" |
| 13 #include "base/strings/string_piece.h" |
13 | 14 |
14 namespace variations { | 15 namespace variations { |
15 | 16 |
16 // The Unique ID of a trial and its active group, where the name and group | 17 // The Unique ID of a trial and its active group, where the name and group |
17 // identifiers are hashes of the trial and group name strings. | 18 // identifiers are hashes of the trial and group name strings. |
18 struct ActiveGroupId { | 19 struct ActiveGroupId { |
19 uint32_t name; | 20 uint32_t name; |
20 uint32_t group; | 21 uint32_t group; |
21 }; | 22 }; |
22 | 23 |
23 // Returns an ActiveGroupId struct for the given trial and group names. | 24 // Returns an ActiveGroupId struct for the given trial and group names. |
24 ActiveGroupId MakeActiveGroupId(const std::string& trial_name, | 25 ActiveGroupId MakeActiveGroupId(base::StringPiece trial_name, |
25 const std::string& group_name); | 26 base::StringPiece group_name); |
26 | 27 |
27 // We need to supply a Compare class for templates since ActiveGroupId is a | 28 // We need to supply a Compare class for templates since ActiveGroupId is a |
28 // user-defined type. | 29 // user-defined type. |
29 struct ActiveGroupIdCompare { | 30 struct ActiveGroupIdCompare { |
30 bool operator() (const ActiveGroupId& lhs, const ActiveGroupId& rhs) const { | 31 bool operator() (const ActiveGroupId& lhs, const ActiveGroupId& rhs) const { |
31 // The group and name fields are just SHA-1 Hashes, so we just need to treat | 32 // The group and name fields are just SHA-1 Hashes, so we just need to treat |
32 // them as IDs and do a less-than comparison. We test group first, since | 33 // them as IDs and do a less-than comparison. We test group first, since |
33 // name is more likely to collide. | 34 // name is more likely to collide. |
34 if (lhs.group != rhs.group) | 35 if (lhs.group != rhs.group) |
35 return lhs.group < rhs.group; | 36 return lhs.group < rhs.group; |
(...skipping 27 matching lines...) Expand all Loading... |
63 | 64 |
64 void TestGetFieldTrialActiveGroupIds( | 65 void TestGetFieldTrialActiveGroupIds( |
65 const base::FieldTrial::ActiveGroups& active_groups, | 66 const base::FieldTrial::ActiveGroups& active_groups, |
66 std::vector<ActiveGroupId>* name_group_ids); | 67 std::vector<ActiveGroupId>* name_group_ids); |
67 | 68 |
68 } // namespace testing | 69 } // namespace testing |
69 | 70 |
70 } // namespace variations | 71 } // namespace variations |
71 | 72 |
72 #endif // COMPONENTS_VARIATIONS_ACTIVE_FIELD_TRIALS_H_ | 73 #endif // COMPONENTS_VARIATIONS_ACTIVE_FIELD_TRIALS_H_ |
OLD | NEW |