OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/instant/instant_field_trial.h" | 5 #include "chrome/browser/instant/instant_field_trial.h" |
6 | 6 |
7 #include "base/metrics/field_trial.h" | |
7 #include "chrome/browser/prefs/pref_service.h" | 8 #include "chrome/browser/prefs/pref_service.h" |
8 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
10 | 11 |
11 namespace { | 12 namespace { |
12 bool field_trial_active_ = false; | 13 |
14 // Field trial IDs of the control and experiment groups. Though they are not | |
15 // literally "const", they are set only once, in Activate() below. | |
16 int kControlGroupId1 = 0; | |
jar (doing other things)
2011/08/08 22:28:29
As you noted, these are not const, and hence shoul
sreeram
2011/08/08 22:42:23
Done. These are unnecessary implementation details
| |
17 int kControlGroupId2 = 0; | |
18 int kExperimentGroupId1 = 0; | |
19 int kExperimentGroupId2 = 0; | |
20 | |
13 } | 21 } |
14 | 22 |
15 // static | 23 // static |
16 void InstantFieldTrial::Activate() { | 24 void InstantFieldTrial::Activate() { |
17 field_trial_active_ = true; | 25 scoped_refptr<base::FieldTrial> trial( |
26 new base::FieldTrial("Instant", 10000, "InstantInactive", 2012, 1, 1)); | |
27 | |
28 // One-time randomization is disabled if the user is not opted into UMA. | |
29 if (!base::FieldTrialList::IsOneTimeRandomizationEnabled()) | |
30 return; | |
31 trial->UseOneTimeRandomization(); | |
32 | |
33 kControlGroupId1 = trial->AppendGroup("InstantControl1", 4500); // 45% | |
34 kControlGroupId2 = trial->AppendGroup("InstantControl2", 4500); // 45% | |
35 kExperimentGroupId1 = trial->AppendGroup("InstantExperiment1", 500); // 5% | |
jar (doing other things)
2011/08/08 22:28:29
Notice that you quite reasonably only use probabil
sreeram
2011/08/08 22:42:23
Done. I've reduced the granularity to 0.1%, but no
jar (doing other things)
2011/08/09 16:34:28
ah... you are correct. My mistake. Thanks!
| |
36 kExperimentGroupId2 = trial->AppendGroup("InstantExperiment2", 500); // 5% | |
18 } | 37 } |
19 | 38 |
20 // static | 39 // static |
21 InstantFieldTrial::Group InstantFieldTrial::GetGroup(Profile* profile) { | 40 InstantFieldTrial::Group InstantFieldTrial::GetGroup(Profile* profile) { |
22 if (!field_trial_active_) | |
23 return INACTIVE; | |
24 | |
25 if (profile->IsOffTheRecord()) | 41 if (profile->IsOffTheRecord()) |
26 return INACTIVE; | 42 return INACTIVE; |
27 | 43 |
28 const PrefService* prefs = profile->GetPrefs(); | 44 const PrefService* prefs = profile->GetPrefs(); |
29 if (!prefs || | 45 if (!prefs || |
30 !prefs->GetBoolean(prefs::kSearchSuggestEnabled) || | 46 !prefs->GetBoolean(prefs::kSearchSuggestEnabled) || |
31 prefs->GetBoolean(prefs::kInstantEnabledOnce) || | 47 prefs->GetBoolean(prefs::kInstantEnabledOnce) || |
32 prefs->IsManagedPreference(prefs::kInstantEnabled)) { | 48 prefs->IsManagedPreference(prefs::kInstantEnabled)) { |
33 return INACTIVE; | 49 return INACTIVE; |
34 } | 50 } |
35 | 51 |
36 const int random = prefs->GetInteger(prefs::kInstantFieldTrialRandomDraw); | 52 const int group = base::FieldTrialList::FindValue("Instant"); |
37 return random < 4500 ? CONTROL1 : // 45% | 53 |
38 random < 9000 ? CONTROL2 : // 45% | 54 if (group == base::FieldTrial::kNotFinalized || |
39 random < 9500 ? EXPERIMENT1 // 5% | 55 group == base::FieldTrial::kDefaultGroupNumber) { |
40 : EXPERIMENT2; // 5% | 56 return INACTIVE; |
57 } | |
58 | |
59 return group == kControlGroupId1 ? CONTROL1 : | |
60 group == kControlGroupId2 ? CONTROL2 : | |
61 group == kExperimentGroupId1 ? EXPERIMENT1 : | |
62 group == kExperimentGroupId2 ? EXPERIMENT2 | |
63 : INACTIVE; | |
41 } | 64 } |
42 | 65 |
43 // static | 66 // static |
44 bool InstantFieldTrial::IsExperimentGroup(Profile* profile) { | 67 bool InstantFieldTrial::IsExperimentGroup(Profile* profile) { |
45 Group group = GetGroup(profile); | 68 Group group = GetGroup(profile); |
46 return group == EXPERIMENT1 || group == EXPERIMENT2; | 69 return group == EXPERIMENT1 || group == EXPERIMENT2; |
47 } | 70 } |
48 | 71 |
49 // static | 72 // static |
50 std::string InstantFieldTrial::GetGroupName(Profile* profile) { | 73 std::string InstantFieldTrial::GetGroupName(Profile* profile) { |
51 switch (GetGroup(profile)) { | 74 switch (GetGroup(profile)) { |
52 case INACTIVE: return "InstantInactive"; | 75 case INACTIVE: return "InstantInactive"; |
53 case CONTROL1: return "InstantControl1"; | 76 case CONTROL1: return "InstantControl1"; |
54 case CONTROL2: return "InstantControl2"; | 77 case CONTROL2: return "InstantControl2"; |
55 case EXPERIMENT1: return "InstantExperiment1"; | 78 case EXPERIMENT1: return "InstantExperiment1"; |
56 case EXPERIMENT2: return "InstantExperiment2"; | 79 case EXPERIMENT2: return "InstantExperiment2"; |
57 } | 80 } |
58 NOTREACHED(); | 81 NOTREACHED(); |
59 return "InstantUnknown"; | 82 return "InstantUnknown"; |
60 } | 83 } |
OLD | NEW |