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_SCAN_RESULTS_PROXY_H_ 6 #define CHROME_CHROME_CLEANER_ENGINES_TARGET_ENGINE_SCAN_RESULTS_PROXY_H_ 7 8 #include "base/memory/ref_counted.h" 9 #include "base/single_thread_task_runner.h" 10 #include "chrome/chrome_cleaner/mojom/engine_sandbox.mojom.h" 11 #include "chrome/chrome_cleaner/pup_data/pup_data.h" 12 #include "mojo/public/cpp/bindings/associated_remote.h" 13 #include "mojo/public/cpp/bindings/pending_associated_remote.h" 14 15 namespace chrome_cleaner { 16 17 // Accessors to send the scan results over the Mojo connection. 18 class EngineScanResultsProxy 19 : public base::RefCountedThreadSafe<EngineScanResultsProxy> { 20 public: 21 EngineScanResultsProxy( 22 mojo::PendingAssociatedRemote<mojom::EngineScanResults> scan_results, 23 scoped_refptr<base::SingleThreadTaskRunner> task_runner); 24 task_runner()25 scoped_refptr<base::SingleThreadTaskRunner> task_runner() const { 26 return task_runner_; 27 } 28 29 void UnbindScanResults(); 30 31 // Notifies the broker process that UwS was found. Will be called on an 32 // arbitrary thread from the sandboxed engine. 33 virtual void FoundUwS(UwSId pup_id, const PUPData::PUP& pup); 34 35 // Notifies the broker process that scan is done. Will be called on an 36 // arbitrary thread from the sandboxed engine. 37 virtual void ScanDone(uint32_t result); 38 39 protected: 40 // Tests can subclass this create a proxy that's not bound to anything. 41 EngineScanResultsProxy(); 42 43 virtual ~EngineScanResultsProxy(); 44 45 private: 46 friend class base::RefCountedThreadSafe<EngineScanResultsProxy>; 47 48 // Invokes scan_results_ptr_->FoundUwS from the IPC thread. 49 void OnFoundUwS(UwSId pup_id, const PUPData::PUP& pup); 50 51 // Invokes scan_results_ptr_->Done from the IPC thread. 52 void OnDone(uint32_t result); 53 54 // An EngineScanResults that will send the results over the Mojo connection. 55 mojo::AssociatedRemote<mojom::EngineScanResults> scan_results_; 56 57 // A task runner for the IPC thread. 58 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 59 }; 60 61 } // namespace chrome_cleaner 62 63 #endif // CHROME_CHROME_CLEANER_ENGINES_TARGET_ENGINE_SCAN_RESULTS_PROXY_H_ 64