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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 | 112 |
113 } // namespace | 113 } // namespace |
114 | 114 |
115 VariationsSeedStore::VariationsSeedStore(PrefService* local_state) | 115 VariationsSeedStore::VariationsSeedStore(PrefService* local_state) |
116 : local_state_(local_state) { | 116 : local_state_(local_state) { |
117 } | 117 } |
118 | 118 |
119 VariationsSeedStore::~VariationsSeedStore() { | 119 VariationsSeedStore::~VariationsSeedStore() { |
120 } | 120 } |
121 | 121 |
122 bool VariationsSeedStore::LoadSeed(VariationsSeed* seed) { | 122 bool VariationsSeedStore::LoadSeed(variations::VariationsSeed* seed) { |
123 const std::string base64_seed_data = | 123 const std::string base64_seed_data = |
124 local_state_->GetString(prefs::kVariationsSeed); | 124 local_state_->GetString(prefs::kVariationsSeed); |
125 if (base64_seed_data.empty()) { | 125 if (base64_seed_data.empty()) { |
126 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_EMPTY); | 126 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_EMPTY); |
127 return false; | 127 return false; |
128 } | 128 } |
129 | 129 |
130 // If the decode process fails, assume the pref value is corrupt and clear it. | 130 // If the decode process fails, assume the pref value is corrupt and clear it. |
131 std::string seed_data; | 131 std::string seed_data; |
132 if (!base::Base64Decode(base64_seed_data, &seed_data) || | 132 if (!base::Base64Decode(base64_seed_data, &seed_data) || |
(...skipping 23 matching lines...) Expand all Loading... |
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 variations::VariationsSeed* parsed_seed) { |
167 if (seed_data.empty()) { | 167 if (seed_data.empty()) { |
168 VLOG(1) << "Variations seed data is empty, rejecting the seed."; | 168 VLOG(1) << "Variations seed data is empty, rejecting the seed."; |
169 return false; | 169 return false; |
170 } | 170 } |
171 | 171 |
172 // Only store the seed data if it parses correctly. | 172 // Only store the seed data if it parses correctly. |
173 VariationsSeed seed; | 173 variations::VariationsSeed seed; |
174 if (!seed.ParseFromString(seed_data)) { | 174 if (!seed.ParseFromString(seed_data)) { |
175 VLOG(1) << "Variations seed data is not in valid proto format, " | 175 VLOG(1) << "Variations seed data is not in valid proto format, " |
176 << "rejecting the seed."; | 176 << "rejecting the seed."; |
177 return false; | 177 return false; |
178 } | 178 } |
179 | 179 |
180 const VerifySignatureResult result = | 180 const VerifySignatureResult result = |
181 VerifySeedSignature(seed_data, base64_seed_signature); | 181 VerifySeedSignature(seed_data, base64_seed_signature); |
182 if (result != VARIATIONS_SEED_SIGNATURE_ENUM_SIZE) { | 182 if (result != VARIATIONS_SEED_SIGNATURE_ENUM_SIZE) { |
183 UMA_HISTOGRAM_ENUMERATION("Variations.StoreSeedSignature", result, | 183 UMA_HISTOGRAM_ENUMERATION("Variations.StoreSeedSignature", result, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 } | 266 } |
267 | 267 |
268 verifier.VerifyUpdate(reinterpret_cast<const uint8*>(seed_bytes.data()), | 268 verifier.VerifyUpdate(reinterpret_cast<const uint8*>(seed_bytes.data()), |
269 seed_bytes.size()); | 269 seed_bytes.size()); |
270 if (verifier.VerifyFinal()) | 270 if (verifier.VerifyFinal()) |
271 return VARIATIONS_SEED_SIGNATURE_VALID; | 271 return VARIATIONS_SEED_SIGNATURE_VALID; |
272 return VARIATIONS_SEED_SIGNATURE_INVALID_SEED; | 272 return VARIATIONS_SEED_SIGNATURE_INVALID_SEED; |
273 } | 273 } |
274 | 274 |
275 } // namespace chrome_variations | 275 } // namespace chrome_variations |
OLD | NEW |