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_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 namespace chrome {
     32 
     33 namespace {
     34 
     35 void AutoLaunchChromeFieldTrial() {
     36   std::string brand;
     37   google_util::GetBrand(&brand);
     38 
     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);
     46   }
     47 }
     48 
     49 void SetupInfiniteCacheFieldTrial() {
     50   const base::FieldTrial::Probability kDivisor = 100;
     51 
     52   base::FieldTrial::Probability infinite_cache_probability = 0;
     53 
     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);
     60 }
     61 
     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();
     68 }
     69 
     70 void SetupPreReadFieldTrial() {
     71   // The chrome executable will have set (or not) an environment variable with
     72   // the group name into which this client belongs.
     73   std::string group;
     74   scoped_ptr<base::Environment> env(base::Environment::Create());
     75   if (!env->GetVar(chrome::kPreReadEnvironmentVariable, &group) ||
     76       group.empty()) {
     77     return;
     78   }
     79 
     80   // Initialize the field trial. We declare all of the groups here (so that
     81   // the dashboard creation tools can find them) but force the probability
     82   // of being assigned to the group already chosen by the executable, if any,
     83   // to 100%.
     84   scoped_refptr<base::FieldTrial> trial(
     85       base::FieldTrialList::FactoryGetFieldTrial(
     86           "BrowserPreReadExperiment", 100, "100-pct-default",
     87           2014, 7, 1, base::FieldTrial::SESSION_RANDOMIZED, NULL));
     88   trial->AppendGroup("100-pct-control", group == "100-pct-control" ? 100 : 0);
     89   trial->AppendGroup("95-pct", group == "95-pct" ? 100 : 0);
     90   trial->AppendGroup("90-pct", group == "90-pct" ? 100 : 0);
     91   trial->AppendGroup("85-pct", group == "85-pct" ? 100 : 0);
     92   trial->AppendGroup("80-pct", group == "80-pct" ? 100 : 0);
     93   trial->AppendGroup("75-pct", group == "75-pct" ? 100 : 0);
     94   trial->AppendGroup("70-pct", group == "70-pct" ? 100 : 0);
     95   trial->AppendGroup("65-pct", group == "65-pct" ? 100 : 0);
     96   trial->AppendGroup("60-pct", group == "60-pct" ? 100 : 0);
     97   trial->AppendGroup("55-pct", group == "55-pct" ? 100 : 0);
     98   trial->AppendGroup("50-pct", group == "50-pct" ? 100 : 0);
     99   trial->AppendGroup("45-pct", group == "45-pct" ? 100 : 0);
    100   trial->AppendGroup("40-pct", group == "40-pct" ? 100 : 0);
    101   trial->AppendGroup("35-pct", group == "35-pct" ? 100 : 0);
    102   trial->AppendGroup("30-pct", group == "30-pct" ? 100 : 0);
    103   trial->AppendGroup("25-pct", group == "25-pct" ? 100 : 0);
    104   trial->AppendGroup("20-pct", group == "20-pct" ? 100 : 0);
    105   trial->AppendGroup("15-pct", group == "15-pct" ? 100 : 0);
    106   trial->AppendGroup("10-pct", group == "10-pct" ? 100 : 0);
    107   trial->AppendGroup("5-pct", group == "5-pct" ? 100 : 0);
    108   trial->AppendGroup("0-pct", group == "0-pct" ? 100 : 0);
    109 
    110   // We have to call group in order to mark the experiment as active.
    111   trial->group();
    112 }
    113 
    114 }  // namespace
    115 
    116 void SetupDesktopFieldTrials(const CommandLine& parsed_command_line,
    117                              const base::Time& install_time,
    118                              PrefService* local_state) {
    119   prerender::ConfigurePrerender(parsed_command_line);
    120   AutoLaunchChromeFieldTrial();
    121   OmniboxFieldTrial::ActivateStaticTrials();
    122   SetupInfiniteCacheFieldTrial();
    123   DisableShowProfileSwitcherTrialIfNecessary();
    124   SetupShowAppLauncherPromoFieldTrial(local_state);
    125   SetupPreReadFieldTrial();
    126 }
    127 
    128 }  // namespace chrome
    129