Commit 3311557a authored by Henrique Ferreiro's avatar Henrique Ferreiro Committed by Commit Bot

Migrate test_pup_typemap.mojom to the new Mojo types

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

Bug: 955171
Change-Id: I76024a22fbdca21cd5f92927ef70da685f226a68
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1863806
Commit-Queue: Henrique Ferreiro <hferreiro@igalia.com>
Reviewed-by: default avatarJoe Mason <joenotcharles@chromium.org>
Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707485}
parent 0dd49956
...@@ -4,16 +4,19 @@ ...@@ -4,16 +4,19 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
#include "chrome/chrome_cleaner/mojom/pup.mojom.h"
#include "chrome/chrome_cleaner/mojom/test_pup_typemap.mojom.h"
#include "chrome/chrome_cleaner/ipc/ipc_test_util.h" #include "chrome/chrome_cleaner/ipc/ipc_test_util.h"
#include "chrome/chrome_cleaner/ipc/mojo_task_runner.h" #include "chrome/chrome_cleaner/ipc/mojo_task_runner.h"
#include "chrome/chrome_cleaner/mojom/pup.mojom.h"
#include "chrome/chrome_cleaner/mojom/test_pup_typemap.mojom.h"
#include "chrome/chrome_cleaner/pup_data/pup_data.h" #include "chrome/chrome_cleaner/pup_data/pup_data.h"
#include "chrome/chrome_cleaner/test/test_extensions.h" #include "chrome/chrome_cleaner/test/test_extensions.h"
#include "chrome/chrome_cleaner/test/test_util.h" #include "chrome/chrome_cleaner/test/test_util.h"
#include "components/chrome_cleaner/test/test_name_helper.h" #include "components/chrome_cleaner/test/test_name_helper.h"
#include "mojo/core/embedder/embedder.h" #include "mojo/core/embedder/embedder.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.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"
...@@ -32,15 +35,16 @@ constexpr int32_t kConnectionBrokenResultCode = 127; ...@@ -32,15 +35,16 @@ constexpr int32_t kConnectionBrokenResultCode = 127;
class TestPUPTypemapImpl : public mojom::TestPUPTypemap { class TestPUPTypemapImpl : public mojom::TestPUPTypemap {
public: public:
explicit TestPUPTypemapImpl(mojom::TestPUPTypemapRequest request) explicit TestPUPTypemapImpl(
: binding_(this, std::move(request)) {} mojo::PendingReceiver<mojom::TestPUPTypemap> receiver)
: receiver_(this, std::move(receiver)) {}
void EchoPUP(const PUPData::PUP& pup, EchoPUPCallback callback) override { void EchoPUP(const PUPData::PUP& pup, EchoPUPCallback callback) override {
std::move(callback).Run(pup); std::move(callback).Run(pup);
} }
private: private:
mojo::Binding<mojom::TestPUPTypemap> binding_; mojo::Receiver<mojom::TestPUPTypemap> receiver_;
}; };
class EchoingParentProcess : public chrome_cleaner::ParentProcess { class EchoingParentProcess : public chrome_cleaner::ParentProcess {
...@@ -50,8 +54,8 @@ class EchoingParentProcess : public chrome_cleaner::ParentProcess { ...@@ -50,8 +54,8 @@ class EchoingParentProcess : public chrome_cleaner::ParentProcess {
protected: protected:
void CreateImpl(mojo::ScopedMessagePipeHandle mojo_pipe) override { void CreateImpl(mojo::ScopedMessagePipeHandle mojo_pipe) override {
mojom::TestPUPTypemapRequest request(std::move(mojo_pipe)); mojo::PendingReceiver<mojom::TestPUPTypemap> receiver(std::move(mojo_pipe));
impl_ = std::make_unique<TestPUPTypemapImpl>(std::move(request)); impl_ = std::make_unique<TestPUPTypemapImpl>(std::move(receiver));
} }
void DestroyImpl() override { impl_.reset(); } void DestroyImpl() override { impl_.reset(); }
...@@ -66,16 +70,17 @@ class EchoingChildProcess : public chrome_cleaner::ChildProcess { ...@@ -66,16 +70,17 @@ class EchoingChildProcess : public chrome_cleaner::ChildProcess {
public: public:
explicit EchoingChildProcess(scoped_refptr<MojoTaskRunner> mojo_task_runner) explicit EchoingChildProcess(scoped_refptr<MojoTaskRunner> mojo_task_runner)
: ChildProcess(mojo_task_runner), : ChildProcess(mojo_task_runner),
ptr_(std::make_unique<mojom::TestPUPTypemapPtr>()) {} remote_(new mojo::Remote<mojom::TestPUPTypemap>(),
base::OnTaskRunnerDeleter(mojo_task_runner)) {}
void BindToPipe(mojo::ScopedMessagePipeHandle mojo_pipe, void BindToPipe(mojo::ScopedMessagePipeHandle mojo_pipe,
WaitableEvent* event) { WaitableEvent* event) {
ptr_->Bind( remote_->Bind(mojo::PendingRemote<chrome_cleaner::mojom::TestPUPTypemap>(
chrome_cleaner::mojom::TestPUPTypemapPtrInfo(std::move(mojo_pipe), 0)); std::move(mojo_pipe), 0));
// If the connection is lost while this object is processing a request or // If the connection is lost while this object is processing a request or
// waiting for a response, then it will terminate with a special result code // waiting for a response, then it will terminate with a special result code
// that will be expected by the parent process. // that will be expected by the parent process.
ptr_->set_connection_error_handler(base::BindOnce( remote_->set_disconnect_handler(base::BindOnce(
[](bool* processing_request) { [](bool* processing_request) {
if (*processing_request) if (*processing_request)
exit(kConnectionBrokenResultCode); exit(kConnectionBrokenResultCode);
...@@ -90,17 +95,11 @@ class EchoingChildProcess : public chrome_cleaner::ChildProcess { ...@@ -90,17 +95,11 @@ class EchoingChildProcess : public chrome_cleaner::ChildProcess {
} }
private: private:
~EchoingChildProcess() override { ~EchoingChildProcess() override = default;
mojo_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(
[](std::unique_ptr<mojom::TestPUPTypemapPtr> ptr) { ptr.reset(); },
base::Passed(&ptr_)));
}
void RunEchoPUP(const PUPData::PUP& input, void RunEchoPUP(const PUPData::PUP& input,
mojom::TestPUPTypemap::EchoPUPCallback callback) { mojom::TestPUPTypemap::EchoPUPCallback callback) {
(*ptr_)->EchoPUP(input, std::move(callback)); (*remote_)->EchoPUP(input, std::move(callback));
} }
template <typename EchoedValue> template <typename EchoedValue>
...@@ -131,7 +130,10 @@ class EchoingChildProcess : public chrome_cleaner::ChildProcess { ...@@ -131,7 +130,10 @@ class EchoingChildProcess : public chrome_cleaner::ChildProcess {
return output; return output;
} }
std::unique_ptr<mojom::TestPUPTypemapPtr> ptr_; std::unique_ptr<mojo::Remote<mojom::TestPUPTypemap>,
base::OnTaskRunnerDeleter>
remote_;
// All requests are synchronous and happen on the same sequence, so no // All requests are synchronous and happen on the same sequence, so no
// synchronization is needed. // synchronization is needed.
bool processing_request_ = false; bool processing_request_ = false;
......
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