[go: nahoru, domu]

blob: 799aed2b9a50896f44dc86deff217231d09084e2 [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
Sorin Jianu2d0c54a2020-02-27 21:35:5264
Michael Changb15df0e22020-03-02 22:21:1265 // These functions access the existence checker path for the specified id.
66 base::FilePath GetExistenceCheckerPath(const std::string& id) const;
67 void SetExistenceCheckerPath(const std::string& id,
68 const base::FilePath& ecp);
69
70 // These functions access the brand code for the specified id.
71 std::string GetBrandCode(const std::string& id) const;
72 void SetBrandCode(const std::string& id, const std::string& bc);
73
Xiaoling Baobb3afae2021-12-03 22:09:3274 // These functions access the brand path for the specified id.
75 base::FilePath GetBrandPath(const std::string& id) const;
76 void SetBrandPath(const std::string& id, const base::FilePath& bp);
77
Joshua Pawlicki89132a02021-10-14 19:53:1478 // These functions access the AP for the specified id.
S. Ganeshaeaff96f2023-06-21 17:37:0979 std::string GetAP(const std::string& id);
Joshua Pawlicki89132a02021-10-14 19:53:1480 void SetAP(const std::string& id, const std::string& ap);
Michael Changb15df0e22020-03-02 22:21:1281
Joshua Pawlicki44e4fdb2023-10-16 19:06:4682 // These functions access the AP path for the specified id.
83 base::FilePath GetAPPath(const std::string& id) const;
84 void SetAPPath(const std::string& id, const base::FilePath& path);
85
86 // These functions access the AP key for the specified id.
87 std::string GetAPKey(const std::string& id) const;
88 void SetAPKey(const std::string& id, const std::string& value);
89
Joshua Pawlicki0363e822023-02-14 17:55:5590 // This function sets any non-empty field in the registration request object
91 // into the persistent data store.
Michael Changb15df0e22020-03-02 22:21:1292 void RegisterApp(const RegistrationRequest& rq);
93
Michael Chang1b9300912020-09-10 17:36:2894 // This function removes a registered application from the persistent store.
95 bool RemoveApp(const std::string& id);
96
Sorin Jianu2d0c54a2020-02-27 21:35:5297 // Returns the app ids of the applications registered in prefs, if the
98 // application has a valid version.
99 std::vector<std::string> GetAppIds() const;
100
Joshua Pawlicki95356f02022-01-12 19:45:17101 // HadApps is set when the updater processes a registration for an app other
102 // than itself, and is never unset, even if the app is uninstalled.
103 bool GetHadApps() const;
104 void SetHadApps();
105
Joshua Pawlickif64b0282023-02-02 17:13:27106 // UsageStatsEnabled reflects whether the updater as a whole is allowed to
107 // send usage stats, and is set or reset periodically based on the usage
108 // stats opt-in state of each product.
109 bool GetUsageStatsEnabled() const;
110 void SetUsageStatsEnabled(bool usage_stats_enabled);
111
Sorin Jianuf5425c322022-01-29 01:14:27112 // LastChecked is set when the updater completed successfully a call to
113 // `UpdateService::UpdateAll` as indicated by the `UpdateService::Result`
114 // argument of the completion callback. This means that the execution path
115 // for updating all applications works end to end, including communicating
116 // with the backend.
117 base::Time GetLastChecked() const;
118 void SetLastChecked(const base::Time& time);
119
120 // LastStarted is set when `UpdateService::RunPeriodicTasks` is called. This
121 // indicates that the mechanism to initiate automated update checks is
122 // working.
123 base::Time GetLastStarted() const;
124 void SetLastStarted(const base::Time& time);
125
S. Ganesh73daf2c2022-06-14 01:03:55126#if BUILDFLAG(IS_WIN)
127 // Retrieves the previously stored OS version.
Sorin Jianua4b3d382023-11-10 20:08:46128 std::optional<OSVERSIONINFOEX> GetLastOSVersion() const;
S. Ganesh73daf2c2022-06-14 01:03:55129
130 // Stores the current os version.
131 void SetLastOSVersion();
132#endif
133
Joshua Pawlicki072744fba2023-12-06 00:57:12134 // update_client::PersistedData overrides:
135 base::Version GetProductVersion(const std::string& id) const override;
136 void SetProductVersion(const std::string& id,
137 const base::Version& pv) override;
138 std::string GetFingerprint(const std::string& id) const override;
139 void SetFingerprint(const std::string& id, const std::string& fp) override;
140 int GetDateLastActive(const std::string& id) const override;
141 int GetDaysSinceLastActive(const std::string& id) const override;
142 void SetDateLastActive(const std::string& id, int dla) override;
143 int GetDateLastRollCall(const std::string& id) const override;
144 int GetDaysSinceLastRollCall(const std::string& id) const override;
145 void SetDateLastRollCall(const std::string& id, int dlrc) override;
146 std::string GetCohort(const std::string& id) const override;
147 void SetCohort(const std::string& id, const std::string& cohort) override;
148 std::string GetCohortName(const std::string& id) const override;
149 void SetCohortName(const std::string& id,
150 const std::string& cohort_name) override;
151 std::string GetCohortHint(const std::string& id) const override;
152 void SetCohortHint(const std::string& id,
153 const std::string& cohort_hint) override;
154 std::string GetPingFreshness(const std::string& id) const override;
155 void SetDateLastData(const std::vector<std::string>& ids,
156 int datenum,
157 base::OnceClosure callback) override;
158 int GetInstallDate(const std::string& id) const override;
159 void GetActiveBits(const std::vector<std::string>& ids,
160 base::OnceCallback<void(const std::set<std::string>&)>
161 callback) const override;
162 base::Time GetThrottleUpdatesUntil() const override;
163 void SetThrottleUpdatesUntil(const base::Time& time) override;
164
Sorin Jianu2d0c54a2020-02-27 21:35:52165 private:
Sorin Jianu94f92a12020-07-22 19:39:33166 friend class base::RefCountedThreadSafe<PersistedData>;
Joshua Pawlicki072744fba2023-12-06 00:57:12167 ~PersistedData() override;
Sorin Jianu2d0c54a2020-02-27 21:35:52168
Joshua Pawlickic9616ce2020-08-11 17:24:48169 // Returns nullptr if the app key does not exist.
Matt Menkeb1732aac2022-06-02 13:48:03170 const base::Value::Dict* GetAppKey(const std::string& id) const;
Joshua Pawlickic9616ce2020-08-11 17:24:48171
172 // Returns an existing or newly created app key under a root pref.
Matt Menkeaee78692022-09-26 15:45:52173 base::Value::Dict* GetOrCreateAppKey(const std::string& id,
174 base::Value::Dict& root);
Joshua Pawlickic9616ce2020-08-11 17:24:48175
Sorin Jianua4b3d382023-11-10 20:08:46176 std::optional<int> GetInteger(const std::string& id,
177 const std::string& key) const;
Xiaoling Bao7152ba82023-03-27 19:19:27178 void SetInteger(const std::string& id, const std::string& key, int value);
Sorin Jianu2d0c54a2020-02-27 21:35:52179 std::string GetString(const std::string& id, const std::string& key) const;
180 void SetString(const std::string& id,
181 const std::string& key,
182 const std::string& value);
Sorin Jianuf5425c322022-01-29 01:14:27183
Sorin Jianu2d0c54a2020-02-27 21:35:52184 SEQUENCE_CHECKER(sequence_checker_);
185
Xiaoling Bao9d44237f2023-01-18 21:00:27186 const UpdaterScope scope_;
Paul Semel89e1f63c2023-06-19 13:34:10187 raw_ptr<PrefService, DanglingUntriaged> pref_service_ = nullptr;
Joshua Pawlicki072744fba2023-12-06 00:57:12188 std::unique_ptr<update_client::PersistedData> delegate_;
Sorin Jianu2d0c54a2020-02-27 21:35:52189};
190
Joshua Pawlicki95356f02022-01-12 19:45:17191void RegisterPersistedDataPrefs(scoped_refptr<PrefRegistrySimple> registry);
192
Sorin Jianu2d0c54a2020-02-27 21:35:52193} // namespace updater
194
195#endif // CHROME_UPDATER_PERSISTED_DATA_H_