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

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: 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 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(MakeNameGroupId("trial", "default"), 123);
32 // FieldTrial::MakeNameGroupId("trial", "default"), 123); 32 // AssociateGoogleExperimentID(MakeNameGroupId("trial", "HighMem"), 456);
33 // AssociateGoogleExperimentID( 33 // AssociateGoogleExperimentID(MakeNameGroupId("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(
41 // FieldTrial::MakeNameGroupId(trial->name(), trial->group_name())); 38 // MakeNameGroupId(trial->name(), 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 {
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 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
59 const experiments_helper::NameGroupId& rhs) const {
60 // The group and name fields are just SHA-1 Hashes, so we just need to treat
61 // them as IDs and do a less-than comparison. We test group first, since
62 // name is more likely to collide.
63 return lhs.group == rhs.group ? lhs.name < rhs.name :
64 lhs.group < rhs.group;
65 }
66 };
67
51 // Used to represent no associated Google experiment ID. Calls to the 68 // Used to represent no associated Google experiment ID. Calls to the
52 // GetGoogleExperimentID API below will return this empty value for FieldTrial 69 // GetGoogleExperimentID API below will return this empty value for FieldTrial
53 // groups uninterested in associating themselves with Google experiments, or 70 // groups uninterested in associating themselves with Google experiments, or
54 // those that have not yet been seen yet. 71 // those that have not yet been seen yet.
55 extern const GoogleExperimentID kEmptyGoogleExperimentID; 72 extern const GoogleExperimentID kEmptyGoogleExperimentID;
56 73
74 // Returns an array of Unique IDs for each Field Trial that has a chosen
75 // group. Field Trials for which a group has not been chosen yet are NOT
76 // returned in this list. In the real world, clients should use
77 // GetFieldTrialNameGroupIds.
78 void GetFieldTrialNameGroupIds(std::vector<NameGroupId>* name_group_ids);
79
80 // Helper function to create a NameGroupId from |trial_name| and |group_name|.
81 NameGroupId MakeNameGroupId(const std::string& trial_name,
82 const std::string& group_name);
83
57 // Set the GoogleExperimentID associated with a FieldTrial group. The group is 84 // Set the GoogleExperimentID associated with a FieldTrial group. The group is
58 // denoted by |group_identifier|, which can be created by passing the 85 // denoted by |group_identifier|, which can be created by passing the
59 // FieldTrial's trial and group names to base::FieldTrial::MakeNameGroupId. 86 // FieldTrial's trial and group names to base::FieldTrial::MakeNameGroupId.
60 // This does not need to be called for FieldTrials uninterested in Google 87 // This does not need to be called for FieldTrials uninterested in Google
61 // experiments. 88 // experiments.
62 void AssociateGoogleExperimentID( 89 void AssociateGoogleExperimentID(const NameGroupId& group_identifier,
63 const base::FieldTrial::NameGroupId& group_identifier, 90 GoogleExperimentID id);
64 GoogleExperimentID id);
65 91
66 // Retrieve the GoogleExperimentID associated with a FieldTrial group. The group 92 // Retrieve the GoogleExperimentID associated with a FieldTrial group. The group
67 // is denoted by |group_identifier| (see comment above). This can be nicely 93 // is denoted by |group_identifier| (see comment above). This can be nicely
68 // combined with FieldTrial::GetFieldTrialNameGroupIds to enumerate the 94 // combined with FieldTrial::GetFieldTrialNameGroupIds to enumerate the
69 // GoogleExperimentIDs for all active FieldTrial groups. 95 // GoogleExperimentIDs for all active FieldTrial groups.
70 GoogleExperimentID GetGoogleExperimentID( 96 GoogleExperimentID GetGoogleExperimentID(const NameGroupId& group_identifier);
71 const base::FieldTrial::NameGroupId& group_identifier);
72 97
73 // Get the current set of chosen FieldTrial groups (aka experiments) and send 98 // 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. 99 // them to the child process logging module so it can save it for crash dumps.
75 void SetChildProcessLoggingExperimentList(); 100 void SetChildProcessLoggingExperimentList();
76 101
77 } // namespace experiments_helper 102 } // namespace experiments_helper
78 103
104 // Expose a couple functions for testing. These functions will just wrap
105 // functionality that is implemented above.
106 namespace testing {
107
108 void TestGetFieldTrialNameGroupIdsForSelectedGroups(
109 const base::FieldTrial::SelectedGroups& selected_groups,
110 std::vector<experiments_helper::NameGroupId>* name_group_ids);
111
112 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
113 const std::string& trial_name,
114 const std::string& group_name);
115
116 uint32 TestHashName(const std::string& name);
117
118 }
119
79 #endif // CHROME_COMMON_METRICS_EXPERIMENTS_HELPER_H_ 120 #endif // CHROME_COMMON_METRICS_EXPERIMENTS_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698