Commit 960d02e7 authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

ime: Rewrite the IME service public protos.

Previously, the Wrapper message was defined to be:

   Wrapper { internal_request, internal_reply, reply, request }

However, internally, internal_request and internal_reply were the same
object, so it seemed a bit overkill.

Change Wrapper to just have a public_message or a private_message.
Although it's more type-safe to distinguish between request/reply, the
terminology can be confusing. Since the private messages don't distinguish
between request/reply, might as well do the same for the public messages too.

Also change the terminology from internal to public/private, since it better
corresponds to the existing terminology about public/private APIs.

Fix a bug where the protos were not being serialized at all.

Change-Id: I98e96dadf42ce8ccb1a1f28cdbdb06c2386ef2cf
Bug: 1019541
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2423828
Commit-Queue: Darren Shen <shend@chromium.org>
Reviewed-by: default avatarKeith Lee <keithlee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810093}
parent e3728b23
...@@ -55,11 +55,11 @@ class ClientDelegate : public ImeClientDelegate { ...@@ -55,11 +55,11 @@ class ClientDelegate : public ImeClientDelegate {
mojo::Remote<mojom::InputChannel> client_remote_; mojo::Remote<mojom::InputChannel> client_remote_;
}; };
std::vector<uint8_t> SerializeRequest(const ime::Request& request) { std::vector<uint8_t> SerializeMessage(ime::PublicMessage message) {
ime::Wrapper wrapper; ime::Wrapper wrapper;
*wrapper.mutable_request() = request; *wrapper.mutable_public_message() = std::move(message);
std::vector<uint8_t> output; std::vector<uint8_t> output;
wrapper.SerializeToArray(output.data(), output.size()); wrapper.SerializeToArray(output.data(), wrapper.ByteSizeLong());
return output; return output;
} }
...@@ -136,11 +136,11 @@ bool DecoderEngine::IsImeSupportedByDecoder(const std::string& ime_spec) { ...@@ -136,11 +136,11 @@ bool DecoderEngine::IsImeSupportedByDecoder(const std::string& ime_spec) {
} }
void DecoderEngine::OnFocus() { void DecoderEngine::OnFocus() {
ime::Request request; ime::PublicMessage message;
request.set_seq_id(current_seq_id_++); message.set_seq_id(current_seq_id_++);
*request.mutable_on_focus() = ime::OnFocus(); *message.mutable_on_focus() = ime::OnFocus();
ProcessMessage(SerializeRequest(request), base::DoNothing()); ProcessMessage(SerializeMessage(std::move(message)), base::DoNothing());
} }
void DecoderEngine::ProcessMessage(const std::vector<uint8_t>& message, void DecoderEngine::ProcessMessage(const std::vector<uint8_t>& message,
......
// Messages sent between the IME service and the shared library.
// Although Chrome communicates with the IME service using Mojo, the shared
// library is built in google3, which doesn't support Mojo yet. Hence, when the
// IME service sends or receives messages via Mojo, it needs to convert the Mojo
// calls into protos before forwarding to and from the shared library:
//
// [Chrome] <---Mojo---> [IME Service] <---Proto---> [Shared Library]
syntax = "proto2"; syntax = "proto2";
option optimize_for = LITE_RUNTIME; option optimize_for = LITE_RUNTIME;
package chromeos.ime; package chromeos.ime;
// Wrapper message to contain either internal messages or public messages. // The base message type for all communication between the IME service and the
// shared library. The IME service and the shared library uses both a public and
// private protocol, so Wrapper has fields for both. For the private messages,
// Wrapper stores it as a serialized proto to keep the message private.
message Wrapper { message Wrapper {
oneof param { oneof param {
bytes internal_request = 1; PublicMessage public_message = 1;
bytes internal_reply = 2; bytes private_message = 2;
Request request = 3;
Reply reply = 4;
} }
} }
// Message from Chrome to the shared library. // Public messages between IME service and the shared library.
message Request { // Each 'oneof' submessage represents a Mojo call / response.
// The sequence id of the request. message PublicMessage {
optional int32 seq_id = 1; optional int32 seq_id = 1;
oneof param { OnFocus on_focus = 2; } oneof param { OnFocus on_focus = 2; }
} }
// Message from the shared library to Chrome.
message Reply {
// The sequence id of the reply.
optional int32 seq_id = 1;
}
// Protobuf version of InputEngine::OnFocus in // Protobuf version of InputEngine::OnFocus in
// chromeos/services/ime/public/mojom/input_engine.mojom // chromeos/services/ime/public/mojom/input_engine.mojom
message OnFocus { message OnFocus {
......
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