dictionary_hash_store_contents.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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_DICTIONARY_HASH_STORE_CONTENTS_H_
  5. #define SERVICES_PREFERENCES_TRACKED_DICTIONARY_HASH_STORE_CONTENTS_H_
  6. #include "base/memory/raw_ptr.h"
  7. #include "services/preferences/tracked/hash_store_contents.h"
  8. namespace base {
  9. class DictionaryValue;
  10. class Value;
  11. } // namespace base
  12. namespace user_prefs {
  13. class PrefRegistrySyncable;
  14. } // namespace user_prefs
  15. // Implements HashStoreContents by storing MACs in a DictionaryValue. The
  16. // DictionaryValue is presumed to be the contents of a PrefStore.
  17. // RegisterProfilePrefs() may be used to register all of the preferences used by
  18. // this object.
  19. class DictionaryHashStoreContents : public HashStoreContents {
  20. public:
  21. // Constructs a DictionaryHashStoreContents that reads from and writes to
  22. // |storage|.
  23. explicit DictionaryHashStoreContents(base::DictionaryValue* storage);
  24. DictionaryHashStoreContents(const DictionaryHashStoreContents&) = delete;
  25. DictionaryHashStoreContents& operator=(const DictionaryHashStoreContents&) =
  26. delete;
  27. // Registers required preferences.
  28. static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
  29. // HashStoreContents implementation
  30. bool IsCopyable() const override;
  31. std::unique_ptr<HashStoreContents> MakeCopy() const override;
  32. base::StringPiece GetUMASuffix() const override;
  33. void Reset() override;
  34. bool GetMac(const std::string& path, std::string* out_value) override;
  35. bool GetSplitMacs(const std::string& path,
  36. std::map<std::string, std::string>* split_macs) override;
  37. void SetMac(const std::string& path, const std::string& value) override;
  38. void SetSplitMac(const std::string& path,
  39. const std::string& split_path,
  40. const std::string& value) override;
  41. void ImportEntry(const std::string& path,
  42. const base::Value* in_value) override;
  43. bool RemoveEntry(const std::string& path) override;
  44. const base::DictionaryValue* GetContents() const override;
  45. std::string GetSuperMac() const override;
  46. void SetSuperMac(const std::string& super_mac) override;
  47. private:
  48. raw_ptr<base::DictionaryValue> storage_;
  49. // Helper function to get a mutable version of the macs from |storage_|,
  50. // creating it if needed and |create_if_null| is true.
  51. base::DictionaryValue* GetMutableContents(bool create_if_null);
  52. };
  53. #endif // SERVICES_PREFERENCES_TRACKED_DICTIONARY_HASH_STORE_CONTENTS_H_