blob: 3ac645d8a0b0b4f7041aa6fb484680e0369878bd [file] [log] [blame]
[email protected]f1050432012-02-15 01:35:461// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]2e114e732011-07-22 02:55:042// 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]2e114e732011-07-22 02:55:047
8#include <string>
9#include <vector>
10
11#include "base/version.h"
12#include "googleurl/src/gurl.h"
13
[email protected]2e114e732011-07-22 02:55:0414namespace net {
15class URLRequestContextGetter;
16}
17
18namespace base {
19class DictionaryValue;
[email protected]a3ef4832013-02-02 05:12:3320class FilePath;
[email protected]2e114e732011-07-22 02:55:0421}
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().
26class ComponentInstaller {
27 public :
[email protected]2e114e732011-07-22 02:55:0428 // 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]d4261bea2013-04-22 05:29:3930 // value which is only meaningful to the component updater.
[email protected]2e114e732011-07-22 02:55:0431 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]14ca8872013-05-02 01:51:0637 virtual bool Install(const base::DictionaryValue& manifest,
[email protected]a3ef4832013-02-02 05:12:3338 const base::FilePath& unpack_path) = 0;
[email protected]d2db5962012-05-29 10:00:0539
40 protected:
41 virtual ~ComponentInstaller() {}
[email protected]2e114e732011-07-22 02:55:0442};
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]dc06f0b2013-01-23 20:03:1649// |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]2e114e732011-07-22 02:55:0453struct CrxComponent {
[email protected]dc06f0b2013-01-23 20:03:1654 // Specifies the source url for manifest check.
55 enum UrlSource {
56 BANDAID,
57 CWS_PUBLIC,
58 CWS_SANDBOX
59 };
60
[email protected]2e114e732011-07-22 02:55:0461 std::vector<uint8> pk_hash;
62 ComponentInstaller* installer;
63 Version version;
64 std::string name;
[email protected]dc06f0b2013-01-23 20:03:1665 UrlSource source;
[email protected]2e114e732011-07-22 02:55:0466 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.
85class ComponentUpdateService {
86 public:
87 enum Status {
88 kOk,
89 kReplaced,
[email protected]ccb4feef2013-02-14 06:16:4790 kInProgress,
[email protected]2e114e732011-07-22 02:55:0491 kError
92 };
93 // Controls the component updater behavior.
94 class Configurator {
95 public:
[email protected]360b8bb2011-09-01 21:48:0696 enum Events {
97 kManifestCheck,
98 kComponentUpdated,
99 kManifestError,
100 kNetworkError,
101 kUnpackError,
102 kInstallerError
103 };
104
[email protected]2e114e732011-07-22 02:55:04105 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]ccb4feef2013-02-14 06:16:47112 // Minimum delta time in seconds before checking again the same component.
[email protected]e8f96ff2011-08-03 05:07:33113 virtual int MinimumReCheckWait() = 0;
[email protected]ccb4feef2013-02-14 06:16:47114 // Minimum delta time in seconds before an on-demand check is allowed
115 // for the same component.
116 virtual int OnDemandDelay() = 0;
[email protected]2e114e732011-07-22 02:55:04117 // The url that is going to be used update checks over Omaha protocol.
[email protected]dc06f0b2013-01-23 20:03:16118 virtual GURL UpdateUrl(CrxComponent::UrlSource source) = 0;
[email protected]926d36332011-10-05 01:06:25119 // Parameters added to each url request. It can be null if none are needed.
120 virtual const char* ExtraRequestParams() = 0;
[email protected]2e114e732011-07-22 02:55:04121 // 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]f1050432012-02-15 01:35:46125 // True means that all ops are performed in this process.
[email protected]2e114e732011-07-22 02:55:04126 virtual bool InProcess() = 0;
[email protected]360b8bb2011-09-01 21:48:06127 // 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]2e114e732011-07-22 02:55:04131 };
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]f1050432012-02-15 01:35:46138 // will not be canceled.
[email protected]2e114e732011-07-22 02:55:04139 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]ccb4feef2013-02-14 06:16:47145 // 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]2e114e732011-07-22 02:55:04156 virtual ~ComponentUpdateService() {}
157};
158
[email protected]e8f96ff2011-08-03 05:07:33159// Creates the component updater. You must pass a valid |config| allocated on
160// the heap which the component updater will own.
[email protected]2e114e732011-07-22 02:55:04161ComponentUpdateService* ComponentUpdateServiceFactory(
162 ComponentUpdateService::Configurator* config);
163
164#endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_SERVICE_H_