1 // Copyright 2014 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_TRACKED_HASH_STORE_CONTENTS_H_
6 #define CHROME_BROWSER_PREFS_TRACKED_HASH_STORE_CONTENTS_H_
10 #include "base/memory/scoped_ptr.h"
13 class DictionaryValue;
16 // Provides access to the contents of a preference hash store. The store
17 // contains the following data:
18 // Contents: a client-defined dictionary that should map preference names to
20 // Version: a client-defined version number for the format of Contents.
21 // Super MAC: a MAC that authenticates the entirety of Contents.
22 // Legacy hash stores may have an ID that was incorporated into MAC
23 // calculations. The ID, if any, is available via |hash_store_id()|.
24 class HashStoreContents {
26 // Used to modify a DictionaryValue stored in the preference hash store. The
27 // MutableDictionary should be destroyed when modifications are complete in
28 // order to allow them to be committed to the underlying storage.
29 class MutableDictionary {
31 virtual ~MutableDictionary() {}
32 // Returns the DictionaryValue, which will be created if it does not already
34 virtual base::DictionaryValue* operator->() = 0;
37 virtual ~HashStoreContents() {}
39 // Returns the hash-store ID. May be empty.
40 virtual std::string hash_store_id() const = 0;
42 // Discards all data related to this hash store.
43 virtual void Reset() = 0;
45 // Indicates whether any data is currently stored for this hash store.
46 virtual bool IsInitialized() const = 0;
48 // Retrieves a version number previously associated with this hash store via
49 // SetVersion. Returns false if no version number has been stored.
50 virtual bool GetVersion(int* version) const = 0;
52 // Associates a version number wih this hash store.
53 virtual void SetVersion(int version) = 0;
55 // Retrieves the contents of this hash store. May return NULL if the hash
56 // store has not been initialized.
57 virtual const base::DictionaryValue* GetContents() const = 0;
59 // Provides mutable access to the contents of this hash store.
60 virtual scoped_ptr<MutableDictionary> GetMutableContents() = 0;
62 // Retrieves the super MAC value previously stored by SetSuperMac. May be
63 // empty if no super MAC has been stored.
64 virtual std::string GetSuperMac() const = 0;
66 // Stores a super MAC value for this hash store.
67 virtual void SetSuperMac(const std::string& super_mac) = 0;
69 // Commit pending writes to this hash store's contents.
70 virtual void CommitPendingWrite() = 0;
73 #endif // CHROME_BROWSER_PREFS_TRACKED_HASH_STORE_CONTENTS_H_