task_send_uninstall_ping.cc 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // 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. #include <utility>
  6. #include "base/bind.h"
  7. #include "base/location.h"
  8. #include "base/threading/thread_task_runner_handle.h"
  9. #include "base/version.h"
  10. #include "components/update_client/update_client.h"
  11. #include "components/update_client/update_engine.h"
  12. namespace update_client {
  13. TaskSendUninstallPing::TaskSendUninstallPing(
  14. scoped_refptr<UpdateEngine> update_engine,
  15. const CrxComponent& crx_component,
  16. int reason,
  17. Callback callback)
  18. : update_engine_(update_engine),
  19. crx_component_(crx_component),
  20. reason_(reason),
  21. callback_(std::move(callback)) {}
  22. TaskSendUninstallPing::~TaskSendUninstallPing() {
  23. DCHECK(thread_checker_.CalledOnValidThread());
  24. }
  25. void TaskSendUninstallPing::Run() {
  26. DCHECK(thread_checker_.CalledOnValidThread());
  27. if (crx_component_.app_id.empty()) {
  28. TaskComplete(Error::INVALID_ARGUMENT);
  29. return;
  30. }
  31. update_engine_->SendUninstallPing(
  32. crx_component_, reason_,
  33. base::BindOnce(&TaskSendUninstallPing::TaskComplete, this));
  34. }
  35. void TaskSendUninstallPing::Cancel() {
  36. DCHECK(thread_checker_.CalledOnValidThread());
  37. TaskComplete(Error::UPDATE_CANCELED);
  38. }
  39. std::vector<std::string> TaskSendUninstallPing::GetIds() const {
  40. return std::vector<std::string>{crx_component_.app_id};
  41. }
  42. void TaskSendUninstallPing::TaskComplete(Error error) {
  43. DCHECK(thread_checker_.CalledOnValidThread());
  44. base::ThreadTaskRunnerHandle::Get()->PostTask(
  45. FROM_HERE,
  46. base::BindOnce(std::move(callback_), scoped_refptr<Task>(this), error));
  47. }
  48. } // namespace update_client