Commit 561c27fa authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

ime: Move system PK logic out into a separate engine.

Right now, all the logic is in DecoderEngine, which is the primary
engine used for the IME service launch. To avoid breaking this important
launch with WIP code, move the WIP system PK code out into a separate
engine that is only used when the system PK flag is enabled.

Bug: b/161490915
Change-Id: I2b2352c88d3276e7d79f17cc4b8afbe14328453a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2498021Reviewed-by: default avatarLeo Zhang <googleo@chromium.org>
Reviewed-by: default avatarDarren Shen <shend@chromium.org>
Commit-Queue: Darren Shen <shend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#822528}
parent 1a8d833e
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "chromeos/constants/chromeos_features.h" #include "chromeos/constants/chromeos_features.h"
#include "chromeos/constants/chromeos_pref_names.h" #include "chromeos/constants/chromeos_pref_names.h"
#include "chromeos/services/ime/decoder/decoder_engine.h" #include "chromeos/services/ime/decoder/system_engine.h"
#include "components/autofill/core/browser/autofill_test_utils.h" #include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/data_model/autofill_profile.h" #include "components/autofill/core/browser/data_model/autofill_profile.h"
#include "components/autofill/core/browser/personal_data_manager.h" #include "components/autofill/core/browser/personal_data_manager.h"
......
...@@ -40,6 +40,8 @@ source_set("lib") { ...@@ -40,6 +40,8 @@ source_set("lib") {
"decoder/downloader_impl.h", "decoder/downloader_impl.h",
"decoder/proto_conversion.cc", "decoder/proto_conversion.cc",
"decoder/proto_conversion.h", "decoder/proto_conversion.h",
"decoder/system_engine.cc",
"decoder/system_engine.h",
"ime_service.cc", "ime_service.cc",
"ime_service.h", "ime_service.h",
"input_engine.cc", "input_engine.cc",
...@@ -95,8 +97,8 @@ source_set("services_unittests") { ...@@ -95,8 +97,8 @@ source_set("services_unittests") {
"//testing/gtest", "//testing/gtest",
] ]
sources = [ sources = [
"decoder/decoder_engine_unittest.cc",
"decoder/proto_conversion_unittest.cc", "decoder/proto_conversion_unittest.cc",
"decoder/system_engine_unittest.cc",
"ime_service_unittest.cc", "ime_service_unittest.cc",
] ]
} }
...@@ -5,25 +5,17 @@ ...@@ -5,25 +5,17 @@
#include "chromeos/services/ime/decoder/decoder_engine.h" #include "chromeos/services/ime/decoder/decoder_engine.h"
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/feature_list.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "chromeos/constants/chromeos_features.h" #include "base/files/file_util.h"
#include "chromeos/services/ime/constants.h" #include "chromeos/services/ime/constants.h"
#include "chromeos/services/ime/decoder/proto_conversion.h"
#include "chromeos/services/ime/ime_decoder.h" #include "chromeos/services/ime/ime_decoder.h"
#include "chromeos/services/ime/public/cpp/buildflags.h" #include "chromeos/services/ime/public/cpp/buildflags.h"
#include "chromeos/services/ime/public/proto/messages.pb.h"
namespace chromeos { namespace chromeos {
namespace ime { namespace ime {
namespace { namespace {
ImeEngineMainEntry* g_fake_main_entry_for_testing = nullptr;
using ReplyCallback =
base::RepeatingCallback<void(const std::vector<uint8_t>&)>;
// A client delegate passed to the shared library in order for the // A client delegate passed to the shared library in order for the
// shared library to send replies back to the engine. // shared library to send replies back to the engine.
class ClientDelegate : public ImeClientDelegate { class ClientDelegate : public ImeClientDelegate {
...@@ -31,11 +23,8 @@ class ClientDelegate : public ImeClientDelegate { ...@@ -31,11 +23,8 @@ class ClientDelegate : public ImeClientDelegate {
// All replies from the shared library will be sent to both |remote| and // All replies from the shared library will be sent to both |remote| and
// |callback|. // |callback|.
ClientDelegate(const std::string& ime_spec, ClientDelegate(const std::string& ime_spec,
mojo::PendingRemote<mojom::InputChannel> remote, mojo::PendingRemote<mojom::InputChannel> remote)
ReplyCallback callback) : ime_spec_(ime_spec), client_remote_(std::move(remote)) {
: ime_spec_(ime_spec),
client_remote_(std::move(remote)),
callback_(callback) {
client_remote_.set_disconnect_handler(base::BindOnce( client_remote_.set_disconnect_handler(base::BindOnce(
&ClientDelegate::OnDisconnected, base::Unretained(this))); &ClientDelegate::OnDisconnected, base::Unretained(this)));
} }
...@@ -48,7 +37,6 @@ class ClientDelegate : public ImeClientDelegate { ...@@ -48,7 +37,6 @@ class ClientDelegate : public ImeClientDelegate {
if (client_remote_ && client_remote_.is_bound()) { if (client_remote_ && client_remote_.is_bound()) {
std::vector<uint8_t> msg(data, data + size); std::vector<uint8_t> msg(data, data + size);
client_remote_->ProcessMessage(msg, base::DoNothing()); client_remote_->ProcessMessage(msg, base::DoNothing());
callback_.Run(msg);
} }
} }
...@@ -65,31 +53,13 @@ class ClientDelegate : public ImeClientDelegate { ...@@ -65,31 +53,13 @@ class ClientDelegate : public ImeClientDelegate {
// The InputChannel remote used to talk to the client. // The InputChannel remote used to talk to the client.
mojo::Remote<mojom::InputChannel> client_remote_; mojo::Remote<mojom::InputChannel> client_remote_;
ReplyCallback callback_;
}; };
std::vector<uint8_t> WrapAndSerializeMessage(PublicMessage message) {
Wrapper wrapper;
*wrapper.mutable_public_message() = std::move(message);
std::vector<uint8_t> output(wrapper.ByteSizeLong());
wrapper.SerializeToArray(output.data(), output.size());
return output;
}
} // namespace } // namespace
void FakeEngineMainEntryForTesting(ImeEngineMainEntry* main_entry) {
g_fake_main_entry_for_testing = main_entry;
}
DecoderEngine::DecoderEngine(ImeCrosPlatform* platform) : platform_(platform) { DecoderEngine::DecoderEngine(ImeCrosPlatform* platform) : platform_(platform) {
if (g_fake_main_entry_for_testing) { if (!TryLoadDecoder()) {
engine_main_entry_ = g_fake_main_entry_for_testing; LOG(WARNING) << "DecoderEngine INIT INCOMPLETED.";
} else {
if (!TryLoadDecoder()) {
LOG(WARNING) << "DecoderEngine INIT INCOMPLETED.";
}
} }
} }
...@@ -118,9 +88,7 @@ bool DecoderEngine::BindRequest( ...@@ -118,9 +88,7 @@ bool DecoderEngine::BindRequest(
// make safe calls on the client. // make safe calls on the client.
if (engine_main_entry_->ActivateIme( if (engine_main_entry_->ActivateIme(
ime_spec.c_str(), ime_spec.c_str(),
new ClientDelegate(ime_spec, std::move(remote), new ClientDelegate(ime_spec, std::move(remote)))) {
base::BindRepeating(&DecoderEngine::OnReply,
base::Unretained(this))))) {
decoder_channel_receivers_.Add(this, std::move(receiver)); decoder_channel_receivers_.Add(this, std::move(receiver));
// TODO(https://crbug.com/837156): Registry connection error handler. // TODO(https://crbug.com/837156): Registry connection error handler.
return true; return true;
...@@ -138,63 +106,6 @@ bool DecoderEngine::IsImeSupportedByDecoder(const std::string& ime_spec) { ...@@ -138,63 +106,6 @@ bool DecoderEngine::IsImeSupportedByDecoder(const std::string& ime_spec) {
engine_main_entry_->IsImeSupported(ime_spec.c_str()); engine_main_entry_->IsImeSupported(ime_spec.c_str());
} }
void DecoderEngine::OnInputMethodChanged(const std::string& engine_id) {
const uint64_t seq_id = current_seq_id_;
++current_seq_id_;
ProcessMessage(
WrapAndSerializeMessage(OnInputMethodChangedToProto(seq_id, engine_id)),
base::DoNothing());
}
void DecoderEngine::OnFocus(mojom::InputFieldInfoPtr input_field_info) {
const uint64_t seq_id = current_seq_id_;
++current_seq_id_;
ProcessMessage(WrapAndSerializeMessage(
OnFocusToProto(seq_id, std::move(input_field_info))),
base::DoNothing());
}
void DecoderEngine::OnBlur() {
const uint64_t seq_id = current_seq_id_;
++current_seq_id_;
ProcessMessage(WrapAndSerializeMessage(OnBlurToProto(seq_id)),
base::DoNothing());
}
void DecoderEngine::OnKeyEvent(mojom::PhysicalKeyEventPtr event,
OnKeyEventCallback callback) {
const uint64_t seq_id = current_seq_id_;
++current_seq_id_;
pending_key_event_callbacks_.emplace(seq_id, std::move(callback));
ProcessMessage(
WrapAndSerializeMessage(OnKeyEventToProto(seq_id, std::move(event))),
base::DoNothing());
}
void DecoderEngine::OnSurroundingTextChanged(
const std::string& text,
uint32_t offset,
mojom::SelectionRangePtr selection_range) {
const uint64_t seq_id = current_seq_id_;
++current_seq_id_;
ProcessMessage(WrapAndSerializeMessage(OnSurroundingTextChangedToProto(
seq_id, text, offset, std::move(selection_range))),
base::DoNothing());
}
void DecoderEngine::OnCompositionCanceled() {
const uint64_t seq_id = current_seq_id_;
++current_seq_id_;
ProcessMessage(WrapAndSerializeMessage(OnCompositionCanceledToProto(seq_id)),
base::DoNothing());
}
void DecoderEngine::ProcessMessage(const std::vector<uint8_t>& message, void DecoderEngine::ProcessMessage(const std::vector<uint8_t>& message,
ProcessMessageCallback callback) { ProcessMessageCallback callback) {
// TODO(https://crbug.com/837156): Set a default protobuf message. // TODO(https://crbug.com/837156): Set a default protobuf message.
...@@ -207,33 +118,5 @@ void DecoderEngine::ProcessMessage(const std::vector<uint8_t>& message, ...@@ -207,33 +118,5 @@ void DecoderEngine::ProcessMessage(const std::vector<uint8_t>& message,
std::move(callback).Run(result); std::move(callback).Run(result);
} }
void DecoderEngine::OnReply(const std::vector<uint8_t>& message) {
if (!base::FeatureList::IsEnabled(
chromeos::features::kSystemLatinPhysicalTyping)) {
return;
}
ime::Wrapper wrapper;
if (!wrapper.ParseFromArray(message.data(), message.size()) ||
!wrapper.has_public_message()) {
return;
}
const ime::PublicMessage& reply = wrapper.public_message();
switch (reply.param_case()) {
case ime::PublicMessage::kOnKeyEventReply: {
const auto it = pending_key_event_callbacks_.find(reply.seq_id());
CHECK(it != pending_key_event_callbacks_.end());
auto callback = std::move(it->second);
std::move(callback).Run(reply.on_key_event_reply().consumed());
pending_key_event_callbacks_.erase(it);
break;
}
default:
NOTREACHED();
break;
}
}
} // namespace ime } // namespace ime
} // namespace chromeos } // namespace chromeos
...@@ -13,9 +13,6 @@ ...@@ -13,9 +13,6 @@
namespace chromeos { namespace chromeos {
namespace ime { namespace ime {
// Only used in tests to set a fake `ImeEngineMainEntry`.
void FakeEngineMainEntryForTesting(ImeEngineMainEntry* main_entry);
// An enhanced implementation of the basic InputEngine which allows the input // An enhanced implementation of the basic InputEngine which allows the input
// engine to call a customized transliteration library (aka decoder) to provide // engine to call a customized transliteration library (aka decoder) to provide
// a premium typing experience. // a premium typing experience.
...@@ -32,16 +29,16 @@ class DecoderEngine : public InputEngine { ...@@ -32,16 +29,16 @@ class DecoderEngine : public InputEngine {
void ProcessMessage(const std::vector<uint8_t>& message, void ProcessMessage(const std::vector<uint8_t>& message,
ProcessMessageCallback callback) override; ProcessMessageCallback callback) override;
void OnInputMethodChanged(const std::string& engine_id) override; void OnInputMethodChanged(const std::string& engine_id) override {}
void OnFocus(mojom::InputFieldInfoPtr input_field_info) override; void OnFocus(mojom::InputFieldInfoPtr input_field_info) override {}
void OnBlur() override; void OnBlur() override {}
void OnKeyEvent(mojom::PhysicalKeyEventPtr event, void OnKeyEvent(mojom::PhysicalKeyEventPtr event,
OnKeyEventCallback callback) override; OnKeyEventCallback callback) override {}
void OnSurroundingTextChanged( void OnSurroundingTextChanged(
const std::string& text, const std::string& text,
uint32_t offset, uint32_t offset,
mojom::SelectionRangePtr selection_range) override; mojom::SelectionRangePtr selection_range) override {}
void OnCompositionCanceled() override; void OnCompositionCanceled() override {}
private: private:
// Try to load the decoding functions from some decoder shared library. // Try to load the decoding functions from some decoder shared library.
...@@ -51,10 +48,6 @@ class DecoderEngine : public InputEngine { ...@@ -51,10 +48,6 @@ class DecoderEngine : public InputEngine {
// Returns whether the decoder shared library supports this ime_spec. // Returns whether the decoder shared library supports this ime_spec.
bool IsImeSupportedByDecoder(const std::string& ime_spec); bool IsImeSupportedByDecoder(const std::string& ime_spec);
// Called when there's a reply from the shared library.
// Deserializes |message| and converts it into Mojo calls to the receiver.
void OnReply(const std::vector<uint8_t>& message);
// Shared library handle of the implementation for input logic with decoders. // Shared library handle of the implementation for input logic with decoders.
base::ScopedNativeLibrary library_; base::ScopedNativeLibrary library_;
...@@ -64,11 +57,6 @@ class DecoderEngine : public InputEngine { ...@@ -64,11 +57,6 @@ class DecoderEngine : public InputEngine {
mojo::ReceiverSet<mojom::InputChannel> decoder_channel_receivers_; mojo::ReceiverSet<mojom::InputChannel> decoder_channel_receivers_;
// Sequence ID for protobuf messages sent from the engine.
uint64_t current_seq_id_ = 0;
std::map<uint64_t, OnKeyEventCallback> pending_key_event_callbacks_;
DISALLOW_COPY_AND_ASSIGN(DecoderEngine); DISALLOW_COPY_AND_ASSIGN(DecoderEngine);
}; };
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromeos/services/ime/decoder/system_engine.h"
#include "base/bind_helpers.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "chromeos/services/ime/constants.h"
#include "chromeos/services/ime/decoder/proto_conversion.h"
#include "chromeos/services/ime/ime_decoder.h"
#include "chromeos/services/ime/public/cpp/buildflags.h"
#include "chromeos/services/ime/public/proto/messages.pb.h"
namespace chromeos {
namespace ime {
namespace {
ImeEngineMainEntry* g_fake_main_entry_for_testing = nullptr;
using ReplyCallback =
base::RepeatingCallback<void(const std::vector<uint8_t>&)>;
// A client delegate passed to the shared library in order for the
// shared library to send replies back to the engine.
class ClientDelegate : public ImeClientDelegate {
public:
// All replies from the shared library will be sent to both |remote| and
// |callback|.
ClientDelegate(const std::string& ime_spec,
mojo::PendingRemote<mojom::InputChannel> remote,
ReplyCallback callback)
: ime_spec_(ime_spec),
client_remote_(std::move(remote)),
callback_(callback) {
client_remote_.set_disconnect_handler(base::BindOnce(
&ClientDelegate::OnDisconnected, base::Unretained(this)));
}
~ClientDelegate() override {}
const char* ImeSpec() override { return ime_spec_.c_str(); }
void Process(const uint8_t* data, size_t size) override {
if (client_remote_ && client_remote_.is_bound()) {
std::vector<uint8_t> msg(data, data + size);
client_remote_->ProcessMessage(msg, base::DoNothing());
callback_.Run(msg);
}
}
void Destroy() override {}
private:
void OnDisconnected() {
client_remote_.reset();
LOG(ERROR) << "Client remote is disconnected." << ime_spec_;
}
// The ime specification which is unique in the scope of engine.
std::string ime_spec_;
// The InputChannel remote used to talk to the client.
mojo::Remote<mojom::InputChannel> client_remote_;
ReplyCallback callback_;
};
std::vector<uint8_t> WrapAndSerializeMessage(PublicMessage message) {
Wrapper wrapper;
*wrapper.mutable_public_message() = std::move(message);
std::vector<uint8_t> output(wrapper.ByteSizeLong());
wrapper.SerializeToArray(output.data(), output.size());
return output;
}
} // namespace
void FakeEngineMainEntryForTesting(ImeEngineMainEntry* main_entry) {
g_fake_main_entry_for_testing = main_entry;
}
SystemEngine::SystemEngine(ImeCrosPlatform* platform) : platform_(platform) {
if (g_fake_main_entry_for_testing) {
engine_main_entry_ = g_fake_main_entry_for_testing;
} else {
if (!TryLoadDecoder()) {
LOG(WARNING) << "DecoderEngine INIT INCOMPLETED.";
}
}
}
SystemEngine::~SystemEngine() {}
bool SystemEngine::TryLoadDecoder() {
if (engine_main_entry_)
return true;
auto* decoder = ImeDecoder::GetInstance();
if (decoder->GetStatus() == ImeDecoder::Status::kSuccess) {
engine_main_entry_ = decoder->CreateMainEntry(platform_);
return true;
}
return false;
}
bool SystemEngine::BindRequest(
const std::string& ime_spec,
mojo::PendingReceiver<mojom::InputChannel> receiver,
mojo::PendingRemote<mojom::InputChannel> remote,
const std::vector<uint8_t>& extra) {
if (IsImeSupportedByDecoder(ime_spec)) {
// Activates an IME engine via the shared library. Passing a
// |ClientDelegate| for engine instance created by the shared library to
// make safe calls on the client.
if (engine_main_entry_->ActivateIme(
ime_spec.c_str(),
new ClientDelegate(ime_spec, std::move(remote),
base::BindRepeating(&SystemEngine::OnReply,
base::Unretained(this))))) {
decoder_channel_receivers_.Add(this, std::move(receiver));
// TODO(https://crbug.com/837156): Registry connection error handler.
return true;
}
return false;
}
// Otherwise, try the rule-based engine.
return InputEngine::BindRequest(ime_spec, std::move(receiver),
std::move(remote), extra);
}
bool SystemEngine::IsImeSupportedByDecoder(const std::string& ime_spec) {
return engine_main_entry_ &&
engine_main_entry_->IsImeSupported(ime_spec.c_str());
}
void SystemEngine::OnInputMethodChanged(const std::string& engine_id) {
const uint64_t seq_id = current_seq_id_;
++current_seq_id_;
ProcessMessage(
WrapAndSerializeMessage(OnInputMethodChangedToProto(seq_id, engine_id)),
base::DoNothing());
}
void SystemEngine::OnFocus(mojom::InputFieldInfoPtr input_field_info) {
const uint64_t seq_id = current_seq_id_;
++current_seq_id_;
ProcessMessage(WrapAndSerializeMessage(
OnFocusToProto(seq_id, std::move(input_field_info))),
base::DoNothing());
}
void SystemEngine::OnBlur() {
const uint64_t seq_id = current_seq_id_;
++current_seq_id_;
ProcessMessage(WrapAndSerializeMessage(OnBlurToProto(seq_id)),
base::DoNothing());
}
void SystemEngine::OnKeyEvent(mojom::PhysicalKeyEventPtr event,
OnKeyEventCallback callback) {
const uint64_t seq_id = current_seq_id_;
++current_seq_id_;
pending_key_event_callbacks_.emplace(seq_id, std::move(callback));
ProcessMessage(
WrapAndSerializeMessage(OnKeyEventToProto(seq_id, std::move(event))),
base::DoNothing());
}
void SystemEngine::OnSurroundingTextChanged(
const std::string& text,
uint32_t offset,
mojom::SelectionRangePtr selection_range) {
const uint64_t seq_id = current_seq_id_;
++current_seq_id_;
ProcessMessage(WrapAndSerializeMessage(OnSurroundingTextChangedToProto(
seq_id, text, offset, std::move(selection_range))),
base::DoNothing());
}
void SystemEngine::OnCompositionCanceled() {
const uint64_t seq_id = current_seq_id_;
++current_seq_id_;
ProcessMessage(WrapAndSerializeMessage(OnCompositionCanceledToProto(seq_id)),
base::DoNothing());
}
void SystemEngine::ProcessMessage(const std::vector<uint8_t>& message,
ProcessMessageCallback callback) {
// TODO(https://crbug.com/837156): Set a default protobuf message.
std::vector<uint8_t> result;
// Handle message via corresponding functions of loaded decoder.
if (engine_main_entry_)
engine_main_entry_->Process(message.data(), message.size());
std::move(callback).Run(result);
}
void SystemEngine::OnReply(const std::vector<uint8_t>& message) {
ime::Wrapper wrapper;
if (!wrapper.ParseFromArray(message.data(), message.size()) ||
!wrapper.has_public_message()) {
return;
}
const ime::PublicMessage& reply = wrapper.public_message();
switch (reply.param_case()) {
case ime::PublicMessage::kOnKeyEventReply: {
const auto it = pending_key_event_callbacks_.find(reply.seq_id());
CHECK(it != pending_key_event_callbacks_.end());
auto callback = std::move(it->second);
std::move(callback).Run(reply.on_key_event_reply().consumed());
pending_key_event_callbacks_.erase(it);
break;
}
default:
NOTREACHED();
break;
}
}
} // namespace ime
} // namespace chromeos
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_SERVICES_IME_DECODER_SYSTEM_ENGINE_H_
#define CHROMEOS_SERVICES_IME_DECODER_SYSTEM_ENGINE_H_
#include "base/scoped_native_library.h"
#include "chromeos/services/ime/input_engine.h"
#include "chromeos/services/ime/public/cpp/shared_lib/interfaces.h"
#include "chromeos/services/ime/public/mojom/input_engine.mojom.h"
namespace chromeos {
namespace ime {
// Only used in tests to set a fake `ImeEngineMainEntry`.
void FakeEngineMainEntryForTesting(ImeEngineMainEntry* main_entry);
// An enhanced implementation of the basic InputEngine that uses a built-in
// shared library for handling key events.
class SystemEngine : public InputEngine {
public:
explicit SystemEngine(ImeCrosPlatform* platform);
SystemEngine(const SystemEngine&) = delete;
SystemEngine& operator=(const SystemEngine&) = delete;
~SystemEngine() override;
// InputEngine overrides:
bool BindRequest(const std::string& ime_spec,
mojo::PendingReceiver<mojom::InputChannel> receiver,
mojo::PendingRemote<mojom::InputChannel> remote,
const std::vector<uint8_t>& extra) override;
void ProcessMessage(const std::vector<uint8_t>& message,
ProcessMessageCallback callback) override;
void OnInputMethodChanged(const std::string& engine_id) override;
void OnFocus(mojom::InputFieldInfoPtr input_field_info) override;
void OnBlur() override;
void OnKeyEvent(mojom::PhysicalKeyEventPtr event,
OnKeyEventCallback callback) override;
void OnSurroundingTextChanged(
const std::string& text,
uint32_t offset,
mojom::SelectionRangePtr selection_range) override;
void OnCompositionCanceled() override;
private:
// Try to load the decoding functions from some decoder shared library.
// Returns whether loading decoder is successful.
bool TryLoadDecoder();
// Returns whether the decoder shared library supports this ime_spec.
bool IsImeSupportedByDecoder(const std::string& ime_spec);
// Called when there's a reply from the shared library.
// Deserializes |message| and converts it into Mojo calls to the receiver.
void OnReply(const std::vector<uint8_t>& message);
// Shared library handle of the implementation for input logic with decoders.
base::ScopedNativeLibrary library_;
ImeEngineMainEntry* engine_main_entry_ = nullptr;
ImeCrosPlatform* platform_ = nullptr;
mojo::ReceiverSet<mojom::InputChannel> decoder_channel_receivers_;
// Sequence ID for protobuf messages sent from the engine.
uint64_t current_seq_id_ = 0;
std::map<uint64_t, OnKeyEventCallback> pending_key_event_callbacks_;
};
} // namespace ime
} // namespace chromeos
#endif // CHROMEOS_SERVICES_IME_DECODER_SYSTEM_ENGINE_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chromeos/services/ime/decoder/decoder_engine.h" #include "chromeos/services/ime/decoder/system_engine.h"
#include "base/test/bind_test_util.h" #include "base/test/bind_test_util.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
...@@ -72,7 +72,7 @@ class StubInputChannel : public mojom::InputChannel { ...@@ -72,7 +72,7 @@ class StubInputChannel : public mojom::InputChannel {
}; };
// Sets up the test environment for Mojo and inject a mock ImeEngineMainEntry. // Sets up the test environment for Mojo and inject a mock ImeEngineMainEntry.
class DecoderEngineTest : public testing::Test { class SystemEngineTest : public testing::Test {
protected: protected:
void SetUp() final { void SetUp() final {
FakeEngineMainEntryForTesting(&mock_main_entry_); FakeEngineMainEntryForTesting(&mock_main_entry_);
...@@ -91,8 +91,8 @@ class DecoderEngineTest : public testing::Test { ...@@ -91,8 +91,8 @@ class DecoderEngineTest : public testing::Test {
base::test::ScopedFeatureList scoped_feature_list_; base::test::ScopedFeatureList scoped_feature_list_;
}; };
TEST_F(DecoderEngineTest, BindRequestBindsInterfaces) { TEST_F(SystemEngineTest, BindRequestBindsInterfaces) {
DecoderEngine engine(/*platform=*/nullptr); SystemEngine engine(/*platform=*/nullptr);
StubInputChannel stub_channel; StubInputChannel stub_channel;
mojo::Receiver<mojom::InputChannel> receiver(&stub_channel); mojo::Receiver<mojom::InputChannel> receiver(&stub_channel);
...@@ -104,8 +104,8 @@ TEST_F(DecoderEngineTest, BindRequestBindsInterfaces) { ...@@ -104,8 +104,8 @@ TEST_F(DecoderEngineTest, BindRequestBindsInterfaces) {
EXPECT_TRUE(receiver.is_bound()); EXPECT_TRUE(receiver.is_bound());
} }
TEST_F(DecoderEngineTest, OnInputMethodChangedSendsMessageToSharedLib) { TEST_F(SystemEngineTest, OnInputMethodChangedSendsMessageToSharedLib) {
DecoderEngine engine(/*platform=*/nullptr); SystemEngine engine(/*platform=*/nullptr);
StubInputChannel stub_channel; StubInputChannel stub_channel;
mojo::Receiver<mojom::InputChannel> receiver(&stub_channel); mojo::Receiver<mojom::InputChannel> receiver(&stub_channel);
mojo::Remote<mojom::InputChannel> client; mojo::Remote<mojom::InputChannel> client;
...@@ -121,8 +121,8 @@ TEST_F(DecoderEngineTest, OnInputMethodChangedSendsMessageToSharedLib) { ...@@ -121,8 +121,8 @@ TEST_F(DecoderEngineTest, OnInputMethodChangedSendsMessageToSharedLib) {
client.FlushForTesting(); client.FlushForTesting();
} }
TEST_F(DecoderEngineTest, OnFocusSendsMessageToSharedLib) { TEST_F(SystemEngineTest, OnFocusSendsMessageToSharedLib) {
DecoderEngine engine(/*platform=*/nullptr); SystemEngine engine(/*platform=*/nullptr);
StubInputChannel stub_channel; StubInputChannel stub_channel;
mojo::Receiver<mojom::InputChannel> receiver(&stub_channel); mojo::Receiver<mojom::InputChannel> receiver(&stub_channel);
mojo::Remote<mojom::InputChannel> client; mojo::Remote<mojom::InputChannel> client;
...@@ -143,8 +143,8 @@ TEST_F(DecoderEngineTest, OnFocusSendsMessageToSharedLib) { ...@@ -143,8 +143,8 @@ TEST_F(DecoderEngineTest, OnFocusSendsMessageToSharedLib) {
client.FlushForTesting(); client.FlushForTesting();
} }
TEST_F(DecoderEngineTest, OnBlurSendsMessageToSharedLib) { TEST_F(SystemEngineTest, OnBlurSendsMessageToSharedLib) {
DecoderEngine engine(/*platform=*/nullptr); SystemEngine engine(/*platform=*/nullptr);
StubInputChannel stub_channel; StubInputChannel stub_channel;
mojo::Receiver<mojom::InputChannel> receiver(&stub_channel); mojo::Receiver<mojom::InputChannel> receiver(&stub_channel);
mojo::Remote<mojom::InputChannel> client; mojo::Remote<mojom::InputChannel> client;
...@@ -159,8 +159,8 @@ TEST_F(DecoderEngineTest, OnBlurSendsMessageToSharedLib) { ...@@ -159,8 +159,8 @@ TEST_F(DecoderEngineTest, OnBlurSendsMessageToSharedLib) {
client.FlushForTesting(); client.FlushForTesting();
} }
TEST_F(DecoderEngineTest, OnKeyEventRepliesWithCallback) { TEST_F(SystemEngineTest, OnKeyEventRepliesWithCallback) {
DecoderEngine engine(/*platform=*/nullptr); SystemEngine engine(/*platform=*/nullptr);
StubInputChannel stub_channel; StubInputChannel stub_channel;
mojo::Receiver<mojom::InputChannel> receiver(&stub_channel); mojo::Receiver<mojom::InputChannel> receiver(&stub_channel);
mojo::Remote<mojom::InputChannel> client; mojo::Remote<mojom::InputChannel> client;
...@@ -195,8 +195,8 @@ TEST_F(DecoderEngineTest, OnKeyEventRepliesWithCallback) { ...@@ -195,8 +195,8 @@ TEST_F(DecoderEngineTest, OnKeyEventRepliesWithCallback) {
EXPECT_TRUE(consumed_by_test); EXPECT_TRUE(consumed_by_test);
} }
TEST_F(DecoderEngineTest, OnSurroundingTextChangedSendsMessageToSharedLib) { TEST_F(SystemEngineTest, OnSurroundingTextChangedSendsMessageToSharedLib) {
DecoderEngine engine(/*platform=*/nullptr); SystemEngine engine(/*platform=*/nullptr);
StubInputChannel stub_channel; StubInputChannel stub_channel;
mojo::Receiver<mojom::InputChannel> receiver(&stub_channel); mojo::Receiver<mojom::InputChannel> receiver(&stub_channel);
mojo::Remote<mojom::InputChannel> client; mojo::Remote<mojom::InputChannel> client;
...@@ -213,8 +213,8 @@ TEST_F(DecoderEngineTest, OnSurroundingTextChangedSendsMessageToSharedLib) { ...@@ -213,8 +213,8 @@ TEST_F(DecoderEngineTest, OnSurroundingTextChangedSendsMessageToSharedLib) {
client.FlushForTesting(); client.FlushForTesting();
} }
TEST_F(DecoderEngineTest, OnCompositionCanceledSendsMessageToSharedLib) { TEST_F(SystemEngineTest, OnCompositionCanceledSendsMessageToSharedLib) {
DecoderEngine engine(/*platform=*/nullptr); SystemEngine engine(/*platform=*/nullptr);
StubInputChannel stub_channel; StubInputChannel stub_channel;
mojo::Receiver<mojom::InputChannel> receiver(&stub_channel); mojo::Receiver<mojom::InputChannel> receiver(&stub_channel);
mojo::Remote<mojom::InputChannel> client; mojo::Remote<mojom::InputChannel> client;
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "chromeos/constants/chromeos_features.h" #include "chromeos/constants/chromeos_features.h"
#include "chromeos/services/ime/constants.h" #include "chromeos/services/ime/constants.h"
#include "chromeos/services/ime/decoder/decoder_engine.h" #include "chromeos/services/ime/decoder/decoder_engine.h"
#include "chromeos/services/ime/decoder/system_engine.h"
#include "chromeos/services/ime/public/cpp/buildflags.h" #include "chromeos/services/ime/public/cpp/buildflags.h"
namespace chromeos { namespace chromeos {
...@@ -37,9 +38,16 @@ enum SimpleDownloadError { ...@@ -37,9 +38,16 @@ enum SimpleDownloadError {
ImeService::ImeService(mojo::PendingReceiver<mojom::ImeService> receiver) ImeService::ImeService(mojo::PendingReceiver<mojom::ImeService> receiver)
: receiver_(this, std::move(receiver)), : receiver_(this, std::move(receiver)),
main_task_runner_(base::SequencedTaskRunnerHandle::Get()) { main_task_runner_(base::SequencedTaskRunnerHandle::Get()) {
input_engine_ = chromeos::features::IsImeSandboxEnabled() if (chromeos::features::IsImeSandboxEnabled()) {
? std::make_unique<DecoderEngine>(this) if (base::FeatureList::IsEnabled(
: std::make_unique<InputEngine>(); chromeos::features::kSystemLatinPhysicalTyping)) {
input_engine_ = std::make_unique<SystemEngine>(this);
} else {
input_engine_ = std::make_unique<DecoderEngine>(this);
}
} else {
input_engine_ = std::make_unique<InputEngine>();
}
} }
ImeService::~ImeService() = default; ImeService::~ImeService() = default;
......
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