Update V8 to version 4.7.1.
[chromium-blink-merge.git] / components / component_updater / component_updater_service.h
blobe667445c45abb608969f204830b7a14c07d04065
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_COMPONENT_UPDATER_COMPONENT_UPDATER_SERVICE_H_
6 #define COMPONENTS_COMPONENT_UPDATER_COMPONENT_UPDATER_SERVICE_H_
8 #include <stdint.h>
10 #include <string>
11 #include <vector>
13 #include "base/callback_forward.h"
14 #include "base/gtest_prod_util.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/version.h"
18 #include "components/update_client/update_client.h"
19 #include "url/gurl.h"
21 class ComponentsUI;
22 class SupervisedUserWhitelistService;
24 namespace base {
25 class DictionaryValue;
26 class FilePath;
27 class SequencedTaskRunner;
30 namespace content {
31 class ResourceThrottle;
34 namespace net {
35 class URLRequestContextGetter;
36 class URLRequest;
39 namespace update_client {
40 class ComponentInstaller;
41 class Configurator;
42 struct CrxComponent;
43 struct CrxUpdateItem;
46 namespace component_updater {
48 class OnDemandUpdater;
50 using Configurator = update_client::Configurator;
51 using CrxComponent = update_client::CrxComponent;
52 using CrxUpdateItem = update_client::CrxUpdateItem;
54 // The component update service is in charge of installing or upgrading
55 // select parts of chrome. Each part is called a component and managed by
56 // instances of CrxComponent registered using RegisterComponent(). On the
57 // server, each component is packaged as a CRX which is the same format used
58 // to package extensions. To the update service each component is identified
59 // by its public key hash (CrxComponent::pk_hash). If there is an update
60 // available and its version is bigger than (CrxComponent::version), it will
61 // be downloaded, verified and unpacked. Then component-specific installer
62 // ComponentInstaller::Install (of CrxComponent::installer) will be called.
64 // During the normal operation of the component updater some specific
65 // notifications are fired, like COMPONENT_UPDATER_STARTED and
66 // COMPONENT_UPDATE_FOUND. See notification_type.h for more details.
68 // All methods are safe to call ONLY from the browser's main thread.
69 class ComponentUpdateService {
70 public:
71 using Observer = update_client::UpdateClient::Observer;
73 // Adds an observer for this class. An observer should not be added more
74 // than once. The caller retains the ownership of the observer object.
75 virtual void AddObserver(Observer* observer) = 0;
77 // Removes an observer. It is safe for an observer to be removed while
78 // the observers are being notified.
79 virtual void RemoveObserver(Observer* observer) = 0;
81 // Add component to be checked for updates.
82 virtual bool RegisterComponent(const CrxComponent& component) = 0;
84 // Unregisters the component with the given ID. This means that the component
85 // is not going to be included in future update checks. If a download or
86 // update operation for the component is currently in progress, it will
87 // silently finish without triggering the next step.
88 // Note that the installer for the component is responsible for removing any
89 // existing versions of the component from disk. Returns true if the
90 // uninstall has completed successfully and the component files have been
91 // removed, or if the uninstalled has been deferred because the component
92 // is being updated. Returns false if the component id is not known or the
93 /// uninstall encountered an error.
94 virtual bool UnregisterComponent(const std::string& id) = 0;
96 // Returns a list of registered components.
97 virtual std::vector<std::string> GetComponentIDs() const = 0;
99 // Returns an interface for on-demand updates. On-demand updates are
100 // proactively triggered outside the normal component update service schedule.
101 virtual OnDemandUpdater& GetOnDemandUpdater() = 0;
103 // This method is used to trigger an on-demand update for component |id|.
104 // This can be used when loading a resource that depends on this component.
106 // |callback| is called on the main thread once the on-demand update is
107 // complete, regardless of success. |callback| may be called immediately
108 // within the method body.
110 // Additionally, this function implements an embedder-defined cooldown
111 // interval between on demand update attempts. This behavior is intended
112 // to be defensive against programming bugs, usually triggered by web fetches,
113 // where the on-demand functionality is invoked too often. If this function
114 // is called while still on cooldown, |callback| will be called immediately.
115 virtual void MaybeThrottle(const std::string& id,
116 const base::Closure& callback) = 0;
118 // Returns a task runner suitable for use by component installers.
119 virtual scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner() = 0;
121 virtual ~ComponentUpdateService() {}
123 private:
124 // Returns details about registered component in the |item| parameter. The
125 // function returns true in case of success and false in case of errors.
126 virtual bool GetComponentDetails(const std::string& id,
127 CrxUpdateItem* item) const = 0;
129 friend class ::ComponentsUI;
132 using ServiceObserver = ComponentUpdateService::Observer;
134 class OnDemandUpdater {
135 public:
136 virtual ~OnDemandUpdater() {}
138 private:
139 friend class OnDemandTester;
140 friend class SupervisedUserWhitelistInstaller;
141 friend class ::ComponentsUI;
143 // Triggers an update check for a component. |id| is a value
144 // returned by GetCrxComponentID(). If an update for this component is already
145 // in progress, the function returns |kInProgress|. If an update is available,
146 // the update will be applied. The caller can subscribe to component update
147 // service notifications to get an indication about the outcome of the
148 // on-demand update. The function does not implement any cooldown interval.
149 // TODO(sorin): improve this API so that the result of this non-blocking
150 // call is provided by a callback.
151 virtual bool OnDemandUpdate(const std::string& id) = 0;
154 // Creates the component updater.
155 scoped_ptr<ComponentUpdateService> ComponentUpdateServiceFactory(
156 const scoped_refptr<Configurator>& config);
158 } // namespace component_updater
160 #endif // COMPONENTS_COMPONENT_UPDATER_COMPONENT_UPDATER_SERVICE_H_