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