OLD | NEW |
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 namespace ExperimentsHelper { | 9 #include "base/metrics/field_trial.h" |
| 10 |
| 11 // This namespace provides various helpers that extend the functionality around |
| 12 // base::FieldTrial. |
| 13 // |
| 14 // This includes a simple API used to handle getting and setting |
| 15 // data related to Google-specific experiments in the browser. This is meant to |
| 16 // be an extension to the base::FieldTrial for Google-specific functionality. |
| 17 // |
| 18 // These calls are meant to be made directly after appending all your groups to |
| 19 // a FieldTrial (for associating IDs) and any time after the group selection has |
| 20 // been done (for retrieving IDs). |
| 21 // |
| 22 // Typical usage looks like this: |
| 23 // |
| 24 // // Set up your trial and groups as usual. |
| 25 // FieldTrial* trial = FieldTrialList::FactoryGetFieldTrial( |
| 26 // "trial", 1000, "default", 2012, 12, 31, NULL); |
| 27 // const int kHighMemGroup = trial->AppendGroup("HighMem", 20); |
| 28 // const int kLowMemGroup = trial->AppendGroup("LowMem", 20); |
| 29 // // All groups are now created. We want to associate GoogleExperimentIDs with |
| 30 // // them, so do that now. |
| 31 // AssociateGoogleExperimentID( |
| 32 // FieldTrial::MakeNameGroupId("trial", "default"), 123); |
| 33 // AssociateGoogleExperimentID( |
| 34 // FieldTrial::MakeNameGroupId("trial", "HighMem"), 456); |
| 35 // AssociateGoogleExperimentID( |
| 36 // FieldTrial::MakeNameGroupId("trial", "LowMem"), 789); |
| 37 // |
| 38 // // Elsewhere, we are interested in retrieving the GoogleExperimentID |
| 39 // // assocaited with |trial|. |
| 40 // GoogleExperimentID id = GetGoogleExperimentID( |
| 41 // FieldTrial::MakeNameGroupId(trial->name(), trial->group_name())); |
| 42 // // Do stuff with |id|... |
| 43 // |
| 44 // The AssociateGoogleExperimentID and GetGoogleExperimentID API methods are |
| 45 // thread safe. |
| 46 namespace experiments_helper { |
| 47 |
| 48 // An ID used by Google servers to identify a local browser experiment. |
| 49 typedef uint32 GoogleExperimentID; |
| 50 |
| 51 // Used to represent no associated Google experiment ID. Calls to the |
| 52 // GetGoogleExperimentID API below will return this empty value for FieldTrial |
| 53 // groups uninterested in associating themselves with Google experiments, or |
| 54 // those that have not yet been seen yet. |
| 55 extern const GoogleExperimentID kEmptyGoogleExperimentID; |
| 56 |
| 57 // Set the GoogleExperimentID associated with a FieldTrial group. The group is |
| 58 // denoted by |group_identifier|, which can be created by passing the |
| 59 // FieldTrial's trial and group names to base::FieldTrial::MakeNameGroupId. |
| 60 // This does not need to be called for FieldTrials uninterested in Google |
| 61 // experiments. |
| 62 void AssociateGoogleExperimentID( |
| 63 const base::FieldTrial::NameGroupId& group_identifier, |
| 64 GoogleExperimentID id); |
| 65 |
| 66 // Retrieve the GoogleExperimentID associated with a FieldTrial group. The group |
| 67 // is denoted by |group_identifier| (see comment above). This can be nicely |
| 68 // combined with FieldTrial::GetFieldTrialNameGroupIds to enumerate the |
| 69 // GoogleExperimentIDs for all active FieldTrial groups. |
| 70 GoogleExperimentID GetGoogleExperimentID( |
| 71 const base::FieldTrial::NameGroupId& group_identifier); |
10 | 72 |
11 // Get the current set of chosen FieldTrial groups (aka experiments) and send | 73 // Get the current set of chosen FieldTrial groups (aka experiments) and send |
12 // them to the child process logging module so it can save it for crash dumps. | 74 // them to the child process logging module so it can save it for crash dumps. |
13 void SetChildProcessLoggingExperimentList(); | 75 void SetChildProcessLoggingExperimentList(); |
14 | 76 |
15 } // namespace ExperimentsHelper | 77 } // namespace experiments_helper |
16 | 78 |
17 #endif // CHROME_COMMON_METRICS_EXPERIMENTS_HELPER_H_ | 79 #endif // CHROME_COMMON_METRICS_EXPERIMENTS_HELPER_H_ |
OLD | NEW |