Update mojo sdk to rev c02a28868825edfa57ab77947b8cb15e741c5598
[chromium-blink-merge.git] / components / update_client / update_client_internal.h
blob74041a06baf45b82a6c4076c3992bf6515c1501a
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_UPDATE_CLIENT_UPDATE_CLIENT_INTERNAL_H_
6 #define COMPONENTS_UPDATE_CLIENT_UPDATE_CLIENT_INTERNAL_H_
8 #include "components/update_client/update_client.h"
10 #include <queue>
11 #include <set>
12 #include <string>
13 #include <vector>
15 #include "base/macros.h"
16 #include "base/observer_list.h"
17 #include "base/threading/thread_checker.h"
18 #include "components/update_client/crx_downloader.h"
19 #include "components/update_client/update_checker.h"
21 namespace base {
22 class SequencedTaskRunner;
23 class SingleThreadTaskRunner;
24 } // namespace base
26 namespace update_client {
28 class Configurator;
29 class PingManager;
30 class Task;
31 struct TaskContext;
32 class UpdateEngine;
34 class UpdateClientImpl : public UpdateClient {
35 public:
36 UpdateClientImpl(const scoped_refptr<Configurator>& config,
37 scoped_ptr<PingManager> ping_manager,
38 UpdateChecker::Factory update_checker_factory,
39 CrxDownloader::Factory crx_downloader_factory);
41 // Overrides for UpdateClient.
42 void AddObserver(Observer* observer) override;
43 void RemoveObserver(Observer* observer) override;
44 void Install(const std::string& id,
45 const CrxDataCallback& crx_data_callback,
46 const CompletionCallback& completion_callback) override;
47 void Update(const std::vector<std::string>& ids,
48 const CrxDataCallback& crx_data_callback,
49 const CompletionCallback& completion_callback) override;
50 bool GetCrxUpdateState(const std::string& id,
51 CrxUpdateItem* update_item) const override;
52 bool IsUpdating(const std::string& id) const override;
54 private:
55 ~UpdateClientImpl() override;
57 void RunTask(Task* task);
58 void OnTaskComplete(const CompletionCallback& completion_callback,
59 Task* task,
60 int error);
62 void NotifyObservers(Observer::Events event, const std::string& id);
64 base::ThreadChecker thread_checker_;
66 scoped_refptr<Configurator> config_;
68 // Contains the tasks that are queued up.
69 std::queue<Task*> task_queue_;
71 // Contains all tasks in progress.
72 std::set<Task*> tasks_;
74 // TODO(sorin): try to make the ping manager an observer of the service.
75 scoped_ptr<PingManager> ping_manager_;
76 scoped_ptr<UpdateEngine> update_engine_;
78 base::ObserverList<Observer> observer_list_;
80 // Used to post responses back to the main thread.
81 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
82 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
84 DISALLOW_COPY_AND_ASSIGN(UpdateClientImpl);
87 } // namespace update_client
89 #endif // COMPONENTS_UPDATE_CLIENT_UPDATE_CLIENT_INTERNAL_H_