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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "chrome/browser/metrics/metrics_service.h" | 9 #include "chrome/browser/metrics/metrics_service.h" |
10 #include "chrome/browser/prefs/pref_service.h" | 10 #include "chrome/browser/prefs/pref_service.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 // Field trial IDs of the control and experiment groups. Though they are not | 17 // Field trial IDs of the control and experiment groups. Though they are not |
18 // literally "const", they are set only once, in Activate() below. See the .h | 18 // literally "const", they are set only once, in Activate() below. See the .h |
19 // file for what these groups represent. | 19 // file for what these groups represent. |
20 int g_instant_control_a = 0; | |
21 int g_instant_control_b = 0; | |
22 int g_instant_experiment_a = 0; | 20 int g_instant_experiment_a = 0; |
23 int g_instant_experiment_b = 0; | 21 int g_instant_experiment_b = 0; |
24 | |
25 int g_hidden_control_a = 0; | |
26 int g_hidden_control_b = 0; | |
27 int g_hidden_experiment_a = 0; | 22 int g_hidden_experiment_a = 0; |
28 int g_hidden_experiment_b = 0; | 23 int g_hidden_experiment_b = 0; |
| 24 int g_silent_experiment_a = 0; |
| 25 int g_silent_experiment_b = 0; |
| 26 |
| 27 int g_uma_control_a = 0; |
| 28 int g_uma_control_b = 0; |
| 29 int g_all_control_a = 0; |
| 30 int g_all_control_b = 0; |
29 | 31 |
30 } | 32 } |
31 | 33 |
32 // static | 34 // static |
33 void InstantFieldTrial::Activate() { | 35 void InstantFieldTrial::Activate() { |
34 scoped_refptr<base::FieldTrial> trial( | 36 scoped_refptr<base::FieldTrial> trial( |
35 new base::FieldTrial("Instant", 1000, "Inactive", 2012, 7, 1)); | 37 new base::FieldTrial("Instant", 1000, "Inactive", 2012, 7, 1)); |
36 | 38 |
37 // Try to give the user a consistent experience, if possible. | 39 // Try to give the user a consistent experience, if possible. |
38 if (base::FieldTrialList::IsOneTimeRandomizationEnabled()) | 40 if (base::FieldTrialList::IsOneTimeRandomizationEnabled()) |
39 trial->UseOneTimeRandomization(); | 41 trial->UseOneTimeRandomization(); |
40 | 42 |
41 // Each group is of size 5%. | 43 // Each group is of total size 10% (5% each for the _a and _b variants). |
42 g_instant_control_a = trial->AppendGroup("InstantControlA", 50); | |
43 g_instant_control_b = trial->AppendGroup("InstantControlB", 50); | |
44 g_instant_experiment_a = trial->AppendGroup("InstantExperimentA", 50); | 44 g_instant_experiment_a = trial->AppendGroup("InstantExperimentA", 50); |
45 g_instant_experiment_b = trial->AppendGroup("InstantExperimentB", 50); | 45 g_instant_experiment_b = trial->AppendGroup("InstantExperimentB", 50); |
46 | |
47 g_hidden_control_a = trial->AppendGroup("HiddenControlA", 50); | |
48 g_hidden_control_b = trial->AppendGroup("HiddenControlB", 50); | |
49 g_hidden_experiment_a = trial->AppendGroup("HiddenExperimentA", 50); | 46 g_hidden_experiment_a = trial->AppendGroup("HiddenExperimentA", 50); |
50 g_hidden_experiment_b = trial->AppendGroup("HiddenExperimentB", 50); | 47 g_hidden_experiment_b = trial->AppendGroup("HiddenExperimentB", 50); |
| 48 g_silent_experiment_a = trial->AppendGroup("SilentExperimentA", 50); |
| 49 g_silent_experiment_b = trial->AppendGroup("SilentExperimentB", 50); |
| 50 |
| 51 g_uma_control_a = trial->AppendGroup("UmaControlA", 50); |
| 52 g_uma_control_b = trial->AppendGroup("UmaControlB", 50); |
| 53 g_all_control_a = trial->AppendGroup("AllControlA", 50); |
| 54 g_all_control_b = trial->AppendGroup("AllControlB", 50); |
51 } | 55 } |
52 | 56 |
53 // static | 57 // static |
54 InstantFieldTrial::Group InstantFieldTrial::GetGroup(Profile* profile) { | 58 InstantFieldTrial::Group InstantFieldTrial::GetGroup(Profile* profile) { |
55 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 59 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
56 if (command_line->HasSwitch(switches::kInstantFieldTrial)) { | 60 if (command_line->HasSwitch(switches::kInstantFieldTrial)) { |
57 std::string switch_value = | 61 std::string switch_value = |
58 command_line->GetSwitchValueASCII(switches::kInstantFieldTrial); | 62 command_line->GetSwitchValueASCII(switches::kInstantFieldTrial); |
59 if (switch_value == switches::kInstantFieldTrialInstant) | 63 if (switch_value == switches::kInstantFieldTrialInstant) |
60 return INSTANT_EXPERIMENT_A; | 64 return INSTANT_EXPERIMENT_A; |
61 else if (switch_value == switches::kInstantFieldTrialHidden) | 65 else if (switch_value == switches::kInstantFieldTrialHidden) |
62 return HIDDEN_EXPERIMENT_A; | 66 return HIDDEN_EXPERIMENT_A; |
| 67 else if (switch_value == switches::kInstantFieldTrialSilent) |
| 68 return SILENT_EXPERIMENT_A; |
63 else | 69 else |
64 return INACTIVE; | 70 return INACTIVE; |
65 } | 71 } |
66 | 72 |
67 const int group = base::FieldTrialList::FindValue("Instant"); | 73 const int group = base::FieldTrialList::FindValue("Instant"); |
68 if (group == base::FieldTrial::kNotFinalized || | 74 if (group == base::FieldTrial::kNotFinalized || |
69 group == base::FieldTrial::kDefaultGroupNumber) { | 75 group == base::FieldTrial::kDefaultGroupNumber) { |
70 return INACTIVE; | 76 return INACTIVE; |
71 } | 77 } |
72 | 78 |
73 if (!profile) | 79 const PrefService* prefs = profile ? profile->GetPrefs() : NULL; |
74 return INACTIVE; | |
75 | |
76 const PrefService* prefs = profile->GetPrefs(); | |
77 if (!prefs || | 80 if (!prefs || |
78 prefs->GetBoolean(prefs::kInstantEnabledOnce) || | 81 prefs->GetBoolean(prefs::kInstantEnabledOnce) || |
79 prefs->IsManagedPreference(prefs::kInstantEnabled)) { | 82 prefs->IsManagedPreference(prefs::kInstantEnabled)) { |
80 return INACTIVE; | 83 return INACTIVE; |
81 } | 84 } |
82 | 85 |
83 // HIDDEN groups. | 86 // First, deal with the groups that don't require UMA opt-in. |
84 if (group == g_hidden_control_a) | 87 if (group == g_silent_experiment_a) |
85 return HIDDEN_CONTROL_A; | 88 return SILENT_EXPERIMENT_A; |
86 if (group == g_hidden_control_b) | 89 if (group == g_silent_experiment_b) |
87 return HIDDEN_CONTROL_B; | 90 return SILENT_EXPERIMENT_B; |
88 if (group == g_hidden_experiment_a) | 91 if (group == g_all_control_a) |
89 return HIDDEN_EXPERIMENT_A; | 92 return ALL_CONTROL_A; |
90 if (group == g_hidden_experiment_b) | 93 if (group == g_all_control_b) |
91 return HIDDEN_EXPERIMENT_B; | 94 return ALL_CONTROL_B; |
92 | 95 |
93 // INSTANT group users must meet some extra requirements. | 96 // All other groups require UMA and suggest, else bounce back to INACTIVE. |
94 if (profile->IsOffTheRecord() || | 97 if (profile->IsOffTheRecord() || |
95 !MetricsServiceHelper::IsMetricsReportingEnabled() || | 98 !MetricsServiceHelper::IsMetricsReportingEnabled() || |
96 !prefs->GetBoolean(prefs::kSearchSuggestEnabled)) { | 99 !prefs->GetBoolean(prefs::kSearchSuggestEnabled)) { |
97 return INACTIVE; | 100 return INACTIVE; |
98 } | 101 } |
99 | 102 |
100 // INSTANT groups. | |
101 if (group == g_instant_control_a) | |
102 return INSTANT_CONTROL_A; | |
103 if (group == g_instant_control_b) | |
104 return INSTANT_CONTROL_B; | |
105 if (group == g_instant_experiment_a) | 103 if (group == g_instant_experiment_a) |
106 return INSTANT_EXPERIMENT_A; | 104 return INSTANT_EXPERIMENT_A; |
107 if (group == g_instant_experiment_b) | 105 if (group == g_instant_experiment_b) |
108 return INSTANT_EXPERIMENT_B; | 106 return INSTANT_EXPERIMENT_B; |
| 107 if (group == g_hidden_experiment_a) |
| 108 return HIDDEN_EXPERIMENT_A; |
| 109 if (group == g_hidden_experiment_b) |
| 110 return HIDDEN_EXPERIMENT_B; |
| 111 if (group == g_uma_control_a) |
| 112 return UMA_CONTROL_A; |
| 113 if (group == g_uma_control_b) |
| 114 return UMA_CONTROL_B; |
109 | 115 |
110 NOTREACHED(); | 116 NOTREACHED(); |
111 return INACTIVE; | 117 return INACTIVE; |
112 } | 118 } |
113 | 119 |
114 // static | 120 // static |
115 bool InstantFieldTrial::IsExperimentGroup(Profile* profile) { | 121 bool InstantFieldTrial::IsExperimentGroup(Profile* profile) { |
116 Group group = GetGroup(profile); | 122 Group group = GetGroup(profile); |
117 return group == INSTANT_EXPERIMENT_A || group == INSTANT_EXPERIMENT_B || | 123 return group == INSTANT_EXPERIMENT_A || group == INSTANT_EXPERIMENT_B || |
118 group == HIDDEN_EXPERIMENT_A || group == HIDDEN_EXPERIMENT_B; | 124 group == HIDDEN_EXPERIMENT_A || group == HIDDEN_EXPERIMENT_B || |
119 } | 125 group == SILENT_EXPERIMENT_A || group == SILENT_EXPERIMENT_B; |
120 | |
121 // static | |
122 bool InstantFieldTrial::IsInstantExperiment(Profile* profile) { | |
123 Group group = GetGroup(profile); | |
124 return group == INSTANT_EXPERIMENT_A || group == INSTANT_EXPERIMENT_B; | |
125 } | 126 } |
126 | 127 |
127 // static | 128 // static |
128 bool InstantFieldTrial::IsHiddenExperiment(Profile* profile) { | 129 bool InstantFieldTrial::IsHiddenExperiment(Profile* profile) { |
129 Group group = GetGroup(profile); | 130 Group group = GetGroup(profile); |
130 return group == HIDDEN_EXPERIMENT_A || group == HIDDEN_EXPERIMENT_B; | 131 return group == HIDDEN_EXPERIMENT_A || group == HIDDEN_EXPERIMENT_B; |
131 } | 132 } |
132 | 133 |
133 // static | 134 // static |
| 135 bool InstantFieldTrial::IsSilentExperiment(Profile* profile) { |
| 136 Group group = GetGroup(profile); |
| 137 return group == SILENT_EXPERIMENT_A || group == SILENT_EXPERIMENT_B; |
| 138 } |
| 139 |
| 140 // static |
134 std::string InstantFieldTrial::GetGroupName(Profile* profile) { | 141 std::string InstantFieldTrial::GetGroupName(Profile* profile) { |
135 switch (GetGroup(profile)) { | 142 switch (GetGroup(profile)) { |
136 case INACTIVE: return std::string(); | 143 case INACTIVE: return std::string(); |
137 | 144 |
138 case INSTANT_CONTROL_A: return "_InstantControlA"; | |
139 case INSTANT_CONTROL_B: return "_InstantControlB"; | |
140 case INSTANT_EXPERIMENT_A: return "_InstantExperimentA"; | 145 case INSTANT_EXPERIMENT_A: return "_InstantExperimentA"; |
141 case INSTANT_EXPERIMENT_B: return "_InstantExperimentB"; | 146 case INSTANT_EXPERIMENT_B: return "_InstantExperimentB"; |
142 | |
143 case HIDDEN_CONTROL_A: return "_HiddenControlA"; | |
144 case HIDDEN_CONTROL_B: return "_HiddenControlB"; | |
145 case HIDDEN_EXPERIMENT_A: return "_HiddenExperimentA"; | 147 case HIDDEN_EXPERIMENT_A: return "_HiddenExperimentA"; |
146 case HIDDEN_EXPERIMENT_B: return "_HiddenExperimentB"; | 148 case HIDDEN_EXPERIMENT_B: return "_HiddenExperimentB"; |
| 149 case SILENT_EXPERIMENT_A: return "_SilentExperimentA"; |
| 150 case SILENT_EXPERIMENT_B: return "_SilentExperimentB"; |
| 151 |
| 152 case UMA_CONTROL_A: return "_UmaControlA"; |
| 153 case UMA_CONTROL_B: return "_UmaControlB"; |
| 154 case ALL_CONTROL_A: return "_AllControlA"; |
| 155 case ALL_CONTROL_B: return "_AllControlB"; |
147 } | 156 } |
148 | 157 |
149 NOTREACHED(); | 158 NOTREACHED(); |
150 return std::string(); | 159 return std::string(); |
151 } | 160 } |
152 | 161 |
153 // static | 162 // static |
154 std::string InstantFieldTrial::GetGroupAsUrlParam(Profile* profile) { | 163 std::string InstantFieldTrial::GetGroupAsUrlParam(Profile* profile) { |
155 switch (GetGroup(profile)) { | 164 switch (GetGroup(profile)) { |
156 case INACTIVE: return std::string(); | 165 case INACTIVE: return std::string(); |
157 | 166 |
158 case INSTANT_CONTROL_A: return "ix=ica&"; | |
159 case INSTANT_CONTROL_B: return "ix=icb&"; | |
160 case INSTANT_EXPERIMENT_A: return "ix=iea&"; | 167 case INSTANT_EXPERIMENT_A: return "ix=iea&"; |
161 case INSTANT_EXPERIMENT_B: return "ix=ieb&"; | 168 case INSTANT_EXPERIMENT_B: return "ix=ieb&"; |
162 | |
163 case HIDDEN_CONTROL_A: return "ix=hca&"; | |
164 case HIDDEN_CONTROL_B: return "ix=hcb&"; | |
165 case HIDDEN_EXPERIMENT_A: return "ix=hea&"; | 169 case HIDDEN_EXPERIMENT_A: return "ix=hea&"; |
166 case HIDDEN_EXPERIMENT_B: return "ix=heb&"; | 170 case HIDDEN_EXPERIMENT_B: return "ix=heb&"; |
| 171 case SILENT_EXPERIMENT_A: return "ix=sea&"; |
| 172 case SILENT_EXPERIMENT_B: return "ix=seb&"; |
| 173 |
| 174 case UMA_CONTROL_A: return "ix=uca&"; |
| 175 case UMA_CONTROL_B: return "ix=ucb&"; |
| 176 case ALL_CONTROL_A: return "ix=aca&"; |
| 177 case ALL_CONTROL_B: return "ix=acb&"; |
167 } | 178 } |
168 | 179 |
169 NOTREACHED(); | 180 NOTREACHED(); |
170 return std::string(); | 181 return std::string(); |
171 } | 182 } |
OLD | NEW |