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)
81320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include <stdint.h>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector>
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
126e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "base/callback_forward.h"
1346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "base/gtest_prod_util.h"
145f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "base/memory/ref_counted.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/version.h"
16eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "url/gurl.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class ComponentsUI;
195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace base {
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class DictionaryValue;
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class FilePath;
235f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)class SequencedTaskRunner;
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
26ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdochnamespace net {
27ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdochclass URLRequestContextGetter;
280f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)class URLRequest;
290f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)}
300f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
310f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)namespace content {
320f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)class ResourceThrottle;
33ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch}
34ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace component_updater {
365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
37116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass Configurator;
38cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class OnDemandUpdater;
39eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Component specific installers must derive from this class and implement
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// OnUpdateError() and Install(). A valid instance of this class must be
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// given to ComponentUpdateService::RegisterComponent().
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ComponentInstaller {
44010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) public:
455f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // Called by the component updater on the main thread when there was a
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // problem unpacking or verifying the component. |error| is a non-zero
47c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // value which is only meaningful to the component updater.
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnUpdateError(int error) = 0;
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called by the component updater when a component has been unpacked
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // and is ready to be installed. |manifest| contains the CRX manifest
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // json dictionary and |unpack_path| contains the temporary directory
535f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // with all the unpacked CRX files. This method may be called from
545f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // a thread other than the main thread.
55c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual bool Install(const base::DictionaryValue& manifest,
562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                       const base::FilePath& unpack_path) = 0;
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
58eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Set |installed_file| to the full path to the installed |file|. |file| is
59eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // the filename of the file in this component's CRX. Returns false if this is
60eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // not possible (the file has been removed or modified, or its current
61eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // location is unknown). Otherwise, returns true.
62eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  virtual bool GetInstalledFile(const std::string& file,
63eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                                base::FilePath* installed_file) = 0;
64eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~ComponentInstaller() {}
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Describes a particular component that can be installed or updated. This
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// structure is required to register a component with the component updater.
70eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// |pk_hash| is the SHA256 hash of the component's public key. If the component
71eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// is to be installed then version should be "0" or "0.0", else it should be
725c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// the current version. |fingerprint|, and |name| are optional.
735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// |allow_background_download| specifies that the component can be background
745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// downloaded in some cases. The default for this value is |true| and the value
755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// can be overriden at the registration time. This is a temporary change until
765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// the issue 340448 is resolved.
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct CrxComponent {
781320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  std::vector<uint8_t> pk_hash;
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ComponentInstaller* installer;
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Version version;
81eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  std::string fingerprint;
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string name;
835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool allow_background_download;
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CrxComponent();
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ~CrxComponent();
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)struct CrxUpdateItem;
893551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The component update service is in charge of installing or upgrading
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// select parts of chrome. Each part is called a component and managed by
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// instances of CrxComponent registered using RegisterComponent(). On the
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// server, each component is packaged as a CRX which is the same format used
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// to package extensions. To the update service each component is identified
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// by its public key hash (CrxComponent::pk_hash). If there is an update
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// available and its version is bigger than (CrxComponent::version), it will
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// be downloaded, verified and unpacked. Then component-specific installer
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// ComponentInstaller::Install (of CrxComponent::installer) will be called.
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// During the normal operation of the component updater some specific
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// notifications are fired, like COMPONENT_UPDATER_STARTED and
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// COMPONENT_UPDATE_FOUND. See notification_type.h for more details.
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
1045f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// All methods are safe to call ONLY from the browser's main thread.
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ComponentUpdateService {
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
107010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  enum Status { kOk, kReplaced, kInProgress, kError };
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1095c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // Defines an interface to observe ComponentUpdateService. It provides
1105c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // notifications when state changes occur for the service or for the
1115c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // registered components.
1125c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  class Observer {
1135c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu   public:
1145c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    enum Events {
1155c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      // Sent when the component updater starts doing update checks.
1165c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      COMPONENT_UPDATER_STARTED,
1175c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
1185c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      // Sent when the component updater is going to take a long nap.
1195c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      COMPONENT_UPDATER_SLEEPING,
1205c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
1215c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      // Sent when there is a new version of a registered component. After
1225c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      // the notification is sent the component will be downloaded.
1235c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      COMPONENT_UPDATE_FOUND,
1245c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
1255c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      // Sent when the new component has been downloaded and an installation
1265c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      // or upgrade is about to be attempted.
1275c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      COMPONENT_UPDATE_READY,
1285c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
1295c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      // Sent when a component has been successfully updated.
1305c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      COMPONENT_UPDATED,
1315c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
1325c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      // Sent when a component has not been updated following an update check:
1335c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      // either there was no update available, or an update failed.
1345c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      COMPONENT_NOT_UPDATED,
135010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
136010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      // Sent when component bytes are being downloaded.
137010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      COMPONENT_UPDATE_DOWNLOADING,
1385c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    };
1395c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
1405c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    virtual ~Observer() {}
1415c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
1425c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    // The component updater service will call this function when an interesting
1435c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    // state change happens. If the |id| is specified, then the event is fired
1445c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    // on behalf of a specific component. The implementors of this interface are
1455c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    // expected to filter the relevant events based on the component id.
1465c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    virtual void OnEvent(Events event, const std::string& id) = 0;
1475c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  };
1485c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
1495c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // Adds an observer for this class. An observer should not be added more
1505c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // than once. The caller retains the ownership of the observer object.
1515c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  virtual void AddObserver(Observer* observer) = 0;
1525c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
1535c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // Removes an observer. It is safe for an observer to be removed while
1545c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // the observers are being notified.
1555c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  virtual void RemoveObserver(Observer* observer) = 0;
1565c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Start doing update checks and installing new versions of registered
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // components after Configurator::InitialDelay() seconds.
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual Status Start() = 0;
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Stop doing update checks. In-flight requests and pending installations
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // will not be canceled.
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual Status Stop() = 0;
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Add component to be checked for updates. You can call this method
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // before calling Start().
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual Status RegisterComponent(const CrxComponent& component) = 0;
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1693551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Returns a list of registered components.
17046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  virtual std::vector<std::string> GetComponentIDs() const = 0;
1712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
172cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Returns an interface for on-demand updates. On-demand updates are
173cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // proactively triggered outside the normal component update service schedule.
174cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual OnDemandUpdater& GetOnDemandUpdater() = 0;
175cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
1766e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // This method is used to trigger an on-demand update for component |crx_id|.
1776e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // This can be used when loading a resource that depends on this component.
1786e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  //
1796e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // |callback| is called on the main thread once the on-demand update is
1806e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // complete, regardless of success. |callback| may be called immediately
1816e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // within the method body.
1826e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  //
1836e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Additionally, this function implements an embedder-defined cooldown
1846e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // interval between on demand update attempts. This behavior is intended
1856e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // to be defensive against programming bugs, usually triggered by web fetches,
1866e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // where the on-demand functionality is invoked too often. If this function
1876e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // is called while still on cooldown, |callback| will be called immediately.
1886e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  virtual void MaybeThrottle(const std::string& crx_id,
1896e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                             const base::Closure& callback) = 0;
1906e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
1915f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // Returns a task runner suitable for use by component installers.
1925f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  virtual scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner() = 0;
1935f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
194cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual ~ComponentUpdateService() {}
195cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
196cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) private:
197f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Returns details about registered component in the |item| parameter. The
198f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // function returns true in case of success and false in case of errors.
199f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  virtual bool GetComponentDetails(const std::string& component_id,
200f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                                   CrxUpdateItem* item) const = 0;
20146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
202cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  friend class ::ComponentsUI;
203cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)};
204cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
205cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)typedef ComponentUpdateService::Observer ServiceObserver;
206cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
207cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class OnDemandUpdater {
208cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) public:
209cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual ~OnDemandUpdater() {}
210cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
211cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) private:
2125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  friend class OnDemandTester;
213cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  friend class ::ComponentsUI;
2141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
215cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Triggers an update check for a component. |component_id| is a value
216cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // returned by GetCrxComponentID(). If an update for this component is already
217cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // in progress, the function returns |kInProgress|. If an update is available,
218cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // the update will be applied. The caller can subscribe to component update
219cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // service notifications to get an indication about the outcome of the
22046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // on-demand update. The function does not implement any cooldown interval.
221cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual ComponentUpdateService::Status OnDemandUpdate(
222cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      const std::string& component_id) = 0;
2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Creates the component updater. You must pass a valid |config| allocated on
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the heap which the component updater will own.
227116680a4aac90f2aa7413d9095a592090648e557Ben MurdochComponentUpdateService* ComponentUpdateServiceFactory(Configurator* config);
228116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
2295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}  // namespace component_updater
2305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
23103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#endif  // COMPONENTS_COMPONENT_UPDATER_COMPONENT_UPDATER_SERVICE_H_
232