[email protected] | f105043 | 2012-02-15 01:35:46 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 2e114e73 | 2011-07-22 02:55:04 | [diff] [blame] | 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 CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_SERVICE_H_ |
| 6 | #define CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_SERVICE_H_ |
[email protected] | 2e114e73 | 2011-07-22 02:55:04 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
| 11 | #include "base/version.h" |
| 12 | #include "googleurl/src/gurl.h" |
| 13 | |
[email protected] | 2e114e73 | 2011-07-22 02:55:04 | [diff] [blame] | 14 | namespace net { |
| 15 | class URLRequestContextGetter; |
| 16 | } |
| 17 | |
| 18 | namespace base { |
| 19 | class DictionaryValue; |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 20 | class FilePath; |
[email protected] | 2e114e73 | 2011-07-22 02:55:04 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | // Component specific installers must derive from this class and implement |
| 24 | // OnUpdateError() and Install(). A valid instance of this class must be |
| 25 | // given to ComponentUpdateService::RegisterComponent(). |
| 26 | class ComponentInstaller { |
| 27 | public : |
[email protected] | 2e114e73 | 2011-07-22 02:55:04 | [diff] [blame] | 28 | // Called by the component updater on the UI thread when there was a |
| 29 | // problem unpacking or verifying the component. |error| is a non-zero |
[email protected] | d4261bea | 2013-04-22 05:29:39 | [diff] [blame] | 30 | // value which is only meaningful to the component updater. |
[email protected] | 2e114e73 | 2011-07-22 02:55:04 | [diff] [blame] | 31 | virtual void OnUpdateError(int error) = 0; |
| 32 | |
| 33 | // Called by the component updater when a component has been unpacked |
| 34 | // and is ready to be installed. |manifest| contains the CRX manifest |
| 35 | // json dictionary and |unpack_path| contains the temporary directory |
| 36 | // with all the unpacked CRX files. |
[email protected] | 14ca887 | 2013-05-02 01:51:06 | [diff] [blame] | 37 | virtual bool Install(const base::DictionaryValue& manifest, |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 38 | const base::FilePath& unpack_path) = 0; |
[email protected] | d2db596 | 2012-05-29 10:00:05 | [diff] [blame] | 39 | |
| 40 | protected: |
| 41 | virtual ~ComponentInstaller() {} |
[email protected] | 2e114e73 | 2011-07-22 02:55:04 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | // Describes a particular component that can be installed or updated. This |
| 45 | // structure is required to register a component with the component updater. |
| 46 | // Only |name| is optional. |pk_hash| is the SHA256 hash of the component's |
| 47 | // public key. If the component is to be installed then version should be |
| 48 | // "0" or "0.0", else it should be the current version. |
[email protected] | dc06f0b | 2013-01-23 20:03:16 | [diff] [blame] | 49 | // |source| is by default pointing to BANDAID but if needed it can be made |
| 50 | // to point to the webstore (CWS_PUBLIC) or to the webstore sandbox. It is |
| 51 | // important to note that the BANDAID source if active throught the day |
| 52 | // can pre-empt updates from the other sources down the list. |
[email protected] | 2e114e73 | 2011-07-22 02:55:04 | [diff] [blame] | 53 | struct CrxComponent { |
[email protected] | dc06f0b | 2013-01-23 20:03:16 | [diff] [blame] | 54 | // Specifies the source url for manifest check. |
| 55 | enum UrlSource { |
| 56 | BANDAID, |
| 57 | CWS_PUBLIC, |
| 58 | CWS_SANDBOX |
| 59 | }; |
| 60 | |
[email protected] | 2e114e73 | 2011-07-22 02:55:04 | [diff] [blame] | 61 | std::vector<uint8> pk_hash; |
| 62 | ComponentInstaller* installer; |
| 63 | Version version; |
| 64 | std::string name; |
[email protected] | dc06f0b | 2013-01-23 20:03:16 | [diff] [blame] | 65 | UrlSource source; |
[email protected] | 2e114e73 | 2011-07-22 02:55:04 | [diff] [blame] | 66 | CrxComponent(); |
| 67 | ~CrxComponent(); |
| 68 | }; |
| 69 | |
| 70 | // The component update service is in charge of installing or upgrading |
| 71 | // select parts of chrome. Each part is called a component and managed by |
| 72 | // instances of CrxComponent registered using RegisterComponent(). On the |
| 73 | // server, each component is packaged as a CRX which is the same format used |
| 74 | // to package extensions. To the update service each component is identified |
| 75 | // by its public key hash (CrxComponent::pk_hash). If there is an update |
| 76 | // available and its version is bigger than (CrxComponent::version), it will |
| 77 | // be downloaded, verified and unpacked. Then component-specific installer |
| 78 | // ComponentInstaller::Install (of CrxComponent::installer) will be called. |
| 79 | // |
| 80 | // During the normal operation of the component updater some specific |
| 81 | // notifications are fired, like COMPONENT_UPDATER_STARTED and |
| 82 | // COMPONENT_UPDATE_FOUND. See notification_type.h for more details. |
| 83 | // |
| 84 | // All methods are safe to call ONLY from chrome's UI thread. |
| 85 | class ComponentUpdateService { |
| 86 | public: |
| 87 | enum Status { |
| 88 | kOk, |
| 89 | kReplaced, |
[email protected] | ccb4feef | 2013-02-14 06:16:47 | [diff] [blame] | 90 | kInProgress, |
[email protected] | 2e114e73 | 2011-07-22 02:55:04 | [diff] [blame] | 91 | kError |
| 92 | }; |
| 93 | // Controls the component updater behavior. |
| 94 | class Configurator { |
| 95 | public: |
[email protected] | 360b8bb | 2011-09-01 21:48:06 | [diff] [blame] | 96 | enum Events { |
| 97 | kManifestCheck, |
| 98 | kComponentUpdated, |
| 99 | kManifestError, |
| 100 | kNetworkError, |
| 101 | kUnpackError, |
| 102 | kInstallerError |
| 103 | }; |
| 104 | |
[email protected] | 2e114e73 | 2011-07-22 02:55:04 | [diff] [blame] | 105 | virtual ~Configurator() {} |
| 106 | // Delay in seconds from calling Start() to the first update check. |
| 107 | virtual int InitialDelay() = 0; |
| 108 | // Delay in seconds to every subsequent update check. 0 means don't check. |
| 109 | virtual int NextCheckDelay() = 0; |
| 110 | // Delay in seconds from each task step. Used to smooth out CPU/IO usage. |
| 111 | virtual int StepDelay() = 0; |
[email protected] | ccb4feef | 2013-02-14 06:16:47 | [diff] [blame] | 112 | // Minimum delta time in seconds before checking again the same component. |
[email protected] | e8f96ff | 2011-08-03 05:07:33 | [diff] [blame] | 113 | virtual int MinimumReCheckWait() = 0; |
[email protected] | ccb4feef | 2013-02-14 06:16:47 | [diff] [blame] | 114 | // Minimum delta time in seconds before an on-demand check is allowed |
| 115 | // for the same component. |
| 116 | virtual int OnDemandDelay() = 0; |
[email protected] | 2e114e73 | 2011-07-22 02:55:04 | [diff] [blame] | 117 | // The url that is going to be used update checks over Omaha protocol. |
[email protected] | dc06f0b | 2013-01-23 20:03:16 | [diff] [blame] | 118 | virtual GURL UpdateUrl(CrxComponent::UrlSource source) = 0; |
[email protected] | 926d3633 | 2011-10-05 01:06:25 | [diff] [blame] | 119 | // Parameters added to each url request. It can be null if none are needed. |
| 120 | virtual const char* ExtraRequestParams() = 0; |
[email protected] | 2e114e73 | 2011-07-22 02:55:04 | [diff] [blame] | 121 | // How big each update request can be. Don't go above 2000. |
| 122 | virtual size_t UrlSizeLimit() = 0; |
| 123 | // The source of contexts for all the url requests. |
| 124 | virtual net::URLRequestContextGetter* RequestContext() = 0; |
[email protected] | f105043 | 2012-02-15 01:35:46 | [diff] [blame] | 125 | // True means that all ops are performed in this process. |
[email protected] | 2e114e73 | 2011-07-22 02:55:04 | [diff] [blame] | 126 | virtual bool InProcess() = 0; |
[email protected] | 360b8bb | 2011-09-01 21:48:06 | [diff] [blame] | 127 | // The component updater will call this function when an interesting event |
| 128 | // happens. It should be used mostly as a place to add application specific |
| 129 | // logging or telemetry. |extra| is |event| dependent. |
| 130 | virtual void OnEvent(Events event, int extra) = 0; |
[email protected] | 2e114e73 | 2011-07-22 02:55:04 | [diff] [blame] | 131 | }; |
| 132 | |
| 133 | // Start doing update checks and installing new versions of registered |
| 134 | // components after Configurator::InitialDelay() seconds. |
| 135 | virtual Status Start() = 0; |
| 136 | |
| 137 | // Stop doing update checks. In-flight requests and pending installations |
[email protected] | f105043 | 2012-02-15 01:35:46 | [diff] [blame] | 138 | // will not be canceled. |
[email protected] | 2e114e73 | 2011-07-22 02:55:04 | [diff] [blame] | 139 | virtual Status Stop() = 0; |
| 140 | |
| 141 | // Add component to be checked for updates. You can call this method |
| 142 | // before calling Start(). |
| 143 | virtual Status RegisterComponent(const CrxComponent& component) = 0; |
| 144 | |
[email protected] | ccb4feef | 2013-02-14 06:16:47 | [diff] [blame] | 145 | // Ask the component updater to do an update check for a previously |
| 146 | // registered component, soon. If an update or check is already in progress, |
| 147 | // returns |kInProgress|. The same component cannot be checked repeatedly |
| 148 | // in a short interval either (returns |kError| if so). |
| 149 | // There is no guarantee that the item will actually be updated, |
| 150 | // since another item may be chosen to be updated. Since there is |
| 151 | // no time guarantee, there is no notification if the item is not updated. |
| 152 | // However, the ComponentInstaller should know if an update succeeded |
| 153 | // via the Install() hook. |
| 154 | virtual Status CheckForUpdateSoon(const CrxComponent& component) = 0; |
| 155 | |
[email protected] | 2e114e73 | 2011-07-22 02:55:04 | [diff] [blame] | 156 | virtual ~ComponentUpdateService() {} |
| 157 | }; |
| 158 | |
[email protected] | e8f96ff | 2011-08-03 05:07:33 | [diff] [blame] | 159 | // Creates the component updater. You must pass a valid |config| allocated on |
| 160 | // the heap which the component updater will own. |
[email protected] | 2e114e73 | 2011-07-22 02:55:04 | [diff] [blame] | 161 | ComponentUpdateService* ComponentUpdateServiceFactory( |
| 162 | ComponentUpdateService::Configurator* config); |
| 163 | |
| 164 | #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_SERVICE_H_ |