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

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

Issue 10764005: Added tests for storing and loading seed data to and from prefs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more merge conflicts Created 8 years, 5 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 | Annotate | Revision Log
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_service.h" 5 #include "chrome/browser/metrics/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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 StoreSeedData(seed_data, response_date, g_browser_process->local_state()); 183 StoreSeedData(seed_data, response_date, g_browser_process->local_state());
184 } 184 }
185 185
186 // static 186 // static
187 void VariationsService::RegisterPrefs(PrefService* prefs) { 187 void VariationsService::RegisterPrefs(PrefService* prefs) {
188 prefs->RegisterStringPref(prefs::kVariationsSeed, std::string()); 188 prefs->RegisterStringPref(prefs::kVariationsSeed, std::string());
189 prefs->RegisterInt64Pref(prefs::kVariationsSeedDate, 189 prefs->RegisterInt64Pref(prefs::kVariationsSeedDate,
190 base::Time().ToInternalValue()); 190 base::Time().ToInternalValue());
191 } 191 }
192 192
193 void VariationsService::StoreSeedData(const std::string& seed_data, 193 bool VariationsService::StoreSeedData(const std::string& seed_data,
194 const base::Time& seed_date, 194 const base::Time& seed_date,
195 PrefService* local_prefs) { 195 PrefService* local_prefs) {
196 // Only store the seed data if it parses correctly. 196 // Only store the seed data if it parses correctly.
197 TrialsSeed seed; 197 TrialsSeed seed;
198 if (!seed.ParseFromString(seed_data)) { 198 if (!seed.ParseFromString(seed_data)) {
199 VLOG(1) << "Variations Seed data from server is not in valid proto format, " 199 VLOG(1) << "Variations Seed data from server is not in valid proto format, "
200 << "rejecting the seed."; 200 << "rejecting the seed.";
201 return; 201 return false;
202 } 202 }
203 203
204 std::string base64_seed_data; 204 std::string base64_seed_data;
205 if (!base::Base64Encode(seed_data, &base64_seed_data)) { 205 if (!base::Base64Encode(seed_data, &base64_seed_data)) {
206 VLOG(1) << "Variations Seed data from server fails Base64Encode, rejecting " 206 VLOG(1) << "Variations Seed data from server fails Base64Encode, rejecting "
207 << "the seed."; 207 << "the seed.";
208 return; 208 return false;
209 } 209 }
210 210
211 local_prefs->SetString(prefs::kVariationsSeed, base64_seed_data); 211 local_prefs->SetString(prefs::kVariationsSeed, base64_seed_data);
212 local_prefs->SetInt64(prefs::kVariationsSeedDate, 212 local_prefs->SetInt64(prefs::kVariationsSeedDate,
213 seed_date.ToInternalValue()); 213 seed_date.ToInternalValue());
214 return true;
214 } 215 }
215 216
216 // static 217 // static
217 bool VariationsService::ShouldAddStudy( 218 bool VariationsService::ShouldAddStudy(
218 const Study& study, 219 const Study& study,
219 const chrome::VersionInfo& version_info, 220 const chrome::VersionInfo& version_info,
220 const base::Time& reference_date) { 221 const base::Time& reference_date) {
221 if (study.has_filter()) { 222 if (study.has_filter()) {
222 if (!CheckStudyChannel(study.filter(), chrome::VersionInfo::GetChannel())) { 223 if (!CheckStudyChannel(study.filter(), chrome::VersionInfo::GetChannel())) {
223 DVLOG(1) << "Filtered out study " << study.name() << " due to channel."; 224 DVLOG(1) << "Filtered out study " << study.name() << " due to channel.";
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 variation_id); 447 variation_id);
447 } 448 }
448 } 449 }
449 450
450 trial->SetForced(); 451 trial->SetForced();
451 if (IsStudyExpired(study, reference_date)) 452 if (IsStudyExpired(study, reference_date))
452 trial->Disable(); 453 trial->Disable();
453 } 454 }
454 455
455 } // namespace chrome_variations 456 } // namespace chrome_variations
OLDNEW
« no previous file with comments | « chrome/browser/metrics/variations_service.h ('k') | chrome/browser/metrics/variations_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698