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

Unified 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: Resolve comments 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 side-by-side diff with in-line comments
Download patch
Index: components/variations/variations_seed_store.cc
diff --git a/components/variations/variations_seed_store.cc b/components/variations/variations_seed_store.cc
index e20b0560069cc23ebc1c66e028fe3bc652734ad0..53280244650d9810619beb94260317aa147f3282 100644
--- a/components/variations/variations_seed_store.cc
+++ b/components/variations/variations_seed_store.cc
@@ -91,6 +91,9 @@ enum VariationsSeedStoreResult {
VARIATIONS_SEED_STORE_FAILED_DELTA_READ_SEED,
VARIATIONS_SEED_STORE_FAILED_DELTA_APPLY,
VARIATIONS_SEED_STORE_FAILED_DELTA_STORE,
+ VARIATIONS_SEED_STORE_FAILED_UNGZIP,
+ VARIATIONS_SEED_STORE_FAILED_EMPTY_GZIP_CONTENTS,
+ VARIATIONS_SEED_STORE_FAILED_UNSUPPORTED_SEED_FORMAT,
VARIATIONS_SEED_STORE_RESULT_ENUM_SIZE,
};
@@ -194,14 +197,37 @@ bool VariationsSeedStore::StoreSeedData(
const std::string& country_code,
const base::Time& date_fetched,
bool is_delta_compressed,
+ bool is_gzip_compressed,
variations::VariationsSeed* parsed_seed) {
+ // If the data is gzip compressed, first uncompress it.
+ std::string ungzipped_data;
+ if (is_gzip_compressed) {
+ if (compression::GzipUncompress(data, &ungzipped_data)) {
+ if (ungzipped_data.empty()) {
+ RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_EMPTY);
+ return false;
+ }
+
+ int size_reduction = ungzipped_data.length() - data.length();
+ UMA_HISTOGRAM_PERCENTAGE("Variations.StoreSeed.GzipSize.ReductionPercent",
+ 100 * size_reduction / ungzipped_data.length());
+ UMA_HISTOGRAM_COUNTS_1000("Variations.StoreSeed.GzipSize",
+ data.length() / 1024);
+ } else {
+ RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_UNGZIP);
+ return false;
+ }
+ } else {
+ ungzipped_data = data;
+ }
+
if (!is_delta_compressed) {
const bool result =
- StoreSeedDataNoDelta(data, base64_seed_signature, country_code,
- date_fetched, parsed_seed);
+ StoreSeedDataNoDelta(ungzipped_data, base64_seed_signature,
+ country_code, date_fetched, parsed_seed);
if (result) {
UMA_HISTOGRAM_COUNTS_1000("Variations.StoreSeed.Size",
- data.length() / 1024);
+ ungzipped_data.length() / 1024);
}
return result;
}
@@ -216,7 +242,8 @@ bool VariationsSeedStore::StoreSeedData(
RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_DELTA_READ_SEED);
return false;
}
- if (!ApplyDeltaPatch(existing_seed_data, data, &updated_seed_data)) {
+ if (!ApplyDeltaPatch(existing_seed_data, ungzipped_data,
+ &updated_seed_data)) {
RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_DELTA_APPLY);
return false;
}
@@ -227,11 +254,11 @@ bool VariationsSeedStore::StoreSeedData(
if (result) {
// Note: |updated_seed_data.length()| is guaranteed to be non-zero, else
// result would be false.
- int size_reduction = updated_seed_data.length() - data.length();
+ int size_reduction = updated_seed_data.length() - ungzipped_data.length();
UMA_HISTOGRAM_PERCENTAGE("Variations.StoreSeed.DeltaSize.ReductionPercent",
100 * size_reduction / updated_seed_data.length());
UMA_HISTOGRAM_COUNTS_1000("Variations.StoreSeed.DeltaSize",
- data.length() / 1024);
+ ungzipped_data.length() / 1024);
} else {
RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_DELTA_STORE);
}
@@ -347,7 +374,7 @@ bool VariationsSeedStore::StoreSeedDataNoDelta(
const base::Time& date_fetched,
variations::VariationsSeed* parsed_seed) {
if (seed_data.empty()) {
- RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_EMPTY);
+ RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_EMPTY_GZIP_CONTENTS);
return false;
}
@@ -450,4 +477,10 @@ bool VariationsSeedStore::ApplyDeltaPatch(const std::string& existing_data,
return true;
}
+void VariationsSeedStore::ReportUnsupportedSeedFormatError() {
+ RecordSeedStoreHistogram(
+ VARIATIONS_SEED_STORE_FAILED_UNSUPPORTED_SEED_FORMAT);
+}
+
Alexei Svitkine (slow) 2015/10/16 21:10:36 Nit: Remove extra blank line.
veranika 2015/10/16 21:42:59 Done.
+
} // namespace variations
« 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