[Session restore] Rename group name Enabled to Restore.
[chromium-blink-merge.git] / components / variations / active_field_trials.h
blob882ab8cb9821ad135a9191ed77401eea0b662566
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.
5 #ifndef COMPONENTS_VARIATIONS_ACTIVE_FIELD_TRIALS_H_
6 #define COMPONENTS_VARIATIONS_ACTIVE_FIELD_TRIALS_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/metrics/field_trial.h"
13 namespace variations {
15 // The Unique ID of a trial and its active group, where the name and group
16 // identifiers are hashes of the trial and group name strings.
17 struct ActiveGroupId {
18 uint32 name;
19 uint32 group;
22 // Returns an ActiveGroupId struct for the given trial and group names.
23 ActiveGroupId MakeActiveGroupId(const std::string& trial_name,
24 const std::string& group_name);
26 // We need to supply a Compare class for templates since ActiveGroupId is a
27 // user-defined type.
28 struct ActiveGroupIdCompare {
29 bool operator() (const ActiveGroupId& lhs, const ActiveGroupId& rhs) const {
30 // The group and name fields are just SHA-1 Hashes, so we just need to treat
31 // them as IDs and do a less-than comparison. We test group first, since
32 // name is more likely to collide.
33 if (lhs.group != rhs.group)
34 return lhs.group < rhs.group;
35 return lhs.name < rhs.name;
39 // Fills the supplied vector |name_group_ids| (which must be empty when called)
40 // with unique ActiveGroupIds for each Field Trial that has a chosen group.
41 // Field Trials for which a group has not been chosen yet are NOT returned in
42 // this list.
43 void GetFieldTrialActiveGroupIds(std::vector<ActiveGroupId>* name_group_ids);
45 // Fills the supplied vector |output| (which must be empty when called) with
46 // unique string representations of ActiveGroupIds for each Field Trial that
47 // has a chosen group. The strings are formatted as "<TrialName>-<GroupName>",
48 // with the names as hex strings. Field Trials for which a group has not been
49 // chosen yet are NOT returned in this list.
50 void GetFieldTrialActiveGroupIdsAsStrings(std::vector<std::string>* output);
52 // Expose some functions for testing. These functions just wrap functionality
53 // that is implemented above.
54 namespace testing {
56 void TestGetFieldTrialActiveGroupIds(
57 const base::FieldTrial::ActiveGroups& active_groups,
58 std::vector<ActiveGroupId>* name_group_ids);
60 } // namespace testing
62 } // namespace variations
64 #endif // COMPONENTS_VARIATIONS_ACTIVE_FIELD_TRIALS_H_