OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_seed_store.h" | 5 #include "chrome/browser/metrics/variations/variations_seed_store.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/prefs/pref_registry_simple.h" | 9 #include "base/prefs/pref_registry_simple.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 } | 155 } |
156 | 156 |
157 variations_serial_number_ = seed->serial_number(); | 157 variations_serial_number_ = seed->serial_number(); |
158 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_NOT_EMPTY); | 158 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_NOT_EMPTY); |
159 return true; | 159 return true; |
160 } | 160 } |
161 | 161 |
162 bool VariationsSeedStore::StoreSeedData( | 162 bool VariationsSeedStore::StoreSeedData( |
163 const std::string& seed_data, | 163 const std::string& seed_data, |
164 const std::string& base64_seed_signature, | 164 const std::string& base64_seed_signature, |
165 const base::Time& date_fetched) { | 165 const base::Time& date_fetched, |
166 VariationsSeed* seed) { | |
jwd
2014/04/25 14:30:34
Should you check that seed isn't null?
Alexei Svitkine (slow)
2014/04/25 15:21:46
Changed logic to allow passing NULL and only filli
| |
166 if (seed_data.empty()) { | 167 if (seed_data.empty()) { |
167 VLOG(1) << "Variations seed data is empty, rejecting the seed."; | 168 VLOG(1) << "Variations seed data is empty, rejecting the seed."; |
168 return false; | 169 return false; |
169 } | 170 } |
170 | 171 |
171 // Only store the seed data if it parses correctly. | 172 // Only store the seed data if it parses correctly. |
172 VariationsSeed seed; | 173 if (!seed->ParseFromString(seed_data)) { |
jwd
2014/04/25 14:30:34
What's in seed when it fails to parse? Should it b
Alexei Svitkine (slow)
2014/04/25 15:21:46
Ditto.
| |
173 if (!seed.ParseFromString(seed_data)) { | |
174 VLOG(1) << "Variations seed data is not in valid proto format, " | 174 VLOG(1) << "Variations seed data is not in valid proto format, " |
175 << "rejecting the seed."; | 175 << "rejecting the seed."; |
176 return false; | 176 return false; |
177 } | 177 } |
178 | 178 |
179 const VerifySignatureResult result = | 179 const VerifySignatureResult result = |
180 VerifySeedSignature(seed_data, base64_seed_signature); | 180 VerifySeedSignature(seed_data, base64_seed_signature); |
181 if (result != VARIATIONS_SEED_SIGNATURE_ENUM_SIZE) { | 181 if (result != VARIATIONS_SEED_SIGNATURE_ENUM_SIZE) { |
182 UMA_HISTOGRAM_ENUMERATION("Variations.StoreSeedSignature", result, | 182 UMA_HISTOGRAM_ENUMERATION("Variations.StoreSeedSignature", result, |
183 VARIATIONS_SEED_SIGNATURE_ENUM_SIZE); | 183 VARIATIONS_SEED_SIGNATURE_ENUM_SIZE); |
184 if (result != VARIATIONS_SEED_SIGNATURE_VALID) { | 184 if (result != VARIATIONS_SEED_SIGNATURE_VALID) { |
185 VLOG(1) << "Variations seed signature missing or invalid with result: " | 185 VLOG(1) << "Variations seed signature missing or invalid with result: " |
186 << result << ". Rejecting the seed."; | 186 << result << ". Rejecting the seed."; |
187 return false; | 187 return false; |
188 } | 188 } |
189 } | 189 } |
190 | 190 |
191 std::string base64_seed_data; | 191 std::string base64_seed_data; |
192 base::Base64Encode(seed_data, &base64_seed_data); | 192 base::Base64Encode(seed_data, &base64_seed_data); |
193 | 193 |
194 // TODO(asvitkine): This pref is no longer being used. Remove it completely | 194 // TODO(asvitkine): This pref is no longer being used. Remove it completely |
195 // in a couple of releases. | 195 // in a couple of releases. |
196 local_state_->ClearPref(prefs::kVariationsSeedHash); | 196 local_state_->ClearPref(prefs::kVariationsSeedHash); |
197 | 197 |
198 local_state_->SetString(prefs::kVariationsSeed, base64_seed_data); | 198 local_state_->SetString(prefs::kVariationsSeed, base64_seed_data); |
199 UpdateSeedDateAndLogDayChange(date_fetched); | 199 UpdateSeedDateAndLogDayChange(date_fetched); |
200 local_state_->SetString(prefs::kVariationsSeedSignature, | 200 local_state_->SetString(prefs::kVariationsSeedSignature, |
201 base64_seed_signature); | 201 base64_seed_signature); |
202 variations_serial_number_ = seed.serial_number(); | 202 variations_serial_number_ = seed->serial_number(); |
203 | 203 |
204 return true; | 204 return true; |
205 } | 205 } |
206 | 206 |
207 void VariationsSeedStore::UpdateSeedDateAndLogDayChange( | 207 void VariationsSeedStore::UpdateSeedDateAndLogDayChange( |
208 const base::Time& server_date_fetched) { | 208 const base::Time& server_date_fetched) { |
209 VariationsSeedDateChangeState date_change = SEED_DATE_NO_OLD_DATE; | 209 VariationsSeedDateChangeState date_change = SEED_DATE_NO_OLD_DATE; |
210 | 210 |
211 if (local_state_->HasPrefPath(prefs::kVariationsSeedDate)) { | 211 if (local_state_->HasPrefPath(prefs::kVariationsSeedDate)) { |
212 const int64 stored_date_value = | 212 const int64 stored_date_value = |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
263 } | 263 } |
264 | 264 |
265 verifier.VerifyUpdate(reinterpret_cast<const uint8*>(seed_bytes.data()), | 265 verifier.VerifyUpdate(reinterpret_cast<const uint8*>(seed_bytes.data()), |
266 seed_bytes.size()); | 266 seed_bytes.size()); |
267 if (verifier.VerifyFinal()) | 267 if (verifier.VerifyFinal()) |
268 return VARIATIONS_SEED_SIGNATURE_VALID; | 268 return VARIATIONS_SEED_SIGNATURE_VALID; |
269 return VARIATIONS_SEED_SIGNATURE_INVALID_SEED; | 269 return VARIATIONS_SEED_SIGNATURE_INVALID_SEED; |
270 } | 270 } |
271 | 271 |
272 } // namespace chrome_variations | 272 } // namespace chrome_variations |
OLD | NEW |