blob: 79b07c8d859d66ce1835715df30d2467db52a6c3 [file] [log] [blame]
sorin9797aba2015-04-17 17:15:031// 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
sorin9797aba2015-04-17 17:15:038#include <string>
9#include <vector>
10
11#include "base/callback.h"
Sorin Jianuf7e356502018-03-07 20:54:3412#include "base/memory/ref_counted.h"
Sorin Jianudfb12a42020-03-10 04:12:0313#include "base/memory/scoped_refptr.h"
sorin9797aba2015-04-17 17:15:0314#include "base/threading/thread_checker.h"
15#include "components/update_client/task.h"
16#include "components/update_client/update_client.h"
17
18namespace update_client {
19
20class UpdateEngine;
sorin7b8650522016-11-02 18:23:4121enum class Error;
sorin9797aba2015-04-17 17:15:0322
23// Defines a specialized task for updating a group of CRXs.
24class TaskUpdate : public Task {
25 public:
Sorin Jianuf7e356502018-03-07 20:54:3426 using Callback =
27 base::OnceCallback<void(scoped_refptr<Task> task, Error error)>;
sorin7c717622015-05-26 19:59:0928
29 // |update_engine| is injected here to handle the task.
Sorin Jianuf7e356502018-03-07 20:54:3430 // |is_foreground| is true when the update task is initiated by the user.
sorin7c717622015-05-26 19:59:0931 // |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 Jianu8cfa58712018-03-08 00:59:0535 TaskUpdate(scoped_refptr<UpdateEngine> update_engine,
sorin7c717622015-05-26 19:59:0936 bool is_foreground,
sorin9797aba2015-04-17 17:15:0337 const std::vector<std::string>& ids,
Sorin Jianua8ef73d2017-11-02 16:55:1738 UpdateClient::CrxDataCallback crx_data_callback,
Sorin Jianudfb12a42020-03-10 04:12:0339 UpdateClient::CrxStateChangeCallback crx_state_change_callback,
Vladislav Kuzkokov12eca792017-10-20 12:45:3840 Callback callback);
Sorin Jianudfb12a42020-03-10 04:12:0341 TaskUpdate(const TaskUpdate&) = delete;
42 TaskUpdate& operator=(const TaskUpdate&) = delete;
sorin9797aba2015-04-17 17:15:0343
Sorin Jianudfb12a42020-03-10 04:12:0344 // Overrides for Task.
sorin7c717622015-05-26 19:59:0945 void Run() override;
sorinecaad3e2015-11-13 19:15:5246 void Cancel() override;
sorin08d153c2015-10-30 00:04:2047 std::vector<std::string> GetIds() const override;
48
sorin9797aba2015-04-17 17:15:0349 private:
Sorin Jianuf7e356502018-03-07 20:54:3450 ~TaskUpdate() override;
51
sorinecaad3e2015-11-13 19:15:5252 // Called when the task has completed either because the task has run or
53 // it has been canceled.
sorin7b8650522016-11-02 18:23:4154 void TaskComplete(Error error);
sorin9797aba2015-04-17 17:15:0355
56 base::ThreadChecker thread_checker_;
Sorin Jianu8cfa58712018-03-08 00:59:0557 scoped_refptr<UpdateEngine> update_engine_;
sorin7c717622015-05-26 19:59:0958 const bool is_foreground_;
sorin9797aba2015-04-17 17:15:0359 const std::vector<std::string> ids_;
Sorin Jianua8ef73d2017-11-02 16:55:1760 UpdateClient::CrxDataCallback crx_data_callback_;
Sorin Jianudfb12a42020-03-10 04:12:0361 UpdateClient::CrxStateChangeCallback crx_state_change_callback_;
Vladislav Kuzkokov12eca792017-10-20 12:45:3862 Callback callback_;
sorin9797aba2015-04-17 17:15:0363};
64
65} // namespace update_client
66
67#endif // COMPONENTS_UPDATE_CLIENT_TASK_UPDATE_H_