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

Side by Side Diff: components/nacl/browser/nacl_validation_cache.cc

Issue 1154283003: Change most uses of Pickle to base::Pickle (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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
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 "components/nacl/browser/nacl_validation_cache.h" 5 #include "components/nacl/browser/nacl_validation_cache.h"
6 6
7 #include "base/pickle.h" 7 #include "base/pickle.h"
8 #include "base/rand_util.h" 8 #include "base/rand_util.h"
9 9
10 namespace nacl { 10 namespace nacl {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 } 45 }
46 return false; 46 return false;
47 } 47 }
48 48
49 void NaClValidationCache::SetKnownToValidate(const std::string& signature) { 49 void NaClValidationCache::SetKnownToValidate(const std::string& signature) {
50 if (signature.length() == kValidationCacheEntrySize) { 50 if (signature.length() == kValidationCacheEntrySize) {
51 validation_cache_.Put(signature, true); 51 validation_cache_.Put(signature, true);
52 } 52 }
53 } 53 }
54 54
55 void NaClValidationCache::Serialize(Pickle* pickle) const { 55 void NaClValidationCache::Serialize(base::Pickle* pickle) const {
56 // Mark the beginning of the data stream. 56 // Mark the beginning of the data stream.
57 pickle->WriteString(kValidationCacheBeginMagic); 57 pickle->WriteString(kValidationCacheBeginMagic);
58 pickle->WriteString(validation_cache_key_); 58 pickle->WriteString(validation_cache_key_);
59 pickle->WriteInt(validation_cache_.size()); 59 pickle->WriteInt(validation_cache_.size());
60 60
61 // Serialize the cache in reverse order so that deserializing it can easily 61 // Serialize the cache in reverse order so that deserializing it can easily
62 // preserve the MRU order. (Last item deserialized => most recently used.) 62 // preserve the MRU order. (Last item deserialized => most recently used.)
63 ValidationCacheType::const_reverse_iterator iter; 63 ValidationCacheType::const_reverse_iterator iter;
64 for (iter = validation_cache_.rbegin(); 64 for (iter = validation_cache_.rbegin();
65 iter != validation_cache_.rend(); 65 iter != validation_cache_.rend();
66 ++iter) { 66 ++iter) {
67 pickle->WriteString(iter->first); 67 pickle->WriteString(iter->first);
68 } 68 }
69 69
70 // Mark the end of the data stream. 70 // Mark the end of the data stream.
71 pickle->WriteString(kValidationCacheEndMagic); 71 pickle->WriteString(kValidationCacheEndMagic);
72 } 72 }
73 73
74 void NaClValidationCache::Reset() { 74 void NaClValidationCache::Reset() {
75 validation_cache_key_ = base::RandBytesAsString(kValidationCacheKeySize); 75 validation_cache_key_ = base::RandBytesAsString(kValidationCacheKeySize);
76 validation_cache_.Clear(); 76 validation_cache_.Clear();
77 } 77 }
78 78
79 bool NaClValidationCache::Deserialize(const Pickle* pickle) { 79 bool NaClValidationCache::Deserialize(const base::Pickle* pickle) {
80 bool success = DeserializeImpl(pickle); 80 bool success = DeserializeImpl(pickle);
81 if (!success) { 81 if (!success) {
82 Reset(); 82 Reset();
83 } 83 }
84 return success; 84 return success;
85 } 85 }
86 86
87 bool NaClValidationCache::DeserializeImpl(const Pickle* pickle) { 87 bool NaClValidationCache::DeserializeImpl(const base::Pickle* pickle) {
88 PickleIterator iter(*pickle); 88 base::PickleIterator iter(*pickle);
89 std::string buffer; 89 std::string buffer;
90 int count; 90 int count;
91 91
92 // Magic 92 // Magic
93 if (!iter.ReadString(&buffer)) 93 if (!iter.ReadString(&buffer))
94 return false; 94 return false;
95 if (0 != buffer.compare(kValidationCacheBeginMagic)) 95 if (0 != buffer.compare(kValidationCacheBeginMagic))
96 return false; 96 return false;
97 97
98 // Key 98 // Key
(...skipping 21 matching lines...) Expand all
120 return false; 120 return false;
121 if (0 != buffer.compare(kValidationCacheEndMagic)) 121 if (0 != buffer.compare(kValidationCacheEndMagic))
122 return false; 122 return false;
123 123
124 // Success! 124 // Success!
125 return true; 125 return true;
126 } 126 }
127 127
128 } // namespace nacl 128 } // namespace nacl
129 129
OLDNEW
« no previous file with comments | « components/nacl/browser/nacl_browser.cc ('k') | components/nacl/browser/nacl_validation_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698