15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 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)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_SERVICE_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_SERVICE_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector>
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/version.h"
12eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "url/gurl.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace base {
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class DictionaryValue;
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class FilePath;
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
19ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdochnamespace net {
20ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdochclass URLRequestContextGetter;
210f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)class URLRequest;
220f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)}
230f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
24f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)namespace component_updater {
25f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class OnDemandTester;
26f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
27f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
280f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)namespace content {
290f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)class ResourceThrottle;
30ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch}
31ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
32eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochclass ComponentPatcher;
33eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Component specific installers must derive from this class and implement
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// OnUpdateError() and Install(). A valid instance of this class must be
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// given to ComponentUpdateService::RegisterComponent().
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ComponentInstaller {
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public :
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called by the component updater on the UI thread when there was a
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // problem unpacking or verifying the component. |error| is a non-zero
41c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // value which is only meaningful to the component updater.
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnUpdateError(int error) = 0;
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called by the component updater when a component has been unpacked
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // and is ready to be installed. |manifest| contains the CRX manifest
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // json dictionary and |unpack_path| contains the temporary directory
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // with all the unpacked CRX files.
48c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual bool Install(const base::DictionaryValue& manifest,
492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                       const base::FilePath& unpack_path) = 0;
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
51eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Set |installed_file| to the full path to the installed |file|. |file| is
52eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // the filename of the file in this component's CRX. Returns false if this is
53eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // not possible (the file has been removed or modified, or its current
54eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // location is unknown). Otherwise, returns true.
55eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  virtual bool GetInstalledFile(const std::string& file,
56eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                                base::FilePath* installed_file) = 0;
57eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~ComponentInstaller() {}
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
61a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// Defines an interface to observe a CrxComponent.
62a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)class ComponentObserver {
63a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) public:
64a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  enum Events {
65a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    // Sent when the component updater starts doing update checks.
66a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    COMPONENT_UPDATER_STARTED,
67a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
68a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    // Sent when the component updater is going to take a long nap.
69a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    COMPONENT_UPDATER_SLEEPING,
70a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
71a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    // Sent when there is a new version of a registered component. After
72a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    // the notification is sent the component will be downloaded.
73a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    COMPONENT_UPDATE_FOUND,
74a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
75a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    // Sent when the new component has been downloaded and an installation
76a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    // or upgrade is about to be attempted.
77a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    COMPONENT_UPDATE_READY,
781e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
791e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    // Sent when a component has been successfully updated.
801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    COMPONENT_UPDATED,
811e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    // Sent when a component has not been updated following an update check:
831e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    // either there was no update available, or an update failed.
841e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    COMPONENT_NOT_UPDATED,
85a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  };
86a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
87a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  virtual ~ComponentObserver() {}
88a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
89a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // The component updater service will call this function when an interesting
90a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // event happens for a specific component. |extra| is |event| dependent.
91a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  virtual void OnEvent(Events event, int extra) = 0;
92a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)};
93a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Describes a particular component that can be installed or updated. This
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// structure is required to register a component with the component updater.
96eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// |pk_hash| is the SHA256 hash of the component's public key. If the component
97eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// is to be installed then version should be "0" or "0.0", else it should be
98a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// the current version. |observer|, |fingerprint|, and |name| are optional.
9981d04fa4ca6b8e7c49e7a3401149aa77d5b4f381Ben Murdoch// |allow_background_download| specifies that the component can be background
10081d04fa4ca6b8e7c49e7a3401149aa77d5b4f381Ben Murdoch// downloaded in some cases. The default for this value is |true| and the value
10181d04fa4ca6b8e7c49e7a3401149aa77d5b4f381Ben Murdoch// can be overriden at the registration time. This is a temporary change until
10281d04fa4ca6b8e7c49e7a3401149aa77d5b4f381Ben Murdoch// the issue 340448 is resolved.
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct CrxComponent {
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::vector<uint8> pk_hash;
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ComponentInstaller* installer;
106a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  ComponentObserver* observer;
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Version version;
108eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  std::string fingerprint;
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string name;
11081d04fa4ca6b8e7c49e7a3401149aa77d5b4f381Ben Murdoch  bool allow_background_download;
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CrxComponent();
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ~CrxComponent();
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1153551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// This convenience function returns component id of given CrxComponent.
1163551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)std::string GetCrxComponentID(const CrxComponent& component);
1173551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
1183551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Convenience structure to use with component listing / enumeration.
1193551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)struct CrxComponentInfo {
1203551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // |id| is currently derived from |CrxComponent.pk_hash|, see rest of the
1213551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // class implementation for details.
1223551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  std::string id;
1233551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  std::string version;
1243551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  std::string name;
1253551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  CrxComponentInfo();
1263551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  ~CrxComponentInfo();
1273551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)};
1283551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The component update service is in charge of installing or upgrading
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// select parts of chrome. Each part is called a component and managed by
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// instances of CrxComponent registered using RegisterComponent(). On the
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// server, each component is packaged as a CRX which is the same format used
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// to package extensions. To the update service each component is identified
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// by its public key hash (CrxComponent::pk_hash). If there is an update
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// available and its version is bigger than (CrxComponent::version), it will
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// be downloaded, verified and unpacked. Then component-specific installer
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// ComponentInstaller::Install (of CrxComponent::installer) will be called.
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// During the normal operation of the component updater some specific
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// notifications are fired, like COMPONENT_UPDATER_STARTED and
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// COMPONENT_UPDATE_FOUND. See notification_type.h for more details.
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// All methods are safe to call ONLY from chrome's UI thread.
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ComponentUpdateService {
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum Status {
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kOk,
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kReplaced,
1492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    kInProgress,
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kError
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Controls the component updater behavior.
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class Configurator {
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   public:
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual ~Configurator() {}
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Delay in seconds from calling Start() to the first update check.
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual int InitialDelay() = 0;
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Delay in seconds to every subsequent update check. 0 means don't check.
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual int NextCheckDelay() = 0;
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Delay in seconds from each task step. Used to smooth out CPU/IO usage.
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual int StepDelay() = 0;
1623551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    // Delay in seconds between applying updates for different components, if
1633551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    // several updates are available at a given time.
1643551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    virtual int StepDelayMedium() = 0;
1652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // Minimum delta time in seconds before checking again the same component.
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual int MinimumReCheckWait() = 0;
1672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // Minimum delta time in seconds before an on-demand check is allowed
1682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // for the same component.
1692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    virtual int OnDemandDelay() = 0;
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // The url that is going to be used update checks over Omaha protocol.
171eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    virtual GURL UpdateUrl() = 0;
172ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    // The url where the completion pings are sent. Invalid if and only if
173ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    // pings are disabled.
174ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    virtual GURL PingUrl() = 0;
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Parameters added to each url request. It can be null if none are needed.
176f60fc993c7b081abf77ce2ffc7fcca1142c8cb01Torne (Richard Coles)    virtual std::string ExtraRequestParams() = 0;
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // How big each update request can be. Don't go above 2000.
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual size_t UrlSizeLimit() = 0;
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // The source of contexts for all the url requests.
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual net::URLRequestContextGetter* RequestContext() = 0;
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // True means that all ops are performed in this process.
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual bool InProcess() = 0;
183eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    // Creates a new ComponentPatcher in a platform-specific way. This is useful
184eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    // for dependency injection.
185eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    virtual ComponentPatcher* CreateComponentPatcher() = 0;
186eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    // True means that this client can handle delta updates.
187eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    virtual bool DeltasEnabled() const = 0;
188a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    // True means that the background downloader can be used for downloading
189a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    // non on-demand components.
190a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    virtual bool UseBackgroundDownloader() const = 0;
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Start doing update checks and installing new versions of registered
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // components after Configurator::InitialDelay() seconds.
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual Status Start() = 0;
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Stop doing update checks. In-flight requests and pending installations
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // will not be canceled.
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual Status Stop() = 0;
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Add component to be checked for updates. You can call this method
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // before calling Start().
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual Status RegisterComponent(const CrxComponent& component) = 0;
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2053551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Returns a list of registered components.
2063551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  virtual void GetComponents(std::vector<CrxComponentInfo>* components) = 0;
2072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2080f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Returns a network resource throttle. It means that a component will be
2090f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // downloaded and installed before the resource is unthrottled. This is the
2100f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // only function callable from the IO thread.
2110f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  virtual content::ResourceThrottle* GetOnDemandResourceThrottle(
2120f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      net::URLRequest* request, const std::string& crx_id) = 0;
2130f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~ComponentUpdateService() {}
2151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
2161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  friend class ComponentsUI;
217f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  friend class component_updater::OnDemandTester;
2181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
2191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) private:
2201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Ask the component updater to do an update check for a previously
2211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // registered component, immediately. If an update or check is already
2221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // in progress, returns |kInProgress|.
2231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // There is no guarantee that the item will actually be updated,
2241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // since an update may not be available. Listeners for the component will
2251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // know the outcome of the check.
2261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual Status OnDemandUpdate(const std::string& component_id) = 0;
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Creates the component updater. You must pass a valid |config| allocated on
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the heap which the component updater will own.
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ComponentUpdateService* ComponentUpdateServiceFactory(
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ComponentUpdateService::Configurator* config);
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_SERVICE_H_
235