1 // Copyright (c) 2012 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.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 "base/strings/string_util.h" 13 #include "base/time/time.h" 14 #include "chrome/browser/metrics/gzipped_protobufs_field_trial.h" 15 #include "chrome/browser/omnibox/omnibox_field_trial.h" 16 #include "chrome/common/chrome_switches.h" 17 #include "chrome/common/chrome_version_info.h" 18 #include "chrome/common/metrics/variations/uniformity_field_trials.h" 19 #include "chrome/common/pref_names.h" 20 21 #if defined(OS_ANDROID) || defined(OS_IOS) 22 #include "chrome/browser/chrome_browser_field_trials_mobile.h" 23 #else 24 #include "chrome/browser/chrome_browser_field_trials_desktop.h" 25 #endif 26 27 ChromeBrowserFieldTrials::ChromeBrowserFieldTrials( 28 const CommandLine& parsed_command_line) 29 : parsed_command_line_(parsed_command_line) { 30 } 31 32 ChromeBrowserFieldTrials::~ChromeBrowserFieldTrials() { 33 } 34 35 void ChromeBrowserFieldTrials::SetupFieldTrials(PrefService* local_state) { 36 const base::Time install_time = base::Time::FromTimeT( 37 local_state->GetInt64(prefs::kInstallDate)); 38 DCHECK(!install_time.is_null()); 39 40 // Field trials that are shared by all platforms. 41 chrome_variations::SetupUniformityFieldTrials(install_time); 42 metrics::CreateGzippedProtobufsFieldTrial(); 43 InstantiateDynamicTrials(); 44 45 #if defined(OS_ANDROID) || defined(OS_IOS) 46 chrome::SetupMobileFieldTrials( 47 parsed_command_line_, install_time, local_state); 48 #else 49 chrome::SetupDesktopFieldTrials( 50 parsed_command_line_, install_time, local_state); 51 #endif 52 } 53 54 void ChromeBrowserFieldTrials::InstantiateDynamicTrials() { 55 // Call |FindValue()| on the trials below, which may come from the server, to 56 // ensure they get marked as "used" for the purposes of data reporting. 57 base::FieldTrialList::FindValue("UMA-Dynamic-Binary-Uniformity-Trial"); 58 base::FieldTrialList::FindValue("UMA-Dynamic-Uniformity-Trial"); 59 base::FieldTrialList::FindValue("InstantDummy"); 60 base::FieldTrialList::FindValue("InstantChannel"); 61 base::FieldTrialList::FindValue("Test0PercentDefault"); 62 // MouseEventPreconnect trial is used from renderer process. 63 // Mark here so it will be sync-ed. 64 base::FieldTrialList::FindValue("MouseEventPreconnect"); 65 // Activate the autocomplete dynamic field trials. 66 OmniboxFieldTrial::ActivateDynamicTrials(); 67 } 68