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

Side by Side Diff: chrome/common/metrics/entropy_provider_unittest.cc

Issue 12226045: Linux/ChromeOS Chromium style checker cleanup, chrome/ edition part 1. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 7 years, 10 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
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 #include <cmath> 5 #include <cmath>
6 #include <limits> 6 #include <limits>
7 #include <numeric> 7 #include <numeric>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/guid.h" 10 #include "base/guid.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 72
73 // An TrialEntropyGenerator that uses the SHA1EntropyProvider with the high 73 // An TrialEntropyGenerator that uses the SHA1EntropyProvider with the high
74 // entropy source (random GUID with 128 bits of entropy + 13 additional bits of 74 // entropy source (random GUID with 128 bits of entropy + 13 additional bits of
75 // entropy corresponding to a low entropy source). 75 // entropy corresponding to a low entropy source).
76 class SHA1EntropyGenerator : public TrialEntropyGenerator { 76 class SHA1EntropyGenerator : public TrialEntropyGenerator {
77 public: 77 public:
78 explicit SHA1EntropyGenerator(const std::string& trial_name) 78 explicit SHA1EntropyGenerator(const std::string& trial_name)
79 : trial_name_(trial_name) { 79 : trial_name_(trial_name) {
80 } 80 }
81 81
82 ~SHA1EntropyGenerator() { 82 virtual ~SHA1EntropyGenerator() {
83 } 83 }
84 84
85 virtual double GenerateEntropyValue() const OVERRIDE { 85 virtual double GenerateEntropyValue() const OVERRIDE {
86 // Use a random GUID + 13 additional bits of entropy to match how the 86 // Use a random GUID + 13 additional bits of entropy to match how the
87 // SHA1EntropyProvider is used in metrics_service.cc. 87 // SHA1EntropyProvider is used in metrics_service.cc.
88 const int low_entropy_source = 88 const int low_entropy_source =
89 static_cast<uint16>(base::RandInt(0, kMaxLowEntropySize - 1)); 89 static_cast<uint16>(base::RandInt(0, kMaxLowEntropySize - 1));
90 const std::string high_entropy_source = 90 const std::string high_entropy_source =
91 base::GenerateGUID() + base::IntToString(low_entropy_source); 91 base::GenerateGUID() + base::IntToString(low_entropy_source);
92 return GenerateSHA1Entropy(high_entropy_source, trial_name_); 92 return GenerateSHA1Entropy(high_entropy_source, trial_name_);
(...skipping 10 matching lines...) Expand all
103 class PermutedEntropyGenerator : public TrialEntropyGenerator { 103 class PermutedEntropyGenerator : public TrialEntropyGenerator {
104 public: 104 public:
105 explicit PermutedEntropyGenerator(const std::string& trial_name) 105 explicit PermutedEntropyGenerator(const std::string& trial_name)
106 : mapping_(kMaxLowEntropySize) { 106 : mapping_(kMaxLowEntropySize) {
107 // Note: Given a trial name, the computed mapping will be the same. 107 // Note: Given a trial name, the computed mapping will be the same.
108 // As a performance optimization, pre-compute the mapping once per trial 108 // As a performance optimization, pre-compute the mapping once per trial
109 // name and index into it for each entropy value. 109 // name and index into it for each entropy value.
110 internal::PermuteMappingUsingTrialName(trial_name, &mapping_); 110 internal::PermuteMappingUsingTrialName(trial_name, &mapping_);
111 } 111 }
112 112
113 ~PermutedEntropyGenerator() { 113 virtual ~PermutedEntropyGenerator() {
114 } 114 }
115 115
116 virtual double GenerateEntropyValue() const OVERRIDE { 116 virtual double GenerateEntropyValue() const OVERRIDE {
117 const int low_entropy_source = 117 const int low_entropy_source =
118 static_cast<uint16>(base::RandInt(0, kMaxLowEntropySize - 1)); 118 static_cast<uint16>(base::RandInt(0, kMaxLowEntropySize - 1));
119 return mapping_[low_entropy_source] / 119 return mapping_[low_entropy_source] /
120 static_cast<double>(kMaxLowEntropySize); 120 static_cast<double>(kMaxLowEntropySize);
121 } 121 }
122 122
123 private: 123 private:
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 ++count; 329 ++count;
330 } 330 }
331 331
332 ASSERT_LT(count, kMaxAttempts) << "Expected average was " << 332 ASSERT_LT(count, kMaxAttempts) << "Expected average was " <<
333 kExpectedAverage << ", average ended at " << cumulative_average << 333 kExpectedAverage << ", average ended at " << cumulative_average <<
334 ", for trial " << kTestTrialNames[i]; 334 ", for trial " << kTestTrialNames[i];
335 } 335 }
336 } 336 }
337 337
338 } // namespace metrics 338 } // namespace metrics
OLDNEW
« no previous file with comments | « chrome/common/json_schema_validator_unittest.cc ('k') | chrome/common/metrics/metrics_log_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698