summaryrefslogtreecommitdiff
path: root/chromium/components/update_client/task_update.h
blob: 4df796b618e057aa5928b7bca5accc43569c407b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_UPDATE_CLIENT_TASK_UPDATE_H_
#define COMPONENTS_UPDATE_CLIENT_TASK_UPDATE_H_

#include <string>
#include <vector>

#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/threading/thread_checker.h"
#include "components/update_client/task.h"
#include "components/update_client/update_client.h"

namespace update_client {

class UpdateEngine;
enum class Error;

// Defines a specialized task for updating a group of CRXs.
class TaskUpdate : public Task {
 public:
  using Callback =
      base::OnceCallback<void(scoped_refptr<Task> task, Error error)>;

  // |update_engine| is injected here to handle the task.
  // |is_foreground| is true when the update task is initiated by the user.
  // |ids| represents the CRXs to be updated by this task.
  // |crx_data_callback| is called to get update data for the these CRXs.
  // |callback| is called to return the execution flow back to creator of
  //    this task when the task is done.
  TaskUpdate(scoped_refptr<UpdateEngine> update_engine,
             bool is_foreground,
             const std::vector<std::string>& ids,
             UpdateClient::CrxDataCallback crx_data_callback,
             Callback callback);

  void Run() override;

  void Cancel() override;

  std::vector<std::string> GetIds() const override;

 private:
  ~TaskUpdate() override;

  // Called when the task has completed either because the task has run or
  // it has been canceled.
  void TaskComplete(Error error);

  base::ThreadChecker thread_checker_;
  scoped_refptr<UpdateEngine> update_engine_;
  const bool is_foreground_;
  const std::vector<std::string> ids_;
  UpdateClient::CrxDataCallback crx_data_callback_;
  Callback callback_;

  DISALLOW_COPY_AND_ASSIGN(TaskUpdate);
};

}  // namespace update_client

#endif  // COMPONENTS_UPDATE_CLIENT_TASK_UPDATE_H_