pref_hash_store_transaction.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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_PREF_HASH_STORE_TRANSACTION_H_
  5. #define SERVICES_PREFERENCES_TRACKED_PREF_HASH_STORE_TRANSACTION_H_
  6. #include <string>
  7. #include <vector>
  8. #include "base/strings/string_piece.h"
  9. #include "services/preferences/public/mojom/tracked_preference_validation_delegate.mojom.h"
  10. namespace base {
  11. class DictionaryValue;
  12. class Value;
  13. } // namespace base
  14. // Used to perform a series of checks/transformations on a PrefHashStore.
  15. class PrefHashStoreTransaction {
  16. public:
  17. // Finalizes any remaining work after the transaction has been performed.
  18. virtual ~PrefHashStoreTransaction() {}
  19. // Returns the suffix to be appended to UMA histograms for the store contained
  20. // in this transaction.
  21. virtual base::StringPiece GetStoreUMASuffix() const = 0;
  22. // Checks |initial_value| against the existing stored value hash.
  23. virtual prefs::mojom::TrackedPreferenceValidationDelegate::ValueState
  24. CheckValue(const std::string& path,
  25. const base::Value* initial_value) const = 0;
  26. // Stores a hash of the current |value| of the preference at |path|.
  27. virtual void StoreHash(const std::string& path, const base::Value* value) = 0;
  28. // Checks |initial_value| against the existing stored hashes for the split
  29. // preference at |path|. |initial_split_value| being an empty dictionary or
  30. // NULL is equivalent. |invalid_keys| must initially be empty. |invalid_keys|
  31. // will not be modified unless the return value is CHANGED, in which case it
  32. // will be filled with the keys that are considered invalid (unknown or
  33. // changed).
  34. virtual prefs::mojom::TrackedPreferenceValidationDelegate::ValueState
  35. CheckSplitValue(const std::string& path,
  36. const base::DictionaryValue* initial_split_value,
  37. std::vector<std::string>* invalid_keys) const = 0;
  38. // Stores hashes for the |value| of the split preference at |path|.
  39. // |split_value| being an empty dictionary or NULL is equivalent.
  40. virtual void StoreSplitHash(const std::string& path,
  41. const base::DictionaryValue* split_value) = 0;
  42. // Indicates whether the store contains a hash for the preference at |path|.
  43. virtual bool HasHash(const std::string& path) const = 0;
  44. // Sets the hash for the preference at |path|.
  45. // If |path| is a split preference |hash| must be a DictionaryValue whose
  46. // keys are keys in the split preference and whose values are MACs of the
  47. // corresponding values in the split preference.
  48. // If |path| is an atomic preference |hash| must be a StringValue
  49. // containing a MAC of the preference value.
  50. // |hash| should originate from a PrefHashStore sharing the same MAC
  51. // parameters as this transaction's store.
  52. // The (in)validity of the super MAC will be maintained by this call.
  53. virtual void ImportHash(const std::string& path, const base::Value* hash) = 0;
  54. // Removes the hash stored at |path|. The (in)validity of the super MAC will
  55. // be maintained by this call.
  56. virtual void ClearHash(const std::string& path) = 0;
  57. // Indicates whether the super MAC was successfully verified at the beginning
  58. // of this transaction.
  59. virtual bool IsSuperMACValid() const = 0;
  60. // Forces a valid super MAC to be stored when this transaction terminates.
  61. // Returns true if this results in a change to the store contents.
  62. virtual bool StampSuperMac() = 0;
  63. };
  64. #endif // SERVICES_PREFERENCES_TRACKED_PREF_HASH_STORE_TRANSACTION_H_