Commit c8a77f81 authored by stevet@chromium.org's avatar stevet@chromium.org

Add a switch for faking channels for Variations filtering.

BUG=162417
TEST=Run Chromium (unofficial build) with --fake-variations-channel=stable and ensure that a stable experiment, such as "UMA-Dynamic-Binary-Uniformity-Trial" shows up in about:version (after restarting once).


Review URL: https://chromiumcodereview.appspot.com/11737025

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175437 0039d316-1c4b-4281-b951-d872f2087c98
parent 0831b6c1
......@@ -60,6 +60,31 @@ chrome::VersionInfo::Channel ConvertStudyChannelToVersionChannel(
return chrome::VersionInfo::CHANNEL_UNKNOWN;
}
// Wrapper around channel checking, used to enable channel mocking for
// testing. If the current browser channel is not UNKNOWN, this will return
// that channel value. Otherwise, if the fake channel flag is provided, this
// will return the fake channel. Failing that, this will return the UNKNOWN
// channel.
chrome::VersionInfo::Channel GetChannelForVariations() {
chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
if (channel != chrome::VersionInfo::CHANNEL_UNKNOWN)
return channel;
std::string forced_channel =
CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kFakeVariationsChannel);
if (forced_channel == "stable")
channel = chrome::VersionInfo::CHANNEL_STABLE;
else if (forced_channel == "beta")
channel = chrome::VersionInfo::CHANNEL_BETA;
else if (forced_channel == "dev")
channel = chrome::VersionInfo::CHANNEL_DEV;
else if (forced_channel == "canary")
channel = chrome::VersionInfo::CHANNEL_CANARY;
else
DVLOG(1) << "Invalid channel provided: " << forced_channel;
return channel;
}
Study_Platform GetCurrentPlatform() {
#if defined(OS_WIN)
return Study_Platform_PLATFORM_WINDOWS;
......@@ -136,9 +161,12 @@ bool VariationsService::CreateTrialsFromSeed(PrefService* local_prefs) {
if (!current_version_info.is_valid())
return false;
chrome::VersionInfo::Channel channel = GetChannelForVariations();
for (int i = 0; i < seed.study_size(); ++i) {
if (ShouldAddStudy(seed.study(i), current_version_info, reference_date))
if (ShouldAddStudy(seed.study(i), current_version_info, reference_date,
channel)) {
CreateTrialFromStudy(seed.study(i), reference_date);
}
}
return true;
......@@ -293,9 +321,10 @@ bool VariationsService::StoreSeedData(const std::string& seed_data,
bool VariationsService::ShouldAddStudy(
const Study& study,
const chrome::VersionInfo& version_info,
const base::Time& reference_date) {
const base::Time& reference_date,
const chrome::VersionInfo::Channel channel) {
if (study.has_filter()) {
if (!CheckStudyChannel(study.filter(), chrome::VersionInfo::GetChannel())) {
if (!CheckStudyChannel(study.filter(), channel)) {
DVLOG(1) << "Filtered out study " << study.name() << " due to channel.";
return false;
}
......
......@@ -99,11 +99,13 @@ class VariationsService
PrefService* local_prefs);
// Returns whether |study| should be disabled according to its restriction
// parameters. Uses |version_info| for min / max version checks and
// |reference_date| for the start date check.
// parameters. Uses |version_info| for min / max version checks,
// |reference_date| for the start date check and |channel| for channel
// checks.
static bool ShouldAddStudy(const Study& study,
const chrome::VersionInfo& version_info,
const base::Time& reference_date);
const base::Time& reference_date,
chrome::VersionInfo::Channel channel);
// Checks whether a study is applicable for the given |channel| per |filter|.
static bool CheckStudyChannel(const Study_Filter& filter,
......
......@@ -679,6 +679,12 @@ const char kExtensionProcess[] = "extension-process";
// Frequency in seconds for Extensions auto-update.
const char kExtensionsUpdateFrequency[] = "extensions-update-frequency";
// Fakes the channel of the browser for purposes of Variations filtering. This
// is to be used for testing only. Possible values are "stable", "beta", "dev"
// and "canary". Note that this only applies if the browser's reported channel
// is UNKNOWN.
const char kFakeVariationsChannel[] = "fake-variations-channel";
// These two flags are added around the switches about:flags adds to the
// command line. This is useful to see which switches were added by about:flags
// on about:version. They don't have any effect.
......
......@@ -189,6 +189,7 @@ extern const char kEventPageUnloadingTime[];
extern const char kExplicitlyAllowedPorts[];
extern const char kExtensionProcess[];
extern const char kExtensionsUpdateFrequency[];
extern const char kFakeVariationsChannel[];
extern const char kFlagSwitchesBegin[];
extern const char kFlagSwitchesEnd[];
extern const char kFeedbackServer[];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment