OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_SERVICE_H_ |
6 #define CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_SERVICE_H_ | 6 #define CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_SERVICE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/version.h" | 11 #include "base/version.h" |
12 #include "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
13 | 13 |
14 namespace net { | 14 namespace net { |
15 class URLRequestContextGetter; | 15 class URLRequestContextGetter; |
16 } | 16 } |
17 | 17 |
18 namespace base { | 18 namespace base { |
19 class DictionaryValue; | 19 class DictionaryValue; |
20 class FilePath; | 20 class FilePath; |
21 } | 21 } |
22 | 22 |
23 class ComponentPatcher; | |
24 | |
25 // Component specific installers must derive from this class and implement | 23 // Component specific installers must derive from this class and implement |
26 // OnUpdateError() and Install(). A valid instance of this class must be | 24 // OnUpdateError() and Install(). A valid instance of this class must be |
27 // given to ComponentUpdateService::RegisterComponent(). | 25 // given to ComponentUpdateService::RegisterComponent(). |
28 class ComponentInstaller { | 26 class ComponentInstaller { |
29 public : | 27 public : |
30 // Called by the component updater on the UI thread when there was a | 28 // Called by the component updater on the UI thread when there was a |
31 // problem unpacking or verifying the component. |error| is a non-zero | 29 // problem unpacking or verifying the component. |error| is a non-zero |
32 // value which is only meaningful to the component updater. | 30 // value which is only meaningful to the component updater. |
33 virtual void OnUpdateError(int error) = 0; | 31 virtual void OnUpdateError(int error) = 0; |
34 | 32 |
35 // Called by the component updater when a component has been unpacked | 33 // Called by the component updater when a component has been unpacked |
36 // and is ready to be installed. |manifest| contains the CRX manifest | 34 // and is ready to be installed. |manifest| contains the CRX manifest |
37 // json dictionary and |unpack_path| contains the temporary directory | 35 // json dictionary and |unpack_path| contains the temporary directory |
38 // with all the unpacked CRX files. | 36 // with all the unpacked CRX files. |
39 virtual bool Install(const base::DictionaryValue& manifest, | 37 virtual bool Install(const base::DictionaryValue& manifest, |
40 const base::FilePath& unpack_path) = 0; | 38 const base::FilePath& unpack_path) = 0; |
41 | 39 |
42 // Set |installed_file| to the full path to the installed |file|. |file| is | |
43 // the filename of the file in this component's CRX. Returns false if this is | |
44 // not possible (the file has been removed or modified, or its current | |
45 // location is unknown). Otherwise, returns true. | |
46 virtual bool GetInstalledFile(const std::string& file, | |
47 base::FilePath* installed_file) = 0; | |
48 | |
49 protected: | 40 protected: |
50 virtual ~ComponentInstaller() {} | 41 virtual ~ComponentInstaller() {} |
51 }; | 42 }; |
52 | 43 |
53 // Describes a particular component that can be installed or updated. This | 44 // Describes a particular component that can be installed or updated. This |
54 // structure is required to register a component with the component updater. | 45 // structure is required to register a component with the component updater. |
55 // |pk_hash| is the SHA256 hash of the component's public key. If the component | 46 // Only |name| is optional. |pk_hash| is the SHA256 hash of the component's |
56 // is to be installed then version should be "0" or "0.0", else it should be | 47 // public key. If the component is to be installed then version should be |
57 // the current version. |fingerprint| and |name| are optional. | 48 // "0" or "0.0", else it should be the current version. |
58 // |source| is by default pointing to BANDAID but if needed it can be made | 49 // |source| is by default pointing to BANDAID but if needed it can be made |
59 // to point to the webstore (CWS_PUBLIC) or to the webstore sandbox. It is | 50 // to point to the webstore (CWS_PUBLIC) or to the webstore sandbox. It is |
60 // important to note that the BANDAID source if active throught the day | 51 // important to note that the BANDAID source if active throught the day |
61 // can pre-empt updates from the other sources down the list. | 52 // can pre-empt updates from the other sources down the list. |
62 struct CrxComponent { | 53 struct CrxComponent { |
63 // Specifies the source url for manifest check. | 54 // Specifies the source url for manifest check. |
64 enum UrlSource { | 55 enum UrlSource { |
65 BANDAID, | 56 BANDAID, |
66 CWS_PUBLIC, | 57 CWS_PUBLIC, |
67 CWS_SANDBOX, | 58 CWS_SANDBOX |
68 }; | 59 }; |
69 | 60 |
70 std::vector<uint8> pk_hash; | 61 std::vector<uint8> pk_hash; |
71 ComponentInstaller* installer; | 62 ComponentInstaller* installer; |
72 Version version; | 63 Version version; |
73 std::string fingerprint; | |
74 std::string name; | 64 std::string name; |
75 UrlSource source; | 65 UrlSource source; |
76 CrxComponent(); | 66 CrxComponent(); |
77 ~CrxComponent(); | 67 ~CrxComponent(); |
78 }; | 68 }; |
79 | 69 |
80 // The component update service is in charge of installing or upgrading | 70 // The component update service is in charge of installing or upgrading |
81 // select parts of chrome. Each part is called a component and managed by | 71 // select parts of chrome. Each part is called a component and managed by |
82 // instances of CrxComponent registered using RegisterComponent(). On the | 72 // instances of CrxComponent registered using RegisterComponent(). On the |
83 // server, each component is packaged as a CRX which is the same format used | 73 // server, each component is packaged as a CRX which is the same format used |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 // How big each update request can be. Don't go above 2000. | 121 // How big each update request can be. Don't go above 2000. |
132 virtual size_t UrlSizeLimit() = 0; | 122 virtual size_t UrlSizeLimit() = 0; |
133 // The source of contexts for all the url requests. | 123 // The source of contexts for all the url requests. |
134 virtual net::URLRequestContextGetter* RequestContext() = 0; | 124 virtual net::URLRequestContextGetter* RequestContext() = 0; |
135 // True means that all ops are performed in this process. | 125 // True means that all ops are performed in this process. |
136 virtual bool InProcess() = 0; | 126 virtual bool InProcess() = 0; |
137 // The component updater will call this function when an interesting event | 127 // The component updater will call this function when an interesting event |
138 // happens. It should be used mostly as a place to add application specific | 128 // happens. It should be used mostly as a place to add application specific |
139 // logging or telemetry. |extra| is |event| dependent. | 129 // logging or telemetry. |extra| is |event| dependent. |
140 virtual void OnEvent(Events event, int extra) = 0; | 130 virtual void OnEvent(Events event, int extra) = 0; |
141 // Creates a new ComponentPatcher in a platform-specific way. This is useful | |
142 // for dependency injection. | |
143 virtual ComponentPatcher* CreateComponentPatcher() = 0; | |
144 // True means that this client can handle delta updates. | |
145 virtual bool DeltasEnabled() const = 0; | |
146 }; | 131 }; |
147 | 132 |
148 // Start doing update checks and installing new versions of registered | 133 // Start doing update checks and installing new versions of registered |
149 // components after Configurator::InitialDelay() seconds. | 134 // components after Configurator::InitialDelay() seconds. |
150 virtual Status Start() = 0; | 135 virtual Status Start() = 0; |
151 | 136 |
152 // Stop doing update checks. In-flight requests and pending installations | 137 // Stop doing update checks. In-flight requests and pending installations |
153 // will not be canceled. | 138 // will not be canceled. |
154 virtual Status Stop() = 0; | 139 virtual Status Stop() = 0; |
155 | 140 |
(...skipping 14 matching lines...) Expand all Loading... |
170 | 155 |
171 virtual ~ComponentUpdateService() {} | 156 virtual ~ComponentUpdateService() {} |
172 }; | 157 }; |
173 | 158 |
174 // Creates the component updater. You must pass a valid |config| allocated on | 159 // Creates the component updater. You must pass a valid |config| allocated on |
175 // the heap which the component updater will own. | 160 // the heap which the component updater will own. |
176 ComponentUpdateService* ComponentUpdateServiceFactory( | 161 ComponentUpdateService* ComponentUpdateServiceFactory( |
177 ComponentUpdateService::Configurator* config); | 162 ComponentUpdateService::Configurator* config); |
178 | 163 |
179 #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_SERVICE_H_ | 164 #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_SERVICE_H_ |
OLD | NEW |