Commit 6e2b3399 authored by Leo Zhang's avatar Leo Zhang Committed by Commit Bot

Convert IME service to new Mojo types

Before a large code refactoring in IME service, convert it to new Mojo
types first in order to avoid any conflict during the refactoring with
an ongoing Mojo types converting.

TEST= /out/ime/chromeos_unittests --gtest_filter=ImeServiceTest*

Bug: 837156
Change-Id: I8ae669cb2fe9da980364696675278d3dc1e9516b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1632131
Commit-Queue: Leo Zhang <googleo@chromium.org>
Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/master@{#664149}
parent a1124fea
...@@ -15,16 +15,17 @@ ...@@ -15,16 +15,17 @@
namespace chromeos { namespace chromeos {
namespace ime { namespace ime {
ImeService::ImeService(service_manager::mojom::ServiceRequest request) ImeService::ImeService(
: service_binding_(this, std::move(request)) {} mojo::PendingReceiver<service_manager::mojom::Service> receiver)
: service_binding_(this, std::move(receiver)) {}
ImeService::~ImeService() = default; ImeService::~ImeService() = default;
void ImeService::OnStart() { void ImeService::OnStart() {
binder_registry_.AddInterface<mojom::InputEngineManager>(base::BindRepeating( binders_.Add(base::BindRepeating(&ImeService::AddInputEngineManagerReceiver,
&ImeService::BindInputEngineManagerRequest, base::Unretained(this))); base::Unretained(this)));
engine_manager_bindings_.set_connection_error_handler(base::BindRepeating( manager_receivers_.set_disconnect_handler(base::BindRepeating(
&ImeService::OnConnectionLost, base::Unretained(this))); &ImeService::OnConnectionLost, base::Unretained(this)));
#if BUILDFLAG(ENABLE_CROS_IME_DECODER) #if BUILDFLAG(ENABLE_CROS_IME_DECODER)
...@@ -38,14 +39,14 @@ void ImeService::OnStart() { ...@@ -38,14 +39,14 @@ void ImeService::OnStart() {
void ImeService::OnBindInterface( void ImeService::OnBindInterface(
const service_manager::BindSourceInfo& source_info, const service_manager::BindSourceInfo& source_info,
const std::string& interface_name, const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe) { mojo::ScopedMessagePipeHandle receiver_pipe) {
binder_registry_.BindInterface(interface_name, std::move(interface_pipe)); binders_.TryBind(interface_name, &receiver_pipe);
} }
void ImeService::ConnectToImeEngine( void ImeService::ConnectToImeEngine(
const std::string& ime_spec, const std::string& ime_spec,
mojom::InputChannelRequest to_engine_request, mojo::PendingReceiver<mojom::InputChannel> to_engine_request,
mojom::InputChannelPtr from_engine, mojo::PendingRemote<mojom::InputChannel> from_engine,
const std::vector<uint8_t>& extra, const std::vector<uint8_t>& extra,
ConnectToImeEngineCallback callback) { ConnectToImeEngineCallback callback) {
DCHECK(input_engine_); DCHECK(input_engine_);
...@@ -54,14 +55,14 @@ void ImeService::ConnectToImeEngine( ...@@ -54,14 +55,14 @@ void ImeService::ConnectToImeEngine(
std::move(callback).Run(bound); std::move(callback).Run(bound);
} }
void ImeService::BindInputEngineManagerRequest( void ImeService::AddInputEngineManagerReceiver(
mojom::InputEngineManagerRequest request) { mojo::PendingReceiver<mojom::InputEngineManager> receiver) {
engine_manager_bindings_.AddBinding(this, std::move(request)); manager_receivers_.Add(this, std::move(receiver));
// TODO(https://crbug.com/837156): Reset the cleanup timer. // TODO(https://crbug.com/837156): Reset the cleanup timer.
} }
void ImeService::OnConnectionLost() { void ImeService::OnConnectionLost() {
if (engine_manager_bindings_.empty()) { if (manager_receivers_.empty()) {
service_binding_.RequestClose(); service_binding_.RequestClose();
// TODO(https://crbug.com/837156): Set a timer to start a cleanup. // TODO(https://crbug.com/837156): Set a timer to start a cleanup.
} }
......
...@@ -7,8 +7,10 @@ ...@@ -7,8 +7,10 @@
#include "chromeos/services/ime/input_engine.h" #include "chromeos/services/ime/input_engine.h"
#include "chromeos/services/ime/public/mojom/input_engine.mojom.h" #include "chromeos/services/ime/public/mojom/input_engine.mojom.h"
#include "mojo/public/cpp/bindings/binding_set.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "services/service_manager/public/cpp/binder_registry.h" #include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "services/service_manager/public/cpp/binder_map.h"
#include "services/service_manager/public/cpp/service.h" #include "services/service_manager/public/cpp/service.h"
#include "services/service_manager/public/cpp/service_binding.h" #include "services/service_manager/public/cpp/service_binding.h"
#include "services/service_manager/public/mojom/service.mojom.h" #include "services/service_manager/public/mojom/service.mojom.h"
...@@ -19,7 +21,8 @@ namespace ime { ...@@ -19,7 +21,8 @@ namespace ime {
class ImeService : public service_manager::Service, class ImeService : public service_manager::Service,
public mojom::InputEngineManager { public mojom::InputEngineManager {
public: public:
explicit ImeService(service_manager::mojom::ServiceRequest request); explicit ImeService(
mojo::PendingReceiver<service_manager::mojom::Service> receiver);
~ImeService() override; ~ImeService() override;
private: private:
...@@ -30,14 +33,16 @@ class ImeService : public service_manager::Service, ...@@ -30,14 +33,16 @@ class ImeService : public service_manager::Service,
mojo::ScopedMessagePipeHandle interface_pipe) override; mojo::ScopedMessagePipeHandle interface_pipe) override;
// mojom::InputEngineManager overrides: // mojom::InputEngineManager overrides:
void ConnectToImeEngine(const std::string& ime_spec, void ConnectToImeEngine(
mojom::InputChannelRequest to_engine_request, const std::string& ime_spec,
mojom::InputChannelPtr from_engine, mojo::PendingReceiver<mojom::InputChannel> to_engine_request,
mojo::PendingRemote<mojom::InputChannel> from_engine,
const std::vector<uint8_t>& extra, const std::vector<uint8_t>& extra,
ConnectToImeEngineCallback callback) override; ConnectToImeEngineCallback callback) override;
// Binds the mojom::InputEngineManager interface to this object. // Adds a mojom::InputEngineManager receiver to this object.
void BindInputEngineManagerRequest(mojom::InputEngineManagerRequest request); void AddInputEngineManagerReceiver(
mojo::PendingReceiver<mojom::InputEngineManager> receiver);
void OnConnectionLost(); void OnConnectionLost();
...@@ -47,9 +52,9 @@ class ImeService : public service_manager::Service, ...@@ -47,9 +52,9 @@ class ImeService : public service_manager::Service,
// input engine instance. // input engine instance.
std::unique_ptr<InputEngine> input_engine_; std::unique_ptr<InputEngine> input_engine_;
mojo::BindingSet<mojom::InputEngineManager> engine_manager_bindings_; mojo::ReceiverSet<mojom::InputEngineManager> manager_receivers_;
service_manager::BinderRegistry binder_registry_; service_manager::BinderMap binders_;
DISALLOW_COPY_AND_ASSIGN(ImeService); DISALLOW_COPY_AND_ASSIGN(ImeService);
}; };
......
...@@ -8,9 +8,10 @@ ...@@ -8,9 +8,10 @@
#include "base/test/scoped_task_environment.h" #include "base/test/scoped_task_environment.h"
#include "chromeos/services/ime/public/mojom/constants.mojom.h" #include "chromeos/services/ime/public/mojom/constants.mojom.h"
#include "chromeos/services/ime/public/mojom/input_engine.mojom.h" #include "chromeos/services/ime/public/mojom/input_engine.mojom.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/binding_set.h" #include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/interface_request.h" #include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/service_manager/public/cpp/service_binding.h" #include "services/service_manager/public/cpp/service_binding.h"
#include "services/service_manager/public/cpp/test/test_connector_factory.h" #include "services/service_manager/public/cpp/test/test_connector_factory.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
...@@ -37,12 +38,10 @@ void TestProcessTextCallback(std::string* res_out, ...@@ -37,12 +38,10 @@ void TestProcessTextCallback(std::string* res_out,
class TestClientChannel : mojom::InputChannel { class TestClientChannel : mojom::InputChannel {
public: public:
TestClientChannel() : binding_(this) {} TestClientChannel() : receiver_(this) {}
mojom::InputChannelPtr CreateInterfacePtrAndBind() { mojo::PendingRemote<mojom::InputChannel> CreatePendingRemote() {
mojom::InputChannelPtr ptr; return receiver_.BindNewPipeAndPassRemote();
binding_.Bind(mojo::MakeRequest(&ptr));
return ptr;
} }
// mojom::InputChannel implementation. // mojom::InputChannel implementation.
...@@ -52,7 +51,7 @@ class TestClientChannel : mojom::InputChannel { ...@@ -52,7 +51,7 @@ class TestClientChannel : mojom::InputChannel {
ProcessMessageCallback)); ProcessMessageCallback));
private: private:
mojo::Binding<mojom::InputChannel> binding_; mojo::Receiver<mojom::InputChannel> receiver_;
DISALLOW_COPY_AND_ASSIGN(TestClientChannel); DISALLOW_COPY_AND_ASSIGN(TestClientChannel);
}; };
...@@ -60,8 +59,8 @@ class TestClientChannel : mojom::InputChannel { ...@@ -60,8 +59,8 @@ class TestClientChannel : mojom::InputChannel {
class ImeServiceTest : public testing::Test { class ImeServiceTest : public testing::Test {
public: public:
ImeServiceTest() ImeServiceTest()
: service_(test_connector_factory_.RegisterInstance(mojom::kServiceName)), : service_(
connector_(test_connector_factory_.CreateConnector()) {} test_connector_factory_.RegisterInstance(mojom::kServiceName)) {}
~ImeServiceTest() override = default; ~ImeServiceTest() override = default;
MOCK_METHOD1(SentTextCallback, void(const std::string&)); MOCK_METHOD1(SentTextCallback, void(const std::string&));
...@@ -69,20 +68,16 @@ class ImeServiceTest : public testing::Test { ...@@ -69,20 +68,16 @@ class ImeServiceTest : public testing::Test {
protected: protected:
void SetUp() override { void SetUp() override {
connector_->BindInterface(mojom::kServiceName, test_connector_factory_.GetDefaultConnector()->Connect(
mojo::MakeRequest(&ime_manager_)); mojom::kServiceName, remote_manager_.BindNewPipeAndPassReceiver());
// TODO(https://crbug.com/837156): Start or bind other services used.
// Eg. connector()->StartService(mojom::kSomeServiceName);
} }
mojom::InputEngineManagerPtr ime_manager_; mojo::Remote<mojom::InputEngineManager> remote_manager_;
private: private:
base::test::ScopedTaskEnvironment task_environment_; base::test::ScopedTaskEnvironment task_environment_;
service_manager::TestConnectorFactory test_connector_factory_; service_manager::TestConnectorFactory test_connector_factory_;
ImeService service_; ImeService service_;
std::unique_ptr<service_manager::Connector> connector_;
DISALLOW_COPY_AND_ASSIGN(ImeServiceTest); DISALLOW_COPY_AND_ASSIGN(ImeServiceTest);
}; };
...@@ -94,58 +89,58 @@ class ImeServiceTest : public testing::Test { ...@@ -94,58 +89,58 @@ class ImeServiceTest : public testing::Test {
TEST_F(ImeServiceTest, ConnectInvalidImeEngine) { TEST_F(ImeServiceTest, ConnectInvalidImeEngine) {
bool success = true; bool success = true;
TestClientChannel test_channel; TestClientChannel test_channel;
mojom::InputChannelPtr to_engine_ptr; mojo::Remote<mojom::InputChannel> remote_engine;
ime_manager_->ConnectToImeEngine( remote_manager_->ConnectToImeEngine(
kInvalidImeSpec, mojo::MakeRequest(&to_engine_ptr), kInvalidImeSpec, remote_engine.BindNewPipeAndPassReceiver(),
test_channel.CreateInterfacePtrAndBind(), extra, test_channel.CreatePendingRemote(), extra,
base::BindOnce(&ConnectCallback, &success)); base::BindOnce(&ConnectCallback, &success));
ime_manager_.FlushForTesting(); remote_manager_.FlushForTesting();
EXPECT_FALSE(success); EXPECT_FALSE(success);
} }
TEST_F(ImeServiceTest, MultipleClients) { TEST_F(ImeServiceTest, MultipleClients) {
bool success = false; bool success = false;
TestClientChannel test_channel1; TestClientChannel test_channel_1;
TestClientChannel test_channel2; TestClientChannel test_channel_2;
mojom::InputChannelPtr to_engine_ptr1; mojo::Remote<mojom::InputChannel> remote_engine_1;
mojom::InputChannelPtr to_engine_ptr2; mojo::Remote<mojom::InputChannel> remote_engine_2;
ime_manager_->ConnectToImeEngine( remote_manager_->ConnectToImeEngine(
"m17n:ar", mojo::MakeRequest(&to_engine_ptr1), "m17n:ar", remote_engine_1.BindNewPipeAndPassReceiver(),
test_channel1.CreateInterfacePtrAndBind(), extra, test_channel_1.CreatePendingRemote(), extra,
base::BindOnce(&ConnectCallback, &success)); base::BindOnce(&ConnectCallback, &success));
ime_manager_.FlushForTesting(); remote_manager_.FlushForTesting();
ime_manager_->ConnectToImeEngine( remote_manager_->ConnectToImeEngine(
"m17n:ar", mojo::MakeRequest(&to_engine_ptr2), "m17n:ar", remote_engine_2.BindNewPipeAndPassReceiver(),
test_channel2.CreateInterfacePtrAndBind(), extra, test_channel_2.CreatePendingRemote(), extra,
base::BindOnce(&ConnectCallback, &success)); base::BindOnce(&ConnectCallback, &success));
ime_manager_.FlushForTesting(); remote_manager_.FlushForTesting();
std::string response; std::string response;
std::string process_text_key = std::string process_text_key =
"{\"method\":\"keyEvent\",\"type\":\"keydown\"" "{\"method\":\"keyEvent\",\"type\":\"keydown\""
",\"code\":\"KeyA\",\"shift\":true,\"altgr\":false,\"caps\":false}"; ",\"code\":\"KeyA\",\"shift\":true,\"altgr\":false,\"caps\":false}";
to_engine_ptr1->ProcessText( remote_engine_1->ProcessText(
process_text_key, base::BindOnce(&TestProcessTextCallback, &response)); process_text_key, base::BindOnce(&TestProcessTextCallback, &response));
to_engine_ptr1.FlushForTesting(); remote_engine_1.FlushForTesting();
to_engine_ptr2->ProcessText( remote_engine_2->ProcessText(
process_text_key, base::BindOnce(&TestProcessTextCallback, &response)); process_text_key, base::BindOnce(&TestProcessTextCallback, &response));
to_engine_ptr2.FlushForTesting(); remote_engine_2.FlushForTesting();
std::string process_text_key_count = "{\"method\":\"countKey\"}"; std::string process_text_key_count = "{\"method\":\"countKey\"}";
to_engine_ptr1->ProcessText( remote_engine_1->ProcessText(
process_text_key_count, process_text_key_count,
base::BindOnce(&TestProcessTextCallback, &response)); base::BindOnce(&TestProcessTextCallback, &response));
to_engine_ptr1.FlushForTesting(); remote_engine_1.FlushForTesting();
EXPECT_EQ("1", response); EXPECT_EQ("1", response);
to_engine_ptr2->ProcessText( remote_engine_2->ProcessText(
process_text_key_count, process_text_key_count,
base::BindOnce(&TestProcessTextCallback, &response)); base::BindOnce(&TestProcessTextCallback, &response));
to_engine_ptr2.FlushForTesting(); remote_engine_2.FlushForTesting();
EXPECT_EQ("1", response); EXPECT_EQ("1", response);
} }
...@@ -153,66 +148,66 @@ TEST_F(ImeServiceTest, MultipleClients) { ...@@ -153,66 +148,66 @@ TEST_F(ImeServiceTest, MultipleClients) {
TEST_F(ImeServiceTest, RuleBasedArabic) { TEST_F(ImeServiceTest, RuleBasedArabic) {
bool success = false; bool success = false;
TestClientChannel test_channel; TestClientChannel test_channel;
mojom::InputChannelPtr to_engine_ptr; mojo::Remote<mojom::InputChannel> remote_engine;
ime_manager_->ConnectToImeEngine("m17n:ar", mojo::MakeRequest(&to_engine_ptr), remote_manager_->ConnectToImeEngine(
test_channel.CreateInterfacePtrAndBind(), "m17n:ar", remote_engine.BindNewPipeAndPassReceiver(),
extra, test_channel.CreatePendingRemote(), extra,
base::BindOnce(&ConnectCallback, &success)); base::BindOnce(&ConnectCallback, &success));
ime_manager_.FlushForTesting(); remote_manager_.FlushForTesting();
EXPECT_TRUE(success); EXPECT_TRUE(success);
// Test Shift+KeyA. // Test Shift+KeyA.
std::string response; std::string response;
to_engine_ptr->ProcessText( remote_engine->ProcessText(
"{\"method\":\"keyEvent\",\"type\":\"keydown\",\"code\":\"KeyA\"," "{\"method\":\"keyEvent\",\"type\":\"keydown\",\"code\":\"KeyA\","
"\"shift\":true,\"altgr\":false,\"caps\":false}", "\"shift\":true,\"altgr\":false,\"caps\":false}",
base::BindOnce(&TestProcessTextCallback, &response)); base::BindOnce(&TestProcessTextCallback, &response));
to_engine_ptr.FlushForTesting(); remote_engine.FlushForTesting();
const wchar_t* expected_response = const wchar_t* expected_response =
L"{\"result\":true,\"operations\":[{\"method\":\"commitText\"," L"{\"result\":true,\"operations\":[{\"method\":\"commitText\","
L"\"arguments\":[\"\u0650\"]}]}"; L"\"arguments\":[\"\u0650\"]}]}";
EXPECT_EQ(base::WideToUTF8(expected_response), response); EXPECT_EQ(base::WideToUTF8(expected_response), response);
// Test KeyB. // Test KeyB.
to_engine_ptr->ProcessText( remote_engine->ProcessText(
"{\"method\":\"keyEvent\",\"type\":\"keydown\",\"code\":\"KeyB\"," "{\"method\":\"keyEvent\",\"type\":\"keydown\",\"code\":\"KeyB\","
"\"shift\":false,\"altgr\":false,\"caps\":false}", "\"shift\":false,\"altgr\":false,\"caps\":false}",
base::BindOnce(&TestProcessTextCallback, &response)); base::BindOnce(&TestProcessTextCallback, &response));
to_engine_ptr.FlushForTesting(); remote_engine.FlushForTesting();
expected_response = expected_response =
L"{\"result\":true,\"operations\":[{\"method\":\"commitText\"," L"{\"result\":true,\"operations\":[{\"method\":\"commitText\","
L"\"arguments\":[\"\u0644\u0627\"]}]}"; L"\"arguments\":[\"\u0644\u0627\"]}]}";
EXPECT_EQ(base::WideToUTF8(expected_response), response); EXPECT_EQ(base::WideToUTF8(expected_response), response);
// Test unhandled key. // Test unhandled key.
to_engine_ptr->ProcessText( remote_engine->ProcessText(
"{\"method\":\"keyEvent\",\"type\":\"keydown\",\"code\":\"Enter\"," "{\"method\":\"keyEvent\",\"type\":\"keydown\",\"code\":\"Enter\","
"\"shift\":false,\"altgr\":false,\"caps\":false}", "\"shift\":false,\"altgr\":false,\"caps\":false}",
base::BindOnce(&TestProcessTextCallback, &response)); base::BindOnce(&TestProcessTextCallback, &response));
to_engine_ptr.FlushForTesting(); remote_engine.FlushForTesting();
EXPECT_EQ("{\"result\":false}", response); EXPECT_EQ("{\"result\":false}", response);
// Test keyup. // Test keyup.
to_engine_ptr->ProcessText( remote_engine->ProcessText(
"{\"method\":\"keyEvent\",\"type\":\"keyup\",\"code\":\"Enter\"," "{\"method\":\"keyEvent\",\"type\":\"keyup\",\"code\":\"Enter\","
"\"shift\":false,\"altgr\":false,\"caps\":false}", "\"shift\":false,\"altgr\":false,\"caps\":false}",
base::BindOnce(&TestProcessTextCallback, &response)); base::BindOnce(&TestProcessTextCallback, &response));
to_engine_ptr.FlushForTesting(); remote_engine.FlushForTesting();
EXPECT_EQ("{\"result\":false}", response); EXPECT_EQ("{\"result\":false}", response);
// Test reset. // Test reset.
to_engine_ptr->ProcessText( remote_engine->ProcessText(
"{\"method\":\"reset\"}", "{\"method\":\"reset\"}",
base::BindOnce(&TestProcessTextCallback, &response)); base::BindOnce(&TestProcessTextCallback, &response));
to_engine_ptr.FlushForTesting(); remote_engine.FlushForTesting();
EXPECT_EQ("{\"result\":true}", response); EXPECT_EQ("{\"result\":true}", response);
// Test invalid request. // Test invalid request.
to_engine_ptr->ProcessText( remote_engine->ProcessText(
"{\"method\":\"keyEvent\",\"type\":\"keydown\"}", "{\"method\":\"keyEvent\",\"type\":\"keydown\"}",
base::BindOnce(&TestProcessTextCallback, &response)); base::BindOnce(&TestProcessTextCallback, &response));
to_engine_ptr.FlushForTesting(); remote_engine.FlushForTesting();
EXPECT_EQ("{\"result\":false}", response); EXPECT_EQ("{\"result\":false}", response);
} }
...@@ -220,60 +215,60 @@ TEST_F(ImeServiceTest, RuleBasedArabic) { ...@@ -220,60 +215,60 @@ TEST_F(ImeServiceTest, RuleBasedArabic) {
TEST_F(ImeServiceTest, RuleBasedDevaPhone) { TEST_F(ImeServiceTest, RuleBasedDevaPhone) {
bool success = false; bool success = false;
TestClientChannel test_channel; TestClientChannel test_channel;
mojom::InputChannelPtr to_engine_ptr; mojo::Remote<mojom::InputChannel> remote_engine;
ime_manager_->ConnectToImeEngine( remote_manager_->ConnectToImeEngine(
"m17n:deva_phone", mojo::MakeRequest(&to_engine_ptr), "m17n:deva_phone", remote_engine.BindNewPipeAndPassReceiver(),
test_channel.CreateInterfacePtrAndBind(), extra, test_channel.CreatePendingRemote(), extra,
base::BindOnce(&ConnectCallback, &success)); base::BindOnce(&ConnectCallback, &success));
ime_manager_.FlushForTesting(); remote_manager_.FlushForTesting();
EXPECT_TRUE(success); EXPECT_TRUE(success);
std::string response; std::string response;
// KeyN. // KeyN.
to_engine_ptr->ProcessText( remote_engine->ProcessText(
"{\"method\":\"keyEvent\",\"type\":\"keydown\",\"code\":\"KeyN\"," "{\"method\":\"keyEvent\",\"type\":\"keydown\",\"code\":\"KeyN\","
"\"shift\":false,\"altgr\":false,\"caps\":false}", "\"shift\":false,\"altgr\":false,\"caps\":false}",
base::BindOnce(&TestProcessTextCallback, &response)); base::BindOnce(&TestProcessTextCallback, &response));
to_engine_ptr.FlushForTesting(); remote_engine.FlushForTesting();
const char* expected_response = const char* expected_response =
u8"{\"result\":true,\"operations\":[{\"method\":\"setComposition\"," u8"{\"result\":true,\"operations\":[{\"method\":\"setComposition\","
u8"\"arguments\":[\"\u0928\"]}]}"; u8"\"arguments\":[\"\u0928\"]}]}";
EXPECT_EQ(expected_response, response); EXPECT_EQ(expected_response, response);
// Backspace. // Backspace.
to_engine_ptr->ProcessText( remote_engine->ProcessText(
"{\"method\":\"keyEvent\",\"type\":\"keydown\",\"code\":\"Backspace\"," "{\"method\":\"keyEvent\",\"type\":\"keydown\",\"code\":\"Backspace\","
"\"shift\":false,\"altgr\":false,\"caps\":false}", "\"shift\":false,\"altgr\":false,\"caps\":false}",
base::BindOnce(&TestProcessTextCallback, &response)); base::BindOnce(&TestProcessTextCallback, &response));
to_engine_ptr.FlushForTesting(); remote_engine.FlushForTesting();
expected_response = expected_response =
u8"{\"result\":true,\"operations\":[{\"method\":\"setComposition\"," u8"{\"result\":true,\"operations\":[{\"method\":\"setComposition\","
u8"\"arguments\":[\"\"]}]}"; u8"\"arguments\":[\"\"]}]}";
EXPECT_EQ(expected_response, response); EXPECT_EQ(expected_response, response);
// KeyN + KeyC. // KeyN + KeyC.
to_engine_ptr->ProcessText( remote_engine->ProcessText(
"{\"method\":\"keyEvent\",\"type\":\"keydown\",\"code\":\"KeyN\"," "{\"method\":\"keyEvent\",\"type\":\"keydown\",\"code\":\"KeyN\","
"\"shift\":false,\"altgr\":false,\"caps\":false}", "\"shift\":false,\"altgr\":false,\"caps\":false}",
base::BindOnce(&TestProcessTextCallback, &response)); base::BindOnce(&TestProcessTextCallback, &response));
to_engine_ptr->ProcessText( remote_engine->ProcessText(
"{\"method\":\"keyEvent\",\"type\":\"keydown\",\"code\":\"KeyC\"," "{\"method\":\"keyEvent\",\"type\":\"keydown\",\"code\":\"KeyC\","
"\"shift\":false,\"altgr\":false,\"caps\":false}", "\"shift\":false,\"altgr\":false,\"caps\":false}",
base::BindOnce(&TestProcessTextCallback, &response)); base::BindOnce(&TestProcessTextCallback, &response));
to_engine_ptr.FlushForTesting(); remote_engine.FlushForTesting();
expected_response = expected_response =
u8"{\"result\":true,\"operations\":[{\"method\":\"setComposition\"," u8"{\"result\":true,\"operations\":[{\"method\":\"setComposition\","
u8"\"arguments\":[\"\u091e\u094d\u091a\"]}]}"; u8"\"arguments\":[\"\u091e\u094d\u091a\"]}]}";
EXPECT_EQ(expected_response, response); EXPECT_EQ(expected_response, response);
// Space. // Space.
to_engine_ptr->ProcessText( remote_engine->ProcessText(
"{\"method\":\"keyEvent\",\"type\":\"keydown\",\"code\":\"Space\"," "{\"method\":\"keyEvent\",\"type\":\"keydown\",\"code\":\"Space\","
"\"shift\":false,\"altgr\":false,\"caps\":false}", "\"shift\":false,\"altgr\":false,\"caps\":false}",
base::BindOnce(&TestProcessTextCallback, &response)); base::BindOnce(&TestProcessTextCallback, &response));
to_engine_ptr.FlushForTesting(); remote_engine.FlushForTesting();
expected_response = expected_response =
u8"{\"result\":true,\"operations\":[{\"method\":\"commitText\"," u8"{\"result\":true,\"operations\":[{\"method\":\"commitText\","
u8"\"arguments\":[\"\u091e\u094d\u091a \"]}]}"; u8"\"arguments\":[\"\u091e\u094d\u091a \"]}]}";
......
...@@ -41,14 +41,15 @@ InputEngine::InputEngine() {} ...@@ -41,14 +41,15 @@ InputEngine::InputEngine() {}
InputEngine::~InputEngine() {} InputEngine::~InputEngine() {}
bool InputEngine::BindRequest(const std::string& ime_spec, bool InputEngine::BindRequest(
mojom::InputChannelRequest request, const std::string& ime_spec,
mojom::InputChannelPtr client, mojo::PendingReceiver<mojom::InputChannel> receiver,
mojo::PendingRemote<mojom::InputChannel> remote,
const std::vector<uint8_t>& extra) { const std::vector<uint8_t>& extra) {
if (!IsImeSupported(ime_spec)) if (!IsImeSupported(ime_spec))
return false; return false;
channel_bindings_.AddBinding(this, std::move(request), channel_receivers_.Add(this, std::move(receiver),
std::make_unique<InputEngineContext>(ime_spec)); std::make_unique<InputEngineContext>(ime_spec));
return true; return true;
...@@ -61,7 +62,7 @@ bool InputEngine::IsImeSupported(const std::string& ime_spec) { ...@@ -61,7 +62,7 @@ bool InputEngine::IsImeSupported(const std::string& ime_spec) {
void InputEngine::ProcessText(const std::string& message, void InputEngine::ProcessText(const std::string& message,
ProcessTextCallback callback) { ProcessTextCallback callback) {
auto& context = channel_bindings_.dispatch_context(); auto& context = channel_receivers_.current_context();
std::string result = Process(message, context.get()); std::string result = Process(message, context.get());
std::move(callback).Run(result); std::move(callback).Run(result);
} }
......
...@@ -6,7 +6,9 @@ ...@@ -6,7 +6,9 @@
#define CHROMEOS_SERVICES_IME_INPUT_ENGINE_H_ #define CHROMEOS_SERVICES_IME_INPUT_ENGINE_H_
#include "chromeos/services/ime/public/mojom/input_engine.mojom.h" #include "chromeos/services/ime/public/mojom/input_engine.mojom.h"
#include "mojo/public/cpp/bindings/binding_set.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
namespace chromeos { namespace chromeos {
namespace ime { namespace ime {
...@@ -36,8 +38,8 @@ class InputEngine : public mojom::InputChannel { ...@@ -36,8 +38,8 @@ class InputEngine : public mojom::InputChannel {
// Binds the mojom::InputChannel interface to this object and returns true if // Binds the mojom::InputChannel interface to this object and returns true if
// the given ime_spec is supported by the engine. // the given ime_spec is supported by the engine.
virtual bool BindRequest(const std::string& ime_spec, virtual bool BindRequest(const std::string& ime_spec,
mojom::InputChannelRequest request, mojo::PendingReceiver<mojom::InputChannel> receiver,
mojom::InputChannelPtr client, mojo::PendingRemote<mojom::InputChannel> remote,
const std::vector<uint8_t>& extra); const std::vector<uint8_t>& extra);
// Returns whether the given ime_spec is supported by this engine. // Returns whether the given ime_spec is supported by this engine.
...@@ -55,8 +57,8 @@ class InputEngine : public mojom::InputChannel { ...@@ -55,8 +57,8 @@ class InputEngine : public mojom::InputChannel {
std::string Process(const std::string& message, std::string Process(const std::string& message,
const InputEngineContext* context); const InputEngineContext* context);
mojo::BindingSet<mojom::InputChannel, std::unique_ptr<InputEngineContext>> mojo::ReceiverSet<mojom::InputChannel, std::unique_ptr<InputEngineContext>>
channel_bindings_; channel_receivers_;
DISALLOW_COPY_AND_ASSIGN(InputEngine); DISALLOW_COPY_AND_ASSIGN(InputEngine);
}; };
......
...@@ -14,8 +14,8 @@ interface InputEngineManager { ...@@ -14,8 +14,8 @@ interface InputEngineManager {
// is implmented on the client and used to receive data sent from the engine. // is implmented on the client and used to receive data sent from the engine.
// On failure (e.g. input engine is not found), |success| is false. // On failure (e.g. input engine is not found), |success| is false.
ConnectToImeEngine(string ime_spec, ConnectToImeEngine(string ime_spec,
InputChannel& to_engine_request, pending_receiver<InputChannel> to_engine_request,
InputChannel from_engine, pending_remote<InputChannel> from_engine,
array<uint8> extra) array<uint8> extra)
=> (bool success); => (bool success);
}; };
......
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