registry_hash_store_contents_win.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2016 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_REGISTRY_HASH_STORE_CONTENTS_WIN_H_
  5. #define SERVICES_PREFERENCES_TRACKED_REGISTRY_HASH_STORE_CONTENTS_WIN_H_
  6. #include <string>
  7. #include "services/preferences/tracked/hash_store_contents.h"
  8. #include "services/preferences/tracked/temp_scoped_dir_cleaner.h"
  9. // Helper object to clear registry entries for scoped temporary pref stores.
  10. class TempScopedDirRegistryCleaner : public TempScopedDirCleaner {
  11. public:
  12. void SetRegistryPath(const std::wstring& registry_path);
  13. private:
  14. friend class base::RefCountedThreadSafe<TempScopedDirRegistryCleaner>;
  15. ~TempScopedDirRegistryCleaner() override;
  16. std::wstring registry_path_;
  17. };
  18. // Implements HashStoreContents by storing MACs in the Windows registry.
  19. class RegistryHashStoreContentsWin : public HashStoreContents {
  20. public:
  21. // Constructs a RegistryHashStoreContents which acts on a registry entry
  22. // defined by |registry_path| and |store_key|.
  23. explicit RegistryHashStoreContentsWin(
  24. const std::wstring& registry_path,
  25. const std::wstring& store_key,
  26. scoped_refptr<TempScopedDirCleaner> temp_dir_cleaner);
  27. ~RegistryHashStoreContentsWin() override;
  28. // HashStoreContents overrides:
  29. bool IsCopyable() const override;
  30. std::unique_ptr<HashStoreContents> MakeCopy() const override;
  31. base::StringPiece GetUMASuffix() const override;
  32. void Reset() override;
  33. bool GetMac(const std::string& path, std::string* out_value) override;
  34. bool GetSplitMacs(const std::string& path,
  35. std::map<std::string, std::string>* split_macs) override;
  36. void SetMac(const std::string& path, const std::string& value) override;
  37. void SetSplitMac(const std::string& path,
  38. const std::string& split_path,
  39. const std::string& value) override;
  40. bool RemoveEntry(const std::string& path) override;
  41. // Unsupported HashStoreContents overrides:
  42. void ImportEntry(const std::string& path,
  43. const base::Value* in_value) 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. // Helper constructor for |MakeCopy|.
  49. explicit RegistryHashStoreContentsWin(
  50. const RegistryHashStoreContentsWin& other);
  51. const std::wstring preference_key_name_;
  52. scoped_refptr<TempScopedDirCleaner> temp_dir_cleaner_;
  53. };
  54. #endif // SERVICES_PREFERENCES_TRACKED_REGISTRY_HASH_STORE_CONTENTS_WIN_H_