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,
const std::vector<uint8_t>& extra, mojo::PendingRemote<mojom::InputChannel> from_engine,
ConnectToImeEngineCallback callback) override; const std::vector<uint8_t>& extra,
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);
}; };
......
...@@ -41,15 +41,16 @@ InputEngine::InputEngine() {} ...@@ -41,15 +41,16 @@ 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,
const std::vector<uint8_t>& extra) { mojo::PendingRemote<mojom::InputChannel> remote,
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;
// TODO(https://crbug.com/837156): Registry connection error handler. // TODO(https://crbug.com/837156): Registry connection error handler.
...@@ -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