OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 // Set |installed_file| to the full path to the installed |file|. |file| is | 51 // Set |installed_file| to the full path to the installed |file|. |file| is |
52 // the filename of the file in this component's CRX. Returns false if this is | 52 // the filename of the file in this component's CRX. Returns false if this is |
53 // not possible (the file has been removed or modified, or its current | 53 // not possible (the file has been removed or modified, or its current |
54 // location is unknown). Otherwise, returns true. | 54 // location is unknown). Otherwise, returns true. |
55 virtual bool GetInstalledFile(const std::string& file, | 55 virtual bool GetInstalledFile(const std::string& file, |
56 base::FilePath* installed_file) = 0; | 56 base::FilePath* installed_file) = 0; |
57 | 57 |
58 virtual ~ComponentInstaller() {} | 58 virtual ~ComponentInstaller() {} |
59 }; | 59 }; |
60 | 60 |
61 // Defines an interface to observe a CrxComponent. | |
62 class ComponentObserver { | |
63 public: | |
64 enum Events { | |
65 // Sent when the component updater starts doing update checks. | |
66 COMPONENT_UPDATER_STARTED, | |
67 | |
68 // Sent when the component updater is going to take a long nap. | |
69 COMPONENT_UPDATER_SLEEPING, | |
70 | |
71 // Sent when there is a new version of a registered component. After | |
72 // the notification is sent the component will be downloaded. | |
73 COMPONENT_UPDATE_FOUND, | |
74 | |
75 // Sent when the new component has been downloaded and an installation | |
76 // or upgrade is about to be attempted. | |
77 COMPONENT_UPDATE_READY, | |
78 | |
79 // Sent when a component has been successfully updated. | |
80 COMPONENT_UPDATED, | |
81 | |
82 // Sent when a component has not been updated following an update check: | |
83 // either there was no update available, or an update failed. | |
84 COMPONENT_NOT_UPDATED, | |
85 }; | |
86 | |
87 virtual ~ComponentObserver() {} | |
88 | |
89 // The component updater service will call this function when an interesting | |
90 // event happens for a specific component. |extra| is |event| dependent. | |
91 virtual void OnEvent(Events event, int extra) = 0; | |
92 }; | |
93 | |
94 // Describes a particular component that can be installed or updated. This | 61 // Describes a particular component that can be installed or updated. This |
95 // structure is required to register a component with the component updater. | 62 // structure is required to register a component with the component updater. |
96 // |pk_hash| is the SHA256 hash of the component's public key. If the component | 63 // |pk_hash| is the SHA256 hash of the component's public key. If the component |
97 // is to be installed then version should be "0" or "0.0", else it should be | 64 // is to be installed then version should be "0" or "0.0", else it should be |
98 // the current version. |observer|, |fingerprint|, and |name| are optional. | 65 // the current version. |fingerprint|, and |name| are optional. |
99 // |allow_background_download| specifies that the component can be background | 66 // |allow_background_download| specifies that the component can be background |
100 // downloaded in some cases. The default for this value is |true| and the value | 67 // downloaded in some cases. The default for this value is |true| and the value |
101 // can be overriden at the registration time. This is a temporary change until | 68 // can be overriden at the registration time. This is a temporary change until |
102 // the issue 340448 is resolved. | 69 // the issue 340448 is resolved. |
103 struct CrxComponent { | 70 struct CrxComponent { |
104 std::vector<uint8> pk_hash; | 71 std::vector<uint8> pk_hash; |
105 ComponentInstaller* installer; | 72 ComponentInstaller* installer; |
106 ComponentObserver* observer; | |
107 Version version; | 73 Version version; |
108 std::string fingerprint; | 74 std::string fingerprint; |
109 std::string name; | 75 std::string name; |
110 bool allow_background_download; | 76 bool allow_background_download; |
111 CrxComponent(); | 77 CrxComponent(); |
112 ~CrxComponent(); | 78 ~CrxComponent(); |
113 }; | 79 }; |
114 | 80 |
115 // Convenience structure to use with component listing / enumeration. | 81 // Convenience structure to use with component listing / enumeration. |
116 struct CrxComponentInfo { | 82 struct CrxComponentInfo { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 virtual net::URLRequestContextGetter* RequestContext() = 0; | 143 virtual net::URLRequestContextGetter* RequestContext() = 0; |
178 // True means that all ops are performed in this process. | 144 // True means that all ops are performed in this process. |
179 virtual bool InProcess() = 0; | 145 virtual bool InProcess() = 0; |
180 // True means that this client can handle delta updates. | 146 // True means that this client can handle delta updates. |
181 virtual bool DeltasEnabled() const = 0; | 147 virtual bool DeltasEnabled() const = 0; |
182 // True means that the background downloader can be used for downloading | 148 // True means that the background downloader can be used for downloading |
183 // non on-demand components. | 149 // non on-demand components. |
184 virtual bool UseBackgroundDownloader() const = 0; | 150 virtual bool UseBackgroundDownloader() const = 0; |
185 }; | 151 }; |
186 | 152 |
| 153 // Defines an interface to observe ComponentUpdateService. It provides |
| 154 // notifications when state changes occur for the service or for the |
| 155 // registered components. |
| 156 class Observer { |
| 157 public: |
| 158 enum Events { |
| 159 // Sent when the component updater starts doing update checks. |
| 160 COMPONENT_UPDATER_STARTED, |
| 161 |
| 162 // Sent when the component updater is going to take a long nap. |
| 163 COMPONENT_UPDATER_SLEEPING, |
| 164 |
| 165 // Sent when there is a new version of a registered component. After |
| 166 // the notification is sent the component will be downloaded. |
| 167 COMPONENT_UPDATE_FOUND, |
| 168 |
| 169 // Sent when the new component has been downloaded and an installation |
| 170 // or upgrade is about to be attempted. |
| 171 COMPONENT_UPDATE_READY, |
| 172 |
| 173 // Sent when a component has been successfully updated. |
| 174 COMPONENT_UPDATED, |
| 175 |
| 176 // Sent when a component has not been updated following an update check: |
| 177 // either there was no update available, or an update failed. |
| 178 COMPONENT_NOT_UPDATED, |
| 179 }; |
| 180 |
| 181 virtual ~Observer() {} |
| 182 |
| 183 // The component updater service will call this function when an interesting |
| 184 // state change happens. If the |id| is specified, then the event is fired |
| 185 // on behalf of a specific component. The implementors of this interface are |
| 186 // expected to filter the relevant events based on the component id. |
| 187 virtual void OnEvent(Events event, const std::string& id) = 0; |
| 188 }; |
| 189 |
| 190 // Adds an observer for this class. An observer should not be added more |
| 191 // than once. The caller retains the ownership of the observer object. |
| 192 virtual void AddObserver(Observer* observer) = 0; |
| 193 |
| 194 // Removes an observer. It is safe for an observer to be removed while |
| 195 // the observers are being notified. |
| 196 virtual void RemoveObserver(Observer* observer) = 0; |
| 197 |
187 // Start doing update checks and installing new versions of registered | 198 // Start doing update checks and installing new versions of registered |
188 // components after Configurator::InitialDelay() seconds. | 199 // components after Configurator::InitialDelay() seconds. |
189 virtual Status Start() = 0; | 200 virtual Status Start() = 0; |
190 | 201 |
191 // Stop doing update checks. In-flight requests and pending installations | 202 // Stop doing update checks. In-flight requests and pending installations |
192 // will not be canceled. | 203 // will not be canceled. |
193 virtual Status Stop() = 0; | 204 virtual Status Stop() = 0; |
194 | 205 |
195 // Add component to be checked for updates. You can call this method | 206 // Add component to be checked for updates. You can call this method |
196 // before calling Start(). | 207 // before calling Start(). |
(...skipping 16 matching lines...) Expand all Loading... |
213 private: | 224 private: |
214 // Ask the component updater to do an update check for a previously | 225 // Ask the component updater to do an update check for a previously |
215 // registered component, immediately. If an update or check is already | 226 // registered component, immediately. If an update or check is already |
216 // in progress, returns |kInProgress|. | 227 // in progress, returns |kInProgress|. |
217 // There is no guarantee that the item will actually be updated, | 228 // There is no guarantee that the item will actually be updated, |
218 // since an update may not be available. Listeners for the component will | 229 // since an update may not be available. Listeners for the component will |
219 // know the outcome of the check. | 230 // know the outcome of the check. |
220 virtual Status OnDemandUpdate(const std::string& component_id) = 0; | 231 virtual Status OnDemandUpdate(const std::string& component_id) = 0; |
221 }; | 232 }; |
222 | 233 |
| 234 typedef ComponentUpdateService::Observer ServiceObserver; |
| 235 |
223 // Creates the component updater. You must pass a valid |config| allocated on | 236 // Creates the component updater. You must pass a valid |config| allocated on |
224 // the heap which the component updater will own. | 237 // the heap which the component updater will own. |
225 ComponentUpdateService* ComponentUpdateServiceFactory( | 238 ComponentUpdateService* ComponentUpdateServiceFactory( |
226 ComponentUpdateService::Configurator* config); | 239 ComponentUpdateService::Configurator* config); |
227 | 240 |
228 } // namespace component_updater | 241 } // namespace component_updater |
229 | 242 |
230 #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_SERVICE_H_ | 243 #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_SERVICE_H_ |
OLD | NEW |