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

Side by Side Diff: components/variations/variations_seed_store.cc

Issue 1404583004: Support gzip-compressed seed data from the variations server. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
OLDNEW
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
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,
95 VARIATIONS_SEED_STORE_FAILED_EMPTY_GZIP_CONTENTS,
96 VARIATIONS_SEED_STORE_FAILED_UNSUPPORTED_SEED_FORMAT,
94 VARIATIONS_SEED_STORE_RESULT_ENUM_SIZE, 97 VARIATIONS_SEED_STORE_RESULT_ENUM_SIZE,
95 }; 98 };
96 99
97 void RecordSeedStoreHistogram(VariationsSeedStoreResult result) { 100 void RecordSeedStoreHistogram(VariationsSeedStoreResult result) {
98 UMA_HISTOGRAM_ENUMERATION("Variations.SeedStoreResult", result, 101 UMA_HISTOGRAM_ENUMERATION("Variations.SeedStoreResult", result,
99 VARIATIONS_SEED_STORE_RESULT_ENUM_SIZE); 102 VARIATIONS_SEED_STORE_RESULT_ENUM_SIZE);
100 } 103 }
101 104
102 // Note: UMA histogram enum - don't re-order or remove entries. 105 // Note: UMA histogram enum - don't re-order or remove entries.
103 enum VariationsSeedDateChangeState { 106 enum VariationsSeedDateChangeState {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_NOT_EMPTY); 190 RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_NOT_EMPTY);
188 return true; 191 return true;
189 } 192 }
190 193
191 bool VariationsSeedStore::StoreSeedData( 194 bool VariationsSeedStore::StoreSeedData(
192 const std::string& data, 195 const std::string& data,
193 const std::string& base64_seed_signature, 196 const std::string& base64_seed_signature,
194 const std::string& country_code, 197 const std::string& country_code,
195 const base::Time& date_fetched, 198 const base::Time& date_fetched,
196 bool is_delta_compressed, 199 bool is_delta_compressed,
200 bool is_gzip_compressed,
197 variations::VariationsSeed* parsed_seed) { 201 variations::VariationsSeed* parsed_seed) {
202 // If the data is gzip compressed, first uncompress it.
203 std::string ungzipped_data;
204 if (is_gzip_compressed) {
205 if (compression::GzipUncompress(data, &ungzipped_data)) {
206 if (ungzipped_data.empty()) {
207 RecordSeedStoreHistogram(
208 VARIATIONS_SEED_STORE_FAILED_EMPTY_GZIP_CONTENTS);
209 return false;
210 }
211
212 int size_reduction = ungzipped_data.length() - data.length();
213 UMA_HISTOGRAM_PERCENTAGE("Variations.StoreSeed.GzipSize.ReductionPercent",
214 100 * size_reduction / ungzipped_data.length());
215 UMA_HISTOGRAM_COUNTS_1000("Variations.StoreSeed.GzipSize",
216 data.length() / 1024);
217 } else {
218 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_UNGZIP);
219 return false;
220 }
221 } else {
222 ungzipped_data = data;
223 }
224
198 if (!is_delta_compressed) { 225 if (!is_delta_compressed) {
199 const bool result = 226 const bool result =
200 StoreSeedDataNoDelta(data, base64_seed_signature, country_code, 227 StoreSeedDataNoDelta(ungzipped_data, base64_seed_signature,
201 date_fetched, parsed_seed); 228 country_code, date_fetched, parsed_seed);
202 if (result) { 229 if (result) {
203 UMA_HISTOGRAM_COUNTS_1000("Variations.StoreSeed.Size", 230 UMA_HISTOGRAM_COUNTS_1000("Variations.StoreSeed.Size",
204 data.length() / 1024); 231 ungzipped_data.length() / 1024);
205 } 232 }
206 return result; 233 return result;
207 } 234 }
208 235
209 // If the data is delta compressed, first decode it. 236 // If the data is delta compressed, first decode it.
210 DCHECK(invalid_base64_signature_.empty()); 237 DCHECK(invalid_base64_signature_.empty());
211 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_DELTA_COUNT); 238 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_DELTA_COUNT);
212 239
213 std::string existing_seed_data; 240 std::string existing_seed_data;
214 std::string updated_seed_data; 241 std::string updated_seed_data;
215 if (!ReadSeedData(&existing_seed_data)) { 242 if (!ReadSeedData(&existing_seed_data)) {
216 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_DELTA_READ_SEED); 243 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_DELTA_READ_SEED);
217 return false; 244 return false;
218 } 245 }
219 if (!ApplyDeltaPatch(existing_seed_data, data, &updated_seed_data)) { 246 if (!ApplyDeltaPatch(existing_seed_data, ungzipped_data,
247 &updated_seed_data)) {
220 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_DELTA_APPLY); 248 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_DELTA_APPLY);
221 return false; 249 return false;
222 } 250 }
223 251
224 const bool result = 252 const bool result =
225 StoreSeedDataNoDelta(updated_seed_data, base64_seed_signature, 253 StoreSeedDataNoDelta(updated_seed_data, base64_seed_signature,
226 country_code, date_fetched, parsed_seed); 254 country_code, date_fetched, parsed_seed);
227 if (result) { 255 if (result) {
228 // Note: |updated_seed_data.length()| is guaranteed to be non-zero, else 256 // Note: |updated_seed_data.length()| is guaranteed to be non-zero, else
229 // result would be false. 257 // result would be false.
230 int size_reduction = updated_seed_data.length() - data.length(); 258 int size_reduction = updated_seed_data.length() - ungzipped_data.length();
231 UMA_HISTOGRAM_PERCENTAGE("Variations.StoreSeed.DeltaSize.ReductionPercent", 259 UMA_HISTOGRAM_PERCENTAGE("Variations.StoreSeed.DeltaSize.ReductionPercent",
232 100 * size_reduction / updated_seed_data.length()); 260 100 * size_reduction / updated_seed_data.length());
233 UMA_HISTOGRAM_COUNTS_1000("Variations.StoreSeed.DeltaSize", 261 UMA_HISTOGRAM_COUNTS_1000("Variations.StoreSeed.DeltaSize",
234 data.length() / 1024); 262 ungzipped_data.length() / 1024);
235 } else { 263 } else {
236 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_DELTA_STORE); 264 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_DELTA_STORE);
237 } 265 }
238 return result; 266 return result;
239 } 267 }
240 268
241 void VariationsSeedStore::UpdateSeedDateAndLogDayChange( 269 void VariationsSeedStore::UpdateSeedDateAndLogDayChange(
242 const base::Time& server_date_fetched) { 270 const base::Time& server_date_fetched) {
243 VariationsSeedDateChangeState date_change = SEED_DATE_NO_OLD_DATE; 271 VariationsSeedDateChangeState date_change = SEED_DATE_NO_OLD_DATE;
244 272
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 return true; 368 return true;
341 } 369 }
342 370
343 bool VariationsSeedStore::StoreSeedDataNoDelta( 371 bool VariationsSeedStore::StoreSeedDataNoDelta(
344 const std::string& seed_data, 372 const std::string& seed_data,
345 const std::string& base64_seed_signature, 373 const std::string& base64_seed_signature,
346 const std::string& country_code, 374 const std::string& country_code,
347 const base::Time& date_fetched, 375 const base::Time& date_fetched,
348 variations::VariationsSeed* parsed_seed) { 376 variations::VariationsSeed* parsed_seed) {
349 if (seed_data.empty()) { 377 if (seed_data.empty()) {
350 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_EMPTY); 378 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_EMPTY_GZIP_CONTENTS);
351 return false; 379 return false;
352 } 380 }
353 381
354 // Only store the seed data if it parses correctly. 382 // Only store the seed data if it parses correctly.
355 variations::VariationsSeed seed; 383 variations::VariationsSeed seed;
356 if (!seed.ParseFromString(seed_data)) { 384 if (!seed.ParseFromString(seed_data)) {
357 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_PARSE); 385 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_PARSE);
358 return false; 386 return false;
359 } 387 }
360 388
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 base::CheckedNumeric<uint32> end_offset(offset); 471 base::CheckedNumeric<uint32> end_offset(offset);
444 end_offset += length; 472 end_offset += length;
445 if (!end_offset.IsValid() || end_offset.ValueOrDie() > existing_data_size) 473 if (!end_offset.IsValid() || end_offset.ValueOrDie() > existing_data_size)
446 return false; 474 return false;
447 output->append(existing_data, offset, length); 475 output->append(existing_data, offset, length);
448 } 476 }
449 } 477 }
450 return true; 478 return true;
451 } 479 }
452 480
481 void VariationsSeedStore::ReportUnsupportedSeedFormatError() {
482 RecordSeedStoreHistogram(
483 VARIATIONS_SEED_STORE_FAILED_UNSUPPORTED_SEED_FORMAT);
484 }
485
453 } // namespace variations 486 } // namespace variations
OLDNEW
« no previous file with comments | « components/variations/variations_seed_store.h ('k') | components/variations/variations_seed_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698