| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/common/metrics/caching_permuted_entropy_provider.h" | 5 #include "chrome/common/metrics/caching_permuted_entropy_provider.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 local_state_->ClearPref(prefs::kMetricsPermutedEntropyCache); | 59 local_state_->ClearPref(prefs::kMetricsPermutedEntropyCache); |
| 60 NOTREACHED(); | 60 NOTREACHED(); |
| 61 } | 61 } |
| 62 } | 62 } |
| 63 | 63 |
| 64 void CachingPermutedEntropyProvider::UpdateLocalState() const { | 64 void CachingPermutedEntropyProvider::UpdateLocalState() const { |
| 65 std::string serialized; | 65 std::string serialized; |
| 66 cache_.SerializeToString(&serialized); | 66 cache_.SerializeToString(&serialized); |
| 67 | 67 |
| 68 std::string base64_encoded; | 68 std::string base64_encoded; |
| 69 if (!base::Base64Encode(serialized, &base64_encoded)) { | 69 base::Base64Encode(serialized, &base64_encoded); |
| 70 NOTREACHED(); | |
| 71 return; | |
| 72 } | |
| 73 local_state_->SetString(prefs::kMetricsPermutedEntropyCache, base64_encoded); | 70 local_state_->SetString(prefs::kMetricsPermutedEntropyCache, base64_encoded); |
| 74 } | 71 } |
| 75 | 72 |
| 76 void CachingPermutedEntropyProvider::AddToCache(uint32 randomization_seed, | 73 void CachingPermutedEntropyProvider::AddToCache(uint32 randomization_seed, |
| 77 uint16 value) const { | 74 uint16 value) const { |
| 78 PermutedEntropyCache::Entry* entry; | 75 PermutedEntropyCache::Entry* entry; |
| 79 const int kMaxSize = 25; | 76 const int kMaxSize = 25; |
| 80 if (cache_.entry_size() >= kMaxSize) { | 77 if (cache_.entry_size() >= kMaxSize) { |
| 81 // If the cache is full, evict the first entry, swapping later entries in | 78 // If the cache is full, evict the first entry, swapping later entries in |
| 82 // to take its place. This effectively creates a FIFO cache, which is good | 79 // to take its place. This effectively creates a FIFO cache, which is good |
| (...skipping 18 matching lines...) Expand all Loading... |
| 101 for (int i = 0; i < cache_.entry_size(); ++i) { | 98 for (int i = 0; i < cache_.entry_size(); ++i) { |
| 102 if (cache_.entry(i).randomization_seed() == randomization_seed) { | 99 if (cache_.entry(i).randomization_seed() == randomization_seed) { |
| 103 *value = cache_.entry(i).value(); | 100 *value = cache_.entry(i).value(); |
| 104 return true; | 101 return true; |
| 105 } | 102 } |
| 106 } | 103 } |
| 107 return false; | 104 return false; |
| 108 } | 105 } |
| 109 | 106 |
| 110 } // namespace metrics | 107 } // namespace metrics |
| OLD | NEW |