1 // Copyright 2019 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 
5 #include "chrome/chrome_cleaner/engines/target/engine_cleanup_results_proxy.h"
6 
7 #include <utility>
8 
9 #include "base/bind.h"
10 #include "base/logging.h"
11 
12 namespace chrome_cleaner {
13 
EngineCleanupResultsProxy(mojo::PendingAssociatedRemote<mojom::EngineCleanupResults> cleanup_results,scoped_refptr<base::SingleThreadTaskRunner> task_runner)14 EngineCleanupResultsProxy::EngineCleanupResultsProxy(
15     mojo::PendingAssociatedRemote<mojom::EngineCleanupResults> cleanup_results,
16     scoped_refptr<base::SingleThreadTaskRunner> task_runner)
17     : task_runner_(task_runner) {
18   cleanup_results_.Bind(std::move(cleanup_results));
19 }
20 
UnbindCleanupResults()21 void EngineCleanupResultsProxy::UnbindCleanupResults() {
22   cleanup_results_.reset();
23 }
24 
CleanupDone(uint32_t result)25 void EngineCleanupResultsProxy::CleanupDone(uint32_t result) {
26   task_runner_->PostTask(
27       FROM_HERE,
28       base::BindOnce(&EngineCleanupResultsProxy::OnDone, this, result));
29 }
30 
31 EngineCleanupResultsProxy::EngineCleanupResultsProxy() = default;
32 
33 EngineCleanupResultsProxy::~EngineCleanupResultsProxy() = default;
34 
OnDone(uint32_t result)35 void EngineCleanupResultsProxy::OnDone(uint32_t result) {
36   if (!cleanup_results_.is_bound()) {
37     LOG(ERROR) << "Cleanup result reported after the engine was shut down";
38     return;
39   }
40   cleanup_results_->Done(result);
41 }
42 
43 }  // namespace chrome_cleaner
44