blob: 4085b34f81bc724c1cc8783d991d95976b6a92ff [file] [log] [blame]
sorin52ac0882015-01-24 01:15:001// Copyright 2015 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 COMPONENTS_UPDATE_CLIENT_UPDATE_CLIENT_H_
6#define COMPONENTS_UPDATE_CLIENT_UPDATE_CLIENT_H_
7
8#include <stdint.h>
dchengd0fc6aa92016-04-22 18:03:129
sorin2adb2ca2016-06-29 01:44:3510#include <map>
Sorin Jianu9d64af672020-02-05 19:14:3411#include <memory>
sorin52ac0882015-01-24 01:15:0012#include <string>
13#include <vector>
14
sorin9797aba2015-04-17 17:15:0315#include "base/callback_forward.h"
bauerb810e60f42015-02-05 01:09:1016#include "base/memory/ref_counted.h"
sorin52ac0882015-01-24 01:15:0017#include "base/version.h"
sorin2892f7212016-11-07 18:59:4318#include "components/update_client/update_client_errors.h"
Anton Bikineev1156b5f2021-05-15 22:35:3619#include "third_party/abseil-cpp/absl/types/optional.h"
sorin52ac0882015-01-24 01:15:0020
sorin9797aba2015-04-17 17:15:0321// The UpdateClient class is a facade with a simple interface. The interface
22// exposes a few APIs to install a CRX or update a group of CRXs.
23//
24// The difference between a CRX install and a CRX update is relatively minor.
25// The terminology going forward will use the word "update" to cover both
26// install and update scenarios, except where details regarding the install
27// case are relevant.
28//
29// Handling an update consists of a series of actions such as sending an update
30// check to the server, followed by parsing the server response, identifying
31// the CRXs that require an update, downloading the differential update if
32// it is available, unpacking and patching the differential update, then
33// falling back to trying a similar set of actions using the full update.
34// At the end of this process, completion pings are sent to the server,
35// as needed, for the CRXs which had updates.
36//
37// As a general idea, this code handles the action steps needed to update
38// a group of components serially, one step at a time. However, concurrent
39// execution of calls to UpdateClient::Update is possible, therefore,
40// queuing of updates could happen in some cases. More below.
41//
42// The UpdateClient class features a subject-observer interface to observe
43// the CRX state changes during an update.
44//
45// The threading model for this code assumes that most of the code in the
46// public interface runs on a SingleThreadTaskRunner.
47// This task runner corresponds to the browser UI thread in many cases. There
48// are parts of the installer interface that run on blocking task runners, which
49// are usually threads in a thread pool.
50//
51// Using the UpdateClient is relatively easy. This assumes that the client
52// of this code has already implemented the observer interface as needed, and
53// can provide an installer, as described below.
54//
dchengd0fc6aa92016-04-22 18:03:1255// std::unique_ptr<UpdateClient> update_client(UpdateClientFactory(...));
sorin9797aba2015-04-17 17:15:0356// update_client->AddObserver(&observer);
57// std::vector<std::string> ids;
58// ids.push_back(...));
Sorin Jianua8ef73d2017-11-02 16:55:1759// update_client->Update(ids, base::BindOnce(...), base::BindOnce(...));
sorin9797aba2015-04-17 17:15:0360//
61// UpdateClient::Update takes two callbacks as parameters. First callback
62// allows the client of this code to provide an instance of CrxComponent
63// data structure that specifies additional parameters of the update.
64// CrxComponent has a CrxInstaller data member, which must be provided by the
65// callers of this class. The second callback indicates that this non-blocking
66// call has completed.
67//
68// There could be several ways of triggering updates for a CRX, user-initiated,
69// or timer-based. Since the execution of updates is concurrent, the parameters
70// for the update must be provided right before the update is handled.
71// Otherwise, the version of the CRX set in the CrxComponent may not be correct.
72//
73// The UpdateClient public interface includes two functions: Install and
74// Update. These functions correspond to installing one CRX immediately as a
75// foreground activity (Install), and updating a group of CRXs silently in the
76// background (Update). This distinction is important. Background updates are
77// queued up and their actions run serially, one at a time, for the purpose of
78// conserving local resources such as CPU, network, and I/O.
79// On the other hand, installs are never queued up but run concurrently, as
80// requested by the user.
81//
82// The update client introduces a runtime constraint regarding interleaving
83// updates and installs. If installs or updates for a given CRX are in progress,
84// then installs for the same CRX will fail with a specific error.
85//
86// Implementation details.
87//
88// The implementation details below are not relevant to callers of this
89// code. However, these design notes are relevant to the owners and maintainers
90// of this module.
91//
92// The design for the update client consists of a number of abstractions
93// such as: task, update engine, update context, and action.
94// The execution model for these abstractions is simple. They usually expose
95// a public, non-blocking Run function, and they invoke a callback when
96// the Run function has completed.
97//
98// A task is the unit of work for the UpdateClient. A task is associated
99// with a single call of the Update function. A task represents a group
100// of CRXs that are updated together.
101//
102// The UpdateClient is responsible for the queuing of tasks, if queuing is
103// needed.
104//
105// When the task runs, it calls the update engine to handle the updates for
106// the CRXs associated with the task. The UpdateEngine is the abstraction
107// responsible for breaking down the update in a set of discrete steps, which
108// are implemented as actions, and running the actions.
109//
110// The UpdateEngine maintains a set of UpdateContext instances. Each of
111// these instances maintains the update state for all the CRXs belonging to
112// a given task. The UpdateContext contains a queue of CRX ids.
113// The UpdateEngine will handle updates for the CRXs in the order they appear
114// in the queue, until the queue is empty.
115//
116// The update state for each CRX is maintained in a container of CrxUpdateItem*.
117// As actions run, each action updates the CRX state, represented by one of
118// these CrxUpdateItem* instances.
119//
120// Although the UpdateEngine can and will run update tasks concurrently, the
121// actions of a task are run sequentially.
122//
123// The Action is a polymorphic type. There is some code reuse for convenience,
124// implemented as a mixin. The polymorphic behavior of some of the actions
125// is achieved using a template method.
126//
127// State changes of a CRX could generate events, which are observed using a
128// subject-observer interface.
129//
130// The actions chain up. In some sense, the actions implement a state machine,
131// as the CRX undergoes a series of state transitions in the process of
132// being checked for updates and applying the update.
133
wafflesd2d9a332016-04-09 01:59:57134class PrefRegistrySimple;
sorin9797aba2015-04-17 17:15:03135
sorin52ac0882015-01-24 01:15:00136namespace base {
sorin52ac0882015-01-24 01:15:00137class FilePath;
138}
139
Joshua Pawlickif4b33f382018-08-17 17:36:51140namespace crx_file {
141enum class VerifierFormat;
142}
143
sorin52ac0882015-01-24 01:15:00144namespace update_client {
145
sorin9797aba2015-04-17 17:15:03146class Configurator;
sorin7b8650522016-11-02 18:23:41147enum class Error;
sorin9797aba2015-04-17 17:15:03148struct CrxUpdateItem;
149
sorin30474f02017-04-27 00:45:48150enum class ComponentState {
151 kNew,
152 kChecking,
153 kCanUpdate,
154 kDownloadingDiff,
155 kDownloading,
156 kDownloaded,
157 kUpdatingDiff,
158 kUpdating,
159 kUpdated,
160 kUpToDate,
161 kUpdateError,
162 kUninstalled,
Sam Sappenfield4a065262020-07-29 19:28:18163 kRegistration,
Sorin Jianu4ab7c292017-06-15 18:40:21164 kRun,
sorin30474f02017-04-27 00:45:48165 kLastStatus
166};
167
sorin9797aba2015-04-17 17:15:03168// Defines an interface for a generic CRX installer.
169class CrxInstaller : public base::RefCountedThreadSafe<CrxInstaller> {
sorin52ac0882015-01-24 01:15:00170 public:
sorin2892f7212016-11-07 18:59:43171 // Contains the result of the Install operation.
172 struct Result {
Sorin Jianu30c0e0b2021-02-01 17:00:52173 Result() = default;
sorin2892f7212016-11-07 18:59:43174 explicit Result(int error, int extended_error = 0)
175 : error(error), extended_error(extended_error) {}
176 explicit Result(InstallError error, int extended_error = 0)
177 : error(static_cast<int>(error)), extended_error(extended_error) {}
Sorin Jianu30c0e0b2021-02-01 17:00:52178
sorin2892f7212016-11-07 18:59:43179 int error = 0; // 0 indicates that install has been successful.
180 int extended_error = 0;
Sorin Jianua26ee33af2021-01-20 04:18:06181
182 // Localized text displayed to the user, if applicable.
183 std::string installer_text;
184
185 // Shell command run at the end of the install, if applicable. This string
186 // must be escaped to be a command line.
187 std::string installer_cmd_line;
sorin2892f7212016-11-07 18:59:43188 };
189
Sorin Jianu9d64af672020-02-05 19:14:34190 struct InstallParams {
191 InstallParams(const std::string& run, const std::string& arguments);
192 std::string run;
193 std::string arguments;
194 };
195
Sorin Jianuc9d32b2f2020-05-08 23:07:26196 using ProgressCallback = base::RepeatingCallback<void(int progress)>;
Sorin Jianua8ef73d2017-11-02 16:55:17197 using Callback = base::OnceCallback<void(const Result& result)>;
Sorin Jianuf40ab4b32017-10-06 22:53:41198
sorin9797aba2015-04-17 17:15:03199 // Called on the main thread when there was a problem unpacking or
200 // verifying the CRX. |error| is a non-zero value which is only meaningful
201 // to the caller.
sorin52ac0882015-01-24 01:15:00202 virtual void OnUpdateError(int error) = 0;
203
sorin9797aba2015-04-17 17:15:03204 // Called by the update service when a CRX has been unpacked
Sorin Jianuc9d32b2f2020-05-08 23:07:26205 // and it is ready to be installed. This method may be called from a
206 // sequence other than the main sequence.
207 // |unpack_path| contains the temporary directory with all the unpacked CRX
208 // files.
209 // |pubkey| contains the public key of the CRX in the PEM format, without the
210 // header and the footer.
211 // |install_params| is an optional parameter which provides the name and the
212 // arguments for a binary program which is invoked as part of the install or
213 // update flows.
214 // |progress_callback| reports installer progress. This callback must be run
215 // directly instead of posting it.
216 // |callback| must be the last callback invoked and it indicates that the
217 // install flow has completed.
Sorin Jianu7aa6d1f2017-10-13 20:29:29218 virtual void Install(const base::FilePath& unpack_path,
Sorin Jianuea5534e92017-10-27 01:40:28219 const std::string& public_key,
Sorin Jianu9d64af672020-02-05 19:14:34220 std::unique_ptr<InstallParams> install_params,
Sorin Jianuc9d32b2f2020-05-08 23:07:26221 ProgressCallback progress_callback,
Sorin Jianua8ef73d2017-11-02 16:55:17222 Callback callback) = 0;
sorin52ac0882015-01-24 01:15:00223
sorin9797aba2015-04-17 17:15:03224 // Sets |installed_file| to the full path to the installed |file|. |file| is
225 // the filename of the file in this CRX. Returns false if this is
sorin52ac0882015-01-24 01:15:00226 // not possible (the file has been removed or modified, or its current
sorin9797aba2015-04-17 17:15:03227 // location is unknown). Otherwise, it returns true.
sorin52ac0882015-01-24 01:15:00228 virtual bool GetInstalledFile(const std::string& file,
229 base::FilePath* installed_file) = 0;
230
sorin9797aba2015-04-17 17:15:03231 // Called when a CRX has been unregistered and all versions should
232 // be uninstalled from disk. Returns true if uninstallation is supported,
233 // and false otherwise.
bauerb1f6657e72015-02-09 00:00:27234 virtual bool Uninstall() = 0;
235
bauerb810e60f42015-02-05 01:09:10236 protected:
sorin9797aba2015-04-17 17:15:03237 friend class base::RefCountedThreadSafe<CrxInstaller>;
bauerb810e60f42015-02-05 01:09:10238
Sorin Jianu30881152020-03-16 14:31:19239 virtual ~CrxInstaller() = default;
sorin52ac0882015-01-24 01:15:00240};
241
Sorin Jianu2fe49a02019-11-25 19:15:56242// Defines an interface to handle |action| elements in the update response.
243// The current implementation only handles run actions bound to a CRX, meaning
244// that such CRX is unpacked and an executable file, contained inside the CRX,
245// is run, then the results of the invocation are collected by the callback.
246class ActionHandler : public base::RefCountedThreadSafe<ActionHandler> {
247 public:
248 using Callback =
249 base::OnceCallback<void(bool succeeded, int error_code, int extra_code1)>;
250
251 virtual void Handle(const base::FilePath& action,
252 const std::string& session_id,
253 Callback callback) = 0;
254
255 protected:
256 friend class base::RefCountedThreadSafe<ActionHandler>;
257
258 virtual ~ActionHandler() = default;
259};
260
sorin2adb2ca2016-06-29 01:44:35261// A dictionary of installer-specific, arbitrary name-value pairs, which
262// may be used in the update checks requests.
263using InstallerAttributes = std::map<std::string, std::string>;
264
sorin52ac0882015-01-24 01:15:00265struct CrxComponent {
sorin52ac0882015-01-24 01:15:00266 CrxComponent();
vmpstrb6449d512016-02-25 23:55:40267 CrxComponent(const CrxComponent& other);
sorin52ac0882015-01-24 01:15:00268 ~CrxComponent();
sorin9797aba2015-04-17 17:15:03269
Joshua Pawlicki9656e3922019-09-16 16:34:51270 // Optional SHA256 hash of the CRX's public key. If not supplied, the
271 // unpacker can accept any CRX for this app, provided that the CRX meets the
272 // VerifierFormat requirements specified by the service's configurator.
273 // Callers that know or need a specific developer signature on acceptable CRX
274 // files must provide this.
sorin9797aba2015-04-17 17:15:03275 std::vector<uint8_t> pk_hash;
Joshua Pawlicki9656e3922019-09-16 16:34:51276
sorin9797aba2015-04-17 17:15:03277 scoped_refptr<CrxInstaller> installer;
Sorin Jianu2fe49a02019-11-25 19:15:56278 scoped_refptr<ActionHandler> action_handler;
279
Joshua Pawlicki9656e3922019-09-16 16:34:51280 std::string app_id;
sorin9797aba2015-04-17 17:15:03281
282 // The current version if the CRX is updated. Otherwise, "0" or "0.0" if
283 // the CRX is installed.
pwnalldb0b72412016-08-19 21:39:12284 base::Version version;
sorin9797aba2015-04-17 17:15:03285
286 std::string fingerprint; // Optional.
287 std::string name; // Optional.
sorin2adb2ca2016-06-29 01:44:35288
289 // Optional.
290 // Valid values for the name part of an attribute match
291 // ^[-_a-zA-Z0-9]{1,256}$ and valid values the value part of an attribute
Joshua Pawlickiaabed6d2019-12-02 17:10:09292 // match ^[-.,;+_=$a-zA-Z0-9]{0,256}$ .
sorin2adb2ca2016-06-29 01:44:35293 InstallerAttributes installer_attributes;
sorin9797aba2015-04-17 17:15:03294
295 // Specifies that the CRX can be background-downloaded in some cases.
sorinfccbf2d2016-04-04 20:34:34296 // The default for this value is |true|.
297 bool allows_background_download;
298
299 // Specifies that the update checks and pings associated with this component
300 // require confidentiality. The default for this value is |true|. As a side
301 // note, the confidentiality of the downloads is enforced by the server,
302 // which only returns secure download URLs in this case.
303 bool requires_network_encryption;
sorincb4e5e92016-08-02 21:48:40304
Joshua Pawlickif4b33f382018-08-17 17:36:51305 // Specifies the strength of package validation required for the item.
306 crx_file::VerifierFormat crx_format_requirement;
307
sorincb4e5e92016-08-02 21:48:40308 // True if the component allows enabling or disabling updates by group policy.
309 // This member should be set to |false| for data, non-binary components, such
310 // as CRLSet, Supervised User Whitelists, STH Set, Origin Trials, and File
311 // Type Policies.
312 bool supports_group_policy_enable_component_updates;
Minh X. Nguyenca599fb2017-09-14 21:10:39313
314 // Reasons why this component/extension is disabled.
315 std::vector<int> disabled_reasons;
Minh X. Nguyenf8c530aa2017-12-13 23:54:17316
317 // Information about where the component/extension was installed from.
318 // For extension, this information is set from the update service, which
319 // gets the install source from the update URL.
320 std::string install_source;
Minh X. Nguyenfc16497e2018-04-24 16:05:35321
322 // Information about where the component/extension was loaded from.
323 // For extensions, this information is inferred from the extension
324 // registry.
325 std::string install_location;
Yann Dago84505252020-08-27 22:20:51326
327 // Information about the channel to send to the update server when updating
328 // the component. This optional field is typically populated by policy and is
329 // only populated on managed devices.
330 std::string channel;
sorin52ac0882015-01-24 01:15:00331};
332
Sorin Jianuf40ab4b32017-10-06 22:53:41333// Called when a non-blocking call of UpdateClient completes.
Vladislav Kuzkokov12eca792017-10-20 12:45:38334using Callback = base::OnceCallback<void(Error error)>;
Sorin Jianuf40ab4b32017-10-06 22:53:41335
sorin7c717622015-05-26 19:59:09336// All methods are safe to call only from the browser's main thread. Once an
337// instance of this class is created, the reference to it must be released
338// only after the thread pools of the browser process have been destroyed and
339// the browser process has gone single-threaded.
Sorin Jianu569aa7192020-07-23 16:09:54340class UpdateClient : public base::RefCountedThreadSafe<UpdateClient> {
sorin9797aba2015-04-17 17:15:03341 public:
Sorin Jianua5d25fb2020-11-04 15:17:07342 // Returns `CrxComponent` instances corresponding to the component ids
343 // passed as an argument to the callback. The order of components in the input
344 // and output vectors must match. If the instance of the `CrxComponent` is not
345 // available for some reason, implementors of the callback must not skip
346 // skip the component, and instead, they must insert a `nullopt` value in
347 // the output vector.
sorin9797aba2015-04-17 17:15:03348 using CrxDataCallback =
Anton Bikineev1156b5f2021-05-15 22:35:36349 base::OnceCallback<std::vector<absl::optional<CrxComponent>>(
Sorin Jianu7c22795b2018-04-26 22:16:52350 const std::vector<std::string>& ids)>;
sorin9797aba2015-04-17 17:15:03351
Sorin Jianudfb12a42020-03-10 04:12:03352 // Called when state changes occur during an Install or Update call.
353 using CrxStateChangeCallback =
354 base::RepeatingCallback<void(CrxUpdateItem item)>;
355
sorin9797aba2015-04-17 17:15:03356 // Defines an interface to observe the UpdateClient. It provides
357 // notifications when state changes occur for the service itself or for the
358 // registered CRXs.
359 class Observer {
360 public:
361 enum class Events {
362 // Sent before the update client does an update check.
sorin30474f02017-04-27 00:45:48363 COMPONENT_CHECKING_FOR_UPDATES = 1,
sorin9797aba2015-04-17 17:15:03364
Sorin Jianud0298dd32019-10-25 16:47:10365 // Sent when there is a new version of a registered CRX. The CRX will be
366 // downloaded after the notification unless the update client inserts
367 // a wait because of a throttling policy.
sorin9797aba2015-04-17 17:15:03368 COMPONENT_UPDATE_FOUND,
369
370 // Sent when a CRX is in the update queue but it can't be acted on
371 // right away, because the update client spaces out CRX updates due to a
372 // throttling policy.
373 COMPONENT_WAIT,
374
375 // Sent after the new CRX has been downloaded but before the install
376 // or the upgrade is attempted.
377 COMPONENT_UPDATE_READY,
378
379 // Sent when a CRX has been successfully updated.
380 COMPONENT_UPDATED,
381
Sorin Jianucbb10e12018-01-23 18:01:44382 // Sent when a CRX has not been updated because there was no update
383 // available for this component.
sorin9797aba2015-04-17 17:15:03384 COMPONENT_NOT_UPDATED,
385
Sorin Jianucbb10e12018-01-23 18:01:44386 // Sent when an error ocurred during an update for any reason, including
387 // the update check itself failed, or the download of the update payload
388 // failed, or applying the update failed.
389 COMPONENT_UPDATE_ERROR,
390
sorin9797aba2015-04-17 17:15:03391 // Sent when CRX bytes are being downloaded.
392 COMPONENT_UPDATE_DOWNLOADING,
Sorin Jianuc9d32b2f2020-05-08 23:07:26393
394 // Sent when install progress is received from the CRX installer.
395 COMPONENT_UPDATE_UPDATING,
sorin9797aba2015-04-17 17:15:03396 };
397
Sorin Jianu30881152020-03-16 14:31:19398 virtual ~Observer() = default;
sorin9797aba2015-04-17 17:15:03399
400 // Called by the update client when a state change happens.
401 // If an |id| is specified, then the event is fired on behalf of the
402 // specific CRX. The implementors of this interface are
403 // expected to filter the relevant events based on the id of the CRX.
404 virtual void OnEvent(Events event, const std::string& id) = 0;
405 };
406
407 // Adds an observer for this class. An observer should not be added more
408 // than once. The caller retains the ownership of the observer object.
409 virtual void AddObserver(Observer* observer) = 0;
410
411 // Removes an observer. It is safe for an observer to be removed while
412 // the observers are being notified.
413 virtual void RemoveObserver(Observer* observer) = 0;
414
sorin842703b2016-11-02 23:59:23415 // Installs the specified CRX. Calls back on |callback| after the
Sorin Jianudfb12a42020-03-10 04:12:03416 // update has been handled. Provides state change notifications through
417 // invocations of the optional |crx_state_change_callback| callback.
418 // The |error| parameter of the |callback| contains an error code in the case
419 // of a run-time error, or 0 if the install has been handled successfully.
420 // Overlapping calls of this function are executed concurrently, as long as
421 // the id parameter is different, meaning that installs of different
422 // components are parallelized.
sorin08d153c2015-10-30 00:04:20423 // The |Install| function is intended to be used for foreground installs of
424 // one CRX. These cases are usually associated with on-demand install
425 // scenarios, which are triggered by user actions. Installs are never
426 // queued up.
sorin9797aba2015-04-17 17:15:03427 virtual void Install(const std::string& id,
Sorin Jianua8ef73d2017-11-02 16:55:17428 CrxDataCallback crx_data_callback,
Sorin Jianudfb12a42020-03-10 04:12:03429 CrxStateChangeCallback crx_state_change_callback,
Vladislav Kuzkokov12eca792017-10-20 12:45:38430 Callback callback) = 0;
sorin9797aba2015-04-17 17:15:03431
432 // Updates the specified CRXs. Calls back on |crx_data_callback| before the
433 // update is attempted to give the caller the opportunity to provide the
Sorin Jianudfb12a42020-03-10 04:12:03434 // instances of CrxComponent to be used for this update. Provides state change
435 // notifications through invocations of the optional
436 // |crx_state_change_callback| callback.
437 // The |Update| function is intended to be used for background updates of
438 // several CRXs. Overlapping calls to this function result in a queuing
439 // behavior, and the execution of each call is serialized. In addition,
440 // updates are always queued up when installs are running. The |is_foreground|
441 // parameter must be set to true if the invocation of this function is a
442 // result of a user initiated update.
sorin9797aba2015-04-17 17:15:03443 virtual void Update(const std::vector<std::string>& ids,
Sorin Jianua8ef73d2017-11-02 16:55:17444 CrxDataCallback crx_data_callback,
Sorin Jianudfb12a42020-03-10 04:12:03445 CrxStateChangeCallback crx_state_change_callback,
Sorin Jianub41a592a2018-03-02 16:30:27446 bool is_foreground,
Vladislav Kuzkokov12eca792017-10-20 12:45:38447 Callback callback) = 0;
sorin9797aba2015-04-17 17:15:03448
sorin805aa03112016-01-14 23:01:31449 // Sends an uninstall ping for the CRX identified by |id| and |version|. The
450 // |reason| parameter is defined by the caller. The current implementation of
451 // this function only sends a best-effort, fire-and-forget ping. It has no
452 // other side effects regarding installs or updates done through an instance
453 // of this class.
454 virtual void SendUninstallPing(const std::string& id,
pwnalldb0b72412016-08-19 21:39:12455 const base::Version& version,
sorin8037ac8c2017-04-19 16:28:00456 int reason,
Vladislav Kuzkokov12eca792017-10-20 12:45:38457 Callback callback) = 0;
sorin805aa03112016-01-14 23:01:31458
Sam Sappenfield4a065262020-07-29 19:28:18459 // Sends a registration ping for the CRX identified by |id| and |version|.
460 // The current implementation of this function only sends a best-effort,
461 // fire-and-forget ping. It has no other side effects regarding installs or
462 // updates done through an instance of this class.
463 virtual void SendRegistrationPing(const std::string& id,
464 const base::Version& version,
465 Callback callback) = 0;
466
sorin9797aba2015-04-17 17:15:03467 // Returns status details about a CRX update. The function returns true in
468 // case of success and false in case of errors, such as |id| was
469 // invalid or not known.
470 virtual bool GetCrxUpdateState(const std::string& id,
471 CrxUpdateItem* update_item) const = 0;
472
sorin08d153c2015-10-30 00:04:20473 // Returns true if the |id| is found in any running task.
sorin9797aba2015-04-17 17:15:03474 virtual bool IsUpdating(const std::string& id) const = 0;
475
sorinecaad3e2015-11-13 19:15:52476 // Cancels the queued updates and makes a best effort to stop updates in
477 // progress as soon as possible. Some updates may not be stopped, in which
478 // case, the updates will run to completion. Calling this function has no
479 // effect if updates are not currently executed or queued up.
480 virtual void Stop() = 0;
481
sorin7c717622015-05-26 19:59:09482 protected:
Sorin Jianu569aa7192020-07-23 16:09:54483 friend class base::RefCountedThreadSafe<UpdateClient>;
sorin7c717622015-05-26 19:59:09484
Sorin Jianu30881152020-03-16 14:31:19485 virtual ~UpdateClient() = default;
sorin9797aba2015-04-17 17:15:03486};
487
488// Creates an instance of the update client.
sorin7c717622015-05-26 19:59:09489scoped_refptr<UpdateClient> UpdateClientFactory(
Sorin Jianu49126332018-02-13 17:07:42490 scoped_refptr<Configurator> config);
sorin9797aba2015-04-17 17:15:03491
wafflesd2d9a332016-04-09 01:59:57492// This must be called prior to the construction of any Configurator that
493// contains a PrefService.
494void RegisterPrefs(PrefRegistrySimple* registry);
495
Minh X. Nguyen3aa40692018-03-28 01:15:59496// This must be called prior to the construction of any Configurator that
497// needs access to local user profiles.
498// This function is mostly used for ExtensionUpdater, which requires update
499// info from user profiles.
500void RegisterProfilePrefs(PrefRegistrySimple* registry);
501
sorin52ac0882015-01-24 01:15:00502} // namespace update_client
503
504#endif // COMPONENTS_UPDATE_CLIENT_UPDATE_CLIENT_H_