Commit 0471e477 authored by Giovanni Ortuño Urquidi's avatar Giovanni Ortuño Urquidi Committed by Commit Bot

mojo: Use new names in interface_support.js

As a first step towards using new primitive types, replace internal use
of Proxy and Target with Remote and Receiver.

Bug: 968369
Change-Id: Ib37130094c9ec85ac8d0f8346910c00764519cbf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1636255
Auto-Submit: Giovanni Ortuño Urquidi <ortuno@chromium.org>
Reviewed-by: default avatarcalamity <calamity@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Commit-Queue: Giovanni Ortuño Urquidi <ortuno@chromium.org>
Cr-Commit-Position: refs/heads/master@{#666551}
parent 2f419137
...@@ -11,7 +11,7 @@ goog.provide('mojo.internal.interfaceSupport'); ...@@ -11,7 +11,7 @@ goog.provide('mojo.internal.interfaceSupport');
/** /**
* Handles incoming interface control messages on a proxy or router endpoint. * Handles incoming interface control messages on a remote or router endpoint.
*/ */
mojo.internal.interfaceSupport.ControlMessageHandler = class { mojo.internal.interfaceSupport.ControlMessageHandler = class {
/** @param {!MojoHandle} handle */ /** @param {!MojoHandle} handle */
...@@ -72,8 +72,8 @@ mojo.internal.interfaceSupport.ControlMessageHandler = class { ...@@ -72,8 +72,8 @@ mojo.internal.interfaceSupport.ControlMessageHandler = class {
}; };
/** /**
* Captures metadata about a request which was sent by a local proxy, for which * Captures metadata about a request which was sent by a remote, for which a
* a response is expected. * response is expected.
*/ */
mojo.internal.interfaceSupport.PendingResponse = class { mojo.internal.interfaceSupport.PendingResponse = class {
/** /**
...@@ -150,16 +150,16 @@ mojo.internal.interfaceSupport.ConnectionErrorEventRouter = class { ...@@ -150,16 +150,16 @@ mojo.internal.interfaceSupport.ConnectionErrorEventRouter = class {
}; };
/** /**
* Generic helper used to implement all generated proxy classes. Knows how to * Generic helper used to implement all generated remote classes. Knows how to
* serialize requests and deserialize their replies, both according to * serialize requests and deserialize their replies, both according to
* declarative message structure specs. * declarative message structure specs.
* @template T * @template T
* @export * @export
*/ */
mojo.internal.interfaceSupport.InterfaceProxyBase = class { mojo.internal.interfaceSupport.InterfaceRemoteBase = class {
/** /**
* @param {!function(new:T, !MojoHandle)} requestType * @param {!function(new:T, !MojoHandle)} requestType
* @param {MojoHandle=} opt_handle The message pipe handle to use as a proxy * @param {MojoHandle=} opt_handle The message pipe handle to use as a remote
* endpoint. If null, this object must be bound with bindHandle before * endpoint. If null, this object must be bound with bindHandle before
* it can be used to send any messages. * it can be used to send any messages.
* @public * @public
...@@ -196,7 +196,7 @@ mojo.internal.interfaceSupport.InterfaceProxyBase = class { ...@@ -196,7 +196,7 @@ mojo.internal.interfaceSupport.InterfaceProxyBase = class {
/** /**
* @return {!T} * @return {!T}
*/ */
createRequest() { bindNewPipeAndPassReceiver() {
let {handle0, handle1} = Mojo.createMessagePipe(); let {handle0, handle1} = Mojo.createMessagePipe();
this.bindHandle(handle0); this.bindHandle(handle0);
return new this.requestType_(handle1); return new this.requestType_(handle1);
...@@ -208,7 +208,7 @@ mojo.internal.interfaceSupport.InterfaceProxyBase = class { ...@@ -208,7 +208,7 @@ mojo.internal.interfaceSupport.InterfaceProxyBase = class {
*/ */
bindHandle(handle) { bindHandle(handle) {
if (this.handle) if (this.handle)
throw new Error('Proxy already bound.'); throw new Error('Remote already bound.');
this.handle = handle; this.handle = handle;
const reader = new mojo.internal.interfaceSupport.HandleReader(handle); const reader = new mojo.internal.interfaceSupport.HandleReader(handle);
...@@ -253,7 +253,8 @@ mojo.internal.interfaceSupport.InterfaceProxyBase = class { ...@@ -253,7 +253,8 @@ mojo.internal.interfaceSupport.InterfaceProxyBase = class {
sendMessage(ordinal, paramStruct, responseStruct, args) { sendMessage(ordinal, paramStruct, responseStruct, args) {
if (!this.handle) { if (!this.handle) {
throw new Error( throw new Error(
'Attempting to use an unbound proxy. Try $.createRequest() first.') 'Attempting to use an unbound remote. Try ' +
'$.bindNewPipeAndPassReceiver() first.')
} }
// The pipe has already been closed, so just drop the message. // The pipe has already been closed, so just drop the message.
...@@ -344,33 +345,42 @@ mojo.internal.interfaceSupport.InterfaceProxyBase = class { ...@@ -344,33 +345,42 @@ mojo.internal.interfaceSupport.InterfaceProxyBase = class {
}; };
/** /**
* Wrapper around mojo.internal.interfaceSupport.InterfaceProxyBase that * Wrapper around mojo.internal.interfaceSupport.InterfaceRemoteBase that
* exposes the subset of InterfaceProxyBase's method that users are allowed * exposes the subset of InterfaceRemoteBase's method that users are allowed
* to use. * to use.
* @template T * @template T
* @export * @export
*/ */
mojo.internal.interfaceSupport.InterfaceProxyBaseWrapper = class { mojo.internal.interfaceSupport.InterfaceRemoteBaseWrapper = class {
/** /**
* @param {!mojo.internal.interfaceSupport.InterfaceProxyBase<T>} proxy * @param {!mojo.internal.interfaceSupport.InterfaceRemoteBase<T>} remote
* @public * @public
*/ */
constructor(proxy) { constructor(remote) {
/** @private {!mojo.internal.interfaceSupport.InterfaceProxyBase<T>} */ /** @private {!mojo.internal.interfaceSupport.InterfaceRemoteBase<T>} */
this.proxy_ = proxy; this.remote_ = remote;
} }
// TODO(ortuno): Remove once new names are used in the exposed interfaces.
/** /**
* @return {!T} * @return {!T}
* @export * @export
*/ */
createRequest() { createRequest() {
return this.proxy_.createRequest(); return this.remote_.bindNewPipeAndPassReceiver();
}
/**
* @return {!T}
* @export
*/
bindNewPipeAndPassReceiver() {
return this.remote_.bindNewPipeAndPassReceiver();
} }
/** @export */ /** @export */
close() { close() {
this.proxy_.close(); this.remote_.close();
} }
/** /**
...@@ -378,7 +388,7 @@ mojo.internal.interfaceSupport.InterfaceProxyBaseWrapper = class { ...@@ -378,7 +388,7 @@ mojo.internal.interfaceSupport.InterfaceProxyBaseWrapper = class {
* @export * @export
*/ */
flushForTesting() { flushForTesting() {
return this.proxy_.flushForTesting(); return this.remote_.flushForTesting();
} }
} }
...@@ -417,7 +427,7 @@ mojo.internal.interfaceSupport.CallbackRouter = class { ...@@ -417,7 +427,7 @@ mojo.internal.interfaceSupport.CallbackRouter = class {
* messages to listeners. * messages to listeners.
* @export * @export
*/ */
mojo.internal.interfaceSupport.InterfaceCallbackTarget = class { mojo.internal.interfaceSupport.InterfaceCallbackReceiver = class {
/** /**
* @public * @public
* @param {!mojo.internal.interfaceSupport.CallbackRouter} callbackRouter * @param {!mojo.internal.interfaceSupport.CallbackRouter} callbackRouter
...@@ -449,7 +459,7 @@ mojo.internal.interfaceSupport.InterfaceCallbackTarget = class { ...@@ -449,7 +459,7 @@ mojo.internal.interfaceSupport.InterfaceCallbackTarget = class {
* @return {!Function} * @return {!Function}
* @export * @export
*/ */
createTargetHandler(expectsResponse) { createReceiverHandler(expectsResponse) {
if (expectsResponse) if (expectsResponse)
return this.dispatchWithResponse_.bind(this); return this.dispatchWithResponse_.bind(this);
return this.dispatch_.bind(this); return this.dispatch_.bind(this);
...@@ -488,7 +498,7 @@ mojo.internal.interfaceSupport.InterfaceCallbackTarget = class { ...@@ -488,7 +498,7 @@ mojo.internal.interfaceSupport.InterfaceCallbackTarget = class {
}; };
/** /**
* Wraps message handlers attached to an InterfaceTarget. * Wraps message handlers attached to an InterfaceReceiver.
*/ */
mojo.internal.interfaceSupport.MessageHandler = class { mojo.internal.interfaceSupport.MessageHandler = class {
/** /**
...@@ -515,7 +525,7 @@ mojo.internal.interfaceSupport.MessageHandler = class { ...@@ -515,7 +525,7 @@ mojo.internal.interfaceSupport.MessageHandler = class {
* message number. * message number.
* @export * @export
*/ */
mojo.internal.interfaceSupport.InterfaceTarget = class { mojo.internal.interfaceSupport.InterfaceReceiver = class {
/** @public */ /** @public */
constructor() { constructor() {
/** /**
...@@ -592,7 +602,7 @@ mojo.internal.interfaceSupport.InterfaceTarget = class { ...@@ -592,7 +602,7 @@ mojo.internal.interfaceSupport.InterfaceTarget = class {
if (this.controlMessageHandler_.maybeHandleControlMessage(header, buffer)) if (this.controlMessageHandler_.maybeHandleControlMessage(header, buffer))
return; return;
if (header.flags & mojo.internal.kMessageFlagIsResponse) if (header.flags & mojo.internal.kMessageFlagIsResponse)
throw new Error('Received unexpected response on interface target'); throw new Error('Received unexpected response on interface receiver');
const handler = this.messageHandlers_.get(header.ordinal); const handler = this.messageHandlers_.get(header.ordinal);
if (!handler) if (!handler)
throw new Error('Received unknown message'); throw new Error('Received unknown message');
...@@ -654,8 +664,8 @@ mojo.internal.interfaceSupport.InterfaceTarget = class { ...@@ -654,8 +664,8 @@ mojo.internal.interfaceSupport.InterfaceTarget = class {
/** /**
* Watches a MojoHandle for readability or peer closure, forwarding either event * Watches a MojoHandle for readability or peer closure, forwarding either event
* to one of two callbacks on the reader. Used by both InterfaceProxyBase and * to one of two callbacks on the reader. Used by both InterfaceRemoteBase and
* InterfaceTarget to watch for incoming messages. * InterfaceReceiver to watch for incoming messages.
*/ */
mojo.internal.interfaceSupport.HandleReader = class { mojo.internal.interfaceSupport.HandleReader = class {
/** /**
......
...@@ -56,17 +56,17 @@ goog.provide('{{module.namespace}}.{{interface.name}}Request'); ...@@ -56,17 +56,17 @@ goog.provide('{{module.namespace}}.{{interface.name}}Request');
/** @param {MojoHandle=} opt_handle */ /** @param {MojoHandle=} opt_handle */
constructor(opt_handle) { constructor(opt_handle) {
/** /**
* @private {!mojo.internal.interfaceSupport.InterfaceProxyBase<!{{module.namespace}}.{{interface.name}}Request>} * @private {!mojo.internal.interfaceSupport.InterfaceRemoteBase<!{{module.namespace}}.{{interface.name}}Request>}
*/ */
this.proxy = this.proxy =
new mojo.internal.interfaceSupport.InterfaceProxyBase( new mojo.internal.interfaceSupport.InterfaceRemoteBase(
{{module.namespace}}.{{interface.name}}Request, {{module.namespace}}.{{interface.name}}Request,
opt_handle); opt_handle);
/** /**
* @public {!mojo.internal.interfaceSupport.InterfaceProxyBaseWrapper<!{{module.namespace}}.{{interface.name}}Request>} * @public {!mojo.internal.interfaceSupport.InterfaceRemoteBaseWrapper<!{{module.namespace}}.{{interface.name}}Request>}
*/ */
this.$ = new mojo.internal.interfaceSupport.InterfaceProxyBaseWrapper(this.proxy); this.$ = new mojo.internal.interfaceSupport.InterfaceRemoteBaseWrapper(this.proxy);
/** @public {!mojo.internal.interfaceSupport.ConnectionErrorEventRouter} */ /** @public {!mojo.internal.interfaceSupport.ConnectionErrorEventRouter} */
this.onConnectionError = this.proxy.getConnectionErrorEventRouter(); this.onConnectionError = this.proxy.getConnectionErrorEventRouter();
...@@ -114,11 +114,11 @@ goog.provide('{{module.namespace}}.{{interface.name}}Request'); ...@@ -114,11 +114,11 @@ goog.provide('{{module.namespace}}.{{interface.name}}Request');
* @param {!{{module.namespace}}.{{interface.name}}Interface } impl * @param {!{{module.namespace}}.{{interface.name}}Interface } impl
*/ */
constructor(impl) { constructor(impl) {
this.target_ = new mojo.internal.interfaceSupport.InterfaceTarget; this.receiver_ = new mojo.internal.interfaceSupport.InterfaceReceiver;
{% for method in interface.methods %} {% for method in interface.methods %}
{%- set interface_message_id = {%- set interface_message_id =
interface.mojom_name ~ "_" ~ method.mojom_name %} interface.mojom_name ~ "_" ~ method.mojom_name %}
this.target_.registerHandler( this.receiver_.registerHandler(
{{method.ordinal}}, {{method.ordinal}},
{{module.namespace}}.{{interface_message_id}}_ParamsSpec.$, {{module.namespace}}.{{interface_message_id}}_ParamsSpec.$,
{%- if method.response_parameters != None %} {%- if method.response_parameters != None %}
...@@ -129,7 +129,7 @@ goog.provide('{{module.namespace}}.{{interface.name}}Request'); ...@@ -129,7 +129,7 @@ goog.provide('{{module.namespace}}.{{interface.name}}Request');
impl.{{method.name}}.bind(impl)); impl.{{method.name}}.bind(impl));
{%- endfor %} {%- endfor %}
/** @public {!mojo.internal.interfaceSupport.ConnectionErrorEventRouter} */ /** @public {!mojo.internal.interfaceSupport.ConnectionErrorEventRouter} */
this.onConnectionError = this.target_.getConnectionErrorEventRouter(); this.onConnectionError = this.receiver_.getConnectionErrorEventRouter();
} }
/** /**
...@@ -140,7 +140,7 @@ goog.provide('{{module.namespace}}.{{interface.name}}Request'); ...@@ -140,7 +140,7 @@ goog.provide('{{module.namespace}}.{{interface.name}}Request');
* @export * @export
*/ */
bindHandle(handle) { bindHandle(handle) {
this.target_.bindHandle(handle); this.receiver_.bindHandle(handle);
} }
/** /**
...@@ -149,7 +149,7 @@ goog.provide('{{module.namespace}}.{{interface.name}}Request'); ...@@ -149,7 +149,7 @@ goog.provide('{{module.namespace}}.{{interface.name}}Request');
* @export * @export
*/ */
closeBindings() { closeBindings() {
this.target_.closeBindings(); this.receiver_.closeBindings();
} }
/** /**
...@@ -163,7 +163,7 @@ goog.provide('{{module.namespace}}.{{interface.name}}Request'); ...@@ -163,7 +163,7 @@ goog.provide('{{module.namespace}}.{{interface.name}}Request');
static getProxy() { static getProxy() {
let proxy = new {{module.namespace}}.{{interface.name}}Proxy; let proxy = new {{module.namespace}}.{{interface.name}}Proxy;
Mojo.bindInterface('{{mojom_namespace}}.{{interface.name}}', Mojo.bindInterface('{{mojom_namespace}}.{{interface.name}}',
proxy.$.createRequest().handle); proxy.$.bindNewPipeAndPassReceiver().handle);
return proxy; return proxy;
} }
...@@ -176,7 +176,7 @@ goog.provide('{{module.namespace}}.{{interface.name}}Request'); ...@@ -176,7 +176,7 @@ goog.provide('{{module.namespace}}.{{interface.name}}Request');
*/ */
createProxy() { createProxy() {
let proxy = new {{module.namespace}}.{{interface.name}}Proxy; let proxy = new {{module.namespace}}.{{interface.name}}Proxy;
this.target_.bindHandle(proxy.$.createRequest().handle); this.receiver_.bindHandle(proxy.$.bindNewPipeAndPassReceiver().handle);
return proxy; return proxy;
} }
}; };
...@@ -198,39 +198,39 @@ goog.provide('{{module.namespace}}.{{interface.name}}Request'); ...@@ -198,39 +198,39 @@ goog.provide('{{module.namespace}}.{{interface.name}}Request');
/** /**
* An object which receives request messages for the {{interface.name}} * An object which receives request messages for the {{interface.name}}
* mojom interface and dispatches them as callbacks. One callback target exists * mojom interface and dispatches them as callbacks. One callback receiver exists
* on this object for each message defined in the mojom interface, and each * on this object for each message defined in the mojom interface, and each
* target can have any number of listeners added to it. * receiver can have any number of listeners added to it.
* *
* @export * @export
*/ */
{{module.namespace}}.{{interface.name}}CallbackRouter = class { {{module.namespace}}.{{interface.name}}CallbackRouter = class {
constructor() { constructor() {
this.target_ = new mojo.internal.interfaceSupport.InterfaceTarget; this.receiver_ = new mojo.internal.interfaceSupport.InterfaceReceiver;
this.router_ = new mojo.internal.interfaceSupport.CallbackRouter; this.router_ = new mojo.internal.interfaceSupport.CallbackRouter;
{% for method in interface.methods %} {% for method in interface.methods %}
{%- set interface_message_id = {%- set interface_message_id =
interface.mojom_name ~ "_" ~ method.mojom_name %} interface.mojom_name ~ "_" ~ method.mojom_name %}
/** /**
* @public {!mojo.internal.interfaceSupport.InterfaceCallbackTarget} * @public {!mojo.internal.interfaceSupport.InterfaceCallbackReceiver}
*/ */
this.{{method.name}} = this.{{method.name}} =
new mojo.internal.interfaceSupport.InterfaceCallbackTarget( new mojo.internal.interfaceSupport.InterfaceCallbackReceiver(
this.router_); this.router_);
this.target_.registerHandler( this.receiver_.registerHandler(
{{method.ordinal}}, {{method.ordinal}},
{{module.namespace}}.{{interface_message_id}}_ParamsSpec.$, {{module.namespace}}.{{interface_message_id}}_ParamsSpec.$,
{%- if method.response_parameters != None %} {%- if method.response_parameters != None %}
{{module.namespace}}.{{interface_message_id}}_ResponseParamsSpec.$, {{module.namespace}}.{{interface_message_id}}_ResponseParamsSpec.$,
this.{{method.name}}.createTargetHandler(true /* expectsResponse */)); this.{{method.name}}.createReceiverHandler(true /* expectsResponse */));
{%- else %} {%- else %}
null, null,
this.{{method.name}}.createTargetHandler(false /* expectsResponse */)); this.{{method.name}}.createReceiverHandler(false /* expectsResponse */));
{%- endif %} {%- endif %}
{%- endfor %} {%- endfor %}
/** @public {!mojo.internal.interfaceSupport.ConnectionErrorEventRouter} */ /** @public {!mojo.internal.interfaceSupport.ConnectionErrorEventRouter} */
this.onConnectionError = this.target_.getConnectionErrorEventRouter(); this.onConnectionError = this.receiver_.getConnectionErrorEventRouter();
} }
/** /**
...@@ -241,15 +241,15 @@ goog.provide('{{module.namespace}}.{{interface.name}}Request'); ...@@ -241,15 +241,15 @@ goog.provide('{{module.namespace}}.{{interface.name}}Request');
* @export * @export
*/ */
bindHandle(handle) { bindHandle(handle) {
this.target_.bindHandle(handle); this.receiver_.bindHandle(handle);
} }
/** /**
* Closes all bindings bound to this target. The target will not receive any * Closes all bindings bound to this receiver. The receiver will not receive any
* further message message events unless rebound to one or more handles. * further message message events unless rebound to one or more handles.
*/ */
closeBindings() { closeBindings() {
this.target_.closeBindings(); this.receiver_.closeBindings();
} }
/** /**
...@@ -261,7 +261,7 @@ goog.provide('{{module.namespace}}.{{interface.name}}Request'); ...@@ -261,7 +261,7 @@ goog.provide('{{module.namespace}}.{{interface.name}}Request');
*/ */
createProxy() { createProxy() {
let proxy = new {{module.namespace}}.{{interface.name}}Proxy; let proxy = new {{module.namespace}}.{{interface.name}}Proxy;
this.target_.bindHandle(proxy.$.createRequest().handle); this.receiver_.bindHandle(proxy.$.bindNewPipeAndPassReceiver().handle);
return proxy; return proxy;
} }
......
...@@ -109,7 +109,7 @@ mojo.makeRequest = function(interfacePtr) {}; ...@@ -109,7 +109,7 @@ mojo.makeRequest = function(interfacePtr) {};
/** @const */ /** @const */
mojo.internal = {}; mojo.internal = {};
mojo.internal.InterfaceProxyBase = class { mojo.internal.InterfaceRemoteBase = class {
/** /**
* @param {MojoHandle=} opt_handle * @param {MojoHandle=} opt_handle
*/ */
......
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