Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chrome_browser_field_trials_desktop.cc
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.
4
5 #include "chrome/browser/chrome_browser_field_trials_desktop.h"
6
7 #include <string>
8
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"
30
31 #if defined(OS_CHROMEOS)
32 #include "chrome/browser/chromeos/login/user_manager.h"
33 #endif
34
35 namespace chrome {
36
37 namespace {
38
39 void AutoLaunchChromeFieldTrial() {
40   std::string brand;
41   google_util::GetBrand(&brand);
42
43   // Create a 100% field trial based on the brand code.
44   if (auto_launch_trial::IsInExperimentGroup(brand)) {
45     base::FieldTrialList::CreateFieldTrial(kAutoLaunchTrialName,
46                                            kAutoLaunchTrialAutoLaunchGroup);
47   } else if (auto_launch_trial::IsInControlGroup(brand)) {
48     base::FieldTrialList::CreateFieldTrial(kAutoLaunchTrialName,
49                                            kAutoLaunchTrialControlGroup);
50   }
51 }
52
53 void SetupInfiniteCacheFieldTrial() {
54   const base::FieldTrial::Probability kDivisor = 100;
55
56   base::FieldTrial::Probability infinite_cache_probability = 0;
57
58   scoped_refptr<base::FieldTrial> trial(
59       base::FieldTrialList::FactoryGetFieldTrial(
60           "InfiniteCache", kDivisor, "No", 2013, 12, 31,
61           base::FieldTrial::ONE_TIME_RANDOMIZED, NULL));
62   trial->AppendGroup("Yes", infinite_cache_probability);
63   trial->AppendGroup("Control", infinite_cache_probability);
64 }
65
66 void DisableShowProfileSwitcherTrialIfNecessary() {
67   // This trial is created by the VariationsService, but it needs to be disabled
68   // if multi-profiles isn't enabled.
69   base::FieldTrial* trial = base::FieldTrialList::Find("ShowProfileSwitcher");
70   if (trial && !profiles::IsMultipleProfilesEnabled())
71     trial->Disable();
72 }
73
74 void SetupPreReadFieldTrial() {
75   // The chrome executable will have set (or not) an environment variable with
76   // the group name into which this client belongs.
77   std::string group;
78   scoped_ptr<base::Environment> env(base::Environment::Create());
79   if (!env->GetVar(chrome::kPreReadEnvironmentVariable, &group) ||
80       group.empty()) {
81     return;
82   }
83
84   // Initialize the field trial. We declare all of the groups here (so that
85   // the dashboard creation tools can find them) but force the probability
86   // of being assigned to the group already chosen by the executable, if any,
87   // to 100%.
88   scoped_refptr<base::FieldTrial> trial(
89       base::FieldTrialList::FactoryGetFieldTrial(
90           "BrowserPreReadExperiment", 100, "100-pct-default",
91           2014, 7, 1, base::FieldTrial::SESSION_RANDOMIZED, NULL));
92   trial->AppendGroup("100-pct-control", group == "100-pct-control" ? 100 : 0);
93   trial->AppendGroup("95-pct", group == "95-pct" ? 100 : 0);
94   trial->AppendGroup("90-pct", group == "90-pct" ? 100 : 0);
95   trial->AppendGroup("85-pct", group == "85-pct" ? 100 : 0);
96   trial->AppendGroup("80-pct", group == "80-pct" ? 100 : 0);
97   trial->AppendGroup("75-pct", group == "75-pct" ? 100 : 0);
98   trial->AppendGroup("70-pct", group == "70-pct" ? 100 : 0);
99   trial->AppendGroup("65-pct", group == "65-pct" ? 100 : 0);
100   trial->AppendGroup("60-pct", group == "60-pct" ? 100 : 0);
101   trial->AppendGroup("55-pct", group == "55-pct" ? 100 : 0);
102   trial->AppendGroup("50-pct", group == "50-pct" ? 100 : 0);
103   trial->AppendGroup("45-pct", group == "45-pct" ? 100 : 0);
104   trial->AppendGroup("40-pct", group == "40-pct" ? 100 : 0);
105   trial->AppendGroup("35-pct", group == "35-pct" ? 100 : 0);
106   trial->AppendGroup("30-pct", group == "30-pct" ? 100 : 0);
107   trial->AppendGroup("25-pct", group == "25-pct" ? 100 : 0);
108   trial->AppendGroup("20-pct", group == "20-pct" ? 100 : 0);
109   trial->AppendGroup("15-pct", group == "15-pct" ? 100 : 0);
110   trial->AppendGroup("10-pct", group == "10-pct" ? 100 : 0);
111   trial->AppendGroup("5-pct", group == "5-pct" ? 100 : 0);
112   trial->AppendGroup("0-pct", group == "0-pct" ? 100 : 0);
113
114   // We have to call group in order to mark the experiment as active.
115   trial->group();
116 }
117
118 #if defined(OS_CHROMEOS)
119 void SetupChromeOSMultiProfilesAllowedTrial() {
120   const char kTrialName[] = "ChromeOSMultiProfilesAllowed";
121   if (chromeos::UserManager::IsMultipleProfilesAllowed())
122     base::FieldTrialList::CreateFieldTrial(kTrialName, "allowed")->group();
123   else
124     base::FieldTrialList::CreateFieldTrial(kTrialName, "not_allowed")->group();
125 }
126 #endif  // defined(OS_CHROMEOS)
127
128 }  // namespace
129
130 void SetupDesktopFieldTrials(const CommandLine& parsed_command_line,
131                              const base::Time& install_time,
132                              PrefService* local_state) {
133   prerender::ConfigurePrerender(parsed_command_line);
134   AutoLaunchChromeFieldTrial();
135   OmniboxFieldTrial::ActivateStaticTrials();
136   SetupInfiniteCacheFieldTrial();
137   DisableShowProfileSwitcherTrialIfNecessary();
138   SetupShowAppLauncherPromoFieldTrial(local_state);
139   SetupPreReadFieldTrial();
140 #if defined(OS_CHROMEOS)
141   SetupChromeOSMultiProfilesAllowedTrial();
142 #endif
143 }
144
145 }  // namespace chrome