rlz_value_store_chromeos.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Copyright (c) 2012 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 RLZ_CHROMEOS_LIB_RLZ_VALUE_STORE_CHROMEOS_H_
  5. #define RLZ_CHROMEOS_LIB_RLZ_VALUE_STORE_CHROMEOS_H_
  6. #include <stddef.h>
  7. #include <stdint.h>
  8. #include <memory>
  9. #include "base/files/file_path.h"
  10. #include "base/sequence_checker.h"
  11. #include "base/values.h"
  12. #include "rlz/lib/rlz_value_store.h"
  13. namespace rlz_lib {
  14. // An implementation of RlzValueStore for ChromeOS.
  15. class RlzValueStoreChromeOS : public RlzValueStore {
  16. public:
  17. // The maximum retry times allowed for |SetRlzPingSent|.
  18. static const int kMaxRetryCount;
  19. // Creates new instance and synchronously reads data from file.
  20. explicit RlzValueStoreChromeOS(const base::FilePath& store_path);
  21. RlzValueStoreChromeOS(const RlzValueStoreChromeOS&) = delete;
  22. RlzValueStoreChromeOS& operator=(const RlzValueStoreChromeOS&) = delete;
  23. ~RlzValueStoreChromeOS() override;
  24. // RlzValueStore overrides:
  25. bool HasAccess(AccessType type) override;
  26. bool WritePingTime(Product product, int64_t time) override;
  27. bool ReadPingTime(Product product, int64_t* time) override;
  28. bool ClearPingTime(Product product) override;
  29. bool WriteAccessPointRlz(AccessPoint access_point,
  30. const char* new_rlz) override;
  31. bool ReadAccessPointRlz(AccessPoint access_point,
  32. char* rlz,
  33. size_t rlz_size) override;
  34. bool ClearAccessPointRlz(AccessPoint access_point) override;
  35. bool UpdateExistingAccessPointRlz(const std::string& brand) override;
  36. bool AddProductEvent(Product product, const char* event_rlz) override;
  37. bool ReadProductEvents(Product product,
  38. std::vector<std::string>* events) override;
  39. bool ClearProductEvent(Product product, const char* event_rlz) override;
  40. bool ClearAllProductEvents(Product product) override;
  41. bool AddStatefulEvent(Product product, const char* event_rlz) override;
  42. bool IsStatefulEvent(Product product, const char* event_rlz) override;
  43. bool ClearAllStatefulEvents(Product product) override;
  44. void CollectGarbage() override;
  45. private:
  46. // Returns true if the |rlz_embargo_end_date| present in VPD has passed
  47. // compared to the current time.
  48. static bool HasRlzEmbargoEndDatePassed();
  49. // Reads RLZ store from file.
  50. void ReadStore();
  51. // Writes RLZ store back to file.
  52. void WriteStore();
  53. // Adds |value| to list at |list_name| path in JSON store.
  54. bool AddValueToList(const std::string& list_name, base::Value value);
  55. // Removes |value| from list at |list_name| path in JSON store.
  56. bool RemoveValueFromList(const std::string& list_name,
  57. const base::Value& value);
  58. // Returns true if |value| is contained in list at |list_name| path in
  59. // JSON store.
  60. bool ListContainsValue(const std::string& list_name,
  61. const base::Value& value) const;
  62. // Returns true if the store contains |access_point|.
  63. bool HasAccessPointRlz(AccessPoint access_point) const;
  64. // In-memory store with RLZ data.
  65. base::Value rlz_store_;
  66. base::FilePath store_path_;
  67. bool read_only_;
  68. SEQUENCE_CHECKER(sequence_checker_);
  69. };
  70. } // namespace rlz_lib
  71. #endif // RLZ_CHROMEOS_LIB_RLZ_VALUE_STORE_CHROMEOS_H_