Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chrome_browser_field_trials_desktop.cc
blob02a68d6e78a3fb383649bed4ea0856f62cdd0be7
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/chrome_browser_field_trials_desktop.h"
7 #include <string>
9 #include "base/command_line.h"
10 #include "base/environment.h"
11 #include "base/metrics/field_trial.h"
12 #include "base/prefs/pref_service.h"
13 #include "base/strings/string_util.h"
14 #include "chrome/browser/auto_launch_trial.h"
15 #include "chrome/browser/google/google_util.h"
16 #include "chrome/browser/omnibox/omnibox_field_trial.h"
17 #include "chrome/browser/prerender/prerender_field_trial.h"
18 #include "chrome/browser/profiles/profiles_state.h"
19 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h"
20 #include "chrome/browser/ui/app_list/app_list_util.h"
21 #include "chrome/browser/ui/sync/one_click_signin_helper.h"
22 #include "chrome/common/chrome_constants.h"
23 #include "chrome/common/chrome_switches.h"
24 #include "chrome/common/chrome_version_info.h"
25 #include "chrome/common/metrics/variations/variations_util.h"
26 #include "chrome/common/pref_names.h"
27 #include "content/public/common/content_constants.h"
28 #include "net/spdy/spdy_session.h"
29 #include "ui/base/layout.h"
31 namespace chrome {
33 namespace {
35 void AutoLaunchChromeFieldTrial() {
36 std::string brand;
37 google_util::GetBrand(&brand);
39 // Create a 100% field trial based on the brand code.
40 if (auto_launch_trial::IsInExperimentGroup(brand)) {
41 base::FieldTrialList::CreateFieldTrial(kAutoLaunchTrialName,
42 kAutoLaunchTrialAutoLaunchGroup);
43 } else if (auto_launch_trial::IsInControlGroup(brand)) {
44 base::FieldTrialList::CreateFieldTrial(kAutoLaunchTrialName,
45 kAutoLaunchTrialControlGroup);
49 void SetupInfiniteCacheFieldTrial() {
50 const base::FieldTrial::Probability kDivisor = 100;
52 base::FieldTrial::Probability infinite_cache_probability = 0;
54 scoped_refptr<base::FieldTrial> trial(
55 base::FieldTrialList::FactoryGetFieldTrial(
56 "InfiniteCache", kDivisor, "No", 2013, 12, 31,
57 base::FieldTrial::ONE_TIME_RANDOMIZED, NULL));
58 trial->AppendGroup("Yes", infinite_cache_probability);
59 trial->AppendGroup("Control", infinite_cache_probability);
62 void DisableShowProfileSwitcherTrialIfNecessary() {
63 // This trial is created by the VariationsService, but it needs to be disabled
64 // if multi-profiles isn't enabled.
65 base::FieldTrial* trial = base::FieldTrialList::Find("ShowProfileSwitcher");
66 if (trial && !profiles::IsMultipleProfilesEnabled())
67 trial->Disable();
70 void SetupLowLatencyFlashAudioFieldTrial() {
71 scoped_refptr<base::FieldTrial> trial(
72 base::FieldTrialList::FactoryGetFieldTrial(
73 content::kLowLatencyFlashAudioFieldTrialName, 100, "Standard",
74 2013, 9, 1, base::FieldTrial::SESSION_RANDOMIZED, NULL));
76 // Trial is enabled for dev / beta / canary users only.
77 if (chrome::VersionInfo::GetChannel() != chrome::VersionInfo::CHANNEL_STABLE)
78 trial->AppendGroup(content::kLowLatencyFlashAudioFieldTrialEnabledName, 25);
81 void SetupPreReadFieldTrial() {
82 // The chrome executable will have set (or not) an environment variable with
83 // the group name into which this client belongs.
84 std::string group;
85 scoped_ptr<base::Environment> env(base::Environment::Create());
86 if (!env->GetVar(chrome::kPreReadEnvironmentVariable, &group) ||
87 group.empty()) {
88 return;
91 // Initialize the field trial. We declare all of the groups here (so that
92 // the dashboard creation tools can find them) but force the probability
93 // of being assigned to the group already chosen by the executable, if any,
94 // to 100%.
95 scoped_refptr<base::FieldTrial> trial(
96 base::FieldTrialList::FactoryGetFieldTrial(
97 "BrowserPreReadExperiment", 100, "100-pct-default",
98 2014, 7, 1, base::FieldTrial::SESSION_RANDOMIZED, NULL));
99 trial->AppendGroup("100-pct-control", group == "100-pct-control" ? 100 : 0);
100 trial->AppendGroup("95-pct", group == "95-pct" ? 100 : 0);
101 trial->AppendGroup("90-pct", group == "90-pct" ? 100 : 0);
102 trial->AppendGroup("85-pct", group == "85-pct" ? 100 : 0);
103 trial->AppendGroup("80-pct", group == "80-pct" ? 100 : 0);
104 trial->AppendGroup("75-pct", group == "75-pct" ? 100 : 0);
105 trial->AppendGroup("70-pct", group == "70-pct" ? 100 : 0);
106 trial->AppendGroup("65-pct", group == "65-pct" ? 100 : 0);
107 trial->AppendGroup("60-pct", group == "60-pct" ? 100 : 0);
108 trial->AppendGroup("55-pct", group == "55-pct" ? 100 : 0);
109 trial->AppendGroup("50-pct", group == "50-pct" ? 100 : 0);
110 trial->AppendGroup("45-pct", group == "45-pct" ? 100 : 0);
111 trial->AppendGroup("40-pct", group == "40-pct" ? 100 : 0);
112 trial->AppendGroup("35-pct", group == "35-pct" ? 100 : 0);
113 trial->AppendGroup("30-pct", group == "30-pct" ? 100 : 0);
114 trial->AppendGroup("25-pct", group == "25-pct" ? 100 : 0);
115 trial->AppendGroup("20-pct", group == "20-pct" ? 100 : 0);
116 trial->AppendGroup("15-pct", group == "15-pct" ? 100 : 0);
117 trial->AppendGroup("10-pct", group == "10-pct" ? 100 : 0);
118 trial->AppendGroup("5-pct", group == "5-pct" ? 100 : 0);
119 trial->AppendGroup("0-pct", group == "0-pct" ? 100 : 0);
121 // We have to call group in order to mark the experiment as active.
122 trial->group();
125 } // namespace
127 void SetupDesktopFieldTrials(const CommandLine& parsed_command_line,
128 const base::Time& install_time,
129 PrefService* local_state) {
130 prerender::ConfigurePrerender(parsed_command_line);
131 AutoLaunchChromeFieldTrial();
132 OmniboxFieldTrial::ActivateStaticTrials();
133 SetupInfiniteCacheFieldTrial();
134 DisableShowProfileSwitcherTrialIfNecessary();
135 SetupShowAppLauncherPromoFieldTrial(local_state);
136 SetupLowLatencyFlashAudioFieldTrial();
137 SetupPreReadFieldTrial();
140 } // namespace chrome