Chromium Code Reviews| Index: chrome/common/metrics/experiments_helper.h |
| diff --git a/chrome/common/metrics/experiments_helper.h b/chrome/common/metrics/experiments_helper.h |
| index 102e6351c75795bfff3d624294d5b8a89f06f2d9..7b37c45a656a8f3b02f6f977f51b71f32037c506 100644 |
| --- a/chrome/common/metrics/experiments_helper.h |
| +++ b/chrome/common/metrics/experiments_helper.h |
| @@ -28,17 +28,14 @@ |
| // const int kLowMemGroup = trial->AppendGroup("LowMem", 20); |
| // // All groups are now created. We want to associate GoogleExperimentIDs with |
| // // them, so do that now. |
| -// AssociateGoogleExperimentID( |
| -// FieldTrial::MakeNameGroupId("trial", "default"), 123); |
| -// AssociateGoogleExperimentID( |
| -// FieldTrial::MakeNameGroupId("trial", "HighMem"), 456); |
| -// AssociateGoogleExperimentID( |
| -// FieldTrial::MakeNameGroupId("trial", "LowMem"), 789); |
| +// AssociateGoogleExperimentID("trial", "default", 123); |
| +// AssociateGoogleExperimentID("trial", "HighMem", 456); |
| +// AssociateGoogleExperimentID("trial", "LowMem", 789); |
| // |
| // // Elsewhere, we are interested in retrieving the GoogleExperimentID |
| // // assocaited with |trial|. |
| -// GoogleExperimentID id = GetGoogleExperimentID( |
| -// FieldTrial::MakeNameGroupId(trial->name(), trial->group_name())); |
| +// GoogleExperimentID id = GetGoogleExperimentID(trial->name(), |
| +// trial->group_name()); |
| // // Do stuff with |id|... |
| // |
| // The AssociateGoogleExperimentID and GetGoogleExperimentID API methods are |
| @@ -48,27 +45,50 @@ namespace experiments_helper { |
| // An ID used by Google servers to identify a local browser experiment. |
| typedef uint32 GoogleExperimentID; |
| +// The Unique ID of a trial, where the name and group identifiers are |
| +// hashes of the trial and group name strings. |
| +struct NameGroupId { |
|
jar (doing other things)
2012/04/26 22:24:22
nit: I found this name hard to guess about. As it
SteveT
2012/04/26 23:42:47
I'll take you up on SelectedGroupIds. "Hashes" is
|
| + uint32 name; |
| + uint32 group; |
| +}; |
| + |
| +// We need to supply a Compare class for templates since NameGroupId is a |
| +// user-defined type. |
| +struct NameGroupIdCompare { |
| + bool operator() (const NameGroupId& lhs, const NameGroupId& rhs) const { |
| + // The group and name fields are just SHA-1 Hashes, so we just need to treat |
| + // them as IDs and do a less-than comparison. We test group first, since |
| + // name is more likely to collide. |
| + return lhs.group == rhs.group ? lhs.name < rhs.name : |
| + lhs.group < rhs.group; |
|
jar (doing other things)
2012/04/26 22:24:22
nit: (You can ignore... as some folks are in love
SteveT
2012/04/26 23:42:47
I personally find ternaries pretty easy to read*,
|
| + } |
| +}; |
| + |
| // Used to represent no associated Google experiment ID. Calls to the |
| // GetGoogleExperimentID API below will return this empty value for FieldTrial |
| // groups uninterested in associating themselves with Google experiments, or |
| // those that have not yet been seen yet. |
| extern const GoogleExperimentID kEmptyGoogleExperimentID; |
| +// Returns an array of Unique IDs for each Field Trial that has a chosen |
|
jar (doing other things)
2012/04/26 22:24:22
nit: "Returns an array..." ---> "Fills in vector
SteveT
2012/04/26 23:42:47
Done.
|
| +// group. Field Trials for which a group has not been chosen yet are NOT |
| +// returned in this list. In the real world, clients should use |
| +// GetFieldTrialNameGroupIds. |
| +void GetFieldTrialNameGroupIds(std::vector<NameGroupId>* name_group_ids); |
| + |
| // Set the GoogleExperimentID associated with a FieldTrial group. The group is |
| -// denoted by |group_identifier|, which can be created by passing the |
| -// FieldTrial's trial and group names to base::FieldTrial::MakeNameGroupId. |
| -// This does not need to be called for FieldTrials uninterested in Google |
| -// experiments. |
| -void AssociateGoogleExperimentID( |
| - const base::FieldTrial::NameGroupId& group_identifier, |
| - GoogleExperimentID id); |
| +// denoted by |trial_name| and |group_name|. This does not need to be called for |
| +// FieldTrials uninterested in Google experiments. |
|
jar (doing other things)
2012/04/26 22:24:22
I couldn't parse the comment, and understand what
SteveT
2012/04/26 23:42:47
Okay, I hope this is a little bit better. We avoid
jar (doing other things)
2012/04/27 19:05:44
Perfect! Thanks!
On 2012/04/26 23:42:47, SteveT w
|
| +void AssociateGoogleExperimentID(const std::string& trial_name, |
| + const std::string& group_name, |
| + GoogleExperimentID id); |
| // Retrieve the GoogleExperimentID associated with a FieldTrial group. The group |
| -// is denoted by |group_identifier| (see comment above). This can be nicely |
| -// combined with FieldTrial::GetFieldTrialNameGroupIds to enumerate the |
| -// GoogleExperimentIDs for all active FieldTrial groups. |
| -GoogleExperimentID GetGoogleExperimentID( |
| - const base::FieldTrial::NameGroupId& group_identifier); |
| +// is denoted by |trial_name| and |group_name|. This can be nicely combined with |
| +// FieldTrial::GetFieldTrialNameGroupIds to enumerate the GoogleExperimentIDs |
| +// for all active FieldTrial groups. |
| +GoogleExperimentID GetGoogleExperimentID(const std::string& trial_name, |
| + const std::string& group_name); |
| // Get the current set of chosen FieldTrial groups (aka experiments) and send |
| // them to the child process logging module so it can save it for crash dumps. |
| @@ -76,4 +96,16 @@ void SetChildProcessLoggingExperimentList(); |
| } // namespace experiments_helper |
| +// Expose some functions for testing. These functions just wrap functionality |
| +// that is implemented above. |
| +namespace testing { |
| + |
| +void TestGetFieldTrialNameGroupIdsForSelectedGroups( |
| + const base::FieldTrial::SelectedGroups& selected_groups, |
| + std::vector<experiments_helper::NameGroupId>* name_group_ids); |
| + |
| +uint32 TestHashName(const std::string& name); |
| + |
| +} |
| + |
| #endif // CHROME_COMMON_METRICS_EXPERIMENTS_HELPER_H_ |