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_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" 12 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_version_info.h" 14 15 namespace chrome { 16 17 namespace { 18 19 // 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. 24 void DataCompressionProxyBaseFieldTrial( 25 const char* trial_name, 26 const base::FieldTrial::Probability enabled_group_probability, 27 const base::FieldTrial::Probability total_probability) { 28 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( 38 trial_name, 39 total_probability, 40 kDisabled, 2015, 1, 1, base::FieldTrial::ONE_TIME_RANDOMIZED, NULL)); 41 42 // Non-stable channels will run with probability 1. 43 const int kEnabledGroup = trial->AppendGroup( 44 kEnabled, 45 kIsStableChannel ? enabled_group_probability : total_probability); 46 47 const int v = trial->group(); 48 VLOG(1) << trial_name << " enabled group id: " << kEnabledGroup 49 << ". Selected group id: " << v; 50 } 51 52 void 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 73 void 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, 98 kDisabled, 2015, 1, 1, base::FieldTrial::ONE_TIME_RANDOMIZED, NULL)); 99 100 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 110 } // namespace 111 112 void SetupMobileFieldTrials(const CommandLine& parsed_command_line, 113 const base::Time& install_time, 114 PrefService* local_state) { 115 DataCompressionProxyFieldTrials(); 116 117 #if defined(OS_ANDROID) 118 NewTabButtonInToolbarFieldTrial(parsed_command_line); 119 #endif 120 } 121 122 } // namespace chrome 123