Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(879)

Side by Side Diff: chrome/browser/metrics/variations/variations_service.cc

Issue 11737025: Add a switch for faking channels for Variations filtering. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rebase Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/metrics/variations/variations_service.h ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/metrics/variations/variations_service.h" 5 #include "chrome/browser/metrics/variations/variations_service.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/build_time.h" 10 #include "base/build_time.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 case Study_Channel_BETA: 53 case Study_Channel_BETA:
54 return chrome::VersionInfo::CHANNEL_BETA; 54 return chrome::VersionInfo::CHANNEL_BETA;
55 case Study_Channel_STABLE: 55 case Study_Channel_STABLE:
56 return chrome::VersionInfo::CHANNEL_STABLE; 56 return chrome::VersionInfo::CHANNEL_STABLE;
57 } 57 }
58 // All enum values of |study_channel| were handled above. 58 // All enum values of |study_channel| were handled above.
59 NOTREACHED(); 59 NOTREACHED();
60 return chrome::VersionInfo::CHANNEL_UNKNOWN; 60 return chrome::VersionInfo::CHANNEL_UNKNOWN;
61 } 61 }
62 62
63 // Wrapper around channel checking, used to enable channel mocking for
64 // testing. If the current browser channel is not UNKNOWN, this will return
65 // that channel value. Otherwise, if the fake channel flag is provided, this
66 // will return the fake channel. Failing that, this will return the UNKNOWN
67 // channel.
68 chrome::VersionInfo::Channel GetChannelForVariations() {
69 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
70 if (channel != chrome::VersionInfo::CHANNEL_UNKNOWN)
71 return channel;
72 std::string forced_channel =
73 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
74 switches::kFakeVariationsChannel);
75 if (forced_channel == "stable")
76 channel = chrome::VersionInfo::CHANNEL_STABLE;
77 else if (forced_channel == "beta")
78 channel = chrome::VersionInfo::CHANNEL_BETA;
79 else if (forced_channel == "dev")
80 channel = chrome::VersionInfo::CHANNEL_DEV;
81 else if (forced_channel == "canary")
82 channel = chrome::VersionInfo::CHANNEL_CANARY;
83 else
84 DVLOG(1) << "Invalid channel provided: " << forced_channel;
85 return channel;
86 }
87
63 Study_Platform GetCurrentPlatform() { 88 Study_Platform GetCurrentPlatform() {
64 #if defined(OS_WIN) 89 #if defined(OS_WIN)
65 return Study_Platform_PLATFORM_WINDOWS; 90 return Study_Platform_PLATFORM_WINDOWS;
66 #elif defined(OS_MACOSX) 91 #elif defined(OS_MACOSX)
67 return Study_Platform_PLATFORM_MAC; 92 return Study_Platform_PLATFORM_MAC;
68 #elif defined(OS_CHROMEOS) 93 #elif defined(OS_CHROMEOS)
69 return Study_Platform_PLATFORM_CHROMEOS; 94 return Study_Platform_PLATFORM_CHROMEOS;
70 #elif defined(OS_ANDROID) 95 #elif defined(OS_ANDROID)
71 return Study_Platform_PLATFORM_ANDROID; 96 return Study_Platform_PLATFORM_ANDROID;
72 #elif defined(OS_IOS) 97 #elif defined(OS_IOS)
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 // Use the build time for date checks if either the seed date is invalid or 154 // Use the build time for date checks if either the seed date is invalid or
130 // the build time is newer than the seed date. 155 // the build time is newer than the seed date.
131 base::Time reference_date = seed_date; 156 base::Time reference_date = seed_date;
132 if (seed_date.is_null() || seed_date < build_time) 157 if (seed_date.is_null() || seed_date < build_time)
133 reference_date = build_time; 158 reference_date = build_time;
134 159
135 const chrome::VersionInfo current_version_info; 160 const chrome::VersionInfo current_version_info;
136 if (!current_version_info.is_valid()) 161 if (!current_version_info.is_valid())
137 return false; 162 return false;
138 163
164 chrome::VersionInfo::Channel channel = GetChannelForVariations();
139 for (int i = 0; i < seed.study_size(); ++i) { 165 for (int i = 0; i < seed.study_size(); ++i) {
140 if (ShouldAddStudy(seed.study(i), current_version_info, reference_date)) 166 if (ShouldAddStudy(seed.study(i), current_version_info, reference_date,
167 channel)) {
141 CreateTrialFromStudy(seed.study(i), reference_date); 168 CreateTrialFromStudy(seed.study(i), reference_date);
169 }
142 } 170 }
143 171
144 return true; 172 return true;
145 } 173 }
146 174
147 void VariationsService::StartRepeatedVariationsSeedFetch() { 175 void VariationsService::StartRepeatedVariationsSeedFetch() {
148 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 176 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
149 177
150 // Check that |CreateTrialsFromSeed| was called, which is necessary to 178 // Check that |CreateTrialsFromSeed| was called, which is necessary to
151 // retrieve the serial number that will be sent to the server. 179 // retrieve the serial number that will be sent to the server.
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 local_prefs->SetInt64(prefs::kVariationsSeedDate, 314 local_prefs->SetInt64(prefs::kVariationsSeedDate,
287 seed_date.ToInternalValue()); 315 seed_date.ToInternalValue());
288 variations_serial_number_ = seed.serial_number(); 316 variations_serial_number_ = seed.serial_number();
289 return true; 317 return true;
290 } 318 }
291 319
292 // static 320 // static
293 bool VariationsService::ShouldAddStudy( 321 bool VariationsService::ShouldAddStudy(
294 const Study& study, 322 const Study& study,
295 const chrome::VersionInfo& version_info, 323 const chrome::VersionInfo& version_info,
296 const base::Time& reference_date) { 324 const base::Time& reference_date,
325 const chrome::VersionInfo::Channel channel) {
297 if (study.has_filter()) { 326 if (study.has_filter()) {
298 if (!CheckStudyChannel(study.filter(), chrome::VersionInfo::GetChannel())) { 327 if (!CheckStudyChannel(study.filter(), channel)) {
299 DVLOG(1) << "Filtered out study " << study.name() << " due to channel."; 328 DVLOG(1) << "Filtered out study " << study.name() << " due to channel.";
300 return false; 329 return false;
301 } 330 }
302 331
303 if (!CheckStudyLocale(study.filter(), 332 if (!CheckStudyLocale(study.filter(),
304 g_browser_process->GetApplicationLocale())) { 333 g_browser_process->GetApplicationLocale())) {
305 DVLOG(1) << "Filtered out study " << study.name() << " due to locale."; 334 DVLOG(1) << "Filtered out study " << study.name() << " due to locale.";
306 return false; 335 return false;
307 } 336 }
308 337
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 variation_id); 553 variation_id);
525 } 554 }
526 } 555 }
527 556
528 trial->SetForced(); 557 trial->SetForced();
529 if (IsStudyExpired(study, reference_date)) 558 if (IsStudyExpired(study, reference_date))
530 trial->Disable(); 559 trial->Disable();
531 } 560 }
532 561
533 } // namespace chrome_variations 562 } // namespace chrome_variations
OLDNEW
« no previous file with comments | « chrome/browser/metrics/variations/variations_service.h ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698