[go: nahoru, domu]

blob: ceb5fe486dbccba00b365904e252cae2dc2505d0 [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2020 The Chromium Authors
Sorin Jianu2d0c54a2020-02-27 21:35:522// 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
Joshua Pawlicki072744fba2023-12-06 00:57:128#include <memory>
Sorin Jianua4b3d382023-11-10 20:08:469#include <optional>
Sorin Jianu2d0c54a2020-02-27 21:35:5210#include <string>
11#include <vector>
12
Keishi Hattori0e45c022021-11-27 09:25:5213#include "base/memory/raw_ptr.h"
Sorin Jianu2d0c54a2020-02-27 21:35:5214#include "base/memory/ref_counted.h"
15#include "base/sequence_checker.h"
Matt Menkeb1732aac2022-06-02 13:48:0316#include "base/values.h"
Xiaoling Bao9d44237f2023-01-18 21:00:2717#include "chrome/updater/updater_scope.h"
Joshua Pawlicki072744fba2023-12-06 00:57:1218#include "components/update_client/persisted_data.h"
S. Ganesh73daf2c2022-06-14 01:03:5519
20#if BUILDFLAG(IS_WIN)
21#include <windows.h>
22#endif
Sorin Jianu2d0c54a2020-02-27 21:35:5223
24class PrefService;
Joshua Pawlicki95356f02022-01-12 19:45:1725class PrefRegistrySimple;
Sorin Jianu2d0c54a2020-02-27 21:35:5226
27namespace base {
Michael Changb15df0e22020-03-02 22:21:1228class FilePath;
Sorin Jianuf5425c322022-01-29 01:14:2729class Time;
Sorin Jianu2d0c54a2020-02-27 21:35:5230class Version;
Michael Changb15df0e22020-03-02 22:21:1231} // namespace base
Sorin Jianu2d0c54a2020-02-27 21:35:5232
Joshua Pawlicki072744fba2023-12-06 00:57:1233namespace update_client {
34class ActivityDataService;
35} // namespace update_client
36
Sorin Jianu2d0c54a2020-02-27 21:35:5237namespace updater {
38
Michael Changb15df0e22020-03-02 22:21:1239struct RegistrationRequest;
40
Sorin Jianu2d0c54a2020-02-27 21:35:5241// PersistedData uses the PrefService to persist updater data that outlives
42// the updater processes.
Joshua Pawlicki072744fba2023-12-06 00:57:1243class PersistedData : public base::RefCountedThreadSafe<PersistedData>,
44 public update_client::PersistedData {
Sorin Jianu2d0c54a2020-02-27 21:35:5245 public:
46 // Constructs a provider using the specified |pref_service|.
47 // The associated preferences are assumed to already be registered.
48 // The |pref_service| must outlive the instance of this class.
Joshua Pawlicki072744fba2023-12-06 00:57:1249 PersistedData(
50 UpdaterScope scope,
51 PrefService* pref_service,
52 std::unique_ptr<update_client::ActivityDataService> activity_service);
Sorin Jianu2d0c54a2020-02-27 21:35:5253 PersistedData(const PersistedData&) = delete;
54 PersistedData& operator=(const PersistedData&) = delete;
55
Joshua Pawlicki44e4fdb2023-10-16 19:06:4656 // These functions access the version path for the specified id.
57 base::FilePath GetProductVersionPath(const std::string& id) const;
58 void SetProductVersionPath(const std::string& id, const base::FilePath& path);
59
60 // These functions access the version key for the specified id.
61 std::string GetProductVersionKey(const std::string& id) const;
62 void SetProductVersionKey(const std::string& id, const std::string& value);
63
Michael Changb15df0e22020-03-02 22:21:1264 // These functions access the existence checker path for the specified id.
65 base::FilePath GetExistenceCheckerPath(const std::string& id) const;
66 void SetExistenceCheckerPath(const std::string& id,
67 const base::FilePath& ecp);
68
69 // These functions access the brand code for the specified id.
70 std::string GetBrandCode(const std::string& id) const;
71 void SetBrandCode(const std::string& id, const std::string& bc);
72
Xiaoling Baobb3afae2021-12-03 22:09:3273 // These functions access the brand path for the specified id.
74 base::FilePath GetBrandPath(const std::string& id) const;
75 void SetBrandPath(const std::string& id, const base::FilePath& bp);
76
Joshua Pawlicki89132a02021-10-14 19:53:1477 // These functions access the AP for the specified id.
S. Ganeshaeaff96f2023-06-21 17:37:0978 std::string GetAP(const std::string& id);
Joshua Pawlicki89132a02021-10-14 19:53:1479 void SetAP(const std::string& id, const std::string& ap);
Michael Changb15df0e22020-03-02 22:21:1280
Joshua Pawlicki44e4fdb2023-10-16 19:06:4681 // These functions access the AP path for the specified id.
82 base::FilePath GetAPPath(const std::string& id) const;
83 void SetAPPath(const std::string& id, const base::FilePath& path);
84
85 // These functions access the AP key for the specified id.
86 std::string GetAPKey(const std::string& id) const;
87 void SetAPKey(const std::string& id, const std::string& value);
88
Joshua Pawlicki0363e822023-02-14 17:55:5589 // This function sets any non-empty field in the registration request object
90 // into the persistent data store.
Michael Changb15df0e22020-03-02 22:21:1291 void RegisterApp(const RegistrationRequest& rq);
92
Michael Chang1b9300912020-09-10 17:36:2893 // This function removes a registered application from the persistent store.
94 bool RemoveApp(const std::string& id);
95
Sorin Jianu2d0c54a2020-02-27 21:35:5296 // Returns the app ids of the applications registered in prefs, if the
97 // application has a valid version.
98 std::vector<std::string> GetAppIds() const;
99
Joshua Pawlicki95356f02022-01-12 19:45:17100 // HadApps is set when the updater processes a registration for an app other
101 // than itself, and is never unset, even if the app is uninstalled.
102 bool GetHadApps() const;
103 void SetHadApps();
104
Joshua Pawlickif64b0282023-02-02 17:13:27105 // UsageStatsEnabled reflects whether the updater as a whole is allowed to
106 // send usage stats, and is set or reset periodically based on the usage
107 // stats opt-in state of each product.
108 bool GetUsageStatsEnabled() const;
109 void SetUsageStatsEnabled(bool usage_stats_enabled);
110
Sorin Jianuf5425c322022-01-29 01:14:27111 // LastChecked is set when the updater completed successfully a call to
112 // `UpdateService::UpdateAll` as indicated by the `UpdateService::Result`
113 // argument of the completion callback. This means that the execution path
114 // for updating all applications works end to end, including communicating
115 // with the backend.
116 base::Time GetLastChecked() const;
117 void SetLastChecked(const base::Time& time);
118
119 // LastStarted is set when `UpdateService::RunPeriodicTasks` is called. This
120 // indicates that the mechanism to initiate automated update checks is
121 // working.
122 base::Time GetLastStarted() const;
123 void SetLastStarted(const base::Time& time);
124
S. Ganesh73daf2c2022-06-14 01:03:55125#if BUILDFLAG(IS_WIN)
126 // Retrieves the previously stored OS version.
Sorin Jianua4b3d382023-11-10 20:08:46127 std::optional<OSVERSIONINFOEX> GetLastOSVersion() const;
S. Ganesh73daf2c2022-06-14 01:03:55128
129 // Stores the current os version.
130 void SetLastOSVersion();
131#endif
132
Joshua Pawlicki072744fba2023-12-06 00:57:12133 // update_client::PersistedData overrides:
134 base::Version GetProductVersion(const std::string& id) const override;
135 void SetProductVersion(const std::string& id,
136 const base::Version& pv) override;
John Rummell0e1cf96e2024-01-30 17:31:33137 base::Version GetMaxPreviousProductVersion(
138 const std::string& id) const override;
139 void SetMaxPreviousProductVersion(const std::string& id,
140 const base::Version& max_version) override;
Joshua Pawlicki072744fba2023-12-06 00:57:12141 std::string GetFingerprint(const std::string& id) const override;
142 void SetFingerprint(const std::string& id, const std::string& fp) override;
143 int GetDateLastActive(const std::string& id) const override;
144 int GetDaysSinceLastActive(const std::string& id) const override;
145 void SetDateLastActive(const std::string& id, int dla) override;
146 int GetDateLastRollCall(const std::string& id) const override;
147 int GetDaysSinceLastRollCall(const std::string& id) const override;
148 void SetDateLastRollCall(const std::string& id, int dlrc) override;
149 std::string GetCohort(const std::string& id) const override;
150 void SetCohort(const std::string& id, const std::string& cohort) override;
151 std::string GetCohortName(const std::string& id) const override;
152 void SetCohortName(const std::string& id,
153 const std::string& cohort_name) override;
154 std::string GetCohortHint(const std::string& id) const override;
155 void SetCohortHint(const std::string& id,
156 const std::string& cohort_hint) override;
157 std::string GetPingFreshness(const std::string& id) const override;
158 void SetDateLastData(const std::vector<std::string>& ids,
159 int datenum,
160 base::OnceClosure callback) override;
161 int GetInstallDate(const std::string& id) const override;
162 void GetActiveBits(const std::vector<std::string>& ids,
163 base::OnceCallback<void(const std::set<std::string>&)>
164 callback) const override;
165 base::Time GetThrottleUpdatesUntil() const override;
166 void SetThrottleUpdatesUntil(const base::Time& time) override;
167
Sorin Jianu2d0c54a2020-02-27 21:35:52168 private:
Sorin Jianu94f92a12020-07-22 19:39:33169 friend class base::RefCountedThreadSafe<PersistedData>;
Joshua Pawlicki072744fba2023-12-06 00:57:12170 ~PersistedData() override;
Sorin Jianu2d0c54a2020-02-27 21:35:52171
Joshua Pawlickic9616ce2020-08-11 17:24:48172 // Returns nullptr if the app key does not exist.
Matt Menkeb1732aac2022-06-02 13:48:03173 const base::Value::Dict* GetAppKey(const std::string& id) const;
Joshua Pawlickic9616ce2020-08-11 17:24:48174
175 // Returns an existing or newly created app key under a root pref.
Matt Menkeaee78692022-09-26 15:45:52176 base::Value::Dict* GetOrCreateAppKey(const std::string& id,
177 base::Value::Dict& root);
Joshua Pawlickic9616ce2020-08-11 17:24:48178
Sorin Jianua4b3d382023-11-10 20:08:46179 std::optional<int> GetInteger(const std::string& id,
180 const std::string& key) const;
Xiaoling Bao7152ba82023-03-27 19:19:27181 void SetInteger(const std::string& id, const std::string& key, int value);
Sorin Jianu2d0c54a2020-02-27 21:35:52182 std::string GetString(const std::string& id, const std::string& key) const;
183 void SetString(const std::string& id,
184 const std::string& key,
185 const std::string& value);
Sorin Jianuf5425c322022-01-29 01:14:27186
Sorin Jianu2d0c54a2020-02-27 21:35:52187 SEQUENCE_CHECKER(sequence_checker_);
188
Xiaoling Bao9d44237f2023-01-18 21:00:27189 const UpdaterScope scope_;
Paul Semel89e1f63c2023-06-19 13:34:10190 raw_ptr<PrefService, DanglingUntriaged> pref_service_ = nullptr;
Joshua Pawlicki072744fba2023-12-06 00:57:12191 std::unique_ptr<update_client::PersistedData> delegate_;
Sorin Jianu2d0c54a2020-02-27 21:35:52192};
193
Joshua Pawlicki95356f02022-01-12 19:45:17194void RegisterPersistedDataPrefs(scoped_refptr<PrefRegistrySimple> registry);
195
Sorin Jianu2d0c54a2020-02-27 21:35:52196} // namespace updater
197
198#endif // CHROME_UPDATER_PERSISTED_DATA_H_