Home | History | Annotate | Download | only in browser
      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 #if defined(OS_ANDROID)
     16 #include "chrome/browser/prerender/prerender_field_trial.h"
     17 #endif
     18 
     19 namespace chrome {
     20 
     21 namespace {
     22 
     23 // Base function used by all data reduction proxy field trials. A trial is
     24 // only conducted for installs that are in the "Enabled" group. They are always
     25 // enabled on DEV and BETA channels, and for STABLE, a percentage will be
     26 // controlled from the server. Until the percentage is learned from the server,
     27 // a client-side configuration is used.
     28 void DataCompressionProxyBaseFieldTrial(
     29     const char* trial_name,
     30     const base::FieldTrial::Probability enabled_group_probability,
     31     const base::FieldTrial::Probability total_probability) {
     32   const char kEnabled[] = "Enabled";
     33   const char kDisabled[] = "Disabled";
     34 
     35   // Find out if this is a stable channel.
     36   const bool kIsStableChannel =
     37       chrome::VersionInfo::GetChannel() == chrome::VersionInfo::CHANNEL_STABLE;
     38 
     39   // Experiment enabled until Jan 1, 2015. By default, disabled.
     40   scoped_refptr<base::FieldTrial> trial(
     41       base::FieldTrialList::FactoryGetFieldTrial(
     42           trial_name,
     43           total_probability,
     44           kDisabled, 2015, 1, 1, base::FieldTrial::ONE_TIME_RANDOMIZED, NULL));
     45 
     46   // Non-stable channels will run with probability 1.
     47   trial->AppendGroup(
     48       kEnabled,
     49       kIsStableChannel ? enabled_group_probability : total_probability);
     50 
     51   trial->group();
     52 }
     53 
     54 void SetupDataCompressionProxyFieldTrials() {
     55   // Governs the rollout of the _promo_ for the compression proxy
     56   // independently from the rollout of compression proxy. The enabled
     57   // percentage is configured to be 10% = 100 / 1000 until overridden by the
     58   // server. When this trial is "Enabled," users get a promo, whereas
     59   // otherwise, compression is available without a promo.
     60   DataCompressionProxyBaseFieldTrial(
     61       "DataCompressionProxyPromoVisibility", 100, 1000);
     62 }
     63 
     64 }  // namespace
     65 
     66 void SetupMobileFieldTrials(const CommandLine& parsed_command_line) {
     67   SetupDataCompressionProxyFieldTrials();
     68 #if defined(OS_ANDROID)
     69   prerender::ConfigurePrerender(parsed_command_line);
     70 #endif
     71 }
     72 
     73 }  // namespace chrome
     74