Sorin Jianu | 2d0c54a | 2020-02-27 21:35:52 | [diff] [blame] | 1 | // Copyright 2020 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 CHROME_UPDATER_PERSISTED_DATA_H_ |
| 6 | #define CHROME_UPDATER_PERSISTED_DATA_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
| 11 | #include "base/memory/ref_counted.h" |
| 12 | #include "base/sequence_checker.h" |
| 13 | |
| 14 | class PrefService; |
| 15 | |
| 16 | namespace base { |
Michael Chang | b15df0e2 | 2020-03-02 22:21:12 | [diff] [blame^] | 17 | class FilePath; |
Sorin Jianu | 2d0c54a | 2020-02-27 21:35:52 | [diff] [blame] | 18 | class Version; |
Michael Chang | b15df0e2 | 2020-03-02 22:21:12 | [diff] [blame^] | 19 | } // namespace base |
Sorin Jianu | 2d0c54a | 2020-02-27 21:35:52 | [diff] [blame] | 20 | |
| 21 | namespace updater { |
| 22 | |
Michael Chang | b15df0e2 | 2020-03-02 22:21:12 | [diff] [blame^] | 23 | struct RegistrationRequest; |
| 24 | |
Sorin Jianu | 2d0c54a | 2020-02-27 21:35:52 | [diff] [blame] | 25 | // PersistedData uses the PrefService to persist updater data that outlives |
| 26 | // the updater processes. |
| 27 | // |
| 28 | // This class has sequence affinity. |
| 29 | // |
| 30 | // A mechanism to remove apps or app versions from prefs is needed. |
| 31 | // TODO(sorin): crbug.com/1056450 |
| 32 | class PersistedData : public base::RefCounted<PersistedData> { |
| 33 | public: |
| 34 | // Constructs a provider using the specified |pref_service|. |
| 35 | // The associated preferences are assumed to already be registered. |
| 36 | // The |pref_service| must outlive the instance of this class. |
| 37 | explicit PersistedData(PrefService* pref_service); |
| 38 | PersistedData(const PersistedData&) = delete; |
| 39 | PersistedData& operator=(const PersistedData&) = delete; |
| 40 | |
| 41 | // These functions access |pv| data for the specified |id|. Returns an empty |
| 42 | // version, if the version is not found. |
| 43 | base::Version GetProductVersion(const std::string& id) const; |
| 44 | void SetProductVersion(const std::string& id, const base::Version& pv); |
| 45 | |
| 46 | // These functions access |fingerprint| data for the specified |id|. |
| 47 | std::string GetFingerprint(const std::string& id) const; |
| 48 | void SetFingerprint(const std::string& id, const std::string& fp); |
| 49 | |
Michael Chang | b15df0e2 | 2020-03-02 22:21:12 | [diff] [blame^] | 50 | // These functions access the existence checker path for the specified id. |
| 51 | base::FilePath GetExistenceCheckerPath(const std::string& id) const; |
| 52 | void SetExistenceCheckerPath(const std::string& id, |
| 53 | const base::FilePath& ecp); |
| 54 | |
| 55 | // These functions access the brand code for the specified id. |
| 56 | std::string GetBrandCode(const std::string& id) const; |
| 57 | void SetBrandCode(const std::string& id, const std::string& bc); |
| 58 | |
| 59 | // These functions access the tag for the specified id. |
| 60 | std::string GetTag(const std::string& id) const; |
| 61 | void SetTag(const std::string& id, const std::string& tag); |
| 62 | |
| 63 | // This function sets everything in the registration request object into the |
| 64 | // persistent data store. |
| 65 | void RegisterApp(const RegistrationRequest& rq); |
| 66 | |
Sorin Jianu | 2d0c54a | 2020-02-27 21:35:52 | [diff] [blame] | 67 | // Returns the app ids of the applications registered in prefs, if the |
| 68 | // application has a valid version. |
| 69 | std::vector<std::string> GetAppIds() const; |
| 70 | |
| 71 | private: |
| 72 | friend class base::RefCounted<PersistedData>; |
| 73 | ~PersistedData(); |
| 74 | |
| 75 | std::string GetString(const std::string& id, const std::string& key) const; |
| 76 | void SetString(const std::string& id, |
| 77 | const std::string& key, |
| 78 | const std::string& value); |
| 79 | |
| 80 | SEQUENCE_CHECKER(sequence_checker_); |
| 81 | |
| 82 | PrefService* pref_service_ = nullptr; // Not owned by this class. |
| 83 | }; |
| 84 | |
| 85 | } // namespace updater |
| 86 | |
| 87 | #endif // CHROME_UPDATER_PERSISTED_DATA_H_ |