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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_PREFS_PREF_HASH_STORE_IMPL_H_
6 #define CHROME_BROWSER_PREFS_PREF_HASH_STORE_IMPL_H_
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/prefs/scoped_user_pref_update.h"
13 #include "chrome/browser/prefs/pref_hash_calculator.h"
14 #include "chrome/browser/prefs/pref_hash_store.h"
16 class PrefHashStoreTransaction;
17 class PrefRegistrySimple;
21 class DictionaryValue;
27 // Hash of hashes for each profile, used to validate the existing hashes when
28 // debating whether an unknown value is to be trusted, will be stored as a
30 // |kProfilePreferenceHashes|.|kHashOfHashesDict|.|hash_stored_id_|.
31 extern const char kHashOfHashesDict[];
33 // Versions for each PrefHashStore are stored in this dictionary under
35 extern const char kStoreVersionsDict[];
37 } // namespace internals
39 // Implements PrefHashStoreImpl by storing preference hashes in a PrefService.
40 class PrefHashStoreImpl : public PrefHashStore {
43 // No hashes have been stored in this PrefHashStore yet.
44 VERSION_UNINITIALIZED = 0,
45 // The hashes in this PrefHashStore were stored before the introduction
46 // of a version number and should be re-initialized.
47 VERSION_PRE_MIGRATION = 1,
48 // The hashes in this PrefHashStore were stored using the latest algorithm.
52 // Constructs a PrefHashStoreImpl that calculates hashes using
53 // |seed| and |device_id| and stores them in |local_state|. Multiple hash
54 // stores can use the same |local_state| with distinct |hash_store_id|s.
56 // The same |seed|, |device_id|, and |hash_store_id| must be used to load and
57 // validate previously stored hashes in |local_state|.
59 // |local_state| must have previously been passed to |RegisterPrefs|.
60 PrefHashStoreImpl(const std::string& hash_store_id,
61 const std::string& seed,
62 const std::string& device_id,
63 PrefService* local_state);
65 // Registers required local state preferences.
66 static void RegisterPrefs(PrefRegistrySimple* registry);
68 // Clears the contents of this PrefHashStore. |IsInitialized()| will return
69 // false after this call.
72 // PrefHashStore implementation.
73 virtual scoped_ptr<PrefHashStoreTransaction> BeginTransaction() OVERRIDE;
75 // Returns the current version of this hash store.
76 StoreVersion GetCurrentVersion() const;
79 class PrefHashStoreTransactionImpl;
81 // Returns true if the dictionary of hashes stored for |hash_store_id_| is
82 // trusted (which implies unknown values can be trusted as newly tracked
84 bool IsHashDictionaryTrusted() const;
86 const std::string hash_store_id_;
87 const PrefHashCalculator pref_hash_calculator_;
88 PrefService* local_state_;
89 // Must come after |local_state_| and |pref_hash_calculator_| in the
90 // initialization list as it depends on them to compute its value via
91 // IsHashDictionaryTrusted().
92 const bool initial_hashes_dictionary_trusted_;
94 DISALLOW_COPY_AND_ASSIGN(PrefHashStoreImpl);
97 #endif // CHROME_BROWSER_PREFS_PREF_HASH_STORE_IMPL_H_