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

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: Fix signed-unsigned comparison issue 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,
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
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 int size_reduction = ungzipped_data.length() - data.length();
205 UMA_HISTOGRAM_PERCENTAGE("Variations.StoreSeed.GzipSize.ReductionPercent",
Alexei Svitkine (slow) 2015/10/15 15:50:44 There should be a guard somewhere that ungzipped_d
veranika 2015/10/15 20:02:57 Done.
206 100 * size_reduction / ungzipped_data.length());
Alexei Svitkine (slow) 2015/10/15 15:50:44 Nit: Align.
veranika 2015/10/15 20:02:57 Done.
207 UMA_HISTOGRAM_COUNTS_1000("Variations.StoreSeed.GzipSize",
208 data.length() / 1024);
209 } else {
210 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_UNGZIP);
211 return false;
212 }
213 } else {
214 ungzipped_data = data;
215 }
216
198 if (!is_delta_compressed) { 217 if (!is_delta_compressed) {
199 const bool result = 218 const bool result =
200 StoreSeedDataNoDelta(data, base64_seed_signature, country_code, 219 StoreSeedDataNoDelta(ungzipped_data, base64_seed_signature,
201 date_fetched, parsed_seed); 220 country_code, date_fetched, parsed_seed);
202 if (result) { 221 if (result) {
203 UMA_HISTOGRAM_COUNTS_1000("Variations.StoreSeed.Size", 222 UMA_HISTOGRAM_COUNTS_1000("Variations.StoreSeed.Size",
204 data.length() / 1024); 223 ungzipped_data.length() / 1024);
205 } 224 }
206 return result; 225 return result;
207 } 226 }
208 227
209 // If the data is delta compressed, first decode it. 228 // If the data is delta compressed, first decode it.
210 DCHECK(invalid_base64_signature_.empty()); 229 DCHECK(invalid_base64_signature_.empty());
211 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_DELTA_COUNT); 230 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_DELTA_COUNT);
212 231
213 std::string existing_seed_data; 232 std::string existing_seed_data;
214 std::string updated_seed_data; 233 std::string updated_seed_data;
215 if (!ReadSeedData(&existing_seed_data)) { 234 if (!ReadSeedData(&existing_seed_data)) {
216 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_DELTA_READ_SEED); 235 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_DELTA_READ_SEED);
217 return false; 236 return false;
218 } 237 }
219 if (!ApplyDeltaPatch(existing_seed_data, data, &updated_seed_data)) { 238 if (!ApplyDeltaPatch(existing_seed_data, ungzipped_data,
239 &updated_seed_data)) {
220 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_DELTA_APPLY); 240 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_DELTA_APPLY);
221 return false; 241 return false;
222 } 242 }
223 243
224 const bool result = 244 const bool result =
225 StoreSeedDataNoDelta(updated_seed_data, base64_seed_signature, 245 StoreSeedDataNoDelta(updated_seed_data, base64_seed_signature,
226 country_code, date_fetched, parsed_seed); 246 country_code, date_fetched, parsed_seed);
227 if (result) { 247 if (result) {
228 // Note: |updated_seed_data.length()| is guaranteed to be non-zero, else 248 // Note: |updated_seed_data.length()| is guaranteed to be non-zero, else
229 // result would be false. 249 // result would be false.
230 int size_reduction = updated_seed_data.length() - data.length(); 250 int size_reduction = updated_seed_data.length() - ungzipped_data.length();
231 UMA_HISTOGRAM_PERCENTAGE("Variations.StoreSeed.DeltaSize.ReductionPercent", 251 UMA_HISTOGRAM_PERCENTAGE("Variations.StoreSeed.DeltaSize.ReductionPercent",
232 100 * size_reduction / updated_seed_data.length()); 252 100 * size_reduction / updated_seed_data.length());
233 UMA_HISTOGRAM_COUNTS_1000("Variations.StoreSeed.DeltaSize", 253 UMA_HISTOGRAM_COUNTS_1000("Variations.StoreSeed.DeltaSize",
234 data.length() / 1024); 254 ungzipped_data.length() / 1024);
235 } else { 255 } else {
236 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_DELTA_STORE); 256 RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_DELTA_STORE);
237 } 257 }
238 return result; 258 return result;
239 } 259 }
240 260
241 void VariationsSeedStore::UpdateSeedDateAndLogDayChange( 261 void VariationsSeedStore::UpdateSeedDateAndLogDayChange(
242 const base::Time& server_date_fetched) { 262 const base::Time& server_date_fetched) {
243 VariationsSeedDateChangeState date_change = SEED_DATE_NO_OLD_DATE; 263 VariationsSeedDateChangeState date_change = SEED_DATE_NO_OLD_DATE;
244 264
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 end_offset += length; 464 end_offset += length;
445 if (!end_offset.IsValid() || end_offset.ValueOrDie() > existing_data_size) 465 if (!end_offset.IsValid() || end_offset.ValueOrDie() > existing_data_size)
446 return false; 466 return false;
447 output->append(existing_data, offset, length); 467 output->append(existing_data, offset, length);
448 } 468 }
449 } 469 }
450 return true; 470 return true;
451 } 471 }
452 472
453 } // namespace variations 473 } // namespace variations
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698