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: components/variations/entropy_provider.cc

Issue 794683005: replace COMPILE_ASSERT with static_assert in components/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: formatting fixup Created 6 years 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
« no previous file with comments | « components/user_manager/user.cc ('k') | components/variations/metrics_util.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 #include "components/variations/entropy_provider.h" 5 #include "components/variations/entropy_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 // it has been observed that this method does not result in a uniform 87 // it has been observed that this method does not result in a uniform
88 // distribution given the same |trial_name|. When using such a low entropy 88 // distribution given the same |trial_name|. When using such a low entropy
89 // source, PermutedEntropyProvider should be used instead. 89 // source, PermutedEntropyProvider should be used instead.
90 std::string input(entropy_source_ + trial_name); 90 std::string input(entropy_source_ + trial_name);
91 unsigned char sha1_hash[base::kSHA1Length]; 91 unsigned char sha1_hash[base::kSHA1Length];
92 base::SHA1HashBytes(reinterpret_cast<const unsigned char*>(input.c_str()), 92 base::SHA1HashBytes(reinterpret_cast<const unsigned char*>(input.c_str()),
93 input.size(), 93 input.size(),
94 sha1_hash); 94 sha1_hash);
95 95
96 uint64 bits; 96 uint64 bits;
97 COMPILE_ASSERT(sizeof(bits) < sizeof(sha1_hash), need_more_data); 97 static_assert(sizeof(bits) < sizeof(sha1_hash), "more data required");
98 memcpy(&bits, sha1_hash, sizeof(bits)); 98 memcpy(&bits, sha1_hash, sizeof(bits));
99 bits = base::ByteSwapToLE64(bits); 99 bits = base::ByteSwapToLE64(bits);
100 100
101 return base::BitsToOpenEndedUnitInterval(bits); 101 return base::BitsToOpenEndedUnitInterval(bits);
102 } 102 }
103 103
104 PermutedEntropyProvider::PermutedEntropyProvider( 104 PermutedEntropyProvider::PermutedEntropyProvider(
105 uint16 low_entropy_source, 105 uint16 low_entropy_source,
106 size_t low_entropy_source_max) 106 size_t low_entropy_source_max)
107 : low_entropy_source_(low_entropy_source), 107 : low_entropy_source_(low_entropy_source),
(...skipping 16 matching lines...) Expand all
124 } 124 }
125 125
126 uint16 PermutedEntropyProvider::GetPermutedValue( 126 uint16 PermutedEntropyProvider::GetPermutedValue(
127 uint32 randomization_seed) const { 127 uint32 randomization_seed) const {
128 std::vector<uint16> mapping(low_entropy_source_max_); 128 std::vector<uint16> mapping(low_entropy_source_max_);
129 internal::PermuteMappingUsingRandomizationSeed(randomization_seed, &mapping); 129 internal::PermuteMappingUsingRandomizationSeed(randomization_seed, &mapping);
130 return mapping[low_entropy_source_]; 130 return mapping[low_entropy_source_];
131 } 131 }
132 132
133 } // namespace metrics 133 } // namespace metrics
OLDNEW
« no previous file with comments | « components/user_manager/user.cc ('k') | components/variations/metrics_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698