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

Side by Side 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: Changed GXID API to accept strings 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 CHROME_COMMON_METRICS_EXPERIMENTS_HELPER_H_ 5 #ifndef CHROME_COMMON_METRICS_EXPERIMENTS_HELPER_H_
6 #define CHROME_COMMON_METRICS_EXPERIMENTS_HELPER_H_ 6 #define CHROME_COMMON_METRICS_EXPERIMENTS_HELPER_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 10
(...skipping 10 matching lines...) Expand all
21 // 21 //
22 // Typical usage looks like this: 22 // Typical usage looks like this:
23 // 23 //
24 // // Set up your trial and groups as usual. 24 // // Set up your trial and groups as usual.
25 // FieldTrial* trial = FieldTrialList::FactoryGetFieldTrial( 25 // FieldTrial* trial = FieldTrialList::FactoryGetFieldTrial(
26 // "trial", 1000, "default", 2012, 12, 31, NULL); 26 // "trial", 1000, "default", 2012, 12, 31, NULL);
27 // const int kHighMemGroup = trial->AppendGroup("HighMem", 20); 27 // const int kHighMemGroup = trial->AppendGroup("HighMem", 20);
28 // const int kLowMemGroup = trial->AppendGroup("LowMem", 20); 28 // const int kLowMemGroup = trial->AppendGroup("LowMem", 20);
29 // // All groups are now created. We want to associate GoogleExperimentIDs with 29 // // All groups are now created. We want to associate GoogleExperimentIDs with
30 // // them, so do that now. 30 // // them, so do that now.
31 // AssociateGoogleExperimentID( 31 // AssociateGoogleExperimentID("trial", "default", 123);
32 // FieldTrial::MakeNameGroupId("trial", "default"), 123); 32 // AssociateGoogleExperimentID("trial", "HighMem", 456);
33 // AssociateGoogleExperimentID( 33 // AssociateGoogleExperimentID("trial", "LowMem", 789);
34 // FieldTrial::MakeNameGroupId("trial", "HighMem"), 456);
35 // AssociateGoogleExperimentID(
36 // FieldTrial::MakeNameGroupId("trial", "LowMem"), 789);
37 // 34 //
38 // // Elsewhere, we are interested in retrieving the GoogleExperimentID 35 // // Elsewhere, we are interested in retrieving the GoogleExperimentID
39 // // assocaited with |trial|. 36 // // assocaited with |trial|.
40 // GoogleExperimentID id = GetGoogleExperimentID( 37 // GoogleExperimentID id = GetGoogleExperimentID(trial->name(),
41 // FieldTrial::MakeNameGroupId(trial->name(), trial->group_name())); 38 // trial->group_name());
42 // // Do stuff with |id|... 39 // // Do stuff with |id|...
43 // 40 //
44 // The AssociateGoogleExperimentID and GetGoogleExperimentID API methods are 41 // The AssociateGoogleExperimentID and GetGoogleExperimentID API methods are
45 // thread safe. 42 // thread safe.
46 namespace experiments_helper { 43 namespace experiments_helper {
47 44
48 // An ID used by Google servers to identify a local browser experiment. 45 // An ID used by Google servers to identify a local browser experiment.
49 typedef uint32 GoogleExperimentID; 46 typedef uint32 GoogleExperimentID;
50 47
48 // The Unique ID of a trial, where the name and group identifiers are
49 // hashes of the trial and group name strings.
50 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
51 uint32 name;
52 uint32 group;
53 };
54
55 // We need to supply a Compare class for templates since NameGroupId is a
56 // user-defined type.
57 struct NameGroupIdCompare {
58 bool operator() (const NameGroupId& lhs, const NameGroupId& rhs) const {
59 // The group and name fields are just SHA-1 Hashes, so we just need to treat
60 // them as IDs and do a less-than comparison. We test group first, since
61 // name is more likely to collide.
62 return lhs.group == rhs.group ? lhs.name < rhs.name :
63 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*,
64 }
65 };
66
51 // Used to represent no associated Google experiment ID. Calls to the 67 // Used to represent no associated Google experiment ID. Calls to the
52 // GetGoogleExperimentID API below will return this empty value for FieldTrial 68 // GetGoogleExperimentID API below will return this empty value for FieldTrial
53 // groups uninterested in associating themselves with Google experiments, or 69 // groups uninterested in associating themselves with Google experiments, or
54 // those that have not yet been seen yet. 70 // those that have not yet been seen yet.
55 extern const GoogleExperimentID kEmptyGoogleExperimentID; 71 extern const GoogleExperimentID kEmptyGoogleExperimentID;
56 72
73 // 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.
74 // group. Field Trials for which a group has not been chosen yet are NOT
75 // returned in this list. In the real world, clients should use
76 // GetFieldTrialNameGroupIds.
77 void GetFieldTrialNameGroupIds(std::vector<NameGroupId>* name_group_ids);
78
57 // Set the GoogleExperimentID associated with a FieldTrial group. The group is 79 // Set the GoogleExperimentID associated with a FieldTrial group. The group is
58 // denoted by |group_identifier|, which can be created by passing the 80 // denoted by |trial_name| and |group_name|. This does not need to be called for
59 // FieldTrial's trial and group names to base::FieldTrial::MakeNameGroupId. 81 // 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
60 // This does not need to be called for FieldTrials uninterested in Google 82 void AssociateGoogleExperimentID(const std::string& trial_name,
61 // experiments. 83 const std::string& group_name,
62 void AssociateGoogleExperimentID( 84 GoogleExperimentID id);
63 const base::FieldTrial::NameGroupId& group_identifier,
64 GoogleExperimentID id);
65 85
66 // Retrieve the GoogleExperimentID associated with a FieldTrial group. The group 86 // Retrieve the GoogleExperimentID associated with a FieldTrial group. The group
67 // is denoted by |group_identifier| (see comment above). This can be nicely 87 // is denoted by |trial_name| and |group_name|. This can be nicely combined with
68 // combined with FieldTrial::GetFieldTrialNameGroupIds to enumerate the 88 // FieldTrial::GetFieldTrialNameGroupIds to enumerate the GoogleExperimentIDs
69 // GoogleExperimentIDs for all active FieldTrial groups. 89 // for all active FieldTrial groups.
70 GoogleExperimentID GetGoogleExperimentID( 90 GoogleExperimentID GetGoogleExperimentID(const std::string& trial_name,
71 const base::FieldTrial::NameGroupId& group_identifier); 91 const std::string& group_name);
72 92
73 // Get the current set of chosen FieldTrial groups (aka experiments) and send 93 // Get the current set of chosen FieldTrial groups (aka experiments) and send
74 // them to the child process logging module so it can save it for crash dumps. 94 // them to the child process logging module so it can save it for crash dumps.
75 void SetChildProcessLoggingExperimentList(); 95 void SetChildProcessLoggingExperimentList();
76 96
77 } // namespace experiments_helper 97 } // namespace experiments_helper
78 98
99 // Expose some functions for testing. These functions just wrap functionality
100 // that is implemented above.
101 namespace testing {
102
103 void TestGetFieldTrialNameGroupIdsForSelectedGroups(
104 const base::FieldTrial::SelectedGroups& selected_groups,
105 std::vector<experiments_helper::NameGroupId>* name_group_ids);
106
107 uint32 TestHashName(const std::string& name);
108
109 }
110
79 #endif // CHROME_COMMON_METRICS_EXPERIMENTS_HELPER_H_ 111 #endif // CHROME_COMMON_METRICS_EXPERIMENTS_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698