blob: 018bb1dfafeb106a1285c3175db39c64a629d6bb [file] [log] [blame]
sorin30474f02017-04-27 00:45:481// Copyright 2017 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_send_uninstall_ping.h"
5
Sorin Jianua8ef73d2017-11-02 16:55:176#include <utility>
7
sorin30474f02017-04-27 00:45:488#include "base/bind.h"
sorin30474f02017-04-27 00:45:489#include "base/location.h"
sorin30474f02017-04-27 00:45:4810#include "base/threading/thread_task_runner_handle.h"
11#include "base/version.h"
12#include "components/update_client/update_client.h"
13#include "components/update_client/update_engine.h"
14
15namespace update_client {
16
Sorin Jianu8cfa58712018-03-08 00:59:0517TaskSendUninstallPing::TaskSendUninstallPing(
18 scoped_refptr<UpdateEngine> update_engine,
19 const std::string& id,
20 const base::Version& version,
21 int reason,
22 Callback callback)
sorin30474f02017-04-27 00:45:4823 : update_engine_(update_engine),
24 id_(id),
25 version_(version),
26 reason_(reason),
Vladislav Kuzkokov12eca792017-10-20 12:45:3827 callback_(std::move(callback)) {}
sorin30474f02017-04-27 00:45:4828
29TaskSendUninstallPing::~TaskSendUninstallPing() {
30 DCHECK(thread_checker_.CalledOnValidThread());
31}
32
33void TaskSendUninstallPing::Run() {
34 DCHECK(thread_checker_.CalledOnValidThread());
35
36 if (id_.empty()) {
37 TaskComplete(Error::INVALID_ARGUMENT);
38 return;
39 }
40
41 update_engine_->SendUninstallPing(
42 id_, version_, reason_,
Sorin Jianuf7e356502018-03-07 20:54:3443 base::BindOnce(&TaskSendUninstallPing::TaskComplete, this));
sorin30474f02017-04-27 00:45:4844}
45
46void TaskSendUninstallPing::Cancel() {
47 DCHECK(thread_checker_.CalledOnValidThread());
48
49 TaskComplete(Error::UPDATE_CANCELED);
50}
51
52std::vector<std::string> TaskSendUninstallPing::GetIds() const {
53 return std::vector<std::string>{id_};
54}
55
56void TaskSendUninstallPing::TaskComplete(Error error) {
57 DCHECK(thread_checker_.CalledOnValidThread());
58
59 base::ThreadTaskRunnerHandle::Get()->PostTask(
Sorin Jianuf7e356502018-03-07 20:54:3460 FROM_HERE,
61 base::BindOnce(std::move(callback_), scoped_refptr<Task>(this), error));
sorin30474f02017-04-27 00:45:4862}
63
64} // namespace update_client