[M120 Migration][VD] Enable direct rendering for TVPlus
[platform/framework/web/chromium-efl.git] / components / component_updater / component_updater_service_internal.h
1 // Copyright 2015 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_COMPONENT_UPDATER_COMPONENT_UPDATER_SERVICE_INTERNAL_H_
6 #define COMPONENTS_COMPONENT_UPDATER_COMPONENT_UPDATER_SERVICE_INTERNAL_H_
7
8 #include <map>
9 #include <memory>
10 #include <string>
11 #include <vector>
12
13 #include "base/containers/flat_map.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/sequence_checker.h"
16 #include "components/component_updater/update_scheduler.h"
17 #include "components/update_client/persisted_data.h"
18 #include "third_party/abseil-cpp/absl/types/optional.h"
19
20 namespace base {
21 class TimeTicks;
22 }
23
24 namespace update_client {
25 enum class Error;
26 }
27
28 namespace component_updater {
29
30 class OnDemandUpdater;
31
32 class CrxUpdateService : public ComponentUpdateService,
33                          public ComponentUpdateService::Observer,
34                          public OnDemandUpdater {
35   using Observer = ComponentUpdateService::Observer;
36
37  public:
38   CrxUpdateService(scoped_refptr<Configurator> config,
39                    std::unique_ptr<UpdateScheduler> scheduler,
40                    scoped_refptr<update_client::UpdateClient> update_client,
41                    const std::string& brand);
42
43   CrxUpdateService(const CrxUpdateService&) = delete;
44   CrxUpdateService& operator=(const CrxUpdateService&) = delete;
45
46   ~CrxUpdateService() override;
47
48   // Overrides for ComponentUpdateService.
49   void AddObserver(Observer* observer) override;
50   void RemoveObserver(Observer* observer) override;
51   bool RegisterComponent(const ComponentRegistration& component) override;
52   bool UnregisterComponent(const std::string& id) override;
53   std::vector<std::string> GetComponentIDs() const override;
54   std::vector<ComponentInfo> GetComponents() const override;
55   OnDemandUpdater& GetOnDemandUpdater() override;
56   void MaybeThrottle(const std::string& id,
57                      base::OnceClosure callback) override;
58   bool GetComponentDetails(const std::string& id,
59                            CrxUpdateItem* item) const override;
60   base::Version GetRegisteredVersion(const std::string& app_id) override;
61
62   // Overrides for Observer.
63   void OnEvent(Events event, const std::string& id) override;
64
65   // Overrides for OnDemandUpdater.
66   void OnDemandUpdate(const std::string& id,
67                       Priority priority,
68                       Callback callback) override;
69
70  private:
71   void Start();
72   void Stop();
73
74   bool CheckForUpdates(UpdateScheduler::OnFinishedCallback on_finished);
75
76   void OnDemandUpdateInternal(const std::string& id,
77                               Priority priority,
78                               Callback callback);
79   bool OnDemandUpdateWithCooldown(const std::string& id);
80
81   bool DoUnregisterComponent(const std::string& id);
82
83   CrxComponent ToCrxComponent(const ComponentRegistration& component) const;
84
85   absl::optional<ComponentRegistration> GetComponent(
86       const std::string& id) const;
87
88   const CrxUpdateItem* GetComponentState(const std::string& id) const;
89
90   void GetCrxComponents(
91       const std::vector<std::string>& ids,
92       base::OnceCallback<void(const std::vector<absl::optional<CrxComponent>>&)>
93           callback);
94   void OnUpdateComplete(Callback callback,
95                         const base::TimeTicks& start_time,
96                         update_client::Error error);
97
98   SEQUENCE_CHECKER(sequence_checker_);
99
100   scoped_refptr<Configurator> config_;
101   std::unique_ptr<UpdateScheduler> scheduler_;
102   scoped_refptr<update_client::UpdateClient> update_client_;
103
104   std::string brand_;
105
106   // A collection of every registered component.
107   using Components = base::flat_map<std::string, ComponentRegistration>;
108   Components components_;
109
110   // Maintains the order in which components have been registered. The position
111   // of a component id in this sequence indicates the priority of the component.
112   // The sooner the component gets registered, the higher its priority, and
113   // the closer this component is to the beginning of the vector.
114   std::vector<std::string> components_order_;
115
116   // Contains the components pending unregistration. If a component is not
117   // busy installing or updating, it can be unregistered right away. Otherwise,
118   // the component will be lazily unregistered after the its operations have
119   // completed.
120   std::vector<std::string> components_pending_unregistration_;
121
122   // Contains the active resource throttles associated with a given component.
123   using ResourceThrottleCallbacks =
124       std::multimap<std::string, base::OnceClosure>;
125   ResourceThrottleCallbacks ready_callbacks_;
126
127   // Contains the state of the component.
128   using ComponentStates = std::map<std::string, CrxUpdateItem>;
129   ComponentStates component_states_;
130
131   // Contains a map of media types to the component that implements a handler
132   // for that media type. Only the most recently-registered component is
133   // tracked. May include the IDs of un-registered components.
134   std::map<std::string, std::string> component_ids_by_mime_type_;
135 };
136
137 }  // namespace component_updater
138
139 #endif  // COMPONENTS_COMPONENT_UPDATER_COMPONENT_UPDATER_SERVICE_INTERNAL_H_