OLD | NEW |
| (Empty) |
1 // Copyright 2014 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. | |
4 | |
5 #ifndef COMPONENTS_USER_PREFS_TRACKED_PREF_HASH_STORE_TRANSACTION_H_ | |
6 #define COMPONENTS_USER_PREFS_TRACKED_PREF_HASH_STORE_TRANSACTION_H_ | |
7 | |
8 #include <string> | |
9 #include <vector> | |
10 | |
11 #include "base/strings/string_piece.h" | |
12 | |
13 namespace base { | |
14 class DictionaryValue; | |
15 class Value; | |
16 } // namespace base | |
17 | |
18 // Used to perform a series of checks/transformations on a PrefHashStore. | |
19 class PrefHashStoreTransaction { | |
20 public: | |
21 enum ValueState { | |
22 // The preference value corresponds to its stored hash. | |
23 UNCHANGED, | |
24 // The preference has been cleared since the last hash. | |
25 CLEARED, | |
26 // The preference value corresponds to its stored hash, but the hash was | |
27 // calculated using a deprecated hash algorithm which is just as safe as | |
28 // the current one. | |
29 SECURE_LEGACY, | |
30 // The preference value has been changed since the last hash. | |
31 CHANGED, | |
32 // No stored hash exists for the preference value. | |
33 UNTRUSTED_UNKNOWN_VALUE, | |
34 // No stored hash exists for the preference value, but the current set of | |
35 // hashes stored is trusted and thus this value can safely be seeded. This | |
36 // happens when all hashes are already properly seeded and a newly | |
37 // tracked value needs to be seeded). | |
38 TRUSTED_UNKNOWN_VALUE, | |
39 // NULL values are inherently trusted. | |
40 TRUSTED_NULL_VALUE, | |
41 // This transaction's store type is not supported. | |
42 UNSUPPORTED, | |
43 }; | |
44 | |
45 // Finalizes any remaining work after the transaction has been performed. | |
46 virtual ~PrefHashStoreTransaction() {} | |
47 | |
48 // Returns the suffix to be appended to UMA histograms for the store contained | |
49 // in this transaction. | |
50 virtual base::StringPiece GetStoreUMASuffix() const = 0; | |
51 | |
52 // Checks |initial_value| against the existing stored value hash. | |
53 virtual ValueState CheckValue(const std::string& path, | |
54 const base::Value* initial_value) const = 0; | |
55 | |
56 // Stores a hash of the current |value| of the preference at |path|. | |
57 virtual void StoreHash(const std::string& path, const base::Value* value) = 0; | |
58 | |
59 // Checks |initial_value| against the existing stored hashes for the split | |
60 // preference at |path|. |initial_split_value| being an empty dictionary or | |
61 // NULL is equivalent. |invalid_keys| must initially be empty. |invalid_keys| | |
62 // will not be modified unless the return value is CHANGED, in which case it | |
63 // will be filled with the keys that are considered invalid (unknown or | |
64 // changed). | |
65 virtual ValueState CheckSplitValue( | |
66 const std::string& path, | |
67 const base::DictionaryValue* initial_split_value, | |
68 std::vector<std::string>* invalid_keys) const = 0; | |
69 | |
70 // Stores hashes for the |value| of the split preference at |path|. | |
71 // |split_value| being an empty dictionary or NULL is equivalent. | |
72 virtual void StoreSplitHash(const std::string& path, | |
73 const base::DictionaryValue* split_value) = 0; | |
74 | |
75 // Indicates whether the store contains a hash for the preference at |path|. | |
76 virtual bool HasHash(const std::string& path) const = 0; | |
77 | |
78 // Sets the hash for the preference at |path|. | |
79 // If |path| is a split preference |hash| must be a DictionaryValue whose | |
80 // keys are keys in the split preference and whose values are MACs of the | |
81 // corresponding values in the split preference. | |
82 // If |path| is an atomic preference |hash| must be a StringValue | |
83 // containing a MAC of the preference value. | |
84 // |hash| should originate from a PrefHashStore sharing the same MAC | |
85 // parameters as this transaction's store. | |
86 // The (in)validity of the super MAC will be maintained by this call. | |
87 virtual void ImportHash(const std::string& path, const base::Value* hash) = 0; | |
88 | |
89 // Removes the hash stored at |path|. The (in)validity of the super MAC will | |
90 // be maintained by this call. | |
91 virtual void ClearHash(const std::string& path) = 0; | |
92 | |
93 // Indicates whether the super MAC was successfully verified at the beginning | |
94 // of this transaction. | |
95 virtual bool IsSuperMACValid() const = 0; | |
96 | |
97 // Forces a valid super MAC to be stored when this transaction terminates. | |
98 // Returns true if this results in a change to the store contents. | |
99 virtual bool StampSuperMac() = 0; | |
100 }; | |
101 | |
102 #endif // COMPONENTS_USER_PREFS_TRACKED_PREF_HASH_STORE_TRANSACTION_H_ | |
OLD | NEW |