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 COMPONENTS_USER_PREFS_TRACKED_PREF_HASH_STORE_IMPL_H_
6 #define COMPONENTS_USER_PREFS_TRACKED_PREF_HASH_STORE_IMPL_H_
10 #include "base/compiler_specific.h"
11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "components/user_prefs/tracked/pref_hash_calculator.h"
14 #include "components/user_prefs/tracked/pref_hash_store.h"
16 class HashStoreContents
;
17 class PrefHashStoreTransaction
;
19 // Implements PrefHashStoreImpl by storing preference hashes in a
21 class PrefHashStoreImpl
: public PrefHashStore
{
24 // No hashes have been stored in this PrefHashStore yet.
25 VERSION_UNINITIALIZED
= 0,
26 // The hashes in this PrefHashStore were stored before the introduction
27 // of a version number and should be re-initialized.
28 VERSION_PRE_MIGRATION
= 1,
29 // The hashes in this PrefHashStore were stored using the latest algorithm.
33 // Constructs a PrefHashStoreImpl that calculates hashes using
34 // |seed| and |device_id| and stores them in |contents|.
36 // The same |seed| and |device_id| must be used to load and validate
37 // previously stored hashes in |contents|.
38 PrefHashStoreImpl(const std::string
& seed
,
39 const std::string
& device_id
,
42 ~PrefHashStoreImpl() override
;
44 // Provides an external HashStoreContents implementation to be used.
45 // BeginTransaction() will ignore |storage| if this is provided.
46 void set_legacy_hash_store_contents(
47 scoped_ptr
<HashStoreContents
> legacy_hash_store_contents
);
49 // Clears the contents of this PrefHashStore. |IsInitialized()| will return
50 // false after this call.
53 // PrefHashStore implementation.
54 scoped_ptr
<PrefHashStoreTransaction
> BeginTransaction(
55 scoped_ptr
<HashStoreContents
> storage
) override
;
58 class PrefHashStoreTransactionImpl
;
60 const PrefHashCalculator pref_hash_calculator_
;
61 scoped_ptr
<HashStoreContents
> legacy_hash_store_contents_
;
64 DISALLOW_COPY_AND_ASSIGN(PrefHashStoreImpl
);
67 #endif // COMPONENTS_USER_PREFS_TRACKED_PREF_HASH_STORE_IMPL_H_