| 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* parsed_seed) { |
| 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 VariationsSeed seed; |
| 173 if (!seed.ParseFromString(seed_data)) { | 174 if (!seed.ParseFromString(seed_data)) { |
| 174 VLOG(1) << "Variations seed data is not in valid proto format, " | 175 VLOG(1) << "Variations seed data is not in valid proto format, " |
| 175 << "rejecting the seed."; | 176 << "rejecting the seed."; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 193 | 194 |
| 194 // TODO(asvitkine): This pref is no longer being used. Remove it completely | 195 // TODO(asvitkine): This pref is no longer being used. Remove it completely |
| 195 // in a couple of releases. | 196 // in a couple of releases. |
| 196 local_state_->ClearPref(prefs::kVariationsSeedHash); | 197 local_state_->ClearPref(prefs::kVariationsSeedHash); |
| 197 | 198 |
| 198 local_state_->SetString(prefs::kVariationsSeed, base64_seed_data); | 199 local_state_->SetString(prefs::kVariationsSeed, base64_seed_data); |
| 199 UpdateSeedDateAndLogDayChange(date_fetched); | 200 UpdateSeedDateAndLogDayChange(date_fetched); |
| 200 local_state_->SetString(prefs::kVariationsSeedSignature, | 201 local_state_->SetString(prefs::kVariationsSeedSignature, |
| 201 base64_seed_signature); | 202 base64_seed_signature); |
| 202 variations_serial_number_ = seed.serial_number(); | 203 variations_serial_number_ = seed.serial_number(); |
| 204 if (parsed_seed) |
| 205 seed.Swap(parsed_seed); |
| 203 | 206 |
| 204 return true; | 207 return true; |
| 205 } | 208 } |
| 206 | 209 |
| 207 void VariationsSeedStore::UpdateSeedDateAndLogDayChange( | 210 void VariationsSeedStore::UpdateSeedDateAndLogDayChange( |
| 208 const base::Time& server_date_fetched) { | 211 const base::Time& server_date_fetched) { |
| 209 VariationsSeedDateChangeState date_change = SEED_DATE_NO_OLD_DATE; | 212 VariationsSeedDateChangeState date_change = SEED_DATE_NO_OLD_DATE; |
| 210 | 213 |
| 211 if (local_state_->HasPrefPath(prefs::kVariationsSeedDate)) { | 214 if (local_state_->HasPrefPath(prefs::kVariationsSeedDate)) { |
| 212 const int64 stored_date_value = | 215 const int64 stored_date_value = |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 } | 266 } |
| 264 | 267 |
| 265 verifier.VerifyUpdate(reinterpret_cast<const uint8*>(seed_bytes.data()), | 268 verifier.VerifyUpdate(reinterpret_cast<const uint8*>(seed_bytes.data()), |
| 266 seed_bytes.size()); | 269 seed_bytes.size()); |
| 267 if (verifier.VerifyFinal()) | 270 if (verifier.VerifyFinal()) |
| 268 return VARIATIONS_SEED_SIGNATURE_VALID; | 271 return VARIATIONS_SEED_SIGNATURE_VALID; |
| 269 return VARIATIONS_SEED_SIGNATURE_INVALID_SEED; | 272 return VARIATIONS_SEED_SIGNATURE_INVALID_SEED; |
| 270 } | 273 } |
| 271 | 274 |
| 272 } // namespace chrome_variations | 275 } // namespace chrome_variations |
| OLD | NEW |