summaryrefslogtreecommitdiff
path: root/chromium/components/update_client/action_runner.h
blob: b63571c3174760cfce4d3646e96e992eba1492f6 (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
67
// Copyright 2017 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_ACTION_RUNNER_H_
#define COMPONENTS_UPDATE_CLIENT_ACTION_RUNNER_H_

#include <stdint.h>

#include <memory>
#include <utility>
#include <vector>

#include "base/callback.h"
#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/threading/thread_checker.h"
#include "components/update_client/component_unpacker.h"

namespace base {
class CommandLine;
class Process;
class SingleThreadTaskRunner;
}

namespace update_client {

class Component;

class ActionRunner {
 public:
  using Callback =
      base::OnceCallback<void(bool succeeded, int error_code, int extra_code1)>;

  explicit ActionRunner(const Component& component);
  ~ActionRunner();

  void Run(Callback run_complete);

 private:
  void Unpack(std::unique_ptr<service_manager::Connector> connector);
  void UnpackComplete(const ComponentUnpacker::Result& result);

  void RunCommand(const base::CommandLine& cmdline);

  base::CommandLine MakeCommandLine(const base::FilePath& unpack_path) const;

  void WaitForCommand(base::Process process);

  const Component& component_;

  // Used to post callbacks to the main thread.
  scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;

  // Contains the unpack path for the component associated with the run action.
  base::FilePath unpack_path_;

  Callback run_complete_;

  THREAD_CHECKER(thread_checker_);
  DISALLOW_COPY_AND_ASSIGN(ActionRunner);
};

}  // namespace update_client

#endif  // COMPONENTS_UPDATE_CLIENT_ACTION_RUNNER_H_