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

Side by Side Diff: chrome/browser/chrome_browser_field_trials.cc

Issue 14247021: Split the field trial setup code into desktop and mobile files. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebased Created 7 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 #include "chrome/browser/chrome_browser_field_trials.h" 5 #include "chrome/browser/chrome_browser_field_trials.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "apps/field_trial_names.h"
10 #include "apps/pref_names.h"
11 #include "base/command_line.h" 9 #include "base/command_line.h"
12 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
13 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
14 #include "base/string_util.h" 12 #include "base/string_util.h"
15 #include "base/stringprintf.h" 13 #include "base/time.h"
16 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/sys_string_conversions.h"
18 #include "base/utf_string_conversions.h"
19 #include "chrome/browser/auto_launch_trial.h"
20 #include "chrome/browser/google/google_util.h"
21 #include "chrome/browser/gpu/chrome_gpu_util.h"
22 #include "chrome/browser/omnibox/omnibox_field_trial.h" 14 #include "chrome/browser/omnibox/omnibox_field_trial.h"
23 #include "chrome/browser/prerender/prerender_field_trial.h"
24 #include "chrome/browser/profiles/profile_manager.h"
25 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h"
26 #include "chrome/browser/ui/sync/one_click_signin_helper.h"
27 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
28 #include "chrome/common/chrome_version_info.h"
29 #include "chrome/common/metrics/variations/uniformity_field_trials.h" 16 #include "chrome/common/metrics/variations/uniformity_field_trials.h"
30 #include "chrome/common/metrics/variations/variations_util.h"
31 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
32 #include "net/spdy/spdy_session.h"
33 #include "ui/base/layout.h"
34 18
35 #if defined(OS_WIN) 19 #if defined(OS_ANDROID) || defined(OS_IOS)
36 #include "net/socket/tcp_client_socket_win.h" 20 #include "chrome/browser/chrome_browser_field_trials_mobile.h"
37 #endif // defined(OS_WIN) 21 #else
22 #include "chrome/browser/chrome_browser_field_trials_desktop.h"
23 #endif
38 24
39 ChromeBrowserFieldTrials::ChromeBrowserFieldTrials( 25 ChromeBrowserFieldTrials::ChromeBrowserFieldTrials(
40 const CommandLine& parsed_command_line) 26 const CommandLine& parsed_command_line)
41 : parsed_command_line_(parsed_command_line) { 27 : parsed_command_line_(parsed_command_line) {
42 } 28 }
43 29
44 ChromeBrowserFieldTrials::~ChromeBrowserFieldTrials() { 30 ChromeBrowserFieldTrials::~ChromeBrowserFieldTrials() {
45 } 31 }
46 32
47 void ChromeBrowserFieldTrials::SetupFieldTrials(PrefService* local_state) { 33 void ChromeBrowserFieldTrials::SetupFieldTrials(PrefService* local_state) {
48 const base::Time install_time = base::Time::FromTimeT( 34 const base::Time install_time = base::Time::FromTimeT(
49 local_state->GetInt64(prefs::kInstallDate)); 35 local_state->GetInt64(prefs::kInstallDate));
50 DCHECK(!install_time.is_null()); 36 DCHECK(!install_time.is_null());
51 37
38 // Field trials that are shared by all platforms.
52 chrome_variations::SetupUniformityFieldTrials(install_time); 39 chrome_variations::SetupUniformityFieldTrials(install_time);
53 SetUpSimpleCacheFieldTrial(); 40 SetUpSimpleCacheFieldTrial();
54 41 InstantiateDynamicTrials();
55 #if !defined(OS_ANDROID) && !defined(OS_IOS)
56 SetupDesktopFieldTrials(local_state);
57 #endif // !defined(OS_ANDROID) && !defined(OS_IOS)
58 42
59 #if defined(OS_ANDROID) || defined(OS_IOS) 43 #if defined(OS_ANDROID) || defined(OS_IOS)
60 SetupMobileFieldTrials(); 44 chrome::SetupMobileFieldTrials(
61 #endif // defined(OS_ANDROID) || defined(OS_IOS) 45 parsed_command_line_, install_time, local_state);
62 46 #else
63 InstantiateDynamicTrials(); 47 chrome::SetupDesktopFieldTrials(
64 } 48 parsed_command_line_, install_time, local_state);
65
66
67 #if defined(OS_ANDROID) || defined(OS_IOS)
68 void ChromeBrowserFieldTrials::SetupMobileFieldTrials() {
69 DataCompressionProxyFieldTrial();
70 }
71
72 // Governs the rollout of the compression proxy for Chrome on mobile platforms.
73 // Always enabled in DEV and BETA versions.
74 // Stable percentage will be controlled from server.
75 void ChromeBrowserFieldTrials::DataCompressionProxyFieldTrial() {
76 const char kDataCompressionProxyFieldTrialName[] =
77 "DataCompressionProxyRollout";
78 const base::FieldTrial::Probability kDataCompressionProxyDivisor = 1000;
79
80 // 10/1000 = 1% for starters.
81 const base::FieldTrial::Probability kDataCompressionProxyStable = 10;
82 const char kEnabled[] = "Enabled";
83 const char kDisabled[] = "Disabled";
84
85 // Find out if this is a stable channel.
86 const bool kIsStableChannel =
87 chrome::VersionInfo::GetChannel() == chrome::VersionInfo::CHANNEL_STABLE;
88
89 // Experiment enabled until Jan 1, 2015. By default, disabled.
90 scoped_refptr<base::FieldTrial> trial(
91 base::FieldTrialList::FactoryGetFieldTrial(
92 kDataCompressionProxyFieldTrialName, kDataCompressionProxyDivisor,
93 kDisabled, 2015, 1, 1, NULL));
94
95 // We want our trial results to be persistent.
96 trial->UseOneTimeRandomization();
97 // Non-stable channels will run with probability 1.
98 const int kEnabledGroup = trial->AppendGroup(
99 kEnabled,
100 kIsStableChannel ?
101 kDataCompressionProxyStable : kDataCompressionProxyDivisor);
102
103 const int v = trial->group();
104 VLOG(1) << "DataCompression proxy enabled group id: " << kEnabledGroup
105 << ". Selected group id: " << v;
106 }
107 #endif // defined(OS_ANDROID) || defined(OS_IOS)
108
109 void ChromeBrowserFieldTrials::SetupDesktopFieldTrials(
110 PrefService* local_state) {
111 prerender::ConfigurePrefetchAndPrerender(parsed_command_line_);
112 SpdyFieldTrial();
113 AutoLaunchChromeFieldTrial();
114 gpu_util::InitializeCompositingFieldTrial();
115 OmniboxFieldTrial::ActivateStaticTrials();
116 SetUpInfiniteCacheFieldTrial();
117 SetUpCacheSensitivityAnalysisFieldTrial();
118 DisableShowProfileSwitcherTrialIfNecessary();
119 WindowsOverlappedTCPReadsFieldTrial();
120 #if defined(ENABLE_ONE_CLICK_SIGNIN)
121 OneClickSigninHelper::InitializeFieldTrial();
122 #endif 49 #endif
123 SetupAppLauncherFieldTrial(local_state);
124 }
125
126 void ChromeBrowserFieldTrials::SetupAppLauncherFieldTrial(
127 PrefService* local_state) {
128 if (base::FieldTrialList::FindFullName(apps::kLauncherPromoTrialName) ==
129 apps::kResetShowLauncherPromoPrefGroupName) {
130 local_state->SetBoolean(apps::prefs::kShowAppLauncherPromo, true);
131 }
132 }
133
134 // When --use-spdy not set, users will be in A/B test for spdy.
135 // group A (npn_with_spdy): this means npn and spdy are enabled. In case server
136 // supports spdy, browser will use spdy.
137 // group B (npn_with_http): this means npn is enabled but spdy won't be used.
138 // Http is still used for all requests.
139 // default group: no npn or spdy is involved. The "old" non-spdy
140 // chrome behavior.
141 void ChromeBrowserFieldTrials::SpdyFieldTrial() {
142 // Setup SPDY CWND Field trial.
143 const base::FieldTrial::Probability kSpdyCwndDivisor = 100;
144 const base::FieldTrial::Probability kSpdyCwnd16 = 20; // fixed at 16
145 const base::FieldTrial::Probability kSpdyCwnd10 = 20; // fixed at 10
146 const base::FieldTrial::Probability kSpdyCwndMin16 = 20; // no less than 16
147 const base::FieldTrial::Probability kSpdyCwndMin10 = 20; // no less than 10
148
149 // After June 30, 2013 builds, it will always be in default group
150 // (cwndDynamic).
151 scoped_refptr<base::FieldTrial> trial(
152 base::FieldTrialList::FactoryGetFieldTrial(
153 "SpdyCwnd", kSpdyCwndDivisor, "cwndDynamic", 2013, 6, 30, NULL));
154
155 trial->AppendGroup("cwnd10", kSpdyCwnd10);
156 trial->AppendGroup("cwnd16", kSpdyCwnd16);
157 trial->AppendGroup("cwndMin16", kSpdyCwndMin16);
158 trial->AppendGroup("cwndMin10", kSpdyCwndMin10);
159 }
160
161 void ChromeBrowserFieldTrials::AutoLaunchChromeFieldTrial() {
162 std::string brand;
163 google_util::GetBrand(&brand);
164
165 // Create a 100% field trial based on the brand code.
166 if (auto_launch_trial::IsInExperimentGroup(brand)) {
167 base::FieldTrialList::CreateFieldTrial(kAutoLaunchTrialName,
168 kAutoLaunchTrialAutoLaunchGroup);
169 } else if (auto_launch_trial::IsInControlGroup(brand)) {
170 base::FieldTrialList::CreateFieldTrial(kAutoLaunchTrialName,
171 kAutoLaunchTrialControlGroup);
172 }
173 }
174
175 void ChromeBrowserFieldTrials::SetUpInfiniteCacheFieldTrial() {
176 const base::FieldTrial::Probability kDivisor = 100;
177
178 base::FieldTrial::Probability infinite_cache_probability = 0;
179
180 scoped_refptr<base::FieldTrial> trial(
181 base::FieldTrialList::FactoryGetFieldTrial("InfiniteCache", kDivisor,
182 "No", 2013, 12, 31, NULL));
183 trial->UseOneTimeRandomization();
184 trial->AppendGroup("Yes", infinite_cache_probability);
185 trial->AppendGroup("Control", infinite_cache_probability);
186 }
187
188 void ChromeBrowserFieldTrials::DisableShowProfileSwitcherTrialIfNecessary() {
189 // This trial is created by the VariationsService, but it needs to be disabled
190 // if multi-profiles isn't enabled or if browser frame avatar menu is
191 // always hidden (Chrome OS).
192 bool avatar_menu_always_hidden = false;
193 #if defined(OS_CHROMEOS)
194 avatar_menu_always_hidden = true;
195 #endif
196 base::FieldTrial* trial = base::FieldTrialList::Find("ShowProfileSwitcher");
197 if (trial && (!ProfileManager::IsMultipleProfilesEnabled() ||
198 avatar_menu_always_hidden)) {
199 trial->Disable();
200 }
201 } 50 }
202 51
203 // Sets up the experiment. The actual cache backend choice is made in the net/ 52 // Sets up the experiment. The actual cache backend choice is made in the net/
204 // internals by looking at the experiment state. 53 // internals by looking at the experiment state.
205 void ChromeBrowserFieldTrials::SetUpSimpleCacheFieldTrial() { 54 void ChromeBrowserFieldTrials::SetUpSimpleCacheFieldTrial() {
206 if (parsed_command_line_.HasSwitch(switches::kUseSimpleCacheBackend)) { 55 if (parsed_command_line_.HasSwitch(switches::kUseSimpleCacheBackend)) {
207 const std::string opt_value = parsed_command_line_.GetSwitchValueASCII( 56 const std::string opt_value = parsed_command_line_.GetSwitchValueASCII(
208 switches::kUseSimpleCacheBackend); 57 switches::kUseSimpleCacheBackend);
209 const base::FieldTrial::Probability kDivisor = 100; 58 const base::FieldTrial::Probability kDivisor = 100;
210 scoped_refptr<base::FieldTrial> trial( 59 scoped_refptr<base::FieldTrial> trial(
(...skipping 15 matching lines...) Expand all
226 // adds a few more necessary features. Also adjust the probability. 75 // adds a few more necessary features. Also adjust the probability.
227 const base::FieldTrial::Probability kSimpleCacheProbability = 1; 76 const base::FieldTrial::Probability kSimpleCacheProbability = 1;
228 trial->AppendGroup("ExperimentYes", kSimpleCacheProbability); 77 trial->AppendGroup("ExperimentYes", kSimpleCacheProbability);
229 trial->AppendGroup("ExperimentControl", kSimpleCacheProbability); 78 trial->AppendGroup("ExperimentControl", kSimpleCacheProbability);
230 trial->group(); 79 trial->group();
231 } 80 }
232 #endif 81 #endif
233 } 82 }
234 } 83 }
235 84
236 void ChromeBrowserFieldTrials::SetUpCacheSensitivityAnalysisFieldTrial() {
237 const base::FieldTrial::Probability kDivisor = 100;
238
239 base::FieldTrial::Probability sensitivity_analysis_probability = 0;
240
241 #if defined(OS_ANDROID)
242 switch (chrome::VersionInfo::GetChannel()) {
243 case chrome::VersionInfo::CHANNEL_DEV:
244 sensitivity_analysis_probability = 10;
245 break;
246 case chrome::VersionInfo::CHANNEL_BETA:
247 sensitivity_analysis_probability = 5;
248 break;
249 case chrome::VersionInfo::CHANNEL_STABLE:
250 sensitivity_analysis_probability = 1;
251 break;
252 default:
253 break;
254 }
255 #endif
256
257 scoped_refptr<base::FieldTrial> trial(
258 base::FieldTrialList::FactoryGetFieldTrial("CacheSensitivityAnalysis",
259 kDivisor, "No",
260 2013, 06, 15, NULL));
261 trial->AppendGroup("ControlA", sensitivity_analysis_probability);
262 trial->AppendGroup("ControlB", sensitivity_analysis_probability);
263 trial->AppendGroup("100A", sensitivity_analysis_probability);
264 trial->AppendGroup("100B", sensitivity_analysis_probability);
265 trial->AppendGroup("200A", sensitivity_analysis_probability);
266 trial->AppendGroup("200B", sensitivity_analysis_probability);
267 // TODO(gavinp,rvargas): Re-add 400 group to field trial if results justify.
268 }
269
270 void ChromeBrowserFieldTrials::WindowsOverlappedTCPReadsFieldTrial() {
271 #if defined(OS_WIN)
272 if (parsed_command_line_.HasSwitch(switches::kOverlappedRead)) {
273 std::string option =
274 parsed_command_line_.GetSwitchValueASCII(switches::kOverlappedRead);
275 if (LowerCaseEqualsASCII(option, "off"))
276 net::TCPClientSocketWin::DisableOverlappedReads();
277 } else {
278 const base::FieldTrial::Probability kDivisor = 2; // 1 in 2 chance
279 const base::FieldTrial::Probability kOverlappedReadProbability = 1;
280 scoped_refptr<base::FieldTrial> overlapped_reads_trial(
281 base::FieldTrialList::FactoryGetFieldTrial("OverlappedReadImpact",
282 kDivisor, "OverlappedReadEnabled", 2013, 6, 1, NULL));
283 int overlapped_reads_disabled_group =
284 overlapped_reads_trial->AppendGroup("OverlappedReadDisabled",
285 kOverlappedReadProbability);
286 int assigned_group = overlapped_reads_trial->group();
287 if (assigned_group == overlapped_reads_disabled_group)
288 net::TCPClientSocketWin::DisableOverlappedReads();
289 }
290 #endif
291 }
292
293 void ChromeBrowserFieldTrials::InstantiateDynamicTrials() { 85 void ChromeBrowserFieldTrials::InstantiateDynamicTrials() {
294 // Call |FindValue()| on the trials below, which may come from the server, to 86 // Call |FindValue()| on the trials below, which may come from the server, to
295 // ensure they get marked as "used" for the purposes of data reporting. 87 // ensure they get marked as "used" for the purposes of data reporting.
296 base::FieldTrialList::FindValue("UMA-Dynamic-Binary-Uniformity-Trial"); 88 base::FieldTrialList::FindValue("UMA-Dynamic-Binary-Uniformity-Trial");
297 base::FieldTrialList::FindValue("UMA-Dynamic-Uniformity-Trial"); 89 base::FieldTrialList::FindValue("UMA-Dynamic-Uniformity-Trial");
298 base::FieldTrialList::FindValue("InstantDummy"); 90 base::FieldTrialList::FindValue("InstantDummy");
299 base::FieldTrialList::FindValue("InstantChannel"); 91 base::FieldTrialList::FindValue("InstantChannel");
300 base::FieldTrialList::FindValue("Test0PercentDefault"); 92 base::FieldTrialList::FindValue("Test0PercentDefault");
301 // Activate the autocomplete dynamic field trials. 93 // Activate the autocomplete dynamic field trials.
302 OmniboxFieldTrial::ActivateDynamicTrials(); 94 OmniboxFieldTrial::ActivateDynamicTrials();
303 } 95 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698