hash_store_contents.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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.
  4. #ifndef SERVICES_PREFERENCES_TRACKED_HASH_STORE_CONTENTS_H_
  5. #define SERVICES_PREFERENCES_TRACKED_HASH_STORE_CONTENTS_H_
  6. #include <map>
  7. #include <memory>
  8. #include <string>
  9. #include "base/strings/string_piece.h"
  10. namespace base {
  11. class DictionaryValue;
  12. class Value;
  13. } // namespace base
  14. // Provides access to the contents of a preference hash store. The store
  15. // contains the following data:
  16. // Contents: a client-defined dictionary that should map preference names to
  17. // MACs.
  18. // Version: a client-defined version number for the format of Contents.
  19. // Super MAC: a MAC that authenticates the entirety of Contents.
  20. class HashStoreContents {
  21. public:
  22. virtual ~HashStoreContents() {}
  23. // Returns true if this implementation of HashStoreContents can be copied via
  24. // MakeCopy().
  25. virtual bool IsCopyable() const = 0;
  26. // Returns a copy of this HashStoreContents. Must only be called on
  27. // lightweight implementations (which return true from IsCopyable()) and only
  28. // in scenarios where a copy cannot be avoided.
  29. virtual std::unique_ptr<HashStoreContents> MakeCopy() const = 0;
  30. // Returns the suffix to be appended to UMA histograms for this store type.
  31. // The returned value must either be an empty string or one of the values in
  32. // histograms.xml's TrackedPreferencesExternalValidators.
  33. virtual base::StringPiece GetUMASuffix() const = 0;
  34. // Discards all data related to this hash store.
  35. virtual void Reset() = 0;
  36. // Outputs the MAC validating the preference at path. Returns true if a MAC
  37. // was successfully read and false otherwise.
  38. virtual bool GetMac(const std::string& path, std::string* out_value) = 0;
  39. // Outputs the MACS validating the split preference at path. Returns true if
  40. // MACS were successfully read and false otherwise.
  41. virtual bool GetSplitMacs(const std::string& path,
  42. std::map<std::string, std::string>* out_value) = 0;
  43. // Set the MAC validating the preference at path.
  44. virtual void SetMac(const std::string& path, const std::string& value) = 0;
  45. // Set the MAC validating the split preference at path and split_path.
  46. // For example, |path| is 'extension' and |split_path| is some extenson id.
  47. virtual void SetSplitMac(const std::string& path,
  48. const std::string& split_path,
  49. const std::string& value) = 0;
  50. // Sets the MAC for the preference at |path|.
  51. // If |path| is a split preference |in_value| must be a DictionaryValue whose
  52. // keys are keys in the split preference and whose values are MACs of the
  53. // corresponding values in the split preference.
  54. // If |path| is an atomic preference |in_value| must be a StringValue
  55. // containing a MAC of the preference value.
  56. virtual void ImportEntry(const std::string& path,
  57. const base::Value* in_value) = 0;
  58. // Removes the MAC (for atomic preferences) or MACs (for split preferences)
  59. // at |path|. Returns true if there was an entry at |path| which was
  60. // successfully removed.
  61. virtual bool RemoveEntry(const std::string& path) = 0;
  62. // Only needed if this store supports super MACs.
  63. virtual const base::DictionaryValue* GetContents() const = 0;
  64. // Retrieves the super MAC value previously stored by SetSuperMac. May be
  65. // empty if no super MAC has been stored or if this store does not support
  66. // super MACs.
  67. virtual std::string GetSuperMac() const = 0;
  68. // Stores a super MAC value for this hash store.
  69. virtual void SetSuperMac(const std::string& super_mac) = 0;
  70. };
  71. #endif // SERVICES_PREFERENCES_TRACKED_HASH_STORE_CONTENTS_H_