Extension syncing: Introduce a NeedsSync pref
[chromium-blink-merge.git] / components / component_updater / component_updater_service_internal.h
blobc91332cbe1c5d7fe08a3223fad4a8396a9dd338f
1 // Copyright 2015 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_INTERNAL_H_
6 #define COMPONENTS_COMPONENT_UPDATER_COMPONENT_UPDATER_SERVICE_INTERNAL_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/sequenced_task_runner.h"
15 #include "base/single_thread_task_runner.h"
16 #include "base/threading/thread_checker.h"
17 #include "components/component_updater/timer.h"
19 namespace component_updater {
21 class OnDemandUpdater;
23 using CrxInstaller = update_client::CrxInstaller;
24 using UpdateClient = update_client::UpdateClient;
26 class CrxUpdateService : public ComponentUpdateService,
27 public ComponentUpdateService::Observer,
28 public OnDemandUpdater {
29 using Observer = ComponentUpdateService::Observer;
31 public:
32 CrxUpdateService(const scoped_refptr<Configurator>& config,
33 const scoped_refptr<UpdateClient>& update_client);
34 ~CrxUpdateService() override;
36 // Overrides for ComponentUpdateService.
37 void AddObserver(Observer* observer) override;
38 void RemoveObserver(Observer* observer) override;
39 bool RegisterComponent(const CrxComponent& component) override;
40 bool UnregisterComponent(const std::string& id) override;
41 std::vector<std::string> GetComponentIDs() const override;
42 OnDemandUpdater& GetOnDemandUpdater() override;
43 void MaybeThrottle(const std::string& id,
44 const base::Closure& callback) override;
45 scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner() override;
46 bool OnDemandUpdate(const std::string& id) override;
47 bool GetComponentDetails(const std::string& id,
48 CrxUpdateItem* item) const override;
50 // Overrides for Observer.
51 void OnEvent(Events event, const std::string& id) override;
53 private:
54 void Start();
55 void Stop();
57 bool CheckForUpdates();
59 bool OnDemandUpdateInternal(const std::string& id);
60 bool OnDemandUpdateWithCooldown(const std::string& id);
62 bool DoUnregisterComponent(const CrxComponent& component);
64 const CrxComponent* GetComponent(const std::string& id) const;
66 const CrxUpdateItem* GetComponentState(const std::string& id) const;
68 void OnUpdate(const std::vector<std::string>& ids,
69 std::vector<CrxComponent>* components);
70 void OnUpdateComplete(int error);
72 base::ThreadChecker thread_checker_;
74 scoped_refptr<Configurator> config_;
76 scoped_refptr<UpdateClient> update_client_;
78 Timer timer_;
80 // A collection of every registered component.
81 using Components = std::map<std::string, CrxComponent>;
82 Components components_;
84 // Maintains the order in which components have been registered. The position
85 // of a component id in this sequence indicates the priority of the component.
86 // The sooner the component gets registered, the higher its priority, and
87 // the closer this component is to the beginning of the vector.
88 std::vector<std::string> components_order_;
90 // Contains the components pending unregistration. If a component is not
91 // busy installing or updating, it can be unregistered right away. Otherwise,
92 // the component will be lazily unregistered after the its operations have
93 // completed.
94 std::vector<std::string> components_pending_unregistration_;
96 // Contains the active resource throttles associated with a given component.
97 using ResourceThrottleCallbacks = std::multimap<std::string, base::Closure>;
98 ResourceThrottleCallbacks ready_callbacks_;
100 // Contains the state of the component.
101 using ComponentStates = std::map<std::string, CrxUpdateItem>;
102 ComponentStates component_states_;
104 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
106 DISALLOW_COPY_AND_ASSIGN(CrxUpdateService);
109 } // namespace component_updater
111 #endif // COMPONENTS_COMPONENT_UPDATER_COMPONENT_UPDATER_SERVICE_INTERNAL_H_