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