Commit 0cd45ed1 authored by Robert Sesek's avatar Robert Sesek Committed by Commit Bot

Convert chrome_cleaner from mojo::WrapPlatformFile to handle<platform>

Bug: 710376
Change-Id: I91314e43fee06ebdbb1e813f38f1ec00504a31f8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2051186Reviewed-by: default avatarJoe Mason <joenotcharles@chromium.org>
Commit-Queue: Robert Sesek <rsesek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742760}
parent 6f262fdd
......@@ -13,7 +13,6 @@
#include "base/strings/utf_string_conversions.h"
#include "base/task/post_task.h"
#include "chrome/chrome_cleaner/engines/broker/scanner_sandbox_interface.h"
#include "mojo/public/cpp/system/platform_handle.h"
namespace chrome_cleaner {
......@@ -166,10 +165,9 @@ void EngineFileRequestsImpl::OpenReadOnlyFile(
base::win::ScopedHandle handle =
chrome_cleaner_sandbox::SandboxOpenReadOnlyFile(file_name,
dwFlagsAndAttribute);
mojo_task_runner_->PostTask(
FROM_HERE, base::BindOnce(std::move(result_callback),
mojo::WrapPlatformFile(handle.Take())));
mojo::PlatformHandle(std::move(handle))));
}
} // namespace chrome_cleaner
......@@ -322,7 +322,7 @@ class TestEngineRequestInvoker {
}
static void OpenReadOnlyFileCallback(base::OnceClosure closure,
mojo::ScopedHandle /*handle*/) {
mojo::PlatformHandle /*handle*/) {
InvokeOnOtherSequence(std::move(closure));
}
......
......@@ -28,7 +28,6 @@
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/system/platform_handle.h"
#include "sandbox/win/src/win_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/multiprocess_func_list.h"
......@@ -62,7 +61,7 @@ class TestWindowsHandleImpl : public TestWindowsHandle {
std::move(callback).Run(handle);
}
void EchoRawHandle(mojo::ScopedHandle handle,
void EchoRawHandle(mojo::PlatformHandle handle,
EchoRawHandleCallback callback) override {
std::move(callback).Run(std::move(handle));
}
......@@ -129,13 +128,13 @@ class SandboxChildProcess : public chrome_cleaner::ChildProcess {
}
HANDLE EchoRawHandle(HANDLE input_handle) {
mojo::ScopedHandle scoped_handle = mojo::WrapPlatformFile(input_handle);
mojo::ScopedHandle output_handle;
mojo::PlatformHandle scoped_handle((base::win::ScopedHandle(input_handle)));
mojo::PlatformHandle output_handle;
WaitableEvent event(WaitableEvent::ResetPolicy::MANUAL,
WaitableEvent::InitialState::NOT_SIGNALED);
auto callback = base::BindOnce(
[](mojo::ScopedHandle* handle_holder, WaitableEvent* event,
mojo::ScopedHandle handle) {
[](mojo::PlatformHandle* handle_holder, WaitableEvent* event,
mojo::PlatformHandle handle) {
*handle_holder = std::move(handle);
event->Signal();
},
......@@ -144,7 +143,7 @@ class SandboxChildProcess : public chrome_cleaner::ChildProcess {
mojo_task_runner_->PostTask(
FROM_HERE, base::BindOnce(
[](mojo::Remote<TestWindowsHandle>* remote,
mojo::ScopedHandle handle,
mojo::PlatformHandle handle,
TestWindowsHandle::EchoRawHandleCallback callback) {
(*remote)->EchoRawHandle(std::move(handle),
std::move(callback));
......@@ -153,11 +152,7 @@ class SandboxChildProcess : public chrome_cleaner::ChildProcess {
base::Passed(&scoped_handle), std::move(callback)));
event.Wait();
HANDLE raw_output_handle;
CHECK_EQ(
mojo::UnwrapPlatformFile(std::move(output_handle), &raw_output_handle),
MOJO_RESULT_OK);
return raw_output_handle;
return output_handle.ReleaseHandle();
}
private:
......
......@@ -9,7 +9,6 @@
#include "base/bind.h"
#include "base/synchronization/waitable_event.h"
#include "mojo/public/cpp/system/platform_handle.h"
namespace chrome_cleaner {
......@@ -51,13 +50,8 @@ void SaveFindCloseCallback(uint32_t* out_result,
void SaveOpenReadOnlyFileCallback(base::win::ScopedHandle* result_holder,
base::WaitableEvent* async_call_done_event,
mojo::ScopedHandle handle) {
HANDLE raw_handle = INVALID_HANDLE_VALUE;
MojoResult mojo_result =
mojo::UnwrapPlatformFile(std::move(handle), &raw_handle);
LOG_IF(ERROR, mojo_result != MOJO_RESULT_OK)
<< "UnwrapPlatformFile failed " << mojo_result;
result_holder->Set(raw_handle);
mojo::PlatformHandle handle) {
*result_holder = handle.TakeHandle();
async_call_done_event->Signal();
}
......
......@@ -42,5 +42,5 @@ interface EngineFileRequests {
// FILE_FLAG_SEQUENTIAL_SCAN, FILE_FLAG_RANDOM_ACCESS, and
// FILE_FLAG_OPEN_REPARSE_POINT.
SandboxOpenReadOnlyFile(FilePath file_name, uint32 dwFlagsAndAttributes) =>
(handle result);
(handle<platform> result);
};
......@@ -24,7 +24,7 @@ interface Parser {
// Passes a handle to a lnk file to a sanbox environment where it will be
// attempted to be parsed, extracting the executable target path and the
// command line arguments.
ParseShortcut(handle lkn_file_handle)
ParseShortcut(handle<platform> lkn_file_handle)
=> (LnkParsingResult parsing_result, mojo_base.mojom.String16? target_path,
mojo_base.mojom.String16? command_line_arguments,
mojo_base.mojom.String16? icon_location);
......
......@@ -4,8 +4,6 @@
#include "chrome/chrome_cleaner/mojom/typemaps/windows_handle_mojom_traits.h"
#include "mojo/public/cpp/system/platform_handle.h"
namespace mojo {
using chrome_cleaner::mojom::PredefinedHandle;
......@@ -120,18 +118,18 @@ bool EnumTraits<PredefinedHandle, HANDLE>::FromMojom(PredefinedHandle input,
}
// static
mojo::ScopedHandle UnionTraits<WindowsHandleDataView, HANDLE>::raw_handle(
mojo::PlatformHandle UnionTraits<WindowsHandleDataView, HANDLE>::raw_handle(
HANDLE handle) {
DCHECK_EQ(WindowsHandleDataView::Tag::RAW_HANDLE, GetTag(handle));
if (IsPredefinedHandle(handle)) {
CHECK(false) << "Accessor raw_handle() should only be called when the "
"union's tag is RAW_HANDLE.";
return mojo::ScopedHandle();
return mojo::PlatformHandle();
}
HANDLE duplicate_handle = DuplicateWindowsHandle(handle);
return WrapPlatformFile(duplicate_handle);
base::win::ScopedHandle duplicate_handle(DuplicateWindowsHandle(handle));
return mojo::PlatformHandle(std::move(duplicate_handle));
}
// static
......@@ -160,14 +158,7 @@ bool UnionTraits<WindowsHandleDataView, HANDLE>::Read(
WindowsHandleDataView windows_handle_view,
HANDLE* out) {
if (windows_handle_view.is_raw_handle()) {
HANDLE handle;
MojoResult mojo_result =
UnwrapPlatformFile(windows_handle_view.TakeRawHandle(), &handle);
if (mojo_result != MOJO_RESULT_OK) {
*out = INVALID_HANDLE_VALUE;
return false;
}
*out = handle;
*out = windows_handle_view.TakeRawHandle().ReleaseHandle();
return true;
}
......
......@@ -19,7 +19,7 @@ struct EnumTraits<chrome_cleaner::mojom::PredefinedHandle, HANDLE> {
template <>
struct UnionTraits<chrome_cleaner::mojom::WindowsHandleDataView, HANDLE> {
static mojo::ScopedHandle raw_handle(HANDLE handle);
static mojo::PlatformHandle raw_handle(HANDLE handle);
static chrome_cleaner::mojom::PredefinedHandle special_handle(HANDLE handle);
static chrome_cleaner::mojom::WindowsHandleDataView::Tag GetTag(
HANDLE handle);
......
......@@ -18,7 +18,7 @@ enum PredefinedHandle {
// wrapper that puts these in |special_handle| and plain handles in
// |raw_handle|. Typemapped to HANDLE.
union WindowsHandle {
handle raw_handle;
handle<platform> raw_handle;
PredefinedHandle special_handle;
};
......@@ -26,5 +26,5 @@ interface TestWindowsHandle {
EchoHandle(WindowsHandle in_WindowsHandle) =>
(WindowsHandle out_WindowsHandle);
EchoRawHandle(handle in_handle) => (handle out_handle);
EchoRawHandle(handle<platform> in_handle) => (handle<platform> out_handle);
};
......@@ -26,7 +26,7 @@ interface ZipArchiver {
// contents of the source file to the zip file, using the name
// |filename_in_zip| in the zip index, and encrypting the file with
// |password|.
Archive(handle src_file_handle, handle zip_file_handle,
Archive(handle<platform> src_file_handle, handle<platform> zip_file_handle,
string filename_in_zip, string password)
=> (ZipArchiverResultCode result_code);
};
......@@ -18,7 +18,6 @@
#include "chrome/chrome_cleaner/mojom/parser_interface.mojom.h"
#include "chrome/chrome_cleaner/parsers/parser_utils/parse_tasks_remaining_counter.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/system/platform_handle.h"
namespace chrome_cleaner {
......@@ -33,11 +32,11 @@ void SandboxedShortcutParser::ParseShortcut(
mojo_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(
[](mojo::Remote<mojom::Parser>* parser, mojo::ScopedHandle handle,
[](mojo::Remote<mojom::Parser>* parser, mojo::PlatformHandle handle,
mojom::Parser::ParseShortcutCallback callback) {
(*parser)->ParseShortcut(std::move(handle), std::move(callback));
},
parser_, mojo::WrapPlatformFile(shortcut_handle.Take()),
parser_, mojo::PlatformHandle(std::move(shortcut_handle)),
std::move(callback)));
}
......
......@@ -10,7 +10,6 @@
#include "base/values.h"
#include "base/win/scoped_handle.h"
#include "chrome/chrome_cleaner/parsers/shortcut_parser/target/lnk_parser.h"
#include "mojo/public/cpp/system/platform_handle.h"
namespace chrome_cleaner {
......@@ -41,11 +40,10 @@ void ParserImpl::ParseJson(const std::string& json,
}
}
void ParserImpl::ParseShortcut(mojo::ScopedHandle lnk_file_handle,
void ParserImpl::ParseShortcut(mojo::PlatformHandle lnk_file_handle,
ParserImpl::ParseShortcutCallback callback) {
HANDLE raw_shortcut_handle;
if (mojo::UnwrapPlatformFile(std::move(lnk_file_handle),
&raw_shortcut_handle) != MOJO_RESULT_OK) {
base::win::ScopedHandle shortcut_handle = lnk_file_handle.TakeHandle();
if (!shortcut_handle.IsValid()) {
LOG(ERROR) << "Unable to get raw file HANDLE from mojo.";
std::move(callback).Run(mojom::LnkParsingResult::INVALID_HANDLE,
base::make_optional<base::string16>(),
......@@ -54,8 +52,6 @@ void ParserImpl::ParseShortcut(mojo::ScopedHandle lnk_file_handle,
return;
}
base::win::ScopedHandle shortcut_handle(raw_shortcut_handle);
ParsedLnkFile parsed_shortcut;
mojom::LnkParsingResult result =
ParseLnk(std::move(shortcut_handle), &parsed_shortcut);
......
......@@ -22,7 +22,7 @@ class ParserImpl : public mojom::Parser {
ParserImpl::ParseJsonCallback callback) override;
// mojom:Parser
void ParseShortcut(mojo::ScopedHandle lnk_file_handle,
void ParseShortcut(mojo::PlatformHandle lnk_file_handle,
ParserImpl::ParseShortcutCallback callback) override;
private:
......
......@@ -18,7 +18,6 @@
#include "chrome/chrome_cleaner/zip_archiver/target/sandbox_setup.h"
#include "chrome/chrome_cleaner/zip_archiver/test_zip_archiver_util.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/system/platform_handle.h"
#include "sandbox/win/src/sandbox.h"
#include "sandbox/win/src/sandbox_factory.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -58,15 +57,15 @@ class ZipArchiverSandboxSetupTest : public base::MultiProcessTest {
mojo_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(RunArchive, base::Unretained(zip_archiver_.get()),
mojo::WrapPlatformFile(src_file_handle.Take()),
mojo::WrapPlatformFile(zip_file_handle.Take()),
mojo::PlatformHandle(std::move(src_file_handle)),
mojo::PlatformHandle(std::move(zip_file_handle)),
filename_in_zip, password, std::move(callback)));
}
private:
static void RunArchive(mojo::Remote<mojom::ZipArchiver>* zip_archiver,
mojo::ScopedHandle mojo_src_handle,
mojo::ScopedHandle mojo_zip_handle,
mojo::PlatformHandle mojo_src_handle,
mojo::PlatformHandle mojo_zip_handle,
const std::string& filename_in_zip,
const std::string& password,
mojom::ZipArchiver::ArchiveCallback callback) {
......
......@@ -18,7 +18,6 @@
#include "chrome/chrome_cleaner/os/disk_util.h"
#include "chrome/chrome_cleaner/os/file_path_sanitization.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/system/platform_handle.h"
namespace chrome_cleaner {
......@@ -63,8 +62,8 @@ bool GetSanitizedFileName(const base::FilePath& path,
}
void RunArchiver(mojo::Remote<mojom::ZipArchiver>* zip_archiver,
mojo::ScopedHandle mojo_src_handle,
mojo::ScopedHandle mojo_zip_handle,
mojo::PlatformHandle mojo_src_handle,
mojo::PlatformHandle mojo_zip_handle,
const std::string& filename,
const std::string& password,
mojom::ZipArchiver::ArchiveCallback callback) {
......@@ -250,8 +249,10 @@ void SandboxedZipArchiver::Archive(const base::FilePath& src_file_path,
mojo_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(RunArchiver, base::Unretained(zip_archiver_.get()),
mojo::WrapPlatformFile(src_file.TakePlatformFile()),
mojo::WrapPlatformFile(zip_file.TakePlatformFile()),
mojo::PlatformHandle(
base::ScopedPlatformFile(src_file.TakePlatformFile())),
mojo::PlatformHandle(
base::ScopedPlatformFile(zip_file.TakePlatformFile())),
filename_in_zip, zip_password_, std::move(done_callback)));
}
......
......@@ -26,7 +26,6 @@
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/system/platform_handle.h"
#include "sandbox/win/src/sandbox.h"
#include "sandbox/win/src/sandbox_factory.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -118,18 +117,12 @@ class ArgumentVerifyingFakeArchiver : public mojom::ZipArchiver {
~ArgumentVerifyingFakeArchiver() override = default;
void Archive(mojo::ScopedHandle src_file_handle,
mojo::ScopedHandle zip_file_handle,
void Archive(mojo::PlatformHandle src_file_handle,
mojo::PlatformHandle zip_file_handle,
const std::string& filename_in_zip,
const std::string& password,
ArchiveCallback callback) override {
HANDLE raw_src_file_handle;
if (mojo::UnwrapPlatformFile(std::move(src_file_handle),
&raw_src_file_handle) != MOJO_RESULT_OK) {
std::move(callback).Run(ZipArchiverResultCode::kErrorInvalidParameter);
return;
}
base::File src_file(raw_src_file_handle);
base::File src_file(src_file_handle.TakeHandle());
if (!src_file.IsValid()) {
std::move(callback).Run(ZipArchiverResultCode::kErrorInvalidParameter);
return;
......@@ -141,13 +134,7 @@ class ArgumentVerifyingFakeArchiver : public mojom::ZipArchiver {
return;
}
HANDLE raw_zip_file_handle;
if (mojo::UnwrapPlatformFile(std::move(zip_file_handle),
&raw_zip_file_handle) != MOJO_RESULT_OK) {
std::move(callback).Run(ZipArchiverResultCode::kErrorInvalidParameter);
return;
}
base::File zip_file(raw_zip_file_handle);
base::File zip_file(zip_file_handle.TakeHandle());
if (!zip_file.IsValid()) {
std::move(callback).Run(ZipArchiverResultCode::kErrorInvalidParameter);
return;
......
......@@ -16,7 +16,6 @@
#include "base/numerics/safe_conversions.h"
#include "base/time/time.h"
#include "chrome/chrome_cleaner/constants/quarantine_constants.h"
#include "mojo/public/cpp/system/platform_handle.h"
#include "third_party/zlib/contrib/minizip/ioapi.h"
#include "third_party/zlib/contrib/minizip/zip.h"
#include "third_party/zlib/zlib.h"
......@@ -204,8 +203,8 @@ ZipArchiverImpl::ZipArchiverImpl(
ZipArchiverImpl::~ZipArchiverImpl() = default;
void ZipArchiverImpl::Archive(mojo::ScopedHandle src_file_handle,
mojo::ScopedHandle zip_file_handle,
void ZipArchiverImpl::Archive(mojo::PlatformHandle src_file_handle,
mojo::PlatformHandle zip_file_handle,
const std::string& filename_in_zip,
const std::string& password,
ArchiveCallback callback) {
......@@ -218,28 +217,14 @@ void ZipArchiverImpl::Archive(mojo::ScopedHandle src_file_handle,
return;
}
HANDLE raw_src_file_handle;
if (mojo::UnwrapPlatformFile(std::move(src_file_handle),
&raw_src_file_handle) != MOJO_RESULT_OK) {
LOG(ERROR) << "Unable to get the source HANDLE from mojo.";
std::move(callback).Run(ZipArchiverResultCode::kErrorInvalidParameter);
return;
}
base::File src_file(raw_src_file_handle);
base::File src_file(src_file_handle.TakeHandle());
if (!src_file.IsValid()) {
LOG(ERROR) << "Source file is invalid.";
std::move(callback).Run(ZipArchiverResultCode::kErrorInvalidParameter);
return;
}
HANDLE raw_zip_file_handle;
if (mojo::UnwrapPlatformFile(std::move(zip_file_handle),
&raw_zip_file_handle) != MOJO_RESULT_OK) {
LOG(ERROR) << "Unable to get the destination HANDLE from mojo.";
std::move(callback).Run(ZipArchiverResultCode::kErrorInvalidParameter);
return;
}
base::File zip_file(raw_zip_file_handle);
base::File zip_file(zip_file_handle.TakeHandle());
if (!zip_file.IsValid()) {
LOG(ERROR) << "Destination file is invalid.";
std::move(callback).Run(ZipArchiverResultCode::kErrorInvalidParameter);
......
......@@ -19,8 +19,8 @@ class ZipArchiverImpl : public mojom::ZipArchiver {
base::OnceClosure connection_error_handler);
~ZipArchiverImpl() override;
void Archive(mojo::ScopedHandle src_file_handle,
mojo::ScopedHandle zip_file_handle,
void Archive(mojo::PlatformHandle src_file_handle,
mojo::PlatformHandle zip_file_handle,
const std::string& filename_in_zip,
const std::string& password,
ArchiveCallback callback) override;
......
......@@ -16,7 +16,6 @@
#include "chrome/chrome_cleaner/mojom/zip_archiver.mojom.h"
#include "chrome/chrome_cleaner/zip_archiver/test_zip_archiver_util.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/system/platform_handle.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chrome_cleaner {
......@@ -63,8 +62,8 @@ void RunArchiver(base::win::ScopedHandle src_file_handle,
ZipArchiverImpl zip_archiver_impl(
zip_archiver.BindNewPipeAndPassReceiver(),
/*connection_error_handler=*/base::DoNothing());
zip_archiver_impl.Archive(mojo::WrapPlatformFile(src_file_handle.Take()),
mojo::WrapPlatformFile(zip_file_handle.Take()),
zip_archiver_impl.Archive(mojo::PlatformHandle(std::move(src_file_handle)),
mojo::PlatformHandle(std::move(zip_file_handle)),
filename, password, std::move(callback));
}
......
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