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 "apps/field_trial_names.h"
     10 #include "apps/pref_names.h"
     11 #include "base/command_line.h"
     12 #include "base/metrics/field_trial.h"
     13 #include "base/prefs/pref_service.h"
     14 #include "base/strings/string_util.h"
     15 #include "chrome/browser/auto_launch_trial.h"
     16 #include "chrome/browser/google/google_util.h"
     17 #include "chrome/browser/gpu/chrome_gpu_util.h"
     18 #include "chrome/browser/omnibox/omnibox_field_trial.h"
     19 #include "chrome/browser/prerender/prerender_field_trial.h"
     20 #include "chrome/browser/profiles/profiles_state.h"
     21 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h"
     22 #include "chrome/browser/ui/sync/one_click_signin_helper.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 "content/public/common/content_constants.h"
     27 #include "net/spdy/spdy_session.h"
     28 #include "ui/base/layout.h"
     29 
     30 #if defined(OS_WIN)
     31 #include "net/socket/tcp_client_socket_win.h"
     32 #endif  // defined(OS_WIN)
     33 
     34 namespace chrome {
     35 
     36 namespace {
     37 
     38 void SetupAppLauncherFieldTrial(PrefService* local_state) {
     39   if (base::FieldTrialList::FindFullName(apps::kLauncherPromoTrialName) ==
     40       apps::kResetShowLauncherPromoPrefGroupName) {
     41     local_state->SetBoolean(apps::prefs::kShowAppLauncherPromo, true);
     42   }
     43 }
     44 
     45 void AutoLaunchChromeFieldTrial() {
     46   std::string brand;
     47   google_util::GetBrand(&brand);
     48 
     49   // Create a 100% field trial based on the brand code.
     50   if (auto_launch_trial::IsInExperimentGroup(brand)) {
     51     base::FieldTrialList::CreateFieldTrial(kAutoLaunchTrialName,
     52                                            kAutoLaunchTrialAutoLaunchGroup);
     53   } else if (auto_launch_trial::IsInControlGroup(brand)) {
     54     base::FieldTrialList::CreateFieldTrial(kAutoLaunchTrialName,
     55                                            kAutoLaunchTrialControlGroup);
     56   }
     57 }
     58 
     59 void SetupInfiniteCacheFieldTrial() {
     60   const base::FieldTrial::Probability kDivisor = 100;
     61 
     62   base::FieldTrial::Probability infinite_cache_probability = 0;
     63 
     64   scoped_refptr<base::FieldTrial> trial(
     65       base::FieldTrialList::FactoryGetFieldTrial(
     66           "InfiniteCache", kDivisor, "No", 2013, 12, 31,
     67           base::FieldTrial::ONE_TIME_RANDOMIZED, NULL));
     68   trial->AppendGroup("Yes", infinite_cache_probability);
     69   trial->AppendGroup("Control", infinite_cache_probability);
     70 }
     71 
     72 void DisableShowProfileSwitcherTrialIfNecessary() {
     73   // This trial is created by the VariationsService, but it needs to be disabled
     74   // if multi-profiles isn't enabled or if browser frame avatar menu is
     75   // always hidden (Chrome OS).
     76   bool avatar_menu_always_hidden = false;
     77 #if defined(OS_CHROMEOS)
     78   avatar_menu_always_hidden = true;
     79 #endif
     80   base::FieldTrial* trial = base::FieldTrialList::Find("ShowProfileSwitcher");
     81   if (trial && (!profiles::IsMultipleProfilesEnabled() ||
     82                 avatar_menu_always_hidden)) {
     83     trial->Disable();
     84   }
     85 }
     86 
     87 void SetupCacheSensitivityAnalysisFieldTrial() {
     88   const base::FieldTrial::Probability kDivisor = 100;
     89 
     90   base::FieldTrial::Probability sensitivity_analysis_probability = 0;
     91 
     92 #if defined(OS_ANDROID)
     93   switch (chrome::VersionInfo::GetChannel()) {
     94     case chrome::VersionInfo::CHANNEL_DEV:
     95       sensitivity_analysis_probability = 10;
     96       break;
     97     case chrome::VersionInfo::CHANNEL_BETA:
     98       sensitivity_analysis_probability = 5;
     99       break;
    100     case chrome::VersionInfo::CHANNEL_STABLE:
    101       sensitivity_analysis_probability = 1;
    102       break;
    103     default:
    104       break;
    105   }
    106 #endif
    107 
    108   scoped_refptr<base::FieldTrial> trial(
    109       base::FieldTrialList::FactoryGetFieldTrial(
    110           "CacheSensitivityAnalysis", kDivisor, "No", 2013, 06, 15,
    111           base::FieldTrial::SESSION_RANDOMIZED, NULL));
    112   trial->AppendGroup("ControlA", sensitivity_analysis_probability);
    113   trial->AppendGroup("ControlB", sensitivity_analysis_probability);
    114   trial->AppendGroup("100A", sensitivity_analysis_probability);
    115   trial->AppendGroup("100B", sensitivity_analysis_probability);
    116   trial->AppendGroup("200A", sensitivity_analysis_probability);
    117   trial->AppendGroup("200B", sensitivity_analysis_probability);
    118   // TODO(gavinp,rvargas): Re-add 400 group to field trial if results justify.
    119 }
    120 
    121 void WindowsOverlappedTCPReadsFieldTrial(
    122     const CommandLine& parsed_command_line) {
    123 #if defined(OS_WIN)
    124   if (parsed_command_line.HasSwitch(switches::kOverlappedRead)) {
    125     std::string option =
    126         parsed_command_line.GetSwitchValueASCII(switches::kOverlappedRead);
    127     if (LowerCaseEqualsASCII(option, "off"))
    128       net::TCPClientSocketWin::DisableOverlappedReads();
    129   } else {
    130     const base::FieldTrial::Probability kDivisor = 2;  // 1 in 2 chance
    131     const base::FieldTrial::Probability kOverlappedReadProbability = 1;
    132     scoped_refptr<base::FieldTrial> overlapped_reads_trial(
    133         base::FieldTrialList::FactoryGetFieldTrial(
    134             "OverlappedReadImpact", kDivisor, "OverlappedReadEnabled",
    135             2013, 6, 1, base::FieldTrial::SESSION_RANDOMIZED, NULL));
    136     int overlapped_reads_disabled_group =
    137         overlapped_reads_trial->AppendGroup("OverlappedReadDisabled",
    138                                             kOverlappedReadProbability);
    139     int assigned_group = overlapped_reads_trial->group();
    140     if (assigned_group == overlapped_reads_disabled_group)
    141       net::TCPClientSocketWin::DisableOverlappedReads();
    142   }
    143 #endif
    144 }
    145 
    146 void SetupLowLatencyFlashAudioFieldTrial() {
    147   scoped_refptr<base::FieldTrial> trial(
    148       base::FieldTrialList::FactoryGetFieldTrial(
    149           content::kLowLatencyFlashAudioFieldTrialName, 100, "Standard",
    150           2013, 9, 1, base::FieldTrial::SESSION_RANDOMIZED, NULL));
    151 
    152   // Trial is enabled for dev / beta / canary users only.
    153   if (chrome::VersionInfo::GetChannel() != chrome::VersionInfo::CHANNEL_STABLE)
    154     trial->AppendGroup(content::kLowLatencyFlashAudioFieldTrialEnabledName, 25);
    155 }
    156 
    157 }  // namespace
    158 
    159 void SetupDesktopFieldTrials(const CommandLine& parsed_command_line,
    160                              const base::Time& install_time,
    161                              PrefService* local_state) {
    162   prerender::ConfigurePrefetchAndPrerender(parsed_command_line);
    163   AutoLaunchChromeFieldTrial();
    164   gpu_util::InitializeCompositingFieldTrial();
    165   OmniboxFieldTrial::ActivateStaticTrials();
    166   SetupInfiniteCacheFieldTrial();
    167   SetupCacheSensitivityAnalysisFieldTrial();
    168   DisableShowProfileSwitcherTrialIfNecessary();
    169   WindowsOverlappedTCPReadsFieldTrial(parsed_command_line);
    170   SetupAppLauncherFieldTrial(local_state);
    171   SetupLowLatencyFlashAudioFieldTrial();
    172 }
    173 
    174 }  // namespace chrome
    175