| 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 |
| 11 #include "base/callback_forward.h" |
| 11 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 13 #include "base/version.h" | 14 #include "base/version.h" |
| 14 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 15 | 16 |
| 16 class ComponentsUI; | 17 class ComponentsUI; |
| 17 | 18 |
| 18 namespace base { | 19 namespace base { |
| 19 class DictionaryValue; | 20 class DictionaryValue; |
| 20 class FilePath; | 21 class FilePath; |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 // before calling Start(). | 165 // before calling Start(). |
| 165 virtual Status RegisterComponent(const CrxComponent& component) = 0; | 166 virtual Status RegisterComponent(const CrxComponent& component) = 0; |
| 166 | 167 |
| 167 // Returns a list of registered components. | 168 // Returns a list of registered components. |
| 168 virtual std::vector<std::string> GetComponentIDs() const = 0; | 169 virtual std::vector<std::string> GetComponentIDs() const = 0; |
| 169 | 170 |
| 170 // Returns an interface for on-demand updates. On-demand updates are | 171 // Returns an interface for on-demand updates. On-demand updates are |
| 171 // proactively triggered outside the normal component update service schedule. | 172 // proactively triggered outside the normal component update service schedule. |
| 172 virtual OnDemandUpdater& GetOnDemandUpdater() = 0; | 173 virtual OnDemandUpdater& GetOnDemandUpdater() = 0; |
| 173 | 174 |
| 175 // This method is used to trigger an on-demand update for component |crx_id|. |
| 176 // This can be used when loading a resource that depends on this component. |
| 177 // |
| 178 // |callback| is called on the main thread once the on-demand update is |
| 179 // complete, regardless of success. |callback| may be called immediately |
| 180 // within the method body. |
| 181 // |
| 182 // Additionally, this function implements an embedder-defined cooldown |
| 183 // interval between on demand update attempts. This behavior is intended |
| 184 // to be defensive against programming bugs, usually triggered by web fetches, |
| 185 // where the on-demand functionality is invoked too often. If this function |
| 186 // is called while still on cooldown, |callback| will be called immediately. |
| 187 virtual void MaybeThrottle(const std::string& crx_id, |
| 188 const base::Closure& callback) = 0; |
| 189 |
| 174 // Returns a task runner suitable for use by component installers. | 190 // Returns a task runner suitable for use by component installers. |
| 175 virtual scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner() = 0; | 191 virtual scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner() = 0; |
| 176 | 192 |
| 177 virtual ~ComponentUpdateService() {} | 193 virtual ~ComponentUpdateService() {} |
| 178 | 194 |
| 179 private: | 195 private: |
| 180 // Returns details about registered component in the |item| parameter. The | 196 // Returns details about registered component in the |item| parameter. The |
| 181 // function returns true in case of success and false in case of errors. | 197 // function returns true in case of success and false in case of errors. |
| 182 virtual bool GetComponentDetails(const std::string& component_id, | 198 virtual bool GetComponentDetails(const std::string& component_id, |
| 183 CrxUpdateItem* item) const = 0; | 199 CrxUpdateItem* item) const = 0; |
| 184 | 200 |
| 185 friend class ::ComponentsUI; | 201 friend class ::ComponentsUI; |
| 186 FRIEND_TEST_ALL_PREFIXES(ComponentUpdaterTest, ResourceThrottleLiveNoUpdate); | |
| 187 }; | 202 }; |
| 188 | 203 |
| 189 typedef ComponentUpdateService::Observer ServiceObserver; | 204 typedef ComponentUpdateService::Observer ServiceObserver; |
| 190 | 205 |
| 191 class OnDemandUpdater { | 206 class OnDemandUpdater { |
| 192 public: | 207 public: |
| 193 virtual ~OnDemandUpdater() {} | 208 virtual ~OnDemandUpdater() {} |
| 194 | 209 |
| 195 // Returns a network resource throttle. It means that a component will be | |
| 196 // downloaded and installed before the resource is unthrottled. This function | |
| 197 // can be called from the IO thread. The function implements a cooldown | |
| 198 // interval of 30 minutes. That means it will ineffective to call the | |
| 199 // function before the cooldown interval has passed. This behavior is intended | |
| 200 // to be defensive against programming bugs, usually triggered by web fetches, | |
| 201 // where the on-demand functionality is invoked too often. | |
| 202 virtual content::ResourceThrottle* GetOnDemandResourceThrottle( | |
| 203 net::URLRequest* request, | |
| 204 const std::string& crx_id) = 0; | |
| 205 | |
| 206 private: | 210 private: |
| 207 friend class OnDemandTester; | 211 friend class OnDemandTester; |
| 208 friend class ::ComponentsUI; | 212 friend class ::ComponentsUI; |
| 209 | 213 |
| 210 // Triggers an update check for a component. |component_id| is a value | 214 // Triggers an update check for a component. |component_id| is a value |
| 211 // returned by GetCrxComponentID(). If an update for this component is already | 215 // returned by GetCrxComponentID(). If an update for this component is already |
| 212 // in progress, the function returns |kInProgress|. If an update is available, | 216 // in progress, the function returns |kInProgress|. If an update is available, |
| 213 // the update will be applied. The caller can subscribe to component update | 217 // the update will be applied. The caller can subscribe to component update |
| 214 // service notifications to get an indication about the outcome of the | 218 // service notifications to get an indication about the outcome of the |
| 215 // on-demand update. The function does not implement any cooldown interval. | 219 // on-demand update. The function does not implement any cooldown interval. |
| 216 virtual ComponentUpdateService::Status OnDemandUpdate( | 220 virtual ComponentUpdateService::Status OnDemandUpdate( |
| 217 const std::string& component_id) = 0; | 221 const std::string& component_id) = 0; |
| 218 }; | 222 }; |
| 219 | 223 |
| 220 // Creates the component updater. You must pass a valid |config| allocated on | 224 // Creates the component updater. You must pass a valid |config| allocated on |
| 221 // the heap which the component updater will own. | 225 // the heap which the component updater will own. |
| 222 ComponentUpdateService* ComponentUpdateServiceFactory(Configurator* config); | 226 ComponentUpdateService* ComponentUpdateServiceFactory(Configurator* config); |
| 223 | 227 |
| 224 } // namespace component_updater | 228 } // namespace component_updater |
| 225 | 229 |
| 226 #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_SERVICE_H_ | 230 #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_SERVICE_H_ |
| OLD | NEW |