component_updater_service.h revision 03b57e008b61dfcb1fbad3aea950ae0e001748b0
103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#ifndef COMPONENTS_COMPONENT_UPDATER_COMPONENT_UPDATER_SERVICE_H_
603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#define COMPONENTS_COMPONENT_UPDATER_COMPONENT_UPDATER_SERVICE_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector>
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
116e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "base/callback_forward.h"
1246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "base/gtest_prod_util.h"
135f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "base/memory/ref_counted.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/version.h"
15eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "url/gurl.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class ComponentsUI;
185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace base {
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class DictionaryValue;
212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class FilePath;
225f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)class SequencedTaskRunner;
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
25ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdochnamespace net {
26ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdochclass URLRequestContextGetter;
270f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)class URLRequest;
280f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)}
290f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
300f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)namespace content {
310f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)class ResourceThrottle;
32ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch}
33ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace component_updater {
355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
36116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass Configurator;
37cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class OnDemandUpdater;
38eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Component specific installers must derive from this class and implement
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// OnUpdateError() and Install(). A valid instance of this class must be
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// given to ComponentUpdateService::RegisterComponent().
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ComponentInstaller {
43010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) public:
445f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // Called by the component updater on the main thread when there was a
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // problem unpacking or verifying the component. |error| is a non-zero
46c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // value which is only meaningful to the component updater.
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnUpdateError(int error) = 0;
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called by the component updater when a component has been unpacked
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // and is ready to be installed. |manifest| contains the CRX manifest
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // json dictionary and |unpack_path| contains the temporary directory
525f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // with all the unpacked CRX files. This method may be called from
535f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // a thread other than the main thread.
54c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual bool Install(const base::DictionaryValue& manifest,
552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                       const base::FilePath& unpack_path) = 0;
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
57eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Set |installed_file| to the full path to the installed |file|. |file| is
58eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // the filename of the file in this component's CRX. Returns false if this is
59eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // not possible (the file has been removed or modified, or its current
60eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // location is unknown). Otherwise, returns true.
61eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  virtual bool GetInstalledFile(const std::string& file,
62eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                                base::FilePath* installed_file) = 0;
63eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~ComponentInstaller() {}
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Describes a particular component that can be installed or updated. This
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// structure is required to register a component with the component updater.
69eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// |pk_hash| is the SHA256 hash of the component's public key. If the component
70eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// is to be installed then version should be "0" or "0.0", else it should be
715c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// the current version. |fingerprint|, and |name| are optional.
725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// |allow_background_download| specifies that the component can be background
735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// downloaded in some cases. The default for this value is |true| and the value
745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// can be overriden at the registration time. This is a temporary change until
755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// the issue 340448 is resolved.
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct CrxComponent {
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::vector<uint8> pk_hash;
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ComponentInstaller* installer;
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Version version;
80eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  std::string fingerprint;
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string name;
825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool allow_background_download;
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CrxComponent();
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ~CrxComponent();
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)struct CrxUpdateItem;
883551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The component update service is in charge of installing or upgrading
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// select parts of chrome. Each part is called a component and managed by
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// instances of CrxComponent registered using RegisterComponent(). On the
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// server, each component is packaged as a CRX which is the same format used
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// to package extensions. To the update service each component is identified
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// by its public key hash (CrxComponent::pk_hash). If there is an update
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// available and its version is bigger than (CrxComponent::version), it will
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// be downloaded, verified and unpacked. Then component-specific installer
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// ComponentInstaller::Install (of CrxComponent::installer) will be called.
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// During the normal operation of the component updater some specific
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// notifications are fired, like COMPONENT_UPDATER_STARTED and
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// COMPONENT_UPDATE_FOUND. See notification_type.h for more details.
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
1035f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// All methods are safe to call ONLY from the browser's main thread.
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ComponentUpdateService {
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
106010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  enum Status { kOk, kReplaced, kInProgress, kError };
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1085c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // Defines an interface to observe ComponentUpdateService. It provides
1095c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // notifications when state changes occur for the service or for the
1105c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // registered components.
1115c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  class Observer {
1125c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu   public:
1135c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    enum Events {
1145c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      // Sent when the component updater starts doing update checks.
1155c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      COMPONENT_UPDATER_STARTED,
1165c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
1175c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      // Sent when the component updater is going to take a long nap.
1185c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      COMPONENT_UPDATER_SLEEPING,
1195c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
1205c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      // Sent when there is a new version of a registered component. After
1215c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      // the notification is sent the component will be downloaded.
1225c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      COMPONENT_UPDATE_FOUND,
1235c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
1245c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      // Sent when the new component has been downloaded and an installation
1255c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      // or upgrade is about to be attempted.
1265c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      COMPONENT_UPDATE_READY,
1275c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
1285c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      // Sent when a component has been successfully updated.
1295c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      COMPONENT_UPDATED,
1305c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
1315c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      // Sent when a component has not been updated following an update check:
1325c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      // either there was no update available, or an update failed.
1335c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      COMPONENT_NOT_UPDATED,
134010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
135010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      // Sent when component bytes are being downloaded.
136010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      COMPONENT_UPDATE_DOWNLOADING,
1375c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    };
1385c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
1395c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    virtual ~Observer() {}
1405c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
1415c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    // The component updater service will call this function when an interesting
1425c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    // state change happens. If the |id| is specified, then the event is fired
1435c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    // on behalf of a specific component. The implementors of this interface are
1445c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    // expected to filter the relevant events based on the component id.
1455c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    virtual void OnEvent(Events event, const std::string& id) = 0;
1465c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  };
1475c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
1485c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // Adds an observer for this class. An observer should not be added more
1495c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // than once. The caller retains the ownership of the observer object.
1505c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  virtual void AddObserver(Observer* observer) = 0;
1515c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
1525c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // Removes an observer. It is safe for an observer to be removed while
1535c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // the observers are being notified.
1545c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  virtual void RemoveObserver(Observer* observer) = 0;
1555c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Start doing update checks and installing new versions of registered
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // components after Configurator::InitialDelay() seconds.
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual Status Start() = 0;
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Stop doing update checks. In-flight requests and pending installations
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // will not be canceled.
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual Status Stop() = 0;
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Add component to be checked for updates. You can call this method
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // before calling Start().
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual Status RegisterComponent(const CrxComponent& component) = 0;
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1683551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Returns a list of registered components.
16946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  virtual std::vector<std::string> GetComponentIDs() const = 0;
1702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
171cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Returns an interface for on-demand updates. On-demand updates are
172cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // proactively triggered outside the normal component update service schedule.
173cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual OnDemandUpdater& GetOnDemandUpdater() = 0;
174cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
1756e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // This method is used to trigger an on-demand update for component |crx_id|.
1766e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // This can be used when loading a resource that depends on this component.
1776e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  //
1786e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // |callback| is called on the main thread once the on-demand update is
1796e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // complete, regardless of success. |callback| may be called immediately
1806e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // within the method body.
1816e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  //
1826e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Additionally, this function implements an embedder-defined cooldown
1836e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // interval between on demand update attempts. This behavior is intended
1846e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // to be defensive against programming bugs, usually triggered by web fetches,
1856e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // where the on-demand functionality is invoked too often. If this function
1866e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // is called while still on cooldown, |callback| will be called immediately.
1876e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  virtual void MaybeThrottle(const std::string& crx_id,
1886e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                             const base::Closure& callback) = 0;
1896e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
1905f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // Returns a task runner suitable for use by component installers.
1915f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  virtual scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner() = 0;
1925f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
193cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual ~ComponentUpdateService() {}
194cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
195cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) private:
196f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Returns details about registered component in the |item| parameter. The
197f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // function returns true in case of success and false in case of errors.
198f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  virtual bool GetComponentDetails(const std::string& component_id,
199f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                                   CrxUpdateItem* item) const = 0;
20046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
201cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  friend class ::ComponentsUI;
202cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)};
203cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
204cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)typedef ComponentUpdateService::Observer ServiceObserver;
205cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
206cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class OnDemandUpdater {
207cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) public:
208cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual ~OnDemandUpdater() {}
209cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
210cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) private:
2115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  friend class OnDemandTester;
212cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  friend class ::ComponentsUI;
2131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
214cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Triggers an update check for a component. |component_id| is a value
215cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // returned by GetCrxComponentID(). If an update for this component is already
216cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // in progress, the function returns |kInProgress|. If an update is available,
217cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // the update will be applied. The caller can subscribe to component update
218cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // service notifications to get an indication about the outcome of the
21946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // on-demand update. The function does not implement any cooldown interval.
220cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual ComponentUpdateService::Status OnDemandUpdate(
221cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      const std::string& component_id) = 0;
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Creates the component updater. You must pass a valid |config| allocated on
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the heap which the component updater will own.
226116680a4aac90f2aa7413d9095a592090648e557Ben MurdochComponentUpdateService* ComponentUpdateServiceFactory(Configurator* config);
227116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
2285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}  // namespace component_updater
2295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
23003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#endif  // COMPONENTS_COMPONENT_UPDATER_COMPONENT_UPDATER_SERVICE_H_
231