sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 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. |
| 4 | |
| 5 | #ifndef COMPONENTS_UPDATE_CLIENT_TASK_UPDATE_H_ |
| 6 | #define COMPONENTS_UPDATE_CLIENT_TASK_UPDATE_H_ |
| 7 | |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
| 11 | #include "base/callback.h" |
Sorin Jianu | f7e35650 | 2018-03-07 20:54:34 | [diff] [blame] | 12 | #include "base/memory/ref_counted.h" |
Sorin Jianu | dfb12a4 | 2020-03-10 04:12:03 | [diff] [blame] | 13 | #include "base/memory/scoped_refptr.h" |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 14 | #include "base/threading/thread_checker.h" |
| 15 | #include "components/update_client/task.h" |
| 16 | #include "components/update_client/update_client.h" |
| 17 | |
| 18 | namespace update_client { |
| 19 | |
| 20 | class UpdateEngine; |
sorin | 7b865052 | 2016-11-02 18:23:41 | [diff] [blame] | 21 | enum class Error; |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 22 | |
| 23 | // Defines a specialized task for updating a group of CRXs. |
| 24 | class TaskUpdate : public Task { |
| 25 | public: |
Sorin Jianu | f7e35650 | 2018-03-07 20:54:34 | [diff] [blame] | 26 | using Callback = |
| 27 | base::OnceCallback<void(scoped_refptr<Task> task, Error error)>; |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 28 | |
| 29 | // |update_engine| is injected here to handle the task. |
Sorin Jianu | f7e35650 | 2018-03-07 20:54:34 | [diff] [blame] | 30 | // |is_foreground| is true when the update task is initiated by the user. |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 31 | // |ids| represents the CRXs to be updated by this task. |
| 32 | // |crx_data_callback| is called to get update data for the these CRXs. |
| 33 | // |callback| is called to return the execution flow back to creator of |
| 34 | // this task when the task is done. |
Sorin Jianu | 8cfa5871 | 2018-03-08 00:59:05 | [diff] [blame] | 35 | TaskUpdate(scoped_refptr<UpdateEngine> update_engine, |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 36 | bool is_foreground, |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 37 | const std::vector<std::string>& ids, |
Sorin Jianu | a8ef73d | 2017-11-02 16:55:17 | [diff] [blame] | 38 | UpdateClient::CrxDataCallback crx_data_callback, |
Sorin Jianu | dfb12a4 | 2020-03-10 04:12:03 | [diff] [blame] | 39 | UpdateClient::CrxStateChangeCallback crx_state_change_callback, |
Vladislav Kuzkokov | 12eca79 | 2017-10-20 12:45:38 | [diff] [blame] | 40 | Callback callback); |
Sorin Jianu | dfb12a4 | 2020-03-10 04:12:03 | [diff] [blame] | 41 | TaskUpdate(const TaskUpdate&) = delete; |
| 42 | TaskUpdate& operator=(const TaskUpdate&) = delete; |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 43 | |
Sorin Jianu | dfb12a4 | 2020-03-10 04:12:03 | [diff] [blame] | 44 | // Overrides for Task. |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 45 | void Run() override; |
sorin | ecaad3e | 2015-11-13 19:15:52 | [diff] [blame] | 46 | void Cancel() override; |
sorin | 08d153c | 2015-10-30 00:04:20 | [diff] [blame] | 47 | std::vector<std::string> GetIds() const override; |
| 48 | |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 49 | private: |
Sorin Jianu | f7e35650 | 2018-03-07 20:54:34 | [diff] [blame] | 50 | ~TaskUpdate() override; |
| 51 | |
sorin | ecaad3e | 2015-11-13 19:15:52 | [diff] [blame] | 52 | // Called when the task has completed either because the task has run or |
| 53 | // it has been canceled. |
sorin | 7b865052 | 2016-11-02 18:23:41 | [diff] [blame] | 54 | void TaskComplete(Error error); |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 55 | |
| 56 | base::ThreadChecker thread_checker_; |
Sorin Jianu | 8cfa5871 | 2018-03-08 00:59:05 | [diff] [blame] | 57 | scoped_refptr<UpdateEngine> update_engine_; |
sorin | 7c71762 | 2015-05-26 19:59:09 | [diff] [blame] | 58 | const bool is_foreground_; |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 59 | const std::vector<std::string> ids_; |
Sorin Jianu | a8ef73d | 2017-11-02 16:55:17 | [diff] [blame] | 60 | UpdateClient::CrxDataCallback crx_data_callback_; |
Sorin Jianu | dfb12a4 | 2020-03-10 04:12:03 | [diff] [blame] | 61 | UpdateClient::CrxStateChangeCallback crx_state_change_callback_; |
Vladislav Kuzkokov | 12eca79 | 2017-10-20 12:45:38 | [diff] [blame] | 62 | Callback callback_; |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | } // namespace update_client |
| 66 | |
| 67 | #endif // COMPONENTS_UPDATE_CLIENT_TASK_UPDATE_H_ |