OLD | NEW |
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 #ifndef COMPONENTS_VARIATIONS_ENTROPY_PROVIDER_H_ | 5 #ifndef COMPONENTS_VARIATIONS_ENTROPY_PROVIDER_H_ |
6 #define COMPONENTS_VARIATIONS_ENTROPY_PROVIDER_H_ | 6 #define COMPONENTS_VARIATIONS_ENTROPY_PROVIDER_H_ |
7 | 7 |
8 #include <functional> | 8 #include <functional> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 class SHA1EntropyProvider : public base::FieldTrial::EntropyProvider { | 45 class SHA1EntropyProvider : public base::FieldTrial::EntropyProvider { |
46 public: | 46 public: |
47 // Creates a SHA1EntropyProvider with the given |entropy_source|, which | 47 // Creates a SHA1EntropyProvider with the given |entropy_source|, which |
48 // should contain a large amount of entropy - for example, a textual | 48 // should contain a large amount of entropy - for example, a textual |
49 // representation of a persistent randomly-generated 128-bit value. | 49 // representation of a persistent randomly-generated 128-bit value. |
50 explicit SHA1EntropyProvider(const std::string& entropy_source); | 50 explicit SHA1EntropyProvider(const std::string& entropy_source); |
51 virtual ~SHA1EntropyProvider(); | 51 virtual ~SHA1EntropyProvider(); |
52 | 52 |
53 // base::FieldTrial::EntropyProvider implementation: | 53 // base::FieldTrial::EntropyProvider implementation: |
54 virtual double GetEntropyForTrial(const std::string& trial_name, | 54 virtual double GetEntropyForTrial(const std::string& trial_name, |
55 uint32 randomization_seed) const OVERRIDE; | 55 uint32 randomization_seed) const override; |
56 | 56 |
57 private: | 57 private: |
58 std::string entropy_source_; | 58 std::string entropy_source_; |
59 | 59 |
60 DISALLOW_COPY_AND_ASSIGN(SHA1EntropyProvider); | 60 DISALLOW_COPY_AND_ASSIGN(SHA1EntropyProvider); |
61 }; | 61 }; |
62 | 62 |
63 // PermutedEntropyProvider is an entropy provider suitable for low entropy | 63 // PermutedEntropyProvider is an entropy provider suitable for low entropy |
64 // sources (below 16 bits). It uses the field trial name to generate a | 64 // sources (below 16 bits). It uses the field trial name to generate a |
65 // permutation of a mapping array from an initial entropy value to a new value. | 65 // permutation of a mapping array from an initial entropy value to a new value. |
66 // Note: This provider's performance is O(2^n), where n is the number of bits | 66 // Note: This provider's performance is O(2^n), where n is the number of bits |
67 // in the entropy source. | 67 // in the entropy source. |
68 class PermutedEntropyProvider : public base::FieldTrial::EntropyProvider { | 68 class PermutedEntropyProvider : public base::FieldTrial::EntropyProvider { |
69 public: | 69 public: |
70 // Creates a PermutedEntropyProvider with the given |low_entropy_source|, | 70 // Creates a PermutedEntropyProvider with the given |low_entropy_source|, |
71 // which should have a value in the range of [0, low_entropy_source_max). | 71 // which should have a value in the range of [0, low_entropy_source_max). |
72 PermutedEntropyProvider(uint16 low_entropy_source, | 72 PermutedEntropyProvider(uint16 low_entropy_source, |
73 size_t low_entropy_source_max); | 73 size_t low_entropy_source_max); |
74 virtual ~PermutedEntropyProvider(); | 74 virtual ~PermutedEntropyProvider(); |
75 | 75 |
76 // base::FieldTrial::EntropyProvider implementation: | 76 // base::FieldTrial::EntropyProvider implementation: |
77 virtual double GetEntropyForTrial(const std::string& trial_name, | 77 virtual double GetEntropyForTrial(const std::string& trial_name, |
78 uint32 randomization_seed) const OVERRIDE; | 78 uint32 randomization_seed) const override; |
79 | 79 |
80 protected: | 80 protected: |
81 // Performs the permutation algorithm and returns the permuted value that | 81 // Performs the permutation algorithm and returns the permuted value that |
82 // corresponds to |low_entropy_source_|. | 82 // corresponds to |low_entropy_source_|. |
83 virtual uint16 GetPermutedValue(uint32 randomization_seed) const; | 83 virtual uint16 GetPermutedValue(uint32 randomization_seed) const; |
84 | 84 |
85 private: | 85 private: |
86 uint16 low_entropy_source_; | 86 uint16 low_entropy_source_; |
87 size_t low_entropy_source_max_; | 87 size_t low_entropy_source_max_; |
88 | 88 |
89 DISALLOW_COPY_AND_ASSIGN(PermutedEntropyProvider); | 89 DISALLOW_COPY_AND_ASSIGN(PermutedEntropyProvider); |
90 }; | 90 }; |
91 | 91 |
92 } // namespace metrics | 92 } // namespace metrics |
93 | 93 |
94 #endif // COMPONENTS_VARIATIONS_ENTROPY_PROVIDER_H_ | 94 #endif // COMPONENTS_VARIATIONS_ENTROPY_PROVIDER_H_ |
OLD | NEW |