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 #include <vector> |
9 | 10 |
10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
11 | 12 |
12 class PrefHashTracker; | |
13 | |
14 namespace base { | 13 namespace base { |
| 14 class DictionaryValue; |
15 class Value; | 15 class Value; |
16 } // namespace base | 16 } // namespace base |
17 | 17 |
18 // Stores hashes of and verifies preference values. To use, first call | 18 // Stores hashes of and verifies preference values. To use, first call |
19 // |InitializeTrackedValue| with each preference that should be tracked. Then | 19 // |InitializeTrackedValue| with each preference that should be tracked. Then |
20 // call |OnPrefValueChanged| to update the hash store when preference values | 20 // call |OnPrefValueChanged| to update the hash store when preference values |
21 // change. | 21 // change. |
22 class PrefHashStore { | 22 class PrefHashStore { |
23 public: | 23 public: |
24 virtual ~PrefHashStore() {} | 24 virtual ~PrefHashStore() {} |
25 | 25 |
26 enum ValueState { | 26 enum ValueState { |
27 // The preference value corresponds to its stored hash. | 27 // The preference value corresponds to its stored hash. |
28 UNCHANGED, | 28 UNCHANGED, |
29 // The preference has been cleared since the last hash. | 29 // The preference has been cleared since the last hash. |
30 CLEARED, | 30 CLEARED, |
31 // The preference value corresponds to its stored hash, which was calculated | 31 // The preference value corresponds to its stored hash, which was calculated |
32 // using a legacy hash algorithm. | 32 // using a legacy hash algorithm. |
33 MIGRATED, | 33 MIGRATED, |
34 // The preference value has been changed since the last hash. | 34 // The preference value has been changed since the last hash. |
35 CHANGED, | 35 CHANGED, |
36 // No stored hash exists for the preference value. | 36 // No stored hash exists for the preference value. |
37 UNKNOWN_VALUE, | 37 UNKNOWN_VALUE, |
38 }; | 38 }; |
39 | 39 |
40 // Checks |initial_value| against the existing stored value hash. | 40 // Checks |initial_value| against the existing stored value hash. |
41 virtual ValueState CheckValue( | 41 virtual ValueState CheckValue( |
42 const std::string& path, const base::Value* initial_value) const = 0; | 42 const std::string& path, const base::Value* initial_value) const = 0; |
43 | 43 |
44 // Stores a hash of the current value of the preference at |path|. | 44 // Stores a hash of the current |value| of the preference at |path|. |
45 virtual void StoreHash(const std::string& path, | 45 virtual void StoreHash(const std::string& path, |
46 const base::Value* value) = 0; | 46 const base::Value* value) = 0; |
| 47 |
| 48 // Checks |initial_value| against the existing stored hashes for the split |
| 49 // preference at |path|. |invalid_keys| must initially be empty. |
| 50 // If the return value is CHANGED: |invalid_keys| will be filled with the keys |
| 51 // that are considered invalid (unknown or changed). |invalid_keys| will not |
| 52 // be modified in all other cases. |
| 53 virtual ValueState CheckSplitValue( |
| 54 const std::string& path, |
| 55 const base::DictionaryValue* initial_split_value, |
| 56 std::vector<std::string>* invalid_keys) const = 0; |
| 57 |
| 58 // Stores hashes for the |value| of the split preference at |path|. |
| 59 virtual void StoreSplitHash( |
| 60 const std::string& path, |
| 61 const base::DictionaryValue* split_value) = 0; |
47 }; | 62 }; |
48 | 63 |
49 #endif // CHROME_BROWSER_PREFS_PREF_HASH_STORE_H_ | 64 #endif // CHROME_BROWSER_PREFS_PREF_HASH_STORE_H_ |
OLD | NEW |