sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 1 | // 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> |
dcheng | d0fc6aa9 | 2016-04-22 18:03:12 | [diff] [blame] | 9 | |
sorin | 2adb2ca | 2016-06-29 01:44:35 | [diff] [blame] | 10 | #include <map> |
dcheng | d0fc6aa9 | 2016-04-22 18:03:12 | [diff] [blame] | 11 | #include <memory> |
sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 12 | #include <string> |
| 13 | #include <vector> |
| 14 | |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 15 | #include "base/callback_forward.h" |
bauerb | 810e60f4 | 2015-02-05 01:09:10 | [diff] [blame] | 16 | #include "base/memory/ref_counted.h" |
sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 17 | #include "base/version.h" |
sorin | 2892f721 | 2016-11-07 18:59:43 | [diff] [blame] | 18 | #include "components/update_client/update_client_errors.h" |
sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 19 | |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 20 | // The UpdateClient class is a facade with a simple interface. The interface |
| 21 | // exposes a few APIs to install a CRX or update a group of CRXs. |
| 22 | // |
| 23 | // The difference between a CRX install and a CRX update is relatively minor. |
| 24 | // The terminology going forward will use the word "update" to cover both |
| 25 | // install and update scenarios, except where details regarding the install |
| 26 | // case are relevant. |
| 27 | // |
| 28 | // Handling an update consists of a series of actions such as sending an update |
| 29 | // check to the server, followed by parsing the server response, identifying |
| 30 | // the CRXs that require an update, downloading the differential update if |
| 31 | // it is available, unpacking and patching the differential update, then |
| 32 | // falling back to trying a similar set of actions using the full update. |
| 33 | // At the end of this process, completion pings are sent to the server, |
| 34 | // as needed, for the CRXs which had updates. |
| 35 | // |
| 36 | // As a general idea, this code handles the action steps needed to update |
| 37 | // a group of components serially, one step at a time. However, concurrent |
| 38 | // execution of calls to UpdateClient::Update is possible, therefore, |
| 39 | // queuing of updates could happen in some cases. More below. |
| 40 | // |
| 41 | // The UpdateClient class features a subject-observer interface to observe |
| 42 | // the CRX state changes during an update. |
| 43 | // |
| 44 | // The threading model for this code assumes that most of the code in the |
| 45 | // public interface runs on a SingleThreadTaskRunner. |
| 46 | // This task runner corresponds to the browser UI thread in many cases. There |
| 47 | // are parts of the installer interface that run on blocking task runners, which |
| 48 | // are usually threads in a thread pool. |
| 49 | // |
| 50 | // Using the UpdateClient is relatively easy. This assumes that the client |
| 51 | // of this code has already implemented the observer interface as needed, and |
| 52 | // can provide an installer, as described below. |
| 53 | // |
dcheng | d0fc6aa9 | 2016-04-22 18:03:12 | [diff] [blame] | 54 | // std::unique_ptr<UpdateClient> update_client(UpdateClientFactory(...)); |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 55 | // update_client->AddObserver(&observer); |
| 56 | // std::vector<std::string> ids; |
| 57 | // ids.push_back(...)); |
Sorin Jianu | a8ef73d | 2017-11-02 16:55:17 | [diff] [blame] | 58 | // update_client->Update(ids, base::BindOnce(...), base::BindOnce(...)); |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 59 | // |
| 60 | // UpdateClient::Update takes two callbacks as parameters. First callback |
| 61 | // allows the client of this code to provide an instance of CrxComponent |
| 62 | // data structure that specifies additional parameters of the update. |
| 63 | // CrxComponent has a CrxInstaller data member, which must be provided by the |
| 64 | // callers of this class. The second callback indicates that this non-blocking |
| 65 | // call has completed. |
| 66 | // |
| 67 | // There could be several ways of triggering updates for a CRX, user-initiated, |
| 68 | // or timer-based. Since the execution of updates is concurrent, the parameters |
| 69 | // for the update must be provided right before the update is handled. |
| 70 | // Otherwise, the version of the CRX set in the CrxComponent may not be correct. |
| 71 | // |
| 72 | // The UpdateClient public interface includes two functions: Install and |
| 73 | // Update. These functions correspond to installing one CRX immediately as a |
| 74 | // foreground activity (Install), and updating a group of CRXs silently in the |
| 75 | // background (Update). This distinction is important. Background updates are |
| 76 | // queued up and their actions run serially, one at a time, for the purpose of |
| 77 | // conserving local resources such as CPU, network, and I/O. |
| 78 | // On the other hand, installs are never queued up but run concurrently, as |
| 79 | // requested by the user. |
| 80 | // |
| 81 | // The update client introduces a runtime constraint regarding interleaving |
| 82 | // updates and installs. If installs or updates for a given CRX are in progress, |
| 83 | // then installs for the same CRX will fail with a specific error. |
| 84 | // |
| 85 | // Implementation details. |
| 86 | // |
| 87 | // The implementation details below are not relevant to callers of this |
| 88 | // code. However, these design notes are relevant to the owners and maintainers |
| 89 | // of this module. |
| 90 | // |
| 91 | // The design for the update client consists of a number of abstractions |
| 92 | // such as: task, update engine, update context, and action. |
| 93 | // The execution model for these abstractions is simple. They usually expose |
| 94 | // a public, non-blocking Run function, and they invoke a callback when |
| 95 | // the Run function has completed. |
| 96 | // |
| 97 | // A task is the unit of work for the UpdateClient. A task is associated |
| 98 | // with a single call of the Update function. A task represents a group |
| 99 | // of CRXs that are updated together. |
| 100 | // |
| 101 | // The UpdateClient is responsible for the queuing of tasks, if queuing is |
| 102 | // needed. |
| 103 | // |
| 104 | // When the task runs, it calls the update engine to handle the updates for |
| 105 | // the CRXs associated with the task. The UpdateEngine is the abstraction |
| 106 | // responsible for breaking down the update in a set of discrete steps, which |
| 107 | // are implemented as actions, and running the actions. |
| 108 | // |
| 109 | // The UpdateEngine maintains a set of UpdateContext instances. Each of |
| 110 | // these instances maintains the update state for all the CRXs belonging to |
| 111 | // a given task. The UpdateContext contains a queue of CRX ids. |
| 112 | // The UpdateEngine will handle updates for the CRXs in the order they appear |
| 113 | // in the queue, until the queue is empty. |
| 114 | // |
| 115 | // The update state for each CRX is maintained in a container of CrxUpdateItem*. |
| 116 | // As actions run, each action updates the CRX state, represented by one of |
| 117 | // these CrxUpdateItem* instances. |
| 118 | // |
| 119 | // Although the UpdateEngine can and will run update tasks concurrently, the |
| 120 | // actions of a task are run sequentially. |
| 121 | // |
| 122 | // The Action is a polymorphic type. There is some code reuse for convenience, |
| 123 | // implemented as a mixin. The polymorphic behavior of some of the actions |
| 124 | // is achieved using a template method. |
| 125 | // |
| 126 | // State changes of a CRX could generate events, which are observed using a |
| 127 | // subject-observer interface. |
| 128 | // |
| 129 | // The actions chain up. In some sense, the actions implement a state machine, |
| 130 | // as the CRX undergoes a series of state transitions in the process of |
| 131 | // being checked for updates and applying the update. |
| 132 | |
waffles | d2d9a33 | 2016-04-09 01:59:57 | [diff] [blame] | 133 | class PrefRegistrySimple; |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 134 | |
sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 135 | namespace base { |
sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 136 | class FilePath; |
| 137 | } |
| 138 | |
| 139 | namespace update_client { |
| 140 | |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 141 | class Configurator; |
sorin | 7b865052 | 2016-11-02 18:23:41 | [diff] [blame] | 142 | enum class Error; |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 143 | struct CrxUpdateItem; |
| 144 | |
sorin | 30474f0 | 2017-04-27 00:45:48 | [diff] [blame] | 145 | enum class ComponentState { |
| 146 | kNew, |
| 147 | kChecking, |
| 148 | kCanUpdate, |
| 149 | kDownloadingDiff, |
| 150 | kDownloading, |
| 151 | kDownloaded, |
| 152 | kUpdatingDiff, |
| 153 | kUpdating, |
| 154 | kUpdated, |
| 155 | kUpToDate, |
| 156 | kUpdateError, |
| 157 | kUninstalled, |
Sorin Jianu | 4ab7c29 | 2017-06-15 18:40:21 | [diff] [blame] | 158 | kRun, |
sorin | 30474f0 | 2017-04-27 00:45:48 | [diff] [blame] | 159 | kLastStatus |
| 160 | }; |
| 161 | |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 162 | // Defines an interface for a generic CRX installer. |
| 163 | class CrxInstaller : public base::RefCountedThreadSafe<CrxInstaller> { |
sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 164 | public: |
sorin | 2892f721 | 2016-11-07 18:59:43 | [diff] [blame] | 165 | // Contains the result of the Install operation. |
| 166 | struct Result { |
| 167 | explicit Result(int error, int extended_error = 0) |
| 168 | : error(error), extended_error(extended_error) {} |
| 169 | explicit Result(InstallError error, int extended_error = 0) |
| 170 | : error(static_cast<int>(error)), extended_error(extended_error) {} |
| 171 | int error = 0; // 0 indicates that install has been successful. |
| 172 | int extended_error = 0; |
| 173 | }; |
| 174 | |
Sorin Jianu | a8ef73d | 2017-11-02 16:55:17 | [diff] [blame] | 175 | using Callback = base::OnceCallback<void(const Result& result)>; |
Sorin Jianu | f40ab4b3 | 2017-10-06 22:53:41 | [diff] [blame] | 176 | |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 177 | // Called on the main thread when there was a problem unpacking or |
| 178 | // verifying the CRX. |error| is a non-zero value which is only meaningful |
| 179 | // to the caller. |
sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 180 | virtual void OnUpdateError(int error) = 0; |
| 181 | |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 182 | // Called by the update service when a CRX has been unpacked |
Sorin Jianu | 7aa6d1f | 2017-10-13 20:29:29 | [diff] [blame] | 183 | // and it is ready to be installed. |unpack_path| contains the |
Sorin Jianu | ea5534e9 | 2017-10-27 01:40:28 | [diff] [blame] | 184 | // temporary directory with all the unpacked CRX files. |pubkey| contains the |
| 185 | // public key of the CRX in the PEM format, without the header and the footer. |
| 186 | // The caller must invoke the |callback| when the install flow has completed. |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 187 | // This method may be called from a thread other than the main thread. |
Sorin Jianu | 7aa6d1f | 2017-10-13 20:29:29 | [diff] [blame] | 188 | virtual void Install(const base::FilePath& unpack_path, |
Sorin Jianu | ea5534e9 | 2017-10-27 01:40:28 | [diff] [blame] | 189 | const std::string& public_key, |
Sorin Jianu | a8ef73d | 2017-11-02 16:55:17 | [diff] [blame] | 190 | Callback callback) = 0; |
sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 191 | |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 192 | // Sets |installed_file| to the full path to the installed |file|. |file| is |
| 193 | // the filename of the file in this CRX. Returns false if this is |
sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 194 | // not possible (the file has been removed or modified, or its current |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 195 | // location is unknown). Otherwise, it returns true. |
sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 196 | virtual bool GetInstalledFile(const std::string& file, |
| 197 | base::FilePath* installed_file) = 0; |
| 198 | |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 199 | // Called when a CRX has been unregistered and all versions should |
| 200 | // be uninstalled from disk. Returns true if uninstallation is supported, |
| 201 | // and false otherwise. |
bauerb | 1f6657e7 | 2015-02-09 00:00:27 | [diff] [blame] | 202 | virtual bool Uninstall() = 0; |
| 203 | |
bauerb | 810e60f4 | 2015-02-05 01:09:10 | [diff] [blame] | 204 | protected: |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 205 | friend class base::RefCountedThreadSafe<CrxInstaller>; |
bauerb | 810e60f4 | 2015-02-05 01:09:10 | [diff] [blame] | 206 | |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 207 | virtual ~CrxInstaller() {} |
sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 208 | }; |
| 209 | |
sorin | 2adb2ca | 2016-06-29 01:44:35 | [diff] [blame] | 210 | // A dictionary of installer-specific, arbitrary name-value pairs, which |
| 211 | // may be used in the update checks requests. |
| 212 | using InstallerAttributes = std::map<std::string, std::string>; |
| 213 | |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 214 | // TODO(sorin): this structure will be refactored soon. |
sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 215 | struct CrxComponent { |
sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 216 | CrxComponent(); |
vmpstr | b6449d51 | 2016-02-25 23:55:40 | [diff] [blame] | 217 | CrxComponent(const CrxComponent& other); |
sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 218 | ~CrxComponent(); |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 219 | |
| 220 | // SHA256 hash of the CRX's public key. |
| 221 | std::vector<uint8_t> pk_hash; |
| 222 | scoped_refptr<CrxInstaller> installer; |
| 223 | |
| 224 | // The current version if the CRX is updated. Otherwise, "0" or "0.0" if |
| 225 | // the CRX is installed. |
pwnall | db0b7241 | 2016-08-19 21:39:12 | [diff] [blame] | 226 | base::Version version; |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 227 | |
| 228 | std::string fingerprint; // Optional. |
| 229 | std::string name; // Optional. |
waffles | 77255cc | 2016-08-02 17:25:12 | [diff] [blame] | 230 | std::vector<std::string> handled_mime_types; |
sorin | 2adb2ca | 2016-06-29 01:44:35 | [diff] [blame] | 231 | |
| 232 | // Optional. |
| 233 | // Valid values for the name part of an attribute match |
| 234 | // ^[-_a-zA-Z0-9]{1,256}$ and valid values the value part of an attribute |
| 235 | // match ^[-.,;+_=a-zA-Z0-9]{0,256}$ . |
| 236 | InstallerAttributes installer_attributes; |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 237 | |
| 238 | // Specifies that the CRX can be background-downloaded in some cases. |
sorin | fccbf2d | 2016-04-04 20:34:34 | [diff] [blame] | 239 | // The default for this value is |true|. |
| 240 | bool allows_background_download; |
| 241 | |
| 242 | // Specifies that the update checks and pings associated with this component |
| 243 | // require confidentiality. The default for this value is |true|. As a side |
| 244 | // note, the confidentiality of the downloads is enforced by the server, |
| 245 | // which only returns secure download URLs in this case. |
| 246 | bool requires_network_encryption; |
sorin | cb4e5e9 | 2016-08-02 21:48:40 | [diff] [blame] | 247 | |
| 248 | // True if the component allows enabling or disabling updates by group policy. |
| 249 | // This member should be set to |false| for data, non-binary components, such |
| 250 | // as CRLSet, Supervised User Whitelists, STH Set, Origin Trials, and File |
| 251 | // Type Policies. |
| 252 | bool supports_group_policy_enable_component_updates; |
Minh X. Nguyen | ca599fb | 2017-09-14 21:10:39 | [diff] [blame] | 253 | |
| 254 | // Reasons why this component/extension is disabled. |
| 255 | std::vector<int> disabled_reasons; |
Minh X. Nguyen | f8c530aa | 2017-12-13 23:54:17 | [diff] [blame] | 256 | |
| 257 | // Information about where the component/extension was installed from. |
| 258 | // For extension, this information is set from the update service, which |
| 259 | // gets the install source from the update URL. |
| 260 | std::string install_source; |
Minh X. Nguyen | fc16497e | 2018-04-24 16:05:35 | [diff] [blame] | 261 | |
| 262 | // Information about where the component/extension was loaded from. |
| 263 | // For extensions, this information is inferred from the extension |
| 264 | // registry. |
| 265 | std::string install_location; |
sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 266 | }; |
| 267 | |
Sorin Jianu | f40ab4b3 | 2017-10-06 22:53:41 | [diff] [blame] | 268 | // Called when a non-blocking call of UpdateClient completes. |
Vladislav Kuzkokov | 12eca79 | 2017-10-20 12:45:38 | [diff] [blame] | 269 | using Callback = base::OnceCallback<void(Error error)>; |
Sorin Jianu | f40ab4b3 | 2017-10-06 22:53:41 | [diff] [blame] | 270 | |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 271 | // All methods are safe to call only from the browser's main thread. Once an |
| 272 | // instance of this class is created, the reference to it must be released |
| 273 | // only after the thread pools of the browser process have been destroyed and |
| 274 | // the browser process has gone single-threaded. |
| 275 | class UpdateClient : public base::RefCounted<UpdateClient> { |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 276 | public: |
| 277 | using CrxDataCallback = |
Sorin Jianu | 7c22795b | 2018-04-26 22:16:52 | [diff] [blame^] | 278 | base::OnceCallback<std::vector<std::unique_ptr<CrxComponent>>( |
| 279 | const std::vector<std::string>& ids)>; |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 280 | |
| 281 | // Defines an interface to observe the UpdateClient. It provides |
| 282 | // notifications when state changes occur for the service itself or for the |
| 283 | // registered CRXs. |
| 284 | class Observer { |
| 285 | public: |
| 286 | enum class Events { |
| 287 | // Sent before the update client does an update check. |
sorin | 30474f0 | 2017-04-27 00:45:48 | [diff] [blame] | 288 | COMPONENT_CHECKING_FOR_UPDATES = 1, |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 289 | |
| 290 | // Sent when there is a new version of a registered CRX. After |
| 291 | // the notification is sent the CRX will be downloaded unless the |
| 292 | // update client inserts a |
| 293 | COMPONENT_UPDATE_FOUND, |
| 294 | |
| 295 | // Sent when a CRX is in the update queue but it can't be acted on |
| 296 | // right away, because the update client spaces out CRX updates due to a |
| 297 | // throttling policy. |
| 298 | COMPONENT_WAIT, |
| 299 | |
| 300 | // Sent after the new CRX has been downloaded but before the install |
| 301 | // or the upgrade is attempted. |
| 302 | COMPONENT_UPDATE_READY, |
| 303 | |
| 304 | // Sent when a CRX has been successfully updated. |
| 305 | COMPONENT_UPDATED, |
| 306 | |
Sorin Jianu | cbb10e1 | 2018-01-23 18:01:44 | [diff] [blame] | 307 | // Sent when a CRX has not been updated because there was no update |
| 308 | // available for this component. |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 309 | COMPONENT_NOT_UPDATED, |
| 310 | |
Sorin Jianu | cbb10e1 | 2018-01-23 18:01:44 | [diff] [blame] | 311 | // Sent when an error ocurred during an update for any reason, including |
| 312 | // the update check itself failed, or the download of the update payload |
| 313 | // failed, or applying the update failed. |
| 314 | COMPONENT_UPDATE_ERROR, |
| 315 | |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 316 | // Sent when CRX bytes are being downloaded. |
| 317 | COMPONENT_UPDATE_DOWNLOADING, |
| 318 | }; |
| 319 | |
| 320 | virtual ~Observer() {} |
| 321 | |
| 322 | // Called by the update client when a state change happens. |
| 323 | // If an |id| is specified, then the event is fired on behalf of the |
| 324 | // specific CRX. The implementors of this interface are |
| 325 | // expected to filter the relevant events based on the id of the CRX. |
| 326 | virtual void OnEvent(Events event, const std::string& id) = 0; |
| 327 | }; |
| 328 | |
| 329 | // Adds an observer for this class. An observer should not be added more |
| 330 | // than once. The caller retains the ownership of the observer object. |
| 331 | virtual void AddObserver(Observer* observer) = 0; |
| 332 | |
| 333 | // Removes an observer. It is safe for an observer to be removed while |
| 334 | // the observers are being notified. |
| 335 | virtual void RemoveObserver(Observer* observer) = 0; |
| 336 | |
sorin | 842703b | 2016-11-02 23:59:23 | [diff] [blame] | 337 | // Installs the specified CRX. Calls back on |callback| after the |
| 338 | // update has been handled. The |error| parameter of the |callback| |
sorin | 08d153c | 2015-10-30 00:04:20 | [diff] [blame] | 339 | // contains an error code in the case of a run-time error, or 0 if the |
| 340 | // install has been handled successfully. Overlapping calls of this function |
| 341 | // are executed concurrently, as long as the id parameter is different, |
| 342 | // meaning that installs of different components are parallelized. |
| 343 | // The |Install| function is intended to be used for foreground installs of |
| 344 | // one CRX. These cases are usually associated with on-demand install |
| 345 | // scenarios, which are triggered by user actions. Installs are never |
| 346 | // queued up. |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 347 | virtual void Install(const std::string& id, |
Sorin Jianu | a8ef73d | 2017-11-02 16:55:17 | [diff] [blame] | 348 | CrxDataCallback crx_data_callback, |
Vladislav Kuzkokov | 12eca79 | 2017-10-20 12:45:38 | [diff] [blame] | 349 | Callback callback) = 0; |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 350 | |
| 351 | // Updates the specified CRXs. Calls back on |crx_data_callback| before the |
| 352 | // update is attempted to give the caller the opportunity to provide the |
sorin | 08d153c | 2015-10-30 00:04:20 | [diff] [blame] | 353 | // instances of CrxComponent to be used for this update. The |Update| function |
| 354 | // is intended to be used for background updates of several CRXs. Overlapping |
| 355 | // calls to this function result in a queuing behavior, and the execution |
| 356 | // of each call is serialized. In addition, updates are always queued up when |
Sorin Jianu | b41a592a | 2018-03-02 16:30:27 | [diff] [blame] | 357 | // installs are running. The |is_foreground| parameter must be set to true if |
| 358 | // the invocation of this function is a result of a user initiated update. |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 359 | virtual void Update(const std::vector<std::string>& ids, |
Sorin Jianu | a8ef73d | 2017-11-02 16:55:17 | [diff] [blame] | 360 | CrxDataCallback crx_data_callback, |
Sorin Jianu | b41a592a | 2018-03-02 16:30:27 | [diff] [blame] | 361 | bool is_foreground, |
Vladislav Kuzkokov | 12eca79 | 2017-10-20 12:45:38 | [diff] [blame] | 362 | Callback callback) = 0; |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 363 | |
sorin | 805aa0311 | 2016-01-14 23:01:31 | [diff] [blame] | 364 | // Sends an uninstall ping for the CRX identified by |id| and |version|. The |
| 365 | // |reason| parameter is defined by the caller. The current implementation of |
| 366 | // this function only sends a best-effort, fire-and-forget ping. It has no |
| 367 | // other side effects regarding installs or updates done through an instance |
| 368 | // of this class. |
| 369 | virtual void SendUninstallPing(const std::string& id, |
pwnall | db0b7241 | 2016-08-19 21:39:12 | [diff] [blame] | 370 | const base::Version& version, |
sorin | 8037ac8c | 2017-04-19 16:28:00 | [diff] [blame] | 371 | int reason, |
Vladislav Kuzkokov | 12eca79 | 2017-10-20 12:45:38 | [diff] [blame] | 372 | Callback callback) = 0; |
sorin | 805aa0311 | 2016-01-14 23:01:31 | [diff] [blame] | 373 | |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 374 | // Returns status details about a CRX update. The function returns true in |
| 375 | // case of success and false in case of errors, such as |id| was |
| 376 | // invalid or not known. |
| 377 | virtual bool GetCrxUpdateState(const std::string& id, |
| 378 | CrxUpdateItem* update_item) const = 0; |
| 379 | |
sorin | 08d153c | 2015-10-30 00:04:20 | [diff] [blame] | 380 | // Returns true if the |id| is found in any running task. |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 381 | virtual bool IsUpdating(const std::string& id) const = 0; |
| 382 | |
sorin | ecaad3e | 2015-11-13 19:15:52 | [diff] [blame] | 383 | // Cancels the queued updates and makes a best effort to stop updates in |
| 384 | // progress as soon as possible. Some updates may not be stopped, in which |
| 385 | // case, the updates will run to completion. Calling this function has no |
| 386 | // effect if updates are not currently executed or queued up. |
| 387 | virtual void Stop() = 0; |
| 388 | |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 389 | protected: |
| 390 | friend class base::RefCounted<UpdateClient>; |
| 391 | |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 392 | virtual ~UpdateClient() {} |
| 393 | }; |
| 394 | |
| 395 | // Creates an instance of the update client. |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 396 | scoped_refptr<UpdateClient> UpdateClientFactory( |
Sorin Jianu | 4912633 | 2018-02-13 17:07:42 | [diff] [blame] | 397 | scoped_refptr<Configurator> config); |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 398 | |
waffles | d2d9a33 | 2016-04-09 01:59:57 | [diff] [blame] | 399 | // This must be called prior to the construction of any Configurator that |
| 400 | // contains a PrefService. |
| 401 | void RegisterPrefs(PrefRegistrySimple* registry); |
| 402 | |
Minh X. Nguyen | 3aa4069 | 2018-03-28 01:15:59 | [diff] [blame] | 403 | // This must be called prior to the construction of any Configurator that |
| 404 | // needs access to local user profiles. |
| 405 | // This function is mostly used for ExtensionUpdater, which requires update |
| 406 | // info from user profiles. |
| 407 | void RegisterProfilePrefs(PrefRegistrySimple* registry); |
| 408 | |
sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 409 | } // namespace update_client |
| 410 | |
| 411 | #endif // COMPONENTS_UPDATE_CLIENT_UPDATE_CLIENT_H_ |