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 #ifndef CHROME_CHROME_CLEANER_ENGINES_TARGET_ENGINE_CLEANUP_RESULTS_PROXY_H_ 6 #define CHROME_CHROME_CLEANER_ENGINES_TARGET_ENGINE_CLEANUP_RESULTS_PROXY_H_ 7 8 #include <stdint.h> 9 10 #include "base/memory/ref_counted.h" 11 #include "base/single_thread_task_runner.h" 12 #include "chrome/chrome_cleaner/mojom/engine_sandbox.mojom.h" 13 #include "mojo/public/cpp/bindings/associated_remote.h" 14 #include "mojo/public/cpp/bindings/pending_associated_remote.h" 15 16 namespace chrome_cleaner { 17 18 // Accessors to send the cleanup results over the Mojo connection. 19 class EngineCleanupResultsProxy 20 : public base::RefCountedThreadSafe<EngineCleanupResultsProxy> { 21 public: 22 EngineCleanupResultsProxy( 23 mojo::PendingAssociatedRemote<mojom::EngineCleanupResults> 24 cleanup_results, 25 scoped_refptr<base::SingleThreadTaskRunner> task_runner); 26 task_runner()27 scoped_refptr<base::SingleThreadTaskRunner> task_runner() const { 28 return task_runner_; 29 } 30 31 void UnbindCleanupResults(); 32 33 // Sends a cleanup done signal to the broken process. Will be called on an 34 // arbitrary thread from the sandboxed engine. 35 void CleanupDone(uint32_t result); 36 37 protected: 38 // Tests can subclass this create a proxy that's not bound to anything. 39 EngineCleanupResultsProxy(); 40 41 private: 42 friend class base::RefCountedThreadSafe<EngineCleanupResultsProxy>; 43 ~EngineCleanupResultsProxy(); 44 45 // Invokes cleanup_results_->Done from the IPC thread. 46 void OnDone(uint32_t result); 47 48 // An EngineCleanupResults that will send the results over the Mojo 49 // connection. 50 mojo::AssociatedRemote<mojom::EngineCleanupResults> cleanup_results_; 51 52 // A task runner for the IPC thread. 53 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 54 }; 55 56 } // namespace chrome_cleaner 57 58 #endif // CHROME_CHROME_CLEANER_ENGINES_TARGET_ENGINE_CLEANUP_RESULTS_PROXY_H_ 59