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