blob: 733649b5711f343ef9cdd23a8ed7986cdc067c00 [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#include "components/update_client/task_update.h"
5
Sorin Jianua8ef73d2017-11-02 16:55:176#include <utility>
7
sorin9797aba2015-04-17 17:15:038#include "base/bind.h"
sorin9797aba2015-04-17 17:15:039#include "base/location.h"
gab7966d312016-05-11 20:35:0110#include "base/threading/thread_task_runner_handle.h"
sorinecaad3e2015-11-13 19:15:5211#include "components/update_client/update_client.h"
sorin9797aba2015-04-17 17:15:0312#include "components/update_client/update_engine.h"
13
14namespace update_client {
15
Sorin Jianudfb12a42020-03-10 04:12:0316TaskUpdate::TaskUpdate(
17 scoped_refptr<UpdateEngine> update_engine,
18 bool is_foreground,
19 const std::vector<std::string>& ids,
20 UpdateClient::CrxDataCallback crx_data_callback,
21 UpdateClient::CrxStateChangeCallback crx_state_change_callback,
22 Callback callback)
sorin9797aba2015-04-17 17:15:0323 : update_engine_(update_engine),
sorin7c717622015-05-26 19:59:0924 is_foreground_(is_foreground),
sorin9797aba2015-04-17 17:15:0325 ids_(ids),
Sorin Jianua8ef73d2017-11-02 16:55:1726 crx_data_callback_(std::move(crx_data_callback)),
Sorin Jianudfb12a42020-03-10 04:12:0327 crx_state_change_callback_(crx_state_change_callback),
Vladislav Kuzkokov12eca792017-10-20 12:45:3828 callback_(std::move(callback)) {}
sorin9797aba2015-04-17 17:15:0329
30TaskUpdate::~TaskUpdate() {
31 DCHECK(thread_checker_.CalledOnValidThread());
32}
33
sorin7c717622015-05-26 19:59:0934void TaskUpdate::Run() {
sorin9797aba2015-04-17 17:15:0335 DCHECK(thread_checker_.CalledOnValidThread());
36
asargente90363b2015-09-09 22:40:0737 if (ids_.empty()) {
sorin7b8650522016-11-02 18:23:4138 TaskComplete(Error::INVALID_ARGUMENT);
asargente90363b2015-09-09 22:40:0739 return;
40 }
sorin9797aba2015-04-17 17:15:0341
Sorin Jianuf7e356502018-03-07 20:54:3442 update_engine_->Update(is_foreground_, ids_, std::move(crx_data_callback_),
Sorin Jianudfb12a42020-03-10 04:12:0343 std::move(crx_state_change_callback_),
Sorin Jianuf7e356502018-03-07 20:54:3444 base::BindOnce(&TaskUpdate::TaskComplete, this));
sorinecaad3e2015-11-13 19:15:5245}
46
47void TaskUpdate::Cancel() {
48 DCHECK(thread_checker_.CalledOnValidThread());
49
sorin7b8650522016-11-02 18:23:4150 TaskComplete(Error::UPDATE_CANCELED);
sorin9797aba2015-04-17 17:15:0351}
52
sorin08d153c2015-10-30 00:04:2053std::vector<std::string> TaskUpdate::GetIds() const {
54 return ids_;
55}
56
sorin7b8650522016-11-02 18:23:4157void TaskUpdate::TaskComplete(Error error) {
sorin9797aba2015-04-17 17:15:0358 DCHECK(thread_checker_.CalledOnValidThread());
59
sorinecaad3e2015-11-13 19:15:5260 base::ThreadTaskRunnerHandle::Get()->PostTask(
Sorin Jianudfb12a42020-03-10 04:12:0361 FROM_HERE,
62 base::BindOnce(std::move(callback_), base::WrapRefCounted(this), error));
sorin9797aba2015-04-17 17:15:0363}
64
65} // namespace update_client