Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4716)

Unified Diff: chrome/common/metrics/experiments_helper.h

Issue 10151017: Remove the hash fields from FieldTrials. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: MAD comments. Reshuffled test methods. Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..57d6037b2173a972f1c8cd9f84ee9d687a5715c6 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(MakeNameGroupId("trial", "default"), 123);
+// AssociateGoogleExperimentID(MakeNameGroupId("trial", "HighMem"), 456);
+// AssociateGoogleExperimentID(MakeNameGroupId("trial", "LowMem"), 789);
//
// // Elsewhere, we are interested in retrieving the GoogleExperimentID
// // assocaited with |trial|.
// GoogleExperimentID id = GetGoogleExperimentID(
-// FieldTrial::MakeNameGroupId(trial->name(), trial->group_name()));
+// MakeNameGroupId(trial->name(), trial->group_name()));
// // Do stuff with |id|...
//
// The AssociateGoogleExperimentID and GetGoogleExperimentID API methods are
@@ -48,27 +45,55 @@ 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 {
+ 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 experiments_helper::NameGroupId& lhs,
MAD 2012/04/26 19:40:13 I don't think you need the namespace scope in here
SteveT 2012/04/26 21:06:03 Yup, thanks for the catch :) Oh, and you're okay
+ const experiments_helper::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;
+ }
+};
+
// 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
+// 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);
+
+// Helper function to create a NameGroupId from |trial_name| and |group_name|.
+NameGroupId MakeNameGroupId(const std::string& trial_name,
+ const std::string& group_name);
+
// 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);
+void AssociateGoogleExperimentID(const NameGroupId& group_identifier,
+ 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);
+GoogleExperimentID GetGoogleExperimentID(const NameGroupId& group_identifier);
// 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 +101,20 @@ void SetChildProcessLoggingExperimentList();
} // namespace experiments_helper
+// Expose a couple functions for testing. These functions will 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);
+
+experiments_helper::NameGroupId TestMakeNameGroupId(
MAD 2012/04/26 19:40:13 I don't think you need TestMakeNameGroupId since t
SteveT 2012/04/26 21:06:03 We discussed changing the API to accept strings an
+ const std::string& trial_name,
+ const std::string& group_name);
+
+uint32 TestHashName(const std::string& name);
+
+}
+
#endif // CHROME_COMMON_METRICS_EXPERIMENTS_HELPER_H_

Powered by Google App Engine
This is Rietveld 408576698