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

Side by Side Diff: chrome/browser/metrics/metrics_service.cc

Issue 17499002: Change kMaxLowEntropySize to have 8000 values instead of 8192. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/common/metrics/entropy_provider_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 //------------------------------------------------------------------------------ 5 //------------------------------------------------------------------------------
6 // Description of the life cycle of a instance of MetricsService. 6 // Description of the life cycle of a instance of MetricsService.
7 // 7 //
8 // OVERVIEW 8 // OVERVIEW
9 // 9 //
10 // A MetricsService instance is typically created at application startup. It is 10 // A MetricsService instance is typically created at application startup. It is
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 case 400: 284 case 400:
285 return BAD_REQUEST; 285 return BAD_REQUEST;
286 case net::URLFetcher::RESPONSE_CODE_INVALID: 286 case net::URLFetcher::RESPONSE_CODE_INVALID:
287 return NO_RESPONSE; 287 return NO_RESPONSE;
288 default: 288 default:
289 return UNKNOWN_FAILURE; 289 return UNKNOWN_FAILURE;
290 } 290 }
291 } 291 }
292 292
293 // The argument used to generate a non-identifying entropy source. We want no 293 // The argument used to generate a non-identifying entropy source. We want no
294 // more than 13 bits of entropy, so use this max to return a number between 1 294 // more than 13 bits of entropy, so use this max to return a number in the range
295 // and 2^13 = 8192 as the entropy source. 295 // [0, 7999] as the entropy source (12.97 bits of entropy).
296 const uint32 kMaxLowEntropySize = (1 << 13); 296 const int kMaxLowEntropySize = 8000;
297 297
298 // Default prefs value for prefs::kMetricsLowEntropySource to indicate that the 298 // Default prefs value for prefs::kMetricsLowEntropySource to indicate that the
299 // value has not yet been set. 299 // value has not yet been set.
300 const int kLowEntropySourceNotSet = -1; 300 const int kLowEntropySourceNotSet = -1;
301 301
302 // Generates a new non-identifying entropy source used to seed persistent 302 // Generates a new non-identifying entropy source used to seed persistent
303 // activities. 303 // activities.
304 int GenerateLowEntropySource() { 304 int GenerateLowEntropySource() {
305 return base::RandInt(0, kMaxLowEntropySize - 1); 305 return base::RandInt(0, kMaxLowEntropySize - 1);
306 } 306 }
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 // value are both kLowEntropySourceNotSet, which is used to identify if the 1036 // value are both kLowEntropySourceNotSet, which is used to identify if the
1037 // value has been set or not. 1037 // value has been set or not.
1038 if (low_entropy_source_ != kLowEntropySourceNotSet) 1038 if (low_entropy_source_ != kLowEntropySourceNotSet)
1039 return low_entropy_source_; 1039 return low_entropy_source_;
1040 1040
1041 PrefService* local_state = g_browser_process->local_state(); 1041 PrefService* local_state = g_browser_process->local_state();
1042 const CommandLine* command_line(CommandLine::ForCurrentProcess()); 1042 const CommandLine* command_line(CommandLine::ForCurrentProcess());
1043 // Only try to load the value from prefs if the user did not request a reset. 1043 // Only try to load the value from prefs if the user did not request a reset.
1044 // Otherwise, skip to generating a new value. 1044 // Otherwise, skip to generating a new value.
1045 if (!command_line->HasSwitch(switches::kResetVariationState)) { 1045 if (!command_line->HasSwitch(switches::kResetVariationState)) {
1046 const int value = local_state->GetInteger(prefs::kMetricsLowEntropySource); 1046 int value = local_state->GetInteger(prefs::kMetricsLowEntropySource);
1047 if (value != kLowEntropySourceNotSet) { 1047 // Old versions of the code would generate values in the range of [1, 8192],
1048 // Ensure the prefs value is in the range [0, kMaxLowEntropySize). Old 1048 // before the range was switched to [0, 8191] and then to [0, 7999]. Map
1049 // versions of the code would generate values in the range of [1, 8192], 1049 // 8192 to 0, so that the 0th bucket remains uniform, while re-generating
1050 // so the below line ensures 8192 gets mapped to 0 and also guards against 1050 // the low entropy source for old values in the [8000, 8191] range.
1051 // the case of corrupted values. 1051 if (value == 8192)
1052 low_entropy_source_ = value % kMaxLowEntropySize; 1052 value = 0;
1053 // If the value is outside the [0, kMaxLowEntropySize) range, re-generate
1054 // it below.
1055 if (value >= 0 && value < kMaxLowEntropySize) {
1056 low_entropy_source_ = value;
1053 UMA_HISTOGRAM_BOOLEAN("UMA.GeneratedLowEntropySource", false); 1057 UMA_HISTOGRAM_BOOLEAN("UMA.GeneratedLowEntropySource", false);
1054 return low_entropy_source_; 1058 return low_entropy_source_;
1055 } 1059 }
1056 } 1060 }
1057 1061
1058 UMA_HISTOGRAM_BOOLEAN("UMA.GeneratedLowEntropySource", true); 1062 UMA_HISTOGRAM_BOOLEAN("UMA.GeneratedLowEntropySource", true);
1059 low_entropy_source_ = GenerateLowEntropySource(); 1063 low_entropy_source_ = GenerateLowEntropySource();
1060 local_state->SetInteger(prefs::kMetricsLowEntropySource, low_entropy_source_); 1064 local_state->SetInteger(prefs::kMetricsLowEntropySource, low_entropy_source_);
1061 metrics::CachingPermutedEntropyProvider::ClearCache(local_state); 1065 metrics::CachingPermutedEntropyProvider::ClearCache(local_state);
1062 1066
(...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after
1814 if (local_state) { 1818 if (local_state) {
1815 const PrefService::Preference* uma_pref = 1819 const PrefService::Preference* uma_pref =
1816 local_state->FindPreference(prefs::kMetricsReportingEnabled); 1820 local_state->FindPreference(prefs::kMetricsReportingEnabled);
1817 if (uma_pref) { 1821 if (uma_pref) {
1818 bool success = uma_pref->GetValue()->GetAsBoolean(&result); 1822 bool success = uma_pref->GetValue()->GetAsBoolean(&result);
1819 DCHECK(success); 1823 DCHECK(success);
1820 } 1824 }
1821 } 1825 }
1822 return result; 1826 return result;
1823 } 1827 }
OLDNEW
« no previous file with comments | « no previous file | chrome/common/metrics/entropy_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698