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/memory/scoped_ptr.h"
13 #include "chrome/browser/prefs/pref_hash_calculator.h"
14 #include "chrome/browser/prefs/pref_hash_store.h"
16 class PrefRegistrySimple;
23 // Implements PrefHashStoreImpl by storing preference hashes in a PrefService.
24 class PrefHashStoreImpl : public PrefHashStore {
26 // Constructs a PrefHashStoreImpl that calculates hashes using
27 // |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.
30 // The same |seed|, |device_id|, and |hash_store_id| must be used to load and
31 // validate previously stored hashes in |local_state|.
33 // |local_state| must have previously been passed to |RegisterPrefs|.
34 PrefHashStoreImpl(const std::string& hash_store_id,
35 const std::string& seed,
36 const std::string& device_id,
37 PrefService* local_state);
39 // Registers required local state preferences.
40 static void RegisterPrefs(PrefRegistrySimple* registry);
42 // Clears the contents of this PrefHashStore. |IsInitialized()| will return
43 // false after this call.
46 // PrefHashStore implementation.
47 virtual bool IsInitialized() const OVERRIDE;
48 virtual ValueState CheckValue(const std::string& path,
49 const base::Value* value) const OVERRIDE;
50 virtual void StoreHash(const std::string& path,
51 const base::Value* value) OVERRIDE;
54 // Returns true if the dictionary of hashes stored for |hash_store_id_| is
55 // trusted (which implies unknown values can be trusted as newly tracked
57 bool IsHashDictionaryTrusted() const;
59 std::string hash_store_id_;
60 PrefHashCalculator pref_hash_calculator_;
61 PrefService* local_state_;
62 bool initial_hashes_dictionary_trusted_;
64 DISALLOW_COPY_AND_ASSIGN(PrefHashStoreImpl);
67 #endif // CHROME_BROWSER_PREFS_PREF_HASH_STORE_IMPL_H_