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

Side by Side Diff: trunk/src/chrome/common/metrics/caching_permuted_entropy_provider.cc

Issue 101113004: Revert 239759 "The comment in base64.h implies that base::Base64..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 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 | Annotate | Revision Log
OLDNEW
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
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 base::Base64Encode(serialized, &base64_encoded); 69 if (!base::Base64Encode(serialized, &base64_encoded)) {
70 NOTREACHED();
71 return;
72 }
70 local_state_->SetString(prefs::kMetricsPermutedEntropyCache, base64_encoded); 73 local_state_->SetString(prefs::kMetricsPermutedEntropyCache, base64_encoded);
71 } 74 }
72 75
73 void CachingPermutedEntropyProvider::AddToCache(uint32 randomization_seed, 76 void CachingPermutedEntropyProvider::AddToCache(uint32 randomization_seed,
74 uint16 value) const { 77 uint16 value) const {
75 PermutedEntropyCache::Entry* entry; 78 PermutedEntropyCache::Entry* entry;
76 const int kMaxSize = 25; 79 const int kMaxSize = 25;
77 if (cache_.entry_size() >= kMaxSize) { 80 if (cache_.entry_size() >= kMaxSize) {
78 // If the cache is full, evict the first entry, swapping later entries in 81 // If the cache is full, evict the first entry, swapping later entries in
79 // to take its place. This effectively creates a FIFO cache, which is good 82 // to take its place. This effectively creates a FIFO cache, which is good
(...skipping 18 matching lines...) Expand all
98 for (int i = 0; i < cache_.entry_size(); ++i) { 101 for (int i = 0; i < cache_.entry_size(); ++i) {
99 if (cache_.entry(i).randomization_seed() == randomization_seed) { 102 if (cache_.entry(i).randomization_seed() == randomization_seed) {
100 *value = cache_.entry(i).value(); 103 *value = cache_.entry(i).value();
101 return true; 104 return true;
102 } 105 }
103 } 106 }
104 return false; 107 return false;
105 } 108 }
106 109
107 } // namespace metrics 110 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698