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

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

Powered by Google App Engine
This is Rietveld 408576698