blob: df95a8091e1836a1f45b3e206f8364616c344800 [file] [log] [blame]
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +01001// 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_mobile.h"
6
7#include <string>
8
9#include "base/command_line.h"
10#include "base/metrics/field_trial.h"
11#include "base/prefs/pref_service.h"
Ben Murdochca12bfa2013-07-23 11:17:05 +010012#include "chrome/common/chrome_switches.h"
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010013#include "chrome/common/chrome_version_info.h"
14
15namespace chrome {
16
17namespace {
18
Ben Murdochbb1529c2013-08-08 10:24:53 +010019// Base function used by all data reduction proxy field trials. A trial is
20// only conducted for installs that are in the "Enabled" group. They are always
21// enabled on DEV and BETA channels, and for STABLE, a percentage will be
22// controlled from the server. Until the percentage is learned from the server,
23// a client-side configuration is used.
24void DataCompressionProxyBaseFieldTrial(
25 const char* trial_name,
26 const base::FieldTrial::Probability enabled_group_probability,
27 const base::FieldTrial::Probability total_probability) {
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010028 const char kEnabled[] = "Enabled";
29 const char kDisabled[] = "Disabled";
30
31 // Find out if this is a stable channel.
32 const bool kIsStableChannel =
33 chrome::VersionInfo::GetChannel() == chrome::VersionInfo::CHANNEL_STABLE;
34
35 // Experiment enabled until Jan 1, 2015. By default, disabled.
36 scoped_refptr<base::FieldTrial> trial(
37 base::FieldTrialList::FactoryGetFieldTrial(
Ben Murdochbb1529c2013-08-08 10:24:53 +010038 trial_name,
39 total_probability,
Ben Murdochd3868032013-07-31 10:55:33 +010040 kDisabled, 2015, 1, 1, base::FieldTrial::ONE_TIME_RANDOMIZED, NULL));
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010041
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010042 // Non-stable channels will run with probability 1.
43 const int kEnabledGroup = trial->AppendGroup(
44 kEnabled,
Ben Murdochbb1529c2013-08-08 10:24:53 +010045 kIsStableChannel ? enabled_group_probability : total_probability);
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010046
47 const int v = trial->group();
Ben Murdochbb1529c2013-08-08 10:24:53 +010048 VLOG(1) << trial_name << " enabled group id: " << kEnabledGroup
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010049 << ". Selected group id: " << v;
50}
51
Ben Murdochbb1529c2013-08-08 10:24:53 +010052void DataCompressionProxyFieldTrials() {
53 // Governs the rollout of the compression proxy for Chrome on mobile
54 // platforms. Always enabled in DEV and BETA channels. For STABLE, the
55 // percentage will be controlled from the server, and is configured to be
56 // 10% = 100 / 1000 until overridden by the server.
57 DataCompressionProxyBaseFieldTrial(
58 "DataCompressionProxyRollout", 100, 1000);
59
60 if (base::FieldTrialList::FindFullName(
61 "DataCompressionProxyRollout") == "Enabled") {
62
63 // Governs the rollout of the _promo_ for the compression proxy
64 // independently from the rollout of compression proxy. The enabled
65 // percentage is configured to be 100% = 1000 / 1000 until overridden by the
66 // server. When this trial is "Enabled," users get a promo, whereas
67 // otherwise, compression is enabled without a promo.
68 DataCompressionProxyBaseFieldTrial(
69 "DataCompressionProxyPromoVisibility", 1000, 1000);
70 }
71}
72
Ben Murdochca12bfa2013-07-23 11:17:05 +010073void NewTabButtonInToolbarFieldTrial(const CommandLine& parsed_command_line) {
74 // Do not enable this field trials for tablet devices.
75 if (parsed_command_line.HasSwitch(switches::kTabletUI))
76 return;
77
78 const char kPhoneNewTabToolbarButtonFieldTrialName[] =
79 "PhoneNewTabToolbarButton";
80 const base::FieldTrial::Probability kPhoneNewTabToolbarButtonDivisor = 100;
81
82 // 50/100 = 50% for Non-Stable users.
83 // 0/100 = 0% for Stable users.
84 const base::FieldTrial::Probability kPhoneNewTabToolbarButtonNonStable = 50;
85 const base::FieldTrial::Probability kPhoneNewTabToolbarButtonStable = 0;
86 const char kEnabled[] = "Enabled";
87 const char kDisabled[] = "Disabled";
88
89 // Find out if this is a stable channel.
90 const bool kIsStableChannel =
91 chrome::VersionInfo::GetChannel() == chrome::VersionInfo::CHANNEL_STABLE;
92
93 // Experiment enabled until Jan 1, 2015. By default, disabled.
94 scoped_refptr<base::FieldTrial> trial(
95 base::FieldTrialList::FactoryGetFieldTrial(
96 kPhoneNewTabToolbarButtonFieldTrialName,
97 kPhoneNewTabToolbarButtonDivisor,
Ben Murdochd3868032013-07-31 10:55:33 +010098 kDisabled, 2015, 1, 1, base::FieldTrial::ONE_TIME_RANDOMIZED, NULL));
Ben Murdochca12bfa2013-07-23 11:17:05 +010099
Ben Murdochca12bfa2013-07-23 11:17:05 +0100100 const int kEnabledGroup = trial->AppendGroup(
101 kEnabled,
102 kIsStableChannel ?
103 kPhoneNewTabToolbarButtonStable : kPhoneNewTabToolbarButtonNonStable);
104
105 const int v = trial->group();
106 VLOG(1) << "Phone NewTab toolbar button enabled group id: " << kEnabledGroup
107 << ". Selected group id: " << v;
108}
109
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100110} // namespace
111
112void SetupMobileFieldTrials(const CommandLine& parsed_command_line,
113 const base::Time& install_time,
114 PrefService* local_state) {
Ben Murdochbb1529c2013-08-08 10:24:53 +0100115 DataCompressionProxyFieldTrials();
Ben Murdochca12bfa2013-07-23 11:17:05 +0100116
117#if defined(OS_ANDROID)
118 NewTabButtonInToolbarFieldTrial(parsed_command_line);
119#endif
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100120}
121
122} // namespace chrome