[go: nahoru, domu]

blob: 212ef5f431430af49c322ba92c182add091563f4 [file] [log] [blame]
Sorin Jianu2d0c54a2020-02-27 21:35:521// 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
14class PrefService;
15
16namespace base {
Michael Changb15df0e22020-03-02 22:21:1217class FilePath;
Joshua Pawlickic9616ce2020-08-11 17:24:4818class Value;
Sorin Jianu2d0c54a2020-02-27 21:35:5219class Version;
Michael Changb15df0e22020-03-02 22:21:1220} // namespace base
Sorin Jianu2d0c54a2020-02-27 21:35:5221
22namespace updater {
23
Michael Changb15df0e22020-03-02 22:21:1224struct RegistrationRequest;
25
Sorin Jianu2d0c54a2020-02-27 21:35:5226// PersistedData uses the PrefService to persist updater data that outlives
27// the updater processes.
28//
29// This class has sequence affinity.
30//
31// A mechanism to remove apps or app versions from prefs is needed.
32// TODO(sorin): crbug.com/1056450
Sorin Jianu94f92a12020-07-22 19:39:3333class PersistedData : public base::RefCountedThreadSafe<PersistedData> {
Sorin Jianu2d0c54a2020-02-27 21:35:5234 public:
35 // Constructs a provider using the specified |pref_service|.
36 // The associated preferences are assumed to already be registered.
37 // The |pref_service| must outlive the instance of this class.
38 explicit PersistedData(PrefService* pref_service);
39 PersistedData(const PersistedData&) = delete;
40 PersistedData& operator=(const PersistedData&) = delete;
41
42 // These functions access |pv| data for the specified |id|. Returns an empty
43 // version, if the version is not found.
44 base::Version GetProductVersion(const std::string& id) const;
45 void SetProductVersion(const std::string& id, const base::Version& pv);
46
47 // These functions access |fingerprint| data for the specified |id|.
48 std::string GetFingerprint(const std::string& id) const;
49 void SetFingerprint(const std::string& id, const std::string& fp);
50
Michael Changb15df0e22020-03-02 22:21:1251 // These functions access the existence checker path for the specified id.
52 base::FilePath GetExistenceCheckerPath(const std::string& id) const;
53 void SetExistenceCheckerPath(const std::string& id,
54 const base::FilePath& ecp);
55
56 // These functions access the brand code for the specified id.
57 std::string GetBrandCode(const std::string& id) const;
58 void SetBrandCode(const std::string& id, const std::string& bc);
59
60 // These functions access the tag for the specified id.
61 std::string GetTag(const std::string& id) const;
62 void SetTag(const std::string& id, const std::string& tag);
63
64 // This function sets everything in the registration request object into the
65 // persistent data store.
66 void RegisterApp(const RegistrationRequest& rq);
67
Michael Chang1b9300912020-09-10 17:36:2868 // This function removes a registered application from the persistent store.
69 bool RemoveApp(const std::string& id);
70
Sorin Jianu2d0c54a2020-02-27 21:35:5271 // Returns the app ids of the applications registered in prefs, if the
72 // application has a valid version.
73 std::vector<std::string> GetAppIds() const;
74
75 private:
Sorin Jianu94f92a12020-07-22 19:39:3376 friend class base::RefCountedThreadSafe<PersistedData>;
Sorin Jianu2d0c54a2020-02-27 21:35:5277 ~PersistedData();
78
Joshua Pawlickic9616ce2020-08-11 17:24:4879 // Returns nullptr if the app key does not exist.
80 const base::Value* GetAppKey(const std::string& id) const;
81
82 // Returns an existing or newly created app key under a root pref.
83 base::Value* GetOrCreateAppKey(const std::string& id, base::Value* root);
84
Sorin Jianu2d0c54a2020-02-27 21:35:5285 std::string GetString(const std::string& id, const std::string& key) const;
86 void SetString(const std::string& id,
87 const std::string& key,
88 const std::string& value);
Sorin Jianu2d0c54a2020-02-27 21:35:5289 SEQUENCE_CHECKER(sequence_checker_);
90
91 PrefService* pref_service_ = nullptr; // Not owned by this class.
92};
93
94} // namespace updater
95
96#endif // CHROME_UPDATER_PERSISTED_DATA_H_