| 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 "components/variations/variations_seed_store.h" | 5 #include "components/variations/variations_seed_store.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "base/numerics/safe_math.h" | 9 #include "base/numerics/safe_math.h" |
| 10 #include "base/prefs/pref_registry_simple.h" | 10 #include "base/prefs/pref_registry_simple.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 VARIATIONS_SEED_STORE_FAILED_PARSE, | 84 VARIATIONS_SEED_STORE_FAILED_PARSE, |
| 85 VARIATIONS_SEED_STORE_FAILED_SIGNATURE, | 85 VARIATIONS_SEED_STORE_FAILED_SIGNATURE, |
| 86 VARIATIONS_SEED_STORE_FAILED_GZIP, | 86 VARIATIONS_SEED_STORE_FAILED_GZIP, |
| 87 // DELTA_COUNT is not so much a result of the seed store, but rather counting | 87 // DELTA_COUNT is not so much a result of the seed store, but rather counting |
| 88 // the number of delta-compressed seeds the SeedStore() function saw. Kept in | 88 // the number of delta-compressed seeds the SeedStore() function saw. Kept in |
| 89 // the same histogram for convenience of comparing against the other values. | 89 // the same histogram for convenience of comparing against the other values. |
| 90 VARIATIONS_SEED_STORE_DELTA_COUNT, | 90 VARIATIONS_SEED_STORE_DELTA_COUNT, |
| 91 VARIATIONS_SEED_STORE_FAILED_DELTA_READ_SEED, | 91 VARIATIONS_SEED_STORE_FAILED_DELTA_READ_SEED, |
| 92 VARIATIONS_SEED_STORE_FAILED_DELTA_APPLY, | 92 VARIATIONS_SEED_STORE_FAILED_DELTA_APPLY, |
| 93 VARIATIONS_SEED_STORE_FAILED_DELTA_STORE, | 93 VARIATIONS_SEED_STORE_FAILED_DELTA_STORE, |
| 94 VARIATIONS_SEED_STORE_FAILED_UNGZIP, |
| 94 VARIATIONS_SEED_STORE_RESULT_ENUM_SIZE, | 95 VARIATIONS_SEED_STORE_RESULT_ENUM_SIZE, |
| 95 }; | 96 }; |
| 96 | 97 |
| 97 void RecordSeedStoreHistogram(VariationsSeedStoreResult result) { | 98 void RecordSeedStoreHistogram(VariationsSeedStoreResult result) { |
| 98 UMA_HISTOGRAM_ENUMERATION("Variations.SeedStoreResult", result, | 99 UMA_HISTOGRAM_ENUMERATION("Variations.SeedStoreResult", result, |
| 99 VARIATIONS_SEED_STORE_RESULT_ENUM_SIZE); | 100 VARIATIONS_SEED_STORE_RESULT_ENUM_SIZE); |
| 100 } | 101 } |
| 101 | 102 |
| 102 // Note: UMA histogram enum - don't re-order or remove entries. | 103 // Note: UMA histogram enum - don't re-order or remove entries. |
| 103 enum VariationsSeedDateChangeState { | 104 enum VariationsSeedDateChangeState { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_NOT_EMPTY); | 188 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_NOT_EMPTY); |
| 188 return true; | 189 return true; |
| 189 } | 190 } |
| 190 | 191 |
| 191 bool VariationsSeedStore::StoreSeedData( | 192 bool VariationsSeedStore::StoreSeedData( |
| 192 const std::string& data, | 193 const std::string& data, |
| 193 const std::string& base64_seed_signature, | 194 const std::string& base64_seed_signature, |
| 194 const std::string& country_code, | 195 const std::string& country_code, |
| 195 const base::Time& date_fetched, | 196 const base::Time& date_fetched, |
| 196 bool is_delta_compressed, | 197 bool is_delta_compressed, |
| 198 bool is_gzip_compressed, |
| 197 variations::VariationsSeed* parsed_seed) { | 199 variations::VariationsSeed* parsed_seed) { |
| 200 // If the data is gzip compressed, first uncompress it. |
| 201 std::string ungzipped_data; |
| 202 if (is_gzip_compressed) { |
| 203 if (compression::GzipUncompress(data, &ungzipped_data)) { |
| 204 if (ungzipped_data.empty()) { |
| 205 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_EMPTY); |
| 206 return false; |
| 207 } |
| 208 |
| 209 int size_reduction = ungzipped_data.length() - data.length(); |
| 210 UMA_HISTOGRAM_PERCENTAGE("Variations.StoreSeed.GzipSize.ReductionPercent", |
| 211 100 * size_reduction / ungzipped_data.length()); |
| 212 UMA_HISTOGRAM_COUNTS_1000("Variations.StoreSeed.GzipSize", |
| 213 data.length() / 1024); |
| 214 } else { |
| 215 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_UNGZIP); |
| 216 return false; |
| 217 } |
| 218 } else { |
| 219 ungzipped_data = data; |
| 220 } |
| 221 |
| 198 if (!is_delta_compressed) { | 222 if (!is_delta_compressed) { |
| 199 const bool result = | 223 const bool result = |
| 200 StoreSeedDataNoDelta(data, base64_seed_signature, country_code, | 224 StoreSeedDataNoDelta(ungzipped_data, base64_seed_signature, |
| 201 date_fetched, parsed_seed); | 225 country_code, date_fetched, parsed_seed); |
| 202 if (result) { | 226 if (result) { |
| 203 UMA_HISTOGRAM_COUNTS_1000("Variations.StoreSeed.Size", | 227 UMA_HISTOGRAM_COUNTS_1000("Variations.StoreSeed.Size", |
| 204 data.length() / 1024); | 228 ungzipped_data.length() / 1024); |
| 205 } | 229 } |
| 206 return result; | 230 return result; |
| 207 } | 231 } |
| 208 | 232 |
| 209 // If the data is delta compressed, first decode it. | 233 // If the data is delta compressed, first decode it. |
| 210 DCHECK(invalid_base64_signature_.empty()); | 234 DCHECK(invalid_base64_signature_.empty()); |
| 211 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_DELTA_COUNT); | 235 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_DELTA_COUNT); |
| 212 | 236 |
| 213 std::string existing_seed_data; | 237 std::string existing_seed_data; |
| 214 std::string updated_seed_data; | 238 std::string updated_seed_data; |
| 215 if (!ReadSeedData(&existing_seed_data)) { | 239 if (!ReadSeedData(&existing_seed_data)) { |
| 216 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_DELTA_READ_SEED); | 240 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_DELTA_READ_SEED); |
| 217 return false; | 241 return false; |
| 218 } | 242 } |
| 219 if (!ApplyDeltaPatch(existing_seed_data, data, &updated_seed_data)) { | 243 if (!ApplyDeltaPatch(existing_seed_data, ungzipped_data, |
| 244 &updated_seed_data)) { |
| 220 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_DELTA_APPLY); | 245 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_DELTA_APPLY); |
| 221 return false; | 246 return false; |
| 222 } | 247 } |
| 223 | 248 |
| 224 const bool result = | 249 const bool result = |
| 225 StoreSeedDataNoDelta(updated_seed_data, base64_seed_signature, | 250 StoreSeedDataNoDelta(updated_seed_data, base64_seed_signature, |
| 226 country_code, date_fetched, parsed_seed); | 251 country_code, date_fetched, parsed_seed); |
| 227 if (result) { | 252 if (result) { |
| 228 // Note: |updated_seed_data.length()| is guaranteed to be non-zero, else | 253 // Note: |updated_seed_data.length()| is guaranteed to be non-zero, else |
| 229 // result would be false. | 254 // result would be false. |
| 230 int size_reduction = updated_seed_data.length() - data.length(); | 255 int size_reduction = updated_seed_data.length() - ungzipped_data.length(); |
| 231 UMA_HISTOGRAM_PERCENTAGE("Variations.StoreSeed.DeltaSize.ReductionPercent", | 256 UMA_HISTOGRAM_PERCENTAGE("Variations.StoreSeed.DeltaSize.ReductionPercent", |
| 232 100 * size_reduction / updated_seed_data.length()); | 257 100 * size_reduction / updated_seed_data.length()); |
| 233 UMA_HISTOGRAM_COUNTS_1000("Variations.StoreSeed.DeltaSize", | 258 UMA_HISTOGRAM_COUNTS_1000("Variations.StoreSeed.DeltaSize", |
| 234 data.length() / 1024); | 259 ungzipped_data.length() / 1024); |
| 235 } else { | 260 } else { |
| 236 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_DELTA_STORE); | 261 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_DELTA_STORE); |
| 237 } | 262 } |
| 238 return result; | 263 return result; |
| 239 } | 264 } |
| 240 | 265 |
| 241 void VariationsSeedStore::UpdateSeedDateAndLogDayChange( | 266 void VariationsSeedStore::UpdateSeedDateAndLogDayChange( |
| 242 const base::Time& server_date_fetched) { | 267 const base::Time& server_date_fetched) { |
| 243 VariationsSeedDateChangeState date_change = SEED_DATE_NO_OLD_DATE; | 268 VariationsSeedDateChangeState date_change = SEED_DATE_NO_OLD_DATE; |
| 244 | 269 |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 end_offset += length; | 469 end_offset += length; |
| 445 if (!end_offset.IsValid() || end_offset.ValueOrDie() > existing_data_size) | 470 if (!end_offset.IsValid() || end_offset.ValueOrDie() > existing_data_size) |
| 446 return false; | 471 return false; |
| 447 output->append(existing_data, offset, length); | 472 output->append(existing_data, offset, length); |
| 448 } | 473 } |
| 449 } | 474 } |
| 450 return true; | 475 return true; |
| 451 } | 476 } |
| 452 | 477 |
| 453 } // namespace variations | 478 } // namespace variations |
| OLD | NEW |