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
|
// 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.
#include "components/update_client/action_runner.h"
#include <utility>
#include "base/bind.h"
#include "base/files/file_path.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/task/thread_pool.h"
#include "base/threading/thread_task_runner_handle.h"
#include "components/update_client/component.h"
#include "components/update_client/task_traits.h"
namespace update_client {
ActionRunner::ActionRunner(const Component& component)
: component_(component),
main_task_runner_(base::ThreadTaskRunnerHandle::Get()) {}
ActionRunner::~ActionRunner() {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
}
void ActionRunner::Run(Callback callback) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
auto action_handler = component_.crx_component()->action_handler;
if (!action_handler) {
DVLOG(1) << component_.action_run() << " is missing an action handler";
main_task_runner_->PostTask(
FROM_HERE, base::BindOnce(std::move(callback), false, -1, 0));
return;
}
callback_ = std::move(callback);
// Resolve an absolute path for the file referred by the run action.
base::ThreadPool::PostTaskAndReplyWithResult(
FROM_HERE, kTaskTraits,
base::BindOnce(
[](const Component* component) {
base::FilePath crx_path;
component->crx_component()->installer->GetInstalledFile(
component->action_run(), &crx_path);
return crx_path;
},
base::Unretained(&component_)),
base::BindOnce(&ActionRunner::Handle, base::Unretained(this)));
}
void ActionRunner::Handle(const base::FilePath& crx_path) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
auto action_handler = component_.crx_component()->action_handler;
DCHECK(action_handler);
action_handler->Handle(crx_path, component_.session_id(),
std::move(callback_));
}
} // namespace update_client
|