Index: chrome/browser/metrics/variations/variations_service.cc |
diff --git a/chrome/browser/metrics/variations/variations_service.cc b/chrome/browser/metrics/variations/variations_service.cc |
index b4e12da5b1bb716dbe4b3ddb0f88b9d6b3ae6461..731e73aa33272a2ae3c029e824b34837e849db75 100644 |
--- a/chrome/browser/metrics/variations/variations_service.cc |
+++ b/chrome/browser/metrics/variations/variations_service.cc |
@@ -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,8 +161,10 @@ 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); |
Alexei Svitkine (slow)
2013/01/04 20:32:16
Nit: Align |channel| with seed.study(i) and add {}
SteveT
2013/01/07 15:43:05
I had a feeling this curly issue would come up. I
Alexei Svitkine (slow)
2013/01/07 15:51:43
The rule I follow is if either if statement or bod
|
} |
@@ -280,9 +307,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; |
} |