Commit ab8018a7 authored by Mark Brand's avatar Mark Brand Committed by Commit Bot

MojoLPM: Simplify the protobuf format for Remote/Receiver types.

This change simplifies the protobuf representation of Remote/Receiver
types, and adjusts the generated code accordingly. It also removes some
duplication of code in the Remote/AssociatedRemote cases so that the
handling of calls to remotes need only be implemented once for each
interface.

Bug: 1076336
Change-Id: Ib4cdb0cb6cf700ebb74feb28cd66acb3b49f2d30
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2302609Reviewed-by: default avatarKen Rockot <rockot@google.com>
Reviewed-by: default avatarOliver Chang <ochang@chromium.org>
Commit-Queue: Mark Brand <markbrand@google.com>
Cr-Commit-Position: refs/heads/master@{#792256}
parent 17c1e319
......@@ -7,9 +7,7 @@ actions {
}
actions {
code_cache_host_call {
remote {
id: 1
}
id: 1
m_did_generate_cacheable_metadata {
m_cache_type: CodeCacheType_kJavascript
m_url {
......
......@@ -7,9 +7,7 @@ actions {
}
actions {
code_cache_host_call {
remote {
id: 1
}
id: 1
m_did_generate_cacheable_metadata {
m_cache_type: CodeCacheType_kJavascript
m_url {
......
......@@ -304,7 +304,7 @@ void CodeCacheHostTestcase::NextAction() {
case content::fuzzing::code_cache_host::proto::Action::
kCodeCacheHostCall: {
mojolpm::HandleRemoteMethodCall(action.code_cache_host_call());
mojolpm::HandleRemoteCall(action.code_cache_host_call());
} break;
case content::fuzzing::code_cache_host::proto::Action::ACTION_NOT_SET:
......
......@@ -30,7 +30,7 @@ message Action {
oneof action {
NewCodeCacheHost new_code_cache_host = 1;
RunUntilIdle run_until_idle = 2;
mojolpm.blink.mojom.CodeCacheHost.RemoteMethodCall code_cache_host_call = 3;
mojolpm.blink.mojom.CodeCacheHost.RemoteCall code_cache_host_call = 3;
}
}
......
......@@ -117,36 +117,36 @@ bool ToProto(
{%- set proto_type = "::mojolpm" ~ (interface|get_qualified_name_for_kind(flatten_nested_kind=True)) %}
// interface {{interface.name}}
bool FromProto(
const {{proto_type}}::PendingRemote& input,
uint32_t input,
::mojo::PendingRemote<{{mojom_type}}>& output);
bool ToProto(
::mojo::PendingRemote<{{mojom_type}}>&& input,
{{proto_type}}::PendingRemote& output);
uint32_t& output);
bool FromProto(
const {{proto_type}}::PendingReceiver& input,
uint32_t input,
::mojo::PendingReceiver<{{mojom_type}}>& output);
bool ToProto(
::mojo::PendingReceiver<{{mojom_type}}>&& input,
{{proto_type}}::PendingReceiver& output);
uint32_t& output);
bool FromProto(
const {{proto_type}}::PendingAssociatedRemote& input,
uint32_t input,
::mojo::PendingAssociatedRemote<{{mojom_type}}>& output);
bool ToProto(
::mojo::PendingAssociatedRemote<{{mojom_type}}>&& input,
{{proto_type}}::PendingAssociatedRemote& output);
uint32_t& output);
bool FromProto(
const {{proto_type}}::PendingAssociatedReceiver& input,
uint32_t input,
::mojo::PendingAssociatedReceiver<{{mojom_type}}>& output);
bool ToProto(
::mojo::PendingAssociatedReceiver<{{mojom_type}}>&& input,
{{proto_type}}::PendingAssociatedReceiver& output);{{"\n"-}}
uint32_t& output);{{"\n"-}}
{%- for method in interface.methods %}
{%- set method_type = proto_type ~ "::" ~ interface.name ~ "_" ~ method.name %}
{%- for param in method.parameters %}
......@@ -177,21 +177,21 @@ bool ToProto(
{%- set mojom_type = interface|get_qualified_name_for_kind(flatten_nested_kind=True) %}
{%- set proto_type = "::mojolpm" ~ (interface|get_qualified_name_for_kind(flatten_nested_kind=True)) %}
{%- if interface.methods %}
bool HandleRemoteMethodCall(
const {{proto_type}}::RemoteMethodCall& input);
bool HandleRemoteCall(
const {{proto_type}}::RemoteCall& input);
bool HandleAssociatedRemoteMethodCall(
const {{proto_type}}::AssociatedRemoteMethodCall& input);
bool HandleAssociatedRemoteCall(
const {{proto_type}}::AssociatedRemoteCall& input);
bool AddResponse(
const {{proto_type}}::ReceiverResponse& response);{{"\n"-}}
{%- for method in interface.methods %}
bool HandleRemoteMethodCall(
::mojo::Remote<{{mojom_type}}>& instance,
bool HandleRemoteCall(
uint32_t instance_id,
const {{proto_type}}::{{interface.name}}_{{method.name}}& input);
bool HandleAssociatedRemoteMethodCall(
::mojo::AssociatedRemote<{{mojom_type}}>& instance,
bool HandleAssociatedRemoteCall(
uint32_t instance_id,
const {{proto_type}}::{{interface.name}}_{{method.name}}& input);{{"\n"-}}
{%- endfor %}
{%- endif %}
......
......@@ -229,22 +229,6 @@ message {{union_name}} {
{%- for interface in interfaces %}
message {{interface.name}} {
message PendingRemote {
required uint32 id = 1;
}
message PendingReceiver {
required uint32 id = 1;
}
message PendingAssociatedRemote {
required uint32 id = 1;
}
message PendingAssociatedReceiver {
required uint32 id = 1;
}
message Reset {
}
......@@ -332,8 +316,8 @@ message {{interface.name}} {
{%- endfor%}
{%- if interface.methods|length %}
message RemoteMethodCall {
required {{interface.name}}.PendingRemote remote = 1;
message RemoteCall {
required uint32 id = 1;
oneof method {
Reset reset = 2;
......@@ -343,8 +327,8 @@ message {{interface.name}} {
}
}
message AssociatedRemoteMethodCall {
required {{interface.name}}.PendingAssociatedRemote remote = 1;
message AssociatedRemoteCall {
required uint32 id = 1;
oneof method {
Reset reset = 2;
......
......@@ -129,6 +129,12 @@ bool ToProto(
mojolpm_result = ToProto(input, value);
output.set_value(value);
return mojolpm_result;
{%- elif kind.kind|is_any_interface_kind %}
bool mojolpm_result;
{{kind.kind|cpp_wrapper_proto_type(add_same_module_namespaces=true)}} value;
mojolpm_result = ToProto(std::move(input), value);
output.set_value(value);
return mojolpm_result;
{%- elif kind.kind|is_move_only_kind %}
return ToProto(std::move(input), *output.mutable_value());
{%- else %}
......@@ -220,6 +226,12 @@ bool ToProto(
mojolpm_result = ToProto(input, value);
output.set_value(value);
return mojolpm_result;
{%- elif kind.value_kind|is_any_interface_kind %}
bool mojolpm_result;
{{kind.value_kind|cpp_wrapper_proto_type(add_same_module_namespaces=true)}} value;
mojolpm_result = ToProto(std::move(input), value);
output.set_value(value);
return mojolpm_result;
{%- elif kind.value_kind|is_move_only_kind %}
return ToProto(std::move(input), *output.mutable_value());
{%- else %}
......@@ -289,6 +301,10 @@ bool ToProto(
{{kind|cpp_wrapper_proto_type(add_same_module_namespaces=true)}} tmp_{{name}};
mojolpm_result &= ToProto(input->{{raw_name}}, tmp_{{name}});
new_instance->set_m_{{name}}(tmp_{{name}});
{%- elif kind|is_any_interface_kind %}
{{kind|cpp_wrapper_proto_type(add_same_module_namespaces=true)}} tmp_{{name}};
mojolpm_result &= ToProto(std::move(input->{{raw_name}}), tmp_{{name}});
new_instance->set_m_{{name}}(tmp_{{name}});
{%- elif kind|is_nullable_kind %}
if ({{util.not_null(kind, 'input->' ~ raw_name)}}) {
{%- if kind|is_move_only_kind %}
......@@ -332,25 +348,27 @@ bool ToProto(
{%- set name = field.name|camel_to_under %}
{%- set kind = field.kind %}
case {{enum_name}}::{{field.name|upper}}: {
{%- if kind|is_move_only_kind and kind|is_nullable_kind %}
if ({{util.not_null(kind, 'input->get_' ~ raw_name ~ '()')}}) {
mojolpm_result &= ToProto(std::move({{util.value(kind, 'input->get_' ~ raw_name ~ '()')}}), *new_instance->mutable_m_{{name}}());
}
{%- elif kind|is_move_only_kind %}
mojolpm_result = ToProto(std::move(input->get_{{raw_name}}()),
*(new_instance->mutable_m_{{name}}()));
{%- elif kind|is_nullable_kind %}
if ({{util.not_null(kind, 'input->get_' ~ raw_name ~ '()')}}) {
mojolpm_result &= ToProto({{util.value(kind, 'input->get_' ~ raw_name ~ '()')}}, *new_instance->mutable_m_{{name}}());
}
{%- elif kind|is_integral_kind or kind|is_enum_kind or kind|is_float_kind or kind|is_double_kind %}
{{kind|cpp_wrapper_proto_type(add_same_module_namespaces=true)}} tmp_{{name}};
mojolpm_result &= ToProto(input->get_{{raw_name}}(), tmp_{{name}});
new_instance->set_m_{{name}}(tmp_{{name}});
{%- if kind|is_integral_kind or kind|is_enum_kind or kind|is_float_kind or kind|is_double_kind %}
{{kind|cpp_wrapper_proto_type(add_same_module_namespaces=true)}} tmp_{{name}};
mojolpm_result &= ToProto(input->get_{{raw_name}}(), tmp_{{name}});
new_instance->set_m_{{name}}(tmp_{{name}});
{%- elif kind|is_any_interface_kind %}
{{kind|cpp_wrapper_proto_type(add_same_module_namespaces=true)}} tmp_{{name}};
mojolpm_result &= ToProto(std::move(input->get_{{raw_name}}()), tmp_{{name}});
new_instance->set_m_{{name}}(tmp_{{name}});
{%- elif kind|is_nullable_kind %}
if ({{util.not_null(kind, 'input->' ~ raw_name)}}) {
{%- if kind|is_move_only_kind %}
mojolpm_result &= ToProto(std::move({{util.value(kind, 'input->get_' ~ raw_name ~ '()')}}), *new_instance->mutable_m_{{name}}());
{%- else %}
mojolpm_result = ToProto(input->get_{{name}}(),
*(new_instance->mutable_m_{{name}}()));
mojolpm_result &= ToProto({{util.value(kind, 'input->get_' ~ raw_name ~ '()')}}, *new_instance->mutable_m_{{name}}());
{%- endif %}
}
{%- elif kind|is_move_only_kind %}
mojolpm_result &= ToProto(std::move(input->get_{{raw_name}}()), *new_instance->mutable_m_{{name}}());
{%- else %}
mojolpm_result &= ToProto(input->get_{{raw_name}}(), *new_instance->mutable_m_{{name}}());
{%- endif %}
} break;
{%- endfor %}
}
......
......@@ -346,18 +346,10 @@ class Generator(CppGenerator):
or mojom.IsUnionKind(kind)):
return self._GetCppProtoNameForKind(
kind, add_same_module_namespaces=add_same_module_namespaces)
elif mojom.IsPendingRemoteKind(kind):
return "%s::PendingRemote" % self._GetCppProtoNameForKind(
kind.kind, add_same_module_namespaces=add_same_module_namespaces)
elif mojom.IsPendingReceiverKind(kind):
return "%s::PendingReceiver" % self._GetCppProtoNameForKind(
kind.kind, add_same_module_namespaces=add_same_module_namespaces)
elif mojom.IsPendingAssociatedRemoteKind(kind):
return "%s::PendingAssociatedRemote" % self._GetCppProtoNameForKind(
kind.kind, add_same_module_namespaces=add_same_module_namespaces)
elif mojom.IsPendingAssociatedReceiverKind(kind):
return "%s::PendingAssociatedReceiver" % self._GetCppProtoNameForKind(
kind.kind, add_same_module_namespaces=add_same_module_namespaces)
elif (mojom.IsPendingRemoteKind(kind) or mojom.IsPendingReceiverKind(kind)
or mojom.IsPendingAssociatedRemoteKind(kind)
or mojom.IsPendingAssociatedReceiverKind(kind)):
return "uint32_t"
elif mojom.IsStringKind(kind):
return "std::string"
elif mojom.IsGenericHandleKind(kind):
......@@ -391,16 +383,10 @@ class Generator(CppGenerator):
return ("map<%sKey, %sValue>" %
(self._GetProtoFieldType(kind.key_kind, quantified=False),
self._GetProtoFieldType(kind.value_kind, quantified=False)))
elif mojom.IsPendingRemoteKind(kind):
unquantified = "%s.PendingRemote" % self._GetProtoNameForKind(kind.kind)
elif mojom.IsPendingReceiverKind(kind):
unquantified = "%s.PendingReceiver" % self._GetProtoNameForKind(kind.kind)
elif mojom.IsPendingAssociatedRemoteKind(kind):
unquantified = ("%s.PendingAssociatedRemote" %
self._GetProtoNameForKind(kind.kind))
elif mojom.IsPendingAssociatedReceiverKind(kind):
unquantified = ("%s.PendingAssociatedReceiver" %
self._GetProtoNameForKind(kind.kind))
elif (mojom.IsPendingRemoteKind(kind) or mojom.IsPendingReceiverKind(kind)
or mojom.IsPendingAssociatedRemoteKind(kind)
or mojom.IsPendingAssociatedReceiverKind(kind)):
unquantified = "uint32"
elif mojom.IsStringKind(kind):
unquantified = "string"
elif mojom.IsGenericHandleKind(kind):
......
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