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 #ifndef CHROME_BROWSER_PREFS_PREF_HASH_STORE_H_ | 5 #ifndef CHROME_BROWSER_PREFS_PREF_HASH_STORE_H_ |
6 #define CHROME_BROWSER_PREFS_PREF_HASH_STORE_H_ | 6 #define CHROME_BROWSER_PREFS_PREF_HASH_STORE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 | 11 |
12 namespace base { | 12 namespace base { |
13 class Value; | 13 class Value; |
14 } // namespace base | 14 } // namespace base |
15 | 15 |
| 16 namespace internals { |
| 17 |
| 18 // Hash of hashes for each profile, used to validate the existing hashes when |
| 19 // debating whether an unknown value is to be trusted, will be stored as a |
| 20 // string under |
| 21 // |kProfilePreferenceHashes|.|kHashOfHashesPref|.|hash_stored_id_|. |
| 22 const char kHashOfHashesPref[] = "hash_of_hashes"; |
| 23 |
| 24 } // namespace internals |
| 25 |
16 // Stores hashes of and verifies preference values. To use, first call | 26 // Stores hashes of and verifies preference values. To use, first call |
17 // |InitializeTrackedValue| with each preference that should be tracked. Then | 27 // |InitializeTrackedValue| with each preference that should be tracked. Then |
18 // call |OnPrefValueChanged| to update the hash store when preference values | 28 // call |OnPrefValueChanged| to update the hash store when preference values |
19 // change. | 29 // change. |
20 class PrefHashStore { | 30 class PrefHashStore { |
21 public: | 31 public: |
22 virtual ~PrefHashStore() {} | 32 virtual ~PrefHashStore() {} |
23 | 33 |
24 enum ValueState { | 34 enum ValueState { |
25 // The preference value corresponds to its stored hash. | 35 // The preference value corresponds to its stored hash. |
26 UNCHANGED, | 36 UNCHANGED, |
27 // The preference has been cleared since the last hash. | 37 // The preference has been cleared since the last hash. |
28 CLEARED, | 38 CLEARED, |
29 // The preference value corresponds to its stored hash, which was calculated | 39 // The preference value corresponds to its stored hash, which was calculated |
30 // using a legacy hash algorithm. | 40 // using a legacy hash algorithm. |
31 MIGRATED, | 41 MIGRATED, |
32 // The preference value has been changed since the last hash. | 42 // The preference value has been changed since the last hash. |
33 CHANGED, | 43 CHANGED, |
34 // No stored hash exists for the preference value. | 44 // No stored hash exists for the preference value. |
35 UNKNOWN_VALUE, | 45 UNTRUSTED_UNKNOWN_VALUE, |
| 46 // No stored hash exists for the preference value, but the current set of |
| 47 // hashes stored is trusted and thus this value can safely be seeded. This |
| 48 // happens when all hashes are already properly seeded and a newly |
| 49 // tracked value needs to be seeded). NULL values are inherently trusted as |
| 50 // well. |
| 51 TRUSTED_UNKNOWN_VALUE, |
36 }; | 52 }; |
37 | 53 |
38 // Checks |initial_value| against the existing stored value hash. | 54 // Checks |initial_value| against the existing stored value hash. |
39 virtual ValueState CheckValue( | 55 virtual ValueState CheckValue( |
40 const std::string& path, const base::Value* initial_value) const = 0; | 56 const std::string& path, const base::Value* initial_value) const = 0; |
41 | 57 |
42 // Stores a hash of the current |value| of the preference at |path|. | 58 // Stores a hash of the current |value| of the preference at |path|. |
43 virtual void StoreHash(const std::string& path, | 59 virtual void StoreHash(const std::string& path, |
44 const base::Value* value) = 0; | 60 const base::Value* value) = 0; |
45 }; | 61 }; |
46 | 62 |
47 #endif // CHROME_BROWSER_PREFS_PREF_HASH_STORE_H_ | 63 #endif // CHROME_BROWSER_PREFS_PREF_HASH_STORE_H_ |
OLD | NEW |