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_IMPL_H_ | 5 #ifndef CHROME_BROWSER_PREFS_PREF_HASH_STORE_IMPL_H_ |
6 #define CHROME_BROWSER_PREFS_PREF_HASH_STORE_IMPL_H_ | 6 #define CHROME_BROWSER_PREFS_PREF_HASH_STORE_IMPL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/prefs/scoped_user_pref_update.h" |
13 #include "chrome/browser/prefs/pref_hash_calculator.h" | 13 #include "chrome/browser/prefs/pref_hash_calculator.h" |
14 #include "chrome/browser/prefs/pref_hash_store.h" | 14 #include "chrome/browser/prefs/pref_hash_store.h" |
15 | 15 |
16 class PrefRegistrySimple; | 16 class PrefRegistrySimple; |
17 class PrefService; | 17 class PrefService; |
18 | 18 |
19 namespace base { | 19 namespace base { |
| 20 class DictionaryValue; |
20 class Value; | 21 class Value; |
21 } // namespace base | 22 } |
22 | 23 |
23 // Implements PrefHashStoreImpl by storing preference hashes in a PrefService. | 24 // Implements PrefHashStoreImpl by storing preference hashes in a PrefService. |
24 class PrefHashStoreImpl : public PrefHashStore { | 25 class PrefHashStoreImpl : public PrefHashStore { |
25 public: | 26 public: |
26 // Constructs a PrefHashStoreImpl that calculates hashes using | 27 // Constructs a PrefHashStoreImpl that calculates hashes using |
27 // |seed| and |device_id| and stores them in |local_state|. Multiple hash | 28 // |seed| and |device_id| and stores them in |local_state|. Multiple hash |
28 // stores can use the same |local_state| with distinct |hash_store_id|s. | 29 // stores can use the same |local_state| with distinct |hash_store_id|s. |
29 // | 30 // |
30 // The same |seed|, |device_id|, and |hash_store_id| must be used to load and | 31 // The same |seed|, |device_id|, and |hash_store_id| must be used to load and |
31 // validate previously stored hashes in |local_state|. | 32 // validate previously stored hashes in |local_state|. |
32 // | 33 // |
33 // |local_state| must have previously been passed to |RegisterPrefs|. | 34 // |local_state| must have previously been passed to |RegisterPrefs|. |
34 PrefHashStoreImpl(const std::string& hash_store_id, | 35 PrefHashStoreImpl(const std::string& hash_store_id, |
35 const std::string& seed, | 36 const std::string& seed, |
36 const std::string& device_id, | 37 const std::string& device_id, |
37 PrefService* local_state); | 38 PrefService* local_state); |
38 | 39 |
39 // Registers required local state preferences. | 40 // Registers required local state preferences. |
40 static void RegisterPrefs(PrefRegistrySimple* registry); | 41 static void RegisterPrefs(PrefRegistrySimple* registry); |
41 | 42 |
42 // PrefHashStore implementation. | 43 // PrefHashStore implementation. |
43 virtual ValueState CheckValue(const std::string& path, | 44 virtual ValueState CheckValue(const std::string& path, |
44 const base::Value* value) const OVERRIDE; | 45 const base::Value* value) const OVERRIDE; |
45 virtual void StoreHash(const std::string& path, | 46 virtual void StoreHash(const std::string& path, |
46 const base::Value* value) OVERRIDE; | 47 const base::Value* value) OVERRIDE; |
| 48 virtual ValueState CheckSplitValue( |
| 49 const std::string& path, |
| 50 const base::DictionaryValue* initial_split_value, |
| 51 std::vector<std::string>* invalid_keys) const OVERRIDE; |
| 52 virtual void StoreSplitHash( |
| 53 const std::string& path, |
| 54 const base::DictionaryValue* split_value) OVERRIDE; |
47 | 55 |
48 private: | 56 private: |
| 57 // Clears any hashes stored for |path| through |update|. |
| 58 void ClearPath(const std::string& path, |
| 59 DictionaryPrefUpdate* update); |
| 60 |
| 61 // Returns true if there are split hashes stored for |path|. |
| 62 bool HasSplitHashesAtPath(const std::string& path) const; |
| 63 |
| 64 // Used by StoreHash and StoreSplitHash to store the hash of |new_value| at |
| 65 // |path| under |update|. Allows multiple hashes to be stored under the same |
| 66 // |update|. |
| 67 void StoreHashInternal(const std::string& path, |
| 68 const base::Value* new_value, |
| 69 DictionaryPrefUpdate* update); |
| 70 |
| 71 // Updates kHashOfHashesPref to reflect the last changes to the |hashes_dict|. |
| 72 // Must be called after every change to the |hashes_dict|, within the scope of |
| 73 // |update|. |
| 74 void UpdateHashOfHashes(const base::DictionaryValue* hashes_dict, |
| 75 DictionaryPrefUpdate* update); |
| 76 |
49 // Returns true if the dictionary of hashes stored for |hash_store_id_| is | 77 // Returns true if the dictionary of hashes stored for |hash_store_id_| is |
50 // trusted (which implies unknown values can be trusted as newly tracked | 78 // trusted (which implies unknown values can be trusted as newly tracked |
51 // values). | 79 // values). |
52 bool IsHashDictionaryTrusted() const; | 80 bool IsHashDictionaryTrusted() const; |
53 | 81 |
54 std::string hash_store_id_; | 82 std::string hash_store_id_; |
55 PrefHashCalculator pref_hash_calculator_; | 83 PrefHashCalculator pref_hash_calculator_; |
56 PrefService* local_state_; | 84 PrefService* local_state_; |
57 bool initial_hashes_dictionary_trusted_; | 85 bool initial_hashes_dictionary_trusted_; |
58 | 86 |
59 DISALLOW_COPY_AND_ASSIGN(PrefHashStoreImpl); | 87 DISALLOW_COPY_AND_ASSIGN(PrefHashStoreImpl); |
60 }; | 88 }; |
61 | 89 |
62 #endif // CHROME_BROWSER_PREFS_PREF_HASH_STORE_IMPL_H_ | 90 #endif // CHROME_BROWSER_PREFS_PREF_HASH_STORE_IMPL_H_ |
OLD | NEW |