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 #include "chrome/browser/ui/webui/sync_promo/sync_promo_trial.h" | 5 #include "chrome/browser/ui/webui/sync_promo/sync_promo_trial.h" |
6 | 6 |
7 #include "base/command_line.h" | |
8 #include "base/metrics/field_trial.h" | |
9 #include "base/string_number_conversions.h" | |
10 #include "base/string_util.h" | |
11 #include "chrome/browser/google/google_util.h" | |
12 #include "chrome/browser/metrics/metrics_service.h" | |
13 #include "chrome/browser/prefs/pref_service.h" | |
14 #include "chrome/browser/profiles/profile.h" | |
15 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" | |
16 #include "chrome/common/chrome_switches.h" | |
17 #include "chrome/common/chrome_version_info.h" | |
18 #include "content/public/browser/web_contents.h" | |
19 #include "content/public/browser/web_ui.h" | |
20 #include "grit/generated_resources.h" | |
21 | |
22 namespace { | |
23 | |
24 const char kLayoutExperimentTrialName[] = "SyncPromoLayoutExperiment"; | |
25 | |
26 enum LayoutExperimentType { | |
27 LAYOUT_EXPERIMENT_DEFAULT = 0, | |
28 LAYOUT_EXPERIMENT_DEVICES, | |
29 LAYOUT_EXPERIMENT_VERBOSE, | |
30 LAYOUT_EXPERIMENT_SIMPLE, | |
31 LAYOUT_EXPERIMENT_NONE, | |
32 LAYOUT_EXPERIMENT_DIALOG, | |
33 LAYOUT_EXPERIMENT_BOUNDARY, | |
34 }; | |
35 | |
36 // Flag to make sure sync_promo_trial::Activate() has been called. | |
37 bool sync_promo_trial_initialized; | |
38 | |
39 // Checks if a sync promo layout experiment is active. If it is active then the | |
40 // layout type is return in |type|. | |
41 bool GetActiveLayoutExperiment(LayoutExperimentType* type) { | |
42 DCHECK(type); | |
43 | |
44 int version = 0; | |
45 if (base::StringToInt(CommandLine::ForCurrentProcess()-> | |
46 GetSwitchValueASCII(switches::kSyncPromoVersion), &version)) { | |
47 switch (version) { | |
48 case SyncPromoUI::VERSION_DEFAULT: | |
49 *type = LAYOUT_EXPERIMENT_DEFAULT; | |
50 return true; | |
51 case SyncPromoUI::VERSION_DEVICES: | |
52 *type = LAYOUT_EXPERIMENT_DEVICES; | |
53 return true; | |
54 case SyncPromoUI::VERSION_VERBOSE: | |
55 *type = LAYOUT_EXPERIMENT_VERBOSE; | |
56 return true; | |
57 case SyncPromoUI::VERSION_SIMPLE: | |
58 *type = LAYOUT_EXPERIMENT_SIMPLE; | |
59 return true; | |
60 case SyncPromoUI::VERSION_DIALOG: | |
61 *type = LAYOUT_EXPERIMENT_DIALOG; | |
62 return true; | |
63 default: | |
64 return false; | |
65 } | |
66 } | |
67 | |
68 if (chrome::VersionInfo::GetChannel() == | |
69 chrome::VersionInfo::CHANNEL_STABLE) { | |
70 std::string brand; | |
71 if (!google_util::GetBrand(&brand)) | |
72 return false; | |
73 | |
74 if (brand == "GGRG" || brand == "CHCG") | |
75 *type = LAYOUT_EXPERIMENT_DEFAULT; | |
76 else if (brand == "GGRH" || brand == "CHCH") | |
77 *type = LAYOUT_EXPERIMENT_DEVICES; | |
78 else if (brand == "GGRI" || brand == "CHCI") | |
79 *type = LAYOUT_EXPERIMENT_VERBOSE; | |
80 else if (brand == "GGRJ" || brand == "CHCJ") | |
81 *type = LAYOUT_EXPERIMENT_SIMPLE; | |
82 else if (brand == "GGRL" || brand == "CHCL") | |
83 *type = LAYOUT_EXPERIMENT_NONE; | |
84 else if (brand == "GGRK" || brand == "CHCK") | |
85 *type = LAYOUT_EXPERIMENT_DIALOG; | |
86 else | |
87 return false; | |
88 } else { | |
89 if (!base::FieldTrialList::TrialExists(kLayoutExperimentTrialName)) | |
90 return false; | |
91 int value = base::FieldTrialList::FindValue(kLayoutExperimentTrialName) - | |
92 base::FieldTrial::kDefaultGroupNumber; | |
93 *type = static_cast<LayoutExperimentType>(value); | |
94 } | |
95 | |
96 return true; | |
97 } | |
98 | |
99 } // namespace | |
100 | |
101 namespace sync_promo_trial { | 7 namespace sync_promo_trial { |
102 | 8 |
103 void Activate() { | |
104 DCHECK(!sync_promo_trial_initialized); | |
105 sync_promo_trial_initialized = true; | |
106 | |
107 // For stable builds we'll use brand codes to enroll uesrs into experiments. | |
108 // For dev and beta we don't have brand codes so we randomly enroll users. | |
109 if (chrome::VersionInfo::GetChannel() != | |
110 chrome::VersionInfo::CHANNEL_STABLE) { | |
111 #if defined(GOOGLE_CHROME_BUILD) | |
112 // Create a field trial that expires in August 8, 2012. It contains 6 groups | |
113 // with each group having an equal chance of enrollment. | |
114 scoped_refptr<base::FieldTrial> trial(new base::FieldTrial( | |
115 kLayoutExperimentTrialName, 6, "default", 2012, 8, 1)); | |
116 if (base::FieldTrialList::IsOneTimeRandomizationEnabled()) | |
117 trial->UseOneTimeRandomization(); | |
118 trial->AppendGroup("", 1); | |
119 trial->AppendGroup("", 1); | |
120 trial->AppendGroup("", 1); | |
121 trial->AppendGroup("", 1); | |
122 trial->AppendGroup("", 1); | |
123 #endif | |
124 } | |
125 } | |
126 | |
127 StartupOverride GetStartupOverrideForCurrentTrial() { | |
128 DCHECK(sync_promo_trial_initialized); | |
129 | |
130 LayoutExperimentType type; | |
131 if (GetActiveLayoutExperiment(&type)) { | |
132 return type == LAYOUT_EXPERIMENT_NONE ? STARTUP_OVERRIDE_HIDE : | |
133 STARTUP_OVERRIDE_SHOW; | |
134 } | |
135 return STARTUP_OVERRIDE_NONE; | |
136 } | |
137 | |
138 void RecordUserShownPromo(content::WebUI* web_ui) { | 9 void RecordUserShownPromo(content::WebUI* web_ui) { |
139 DCHECK(sync_promo_trial_initialized); | 10 // TODO(sail): Add new UMA stats here. |
140 | |
141 LayoutExperimentType type; | |
142 if (GetActiveLayoutExperiment(&type)) { | |
143 bool is_at_startup = SyncPromoUI::GetIsLaunchPageForSyncPromoURL( | |
144 web_ui->GetWebContents()->GetURL()); | |
145 if (is_at_startup) { | |
146 DCHECK(SyncPromoUI::HasShownPromoAtStartup(Profile::FromWebUI(web_ui))); | |
147 UMA_HISTOGRAM_ENUMERATION("SyncPromo.ShownPromoWithLayoutExpAtStartup", | |
148 type, LAYOUT_EXPERIMENT_BOUNDARY); | |
149 } else { | |
150 UMA_HISTOGRAM_ENUMERATION("SyncPromo.ShownPromoWithLayoutExp", | |
151 type, LAYOUT_EXPERIMENT_BOUNDARY); | |
152 } | |
153 } | |
154 } | |
155 | |
156 void RecordSyncPromoSuppressedForCurrentTrial() { | |
157 DCHECK(sync_promo_trial_initialized); | |
158 LayoutExperimentType type = LAYOUT_EXPERIMENT_DEFAULT; | |
159 DCHECK(GetActiveLayoutExperiment(&type) && type == LAYOUT_EXPERIMENT_NONE); | |
160 // Avoid warning about unused variable in release builds. | |
161 (void)type; | |
162 UMA_HISTOGRAM_ENUMERATION("SyncPromo.ShownPromoWithLayoutExpAtStartup", | |
163 LAYOUT_EXPERIMENT_NONE, LAYOUT_EXPERIMENT_BOUNDARY); | |
164 } | 11 } |
165 | 12 |
166 void RecordUserSignedIn(content::WebUI* web_ui) { | 13 void RecordUserSignedIn(content::WebUI* web_ui) { |
167 DCHECK(sync_promo_trial_initialized); | 14 // TODO(sail): Add new UMA stats here. |
168 | |
169 LayoutExperimentType type; | |
170 if (GetActiveLayoutExperiment(&type)) { | |
171 bool is_at_startup = SyncPromoUI::GetIsLaunchPageForSyncPromoURL( | |
172 web_ui->GetWebContents()->GetURL()); | |
173 if (is_at_startup) { | |
174 DCHECK(SyncPromoUI::HasShownPromoAtStartup(Profile::FromWebUI(web_ui))); | |
175 UMA_HISTOGRAM_ENUMERATION("SyncPromo.SignedInWithLayoutExpAtStartup", | |
176 type, LAYOUT_EXPERIMENT_BOUNDARY); | |
177 } else { | |
178 UMA_HISTOGRAM_ENUMERATION("SyncPromo.SignedInWithLayoutExp", | |
179 type, LAYOUT_EXPERIMENT_BOUNDARY); | |
180 } | |
181 } | |
182 } | |
183 | |
184 bool GetSyncPromoVersionForCurrentTrial(SyncPromoUI::Version* version) { | |
185 DCHECK(sync_promo_trial_initialized); | |
186 DCHECK(version); | |
187 | |
188 LayoutExperimentType type; | |
189 if (!GetActiveLayoutExperiment(&type)) | |
190 return false; | |
191 | |
192 switch (type) { | |
193 case LAYOUT_EXPERIMENT_DEFAULT: | |
194 *version = SyncPromoUI::VERSION_DEFAULT; | |
195 return true; | |
196 case LAYOUT_EXPERIMENT_DEVICES: | |
197 *version = SyncPromoUI::VERSION_DEVICES; | |
198 return true; | |
199 case LAYOUT_EXPERIMENT_VERBOSE: | |
200 *version = SyncPromoUI::VERSION_VERBOSE; | |
201 return true; | |
202 case LAYOUT_EXPERIMENT_SIMPLE: | |
203 *version = SyncPromoUI::VERSION_SIMPLE; | |
204 return true; | |
205 case LAYOUT_EXPERIMENT_DIALOG: | |
206 *version = SyncPromoUI::VERSION_DIALOG; | |
207 return true; | |
208 default: | |
209 return false; | |
210 } | |
211 } | 15 } |
212 | 16 |
213 } // namespace sync_promo_trial | 17 } // namespace sync_promo_trial |
OLD | NEW |