QUIC - cleanup changes to sync chromium tree with internal source.
[chromium-blink-merge.git] / components / nacl / browser / nacl_validation_cache.h
blobc7ca137636bd8ac0486589a34874a657d171ee7a
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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_NACL_BROWSER_NACL_VALIDATION_CACHE_H_
6 #define COMPONENTS_NACL_BROWSER_NACL_VALIDATION_CACHE_H_
8 #include <vector>
10 #include "base/containers/mru_cache.h"
12 namespace base {
13 class Pickle;
16 namespace nacl {
18 class NaClValidationCache {
19 public:
20 NaClValidationCache();
21 ~NaClValidationCache();
23 // Get the key used for HMACing validation signatures. This should be a
24 // string of cryptographically secure random bytes.
25 const std::string& GetValidationCacheKey() const {
26 return validation_cache_key_;
29 // Is the validation signature in the database?
30 bool QueryKnownToValidate(const std::string& signature, bool reorder);
32 // Put the validation signature in the database.
33 void SetKnownToValidate(const std::string& signature);
35 void Reset();
36 void Serialize(base::Pickle* pickle) const;
37 bool Deserialize(const base::Pickle* pickle);
39 // Testing functions
40 size_t size() const {
41 return validation_cache_.size();
43 void SetValidationCacheKey(std::string& key) {
44 validation_cache_key_ = key;
46 std::vector<std::string> GetContents() const {
47 std::vector<std::string> contents;
48 ValidationCacheType::const_iterator iter = validation_cache_.begin();
49 for (iter = validation_cache_.begin();
50 iter != validation_cache_.end();
51 iter++) {
52 contents.push_back(iter->first);
54 return contents;
57 private:
58 bool DeserializeImpl(const base::Pickle* pickle);
60 typedef base::HashingMRUCache<std::string, bool> ValidationCacheType;
61 ValidationCacheType validation_cache_;
63 std::string validation_cache_key_;
65 DISALLOW_COPY_AND_ASSIGN(NaClValidationCache);
68 } // namespace nacl
70 #endif // COMPONENTS_NACL_BROWSER_NACL_VALIDATION_CACHE_H_