OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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); |
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
| |
142 } | 169 } |
143 | 170 |
144 return true; | 171 return true; |
145 } | 172 } |
146 | 173 |
147 void VariationsService::StartRepeatedVariationsSeedFetch() { | 174 void VariationsService::StartRepeatedVariationsSeedFetch() { |
148 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 175 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
149 | 176 |
150 // Check that |CreateTrialsFromSeed| was called, which is necessary to | 177 // Check that |CreateTrialsFromSeed| was called, which is necessary to |
151 // retrieve the serial number that will be sent to the server. | 178 // retrieve the serial number that will be sent to the server. |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
273 local_prefs->SetInt64(prefs::kVariationsSeedDate, | 300 local_prefs->SetInt64(prefs::kVariationsSeedDate, |
274 seed_date.ToInternalValue()); | 301 seed_date.ToInternalValue()); |
275 variations_serial_number_ = seed.serial_number(); | 302 variations_serial_number_ = seed.serial_number(); |
276 return true; | 303 return true; |
277 } | 304 } |
278 | 305 |
279 // static | 306 // static |
280 bool VariationsService::ShouldAddStudy( | 307 bool VariationsService::ShouldAddStudy( |
281 const Study& study, | 308 const Study& study, |
282 const chrome::VersionInfo& version_info, | 309 const chrome::VersionInfo& version_info, |
283 const base::Time& reference_date) { | 310 const base::Time& reference_date, |
311 const chrome::VersionInfo::Channel channel) { | |
284 if (study.has_filter()) { | 312 if (study.has_filter()) { |
285 if (!CheckStudyChannel(study.filter(), chrome::VersionInfo::GetChannel())) { | 313 if (!CheckStudyChannel(study.filter(), channel)) { |
286 DVLOG(1) << "Filtered out study " << study.name() << " due to channel."; | 314 DVLOG(1) << "Filtered out study " << study.name() << " due to channel."; |
287 return false; | 315 return false; |
288 } | 316 } |
289 | 317 |
290 if (!CheckStudyLocale(study.filter(), | 318 if (!CheckStudyLocale(study.filter(), |
291 g_browser_process->GetApplicationLocale())) { | 319 g_browser_process->GetApplicationLocale())) { |
292 DVLOG(1) << "Filtered out study " << study.name() << " due to locale."; | 320 DVLOG(1) << "Filtered out study " << study.name() << " due to locale."; |
293 return false; | 321 return false; |
294 } | 322 } |
295 | 323 |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
511 variation_id); | 539 variation_id); |
512 } | 540 } |
513 } | 541 } |
514 | 542 |
515 trial->SetForced(); | 543 trial->SetForced(); |
516 if (IsStudyExpired(study, reference_date)) | 544 if (IsStudyExpired(study, reference_date)) |
517 trial->Disable(); | 545 trial->Disable(); |
518 } | 546 } |
519 | 547 |
520 } // namespace chrome_variations | 548 } // namespace chrome_variations |
OLD | NEW |