Commit 2bf6c6a2 authored by Henrique Ferreiro's avatar Henrique Ferreiro Committed by Commit Bot

Migrate engine_requests.mojom to the new Mojo types

Convert the implementation and all users of the
chrome_cleaner::mojom::EngineRequests interface.

Bug: 955171
Change-Id: I32b6bc3f8d1e1f7c55f688c8dca5df85b9097472
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1855980
Commit-Queue: Henrique Ferreiro <hferreiro@igalia.com>
Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarJoe Mason <joenotcharles@chromium.org>
Cr-Commit-Position: refs/heads/master@{#711526}
parent 5f161562
......@@ -349,8 +349,8 @@ void EngineClient::StartScanAsync(
mojo::PendingAssociatedRemote<mojom::EngineFileRequests> file_requests;
sandbox_file_requests_->Bind(&file_requests);
mojom::EngineRequestsAssociatedPtrInfo engine_requests_info;
sandbox_requests_->Bind(&engine_requests_info);
mojo::PendingAssociatedRemote<mojom::EngineRequests> engine_requests;
sandbox_requests_->Bind(&engine_requests);
// Create a receiver to the EngineScanResults interface that will receive
// results and pass them on to |found_callback| and |done_callback|.
......@@ -368,7 +368,7 @@ void EngineClient::StartScanAsync(
// |done_callback|) with further results.
(*engine_commands_)
->StartScan(enabled_uws, enabled_locations, include_details,
std::move(file_requests), std::move(engine_requests_info),
std::move(file_requests), std::move(engine_requests),
std::move(scan_results),
CallbackWithErrorHandling(std::move(result_callback)));
}
......@@ -411,8 +411,8 @@ void EngineClient::StartCleanupAsync(const std::vector<UwSId>& enabled_uws,
mojo::PendingAssociatedRemote<mojom::EngineFileRequests> file_requests;
sandbox_file_requests_->Bind(&file_requests);
mojom::EngineRequestsAssociatedPtrInfo engine_requests_info;
sandbox_requests_->Bind(&engine_requests_info);
mojo::PendingAssociatedRemote<mojom::EngineRequests> engine_requests;
sandbox_requests_->Bind(&engine_requests);
mojom::CleanerEngineRequestsAssociatedPtrInfo cleaner_engine_requests_info;
sandbox_cleaner_requests_->Bind(&cleaner_engine_requests_info);
......@@ -427,11 +427,10 @@ void EngineClient::StartCleanupAsync(const std::vector<UwSId>& enabled_uws,
interface_metadata_observer_->ObserveCall(CURRENT_FILE_AND_METHOD);
(*engine_commands_)
->StartCleanup(enabled_uws, std::move(file_requests),
std::move(engine_requests_info),
std::move(cleaner_engine_requests_info),
std::move(cleanup_results),
CallbackWithErrorHandling(std::move(result_callback)));
->StartCleanup(
enabled_uws, std::move(file_requests), std::move(engine_requests),
std::move(cleaner_engine_requests_info), std::move(cleanup_results),
CallbackWithErrorHandling(std::move(result_callback)));
}
uint32_t EngineClient::Finalize() {
......
......@@ -64,18 +64,17 @@ EngineRequestsImpl::EngineRequestsImpl(
scoped_refptr<MojoTaskRunner> mojo_task_runner,
InterfaceMetadataObserver* metadata_observer)
: mojo_task_runner_(mojo_task_runner),
metadata_observer_(metadata_observer),
binding_(this) {}
metadata_observer_(metadata_observer) {}
EngineRequestsImpl::~EngineRequestsImpl() = default;
void EngineRequestsImpl::Bind(
mojom::EngineRequestsAssociatedPtrInfo* ptr_info) {
if (binding_.is_bound())
binding_.Unbind();
mojo::PendingAssociatedRemote<mojom::EngineRequests>* remote) {
if (receiver_.is_bound())
receiver_.reset();
binding_.Bind(mojo::MakeRequest(ptr_info));
// There's no need to call set_connection_error_handler on this since it's an
receiver_.Bind(remote->InitWithNewEndpointAndPassReceiver());
// There's no need to call set_disconnect_handler on this since it's an
// associated interface. Any errors will be handled on the main EngineCommands
// interface.
}
......
......@@ -10,10 +10,11 @@
#include "base/process/process_handle.h"
#include "base/strings/string16.h"
#include "chrome/chrome_cleaner/engines/broker/interface_metadata_observer.h"
#include "chrome/chrome_cleaner/mojom/engine_requests.mojom.h"
#include "chrome/chrome_cleaner/ipc/mojo_task_runner.h"
#include "chrome/chrome_cleaner/mojom/engine_requests.mojom.h"
#include "chrome/chrome_cleaner/strings/string16_embedded_nulls.h"
#include "mojo/public/cpp/bindings/associated_binding.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_associated_remote.h"
namespace chrome_cleaner {
......@@ -23,7 +24,7 @@ class EngineRequestsImpl : public mojom::EngineRequests {
InterfaceMetadataObserver* metadata_observer = nullptr);
~EngineRequestsImpl() override;
void Bind(mojom::EngineRequestsAssociatedPtrInfo* ptr_info);
void Bind(mojo::PendingAssociatedRemote<mojom::EngineRequests>* remote);
// mojom::EngineRequests
void SandboxGetFileAttributes(
......@@ -87,7 +88,7 @@ class EngineRequestsImpl : public mojom::EngineRequests {
scoped_refptr<MojoTaskRunner> mojo_task_runner_;
InterfaceMetadataObserver* metadata_observer_ = nullptr;
mojo::AssociatedBinding<mojom::EngineRequests> binding_;
mojo::AssociatedReceiver<mojom::EngineRequests> receiver_{this};
};
} // namespace chrome_cleaner
......
......@@ -20,8 +20,6 @@ namespace chrome_cleaner {
using mojom::CleanerEngineRequestsAssociatedPtr;
using mojom::CleanerEngineRequestsAssociatedPtrInfo;
using mojom::EngineRequestsAssociatedPtr;
using mojom::EngineRequestsAssociatedPtrInfo;
namespace {
......@@ -86,7 +84,8 @@ void EngineCommandsImpl::StartScan(
const std::vector<UwS::TraceLocation>& enabled_trace_locations,
bool include_details,
mojo::PendingAssociatedRemote<mojom::EngineFileRequests> file_requests,
mojom::EngineRequestsAssociatedPtrInfo sandboxed_engine_requests,
mojo::PendingAssociatedRemote<mojom::EngineRequests>
sandboxed_engine_requests,
mojo::PendingAssociatedRemote<mojom::EngineScanResults> scan_results,
StartScanCallback callback) {
ScopedCrashStageRecorder crash_stage(__func__);
......@@ -96,11 +95,9 @@ void EngineCommandsImpl::StartScan(
base::MakeRefCounted<EngineFileRequestsProxy>(std::move(file_requests),
task_runner_);
EngineRequestsAssociatedPtr engine_requests_ptr;
engine_requests_ptr.Bind(std::move(sandboxed_engine_requests));
scoped_refptr<EngineRequestsProxy> engine_requests_proxy =
base::MakeRefCounted<EngineRequestsProxy>(std::move(engine_requests_ptr),
task_runner_);
base::MakeRefCounted<EngineRequestsProxy>(
std::move(sandboxed_engine_requests), task_runner_);
// Create an EngineScanResults proxy to send results back over the
// Mojo connection.
......@@ -117,7 +114,8 @@ void EngineCommandsImpl::StartScan(
void EngineCommandsImpl::StartCleanup(
const std::vector<UwSId>& enabled_uws,
mojo::PendingAssociatedRemote<mojom::EngineFileRequests> file_requests,
mojom::EngineRequestsAssociatedPtrInfo sandboxed_engine_requests,
mojo::PendingAssociatedRemote<mojom::EngineRequests>
sandboxed_engine_requests,
mojom::CleanerEngineRequestsAssociatedPtrInfo
sandboxed_cleaner_engine_requests,
mojo::PendingAssociatedRemote<mojom::EngineCleanupResults> cleanup_results,
......@@ -129,11 +127,9 @@ void EngineCommandsImpl::StartCleanup(
base::MakeRefCounted<EngineFileRequestsProxy>(std::move(file_requests),
task_runner_);
EngineRequestsAssociatedPtr engine_requests_ptr;
engine_requests_ptr.Bind(std::move(sandboxed_engine_requests));
scoped_refptr<EngineRequestsProxy> engine_requests_proxy =
base::MakeRefCounted<EngineRequestsProxy>(std::move(engine_requests_ptr),
task_runner_);
base::MakeRefCounted<EngineRequestsProxy>(
std::move(sandboxed_engine_requests), task_runner_);
CleanerEngineRequestsAssociatedPtr cleaner_engine_requests_ptr;
cleaner_engine_requests_ptr.Bind(
......
......@@ -41,13 +41,15 @@ class EngineCommandsImpl : public mojom::EngineCommands {
const std::vector<UwS::TraceLocation>& enabled_trace_locations,
bool include_details,
mojo::PendingAssociatedRemote<mojom::EngineFileRequests> file_requests,
mojom::EngineRequestsAssociatedPtrInfo sandboxed_engine_requests,
mojo::PendingAssociatedRemote<mojom::EngineRequests>
sandboxed_engine_requests,
mojo::PendingAssociatedRemote<mojom::EngineScanResults> scan_results,
StartScanCallback callback) override;
void StartCleanup(
const std::vector<UwSId>& enabled_uws,
mojo::PendingAssociatedRemote<mojom::EngineFileRequests> file_requests,
mojom::EngineRequestsAssociatedPtrInfo sandboxed_engine_requests,
mojo::PendingAssociatedRemote<mojom::EngineRequests>
sandboxed_engine_requests,
mojom::CleanerEngineRequestsAssociatedPtrInfo
sandboxed_cleaner_engine_requests,
mojo::PendingAssociatedRemote<mojom::EngineCleanupResults>
......
......@@ -93,13 +93,12 @@ void SaveUserInformationCallback(bool* out_success,
} // namespace
EngineRequestsProxy::EngineRequestsProxy(
mojom::EngineRequestsAssociatedPtr engine_requests_ptr,
mojo::PendingAssociatedRemote<mojom::EngineRequests> engine_requests,
scoped_refptr<base::SingleThreadTaskRunner> task_runner)
: engine_requests_ptr_(std::move(engine_requests_ptr)),
task_runner_(task_runner) {}
: engine_requests_(std::move(engine_requests)), task_runner_(task_runner) {}
void EngineRequestsProxy::UnbindRequestsPtr() {
engine_requests_ptr_.reset();
void EngineRequestsProxy::UnbindRequestsRemote() {
engine_requests_.reset();
}
uint32_t EngineRequestsProxy::GetFileAttributes(const base::FilePath& file_path,
......@@ -300,50 +299,50 @@ EngineRequestsProxy::~EngineRequestsProxy() = default;
MojoCallStatus EngineRequestsProxy::SandboxGetFileAttributes(
const base::FilePath& file_path,
mojom::EngineRequests::SandboxGetFileAttributesCallback result_callback) {
if (!engine_requests_ptr_.is_bound()) {
LOG(ERROR) << "SandboxGetFileAttributes called without bound pointer";
if (!engine_requests_.is_bound()) {
LOG(ERROR) << "SandboxGetFileAttributes called without bound remote";
return MojoCallStatus::Failure(SandboxErrorCode::INTERNAL_ERROR);
}
engine_requests_ptr_->SandboxGetFileAttributes(file_path,
std::move(result_callback));
engine_requests_->SandboxGetFileAttributes(file_path,
std::move(result_callback));
return MojoCallStatus::Success();
}
MojoCallStatus EngineRequestsProxy::SandboxGetKnownFolderPath(
mojom::KnownFolder folder_id,
mojom::EngineRequests::SandboxGetKnownFolderPathCallback result_callback) {
if (!engine_requests_ptr_.is_bound()) {
LOG(ERROR) << "SandboxGetKnownFolderPath called without bound pointer";
if (!engine_requests_.is_bound()) {
LOG(ERROR) << "SandboxGetKnownFolderPath called without bound remote";
return MojoCallStatus::Failure(SandboxErrorCode::INTERNAL_ERROR);
}
engine_requests_ptr_->SandboxGetKnownFolderPath(folder_id,
std::move(result_callback));
engine_requests_->SandboxGetKnownFolderPath(folder_id,
std::move(result_callback));
return MojoCallStatus::Success();
}
MojoCallStatus EngineRequestsProxy::SandboxGetProcesses(
mojom::EngineRequests::SandboxGetProcessesCallback result_callback) {
if (!engine_requests_ptr_.is_bound()) {
LOG(ERROR) << "SandboxGetProcesses called without bound pointer";
if (!engine_requests_.is_bound()) {
LOG(ERROR) << "SandboxGetProcesses called without bound remote";
return MojoCallStatus::Failure(SandboxErrorCode::INTERNAL_ERROR);
}
engine_requests_ptr_->SandboxGetProcesses(std::move(result_callback));
engine_requests_->SandboxGetProcesses(std::move(result_callback));
return MojoCallStatus::Success();
}
MojoCallStatus EngineRequestsProxy::SandboxGetTasks(
mojom::EngineRequests::SandboxGetTasksCallback result_callback) {
if (!engine_requests_ptr_.is_bound()) {
LOG(ERROR) << "SandboxGetTasks called without bound pointer";
if (!engine_requests_.is_bound()) {
LOG(ERROR) << "SandboxGetTasks called without bound remote";
return MojoCallStatus::Failure(SandboxErrorCode::INTERNAL_ERROR);
}
engine_requests_ptr_->SandboxGetTasks(std::move(result_callback));
engine_requests_->SandboxGetTasks(std::move(result_callback));
return MojoCallStatus::Success();
}
......@@ -351,13 +350,12 @@ MojoCallStatus EngineRequestsProxy::SandboxGetTasks(
MojoCallStatus EngineRequestsProxy::SandboxGetProcessImagePath(
base::ProcessId pid,
mojom::EngineRequests::SandboxGetProcessImagePathCallback result_callback) {
if (!engine_requests_ptr_.is_bound()) {
LOG(ERROR) << "SandboxGetProcessImagePath called without bound pointer";
if (!engine_requests_.is_bound()) {
LOG(ERROR) << "SandboxGetProcessImagePath called without bound remote";
return MojoCallStatus::Failure(SandboxErrorCode::INTERNAL_ERROR);
}
engine_requests_ptr_->SandboxGetProcessImagePath(pid,
std::move(result_callback));
engine_requests_->SandboxGetProcessImagePath(pid, std::move(result_callback));
return MojoCallStatus::Success();
}
......@@ -365,13 +363,12 @@ MojoCallStatus EngineRequestsProxy::SandboxGetProcessImagePath(
MojoCallStatus EngineRequestsProxy::SandboxGetLoadedModules(
base::ProcessId pid,
mojom::EngineRequests::SandboxGetLoadedModulesCallback result_callback) {
if (!engine_requests_ptr_.is_bound()) {
LOG(ERROR) << "SandboxGetLoadedModules called without bound pointer";
if (!engine_requests_.is_bound()) {
LOG(ERROR) << "SandboxGetLoadedModules called without bound remote";
return MojoCallStatus::Failure(SandboxErrorCode::INTERNAL_ERROR);
}
engine_requests_ptr_->SandboxGetLoadedModules(pid,
std::move(result_callback));
engine_requests_->SandboxGetLoadedModules(pid, std::move(result_callback));
return MojoCallStatus::Success();
}
......@@ -380,13 +377,13 @@ MojoCallStatus EngineRequestsProxy::SandboxGetProcessCommandLine(
base::ProcessId pid,
mojom::EngineRequestsProxy::SandboxGetProcessCommandLineCallback
result_callback) {
if (!engine_requests_ptr_.is_bound()) {
LOG(ERROR) << "SandboxGetProcessCommandLine called without bound pointer";
if (!engine_requests_.is_bound()) {
LOG(ERROR) << "SandboxGetProcessCommandLine called without bound remote";
return MojoCallStatus::Failure(SandboxErrorCode::INTERNAL_ERROR);
}
engine_requests_ptr_->SandboxGetProcessCommandLine(
pid, std::move(result_callback));
engine_requests_->SandboxGetProcessCommandLine(pid,
std::move(result_callback));
return MojoCallStatus::Success();
}
......@@ -394,8 +391,8 @@ MojoCallStatus EngineRequestsProxy::SandboxGetProcessCommandLine(
MojoCallStatus EngineRequestsProxy::SandboxGetUserInfoFromSID(
const SID* const sid,
mojom::EngineRequests::SandboxGetUserInfoFromSIDCallback result_callback) {
if (!engine_requests_ptr_.is_bound()) {
LOG(ERROR) << "SandboxGetUserInfoFromSID called without bound pointer";
if (!engine_requests_.is_bound()) {
LOG(ERROR) << "SandboxGetUserInfoFromSID called without bound remote";
return MojoCallStatus::Failure(SandboxErrorCode::INTERNAL_ERROR);
}
......@@ -408,8 +405,8 @@ MojoCallStatus EngineRequestsProxy::SandboxGetUserInfoFromSID(
auto mojom_string_sid = mojom::StringSid::New(sid_buffer);
LocalFree(sid_buffer);
engine_requests_ptr_->SandboxGetUserInfoFromSID(std::move(mojom_string_sid),
std::move(result_callback));
engine_requests_->SandboxGetUserInfoFromSID(std::move(mojom_string_sid),
std::move(result_callback));
return MojoCallStatus::Success();
}
......@@ -420,13 +417,13 @@ MojoCallStatus EngineRequestsProxy::SandboxOpenReadOnlyRegistry(
uint32_t dw_access,
mojom::EngineRequests::SandboxOpenReadOnlyRegistryCallback
result_callback) {
if (!engine_requests_ptr_.is_bound()) {
LOG(ERROR) << "SandboxOpenReadOnlyRegistry called without bound pointer";
if (!engine_requests_.is_bound()) {
LOG(ERROR) << "SandboxOpenReadOnlyRegistry called without bound remote";
return MojoCallStatus::Failure(SandboxErrorCode::INTERNAL_ERROR);
}
engine_requests_ptr_->SandboxOpenReadOnlyRegistry(
root_key, sub_key, dw_access, std::move(result_callback));
engine_requests_->SandboxOpenReadOnlyRegistry(root_key, sub_key, dw_access,
std::move(result_callback));
return MojoCallStatus::Success();
}
......@@ -436,13 +433,13 @@ MojoCallStatus EngineRequestsProxy::SandboxNtOpenReadOnlyRegistry(
uint32_t dw_access,
mojom::EngineRequests::SandboxNtOpenReadOnlyRegistryCallback
result_callback) {
if (!engine_requests_ptr_.is_bound()) {
LOG(ERROR) << "SandboxNtOpenReadOnlyRegistry called without bound pointer";
if (!engine_requests_.is_bound()) {
LOG(ERROR) << "SandboxNtOpenReadOnlyRegistry called without bound remote";
return MojoCallStatus::Failure(SandboxErrorCode::INTERNAL_ERROR);
}
engine_requests_ptr_->SandboxNtOpenReadOnlyRegistry(
root_key, sub_key, dw_access, std::move(result_callback));
engine_requests_->SandboxNtOpenReadOnlyRegistry(root_key, sub_key, dw_access,
std::move(result_callback));
return MojoCallStatus::Success();
}
......
......@@ -17,6 +17,8 @@
#include "chrome/chrome_cleaner/engines/target/sandbox_request_helper.h"
#include "chrome/chrome_cleaner/mojom/engine_requests.mojom.h"
#include "chrome/chrome_cleaner/os/task_scheduler.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "mojo/public/cpp/bindings/pending_associated_remote.h"
namespace chrome_cleaner {
......@@ -24,14 +26,15 @@ namespace chrome_cleaner {
class EngineRequestsProxy
: public base::RefCountedThreadSafe<EngineRequestsProxy> {
public:
EngineRequestsProxy(mojom::EngineRequestsAssociatedPtr engine_requests_ptr,
scoped_refptr<base::SingleThreadTaskRunner> task_runner);
EngineRequestsProxy(
mojo::PendingAssociatedRemote<mojom::EngineRequests> engine_requests,
scoped_refptr<base::SingleThreadTaskRunner> task_runner);
scoped_refptr<base::SingleThreadTaskRunner> task_runner() const {
return task_runner_;
}
void UnbindRequestsPtr();
void UnbindRequestsRemote();
// Implements synchronous callbacks to be called on arbitrary threads.
virtual uint32_t GetFileAttributes(const base::FilePath& file_path,
......@@ -104,7 +107,7 @@ class EngineRequestsProxy
// A EngineRequests that will send the requests over the Mojo
// connection.
mojom::EngineRequestsAssociatedPtr engine_requests_ptr_;
mojo::AssociatedRemote<mojom::EngineRequests> engine_requests_;
// A task runner for the IPC thread.
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
......
......@@ -79,7 +79,7 @@ class SandboxChildProcess::FakeEngineDelegate : public EngineDelegate {
void UnbindRequestsPtrs() {
if (privileged_scan_calls_) {
privileged_scan_calls_->UnbindRequestsPtr();
privileged_scan_calls_->UnbindRequestsRemote();
}
if (privileged_file_calls_) {
privileged_file_calls_->UnbindRequestsRemote();
......
......@@ -89,11 +89,11 @@ class MaybeSandboxedParentProcess : public BaseClass {
file_requests_impl_->Bind(&file_requests);
// Bind to empty callbacks as we don't care about the result.
mojom::EngineRequestsAssociatedPtrInfo scanner_info;
mojo::PendingAssociatedRemote<mojom::EngineRequests> scanner;
mojo::PendingAssociatedRemote<mojom::EngineScanResults> scanner_results;
if (requests_to_setup_ == CallbacksToSetup::kScanAndCleanupRequests ||
requests_to_setup_ == CallbacksToSetup::kCleanupRequests) {
scanner_impl_->Bind(&scanner_info);
scanner_impl_->Bind(&scanner);
scan_results_impl_->BindToCallbacks(
&scanner_results,
base::BindRepeating(
......@@ -122,13 +122,13 @@ class MaybeSandboxedParentProcess : public BaseClass {
->StartScan(/*enabled_uws=*/std::vector<UwSId>{},
/*enabled_locations=*/std::vector<UwS::TraceLocation>{},
/*include_details=*/false, std::move(file_requests),
std::move(scanner_info), std::move(scanner_results),
std::move(scanner), std::move(scanner_results),
std::move(operation_started));
} else if (requests_to_setup_ == CallbacksToSetup::kCleanupRequests) {
(*engine_commands_)
->StartCleanup(/*enabled_uws=*/std::vector<UwSId>(),
std::move(file_requests), std::move(scanner_info),
std::move(file_requests), std::move(scanner),
std::move(cleaner_info), std::move(cleanup_results),
std::move(operation_started));
}
......
......@@ -57,7 +57,7 @@ interface EngineCommands {
array<TraceLocation> enabled_trace_locations,
bool include_details,
pending_associated_remote<EngineFileRequests> file_requests,
associated EngineRequests sandboxed_engine_requests,
pending_associated_remote<EngineRequests> sandboxed_engine_requests,
pending_associated_remote<EngineScanResults> results) =>
(uint32 result_code);
......@@ -71,7 +71,7 @@ interface EngineCommands {
StartCleanup(
array<uint32> enabled_uws,
pending_associated_remote<EngineFileRequests> file_requests,
associated EngineRequests sandboxed_engine_requests,
pending_associated_remote<EngineRequests> sandboxed_engine_requests,
associated CleanerEngineRequests sandboxed_cleaner_engine_requests,
pending_associated_remote<EngineCleanupResults> results) =>
(uint32 result_code);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment