Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(775)

Unified Diff: mojo/public/js/bindings.js

Issue 2744963002: Introduce InterfaceEndpointClient(IEC), InterfaceEndpointHandle and (Closed)
Patch Set: Add binding.html layout test for connection error with reason. Reset IEC when reset() or close()… Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/public/js/bindings.js
diff --git a/mojo/public/js/bindings.js b/mojo/public/js/bindings.js
index f3e40d293ebb025f4bf3c8a3c4e01c81626b5aa4..6e97ffb63da901c8aa5122524ffe6ae48f4e4c5e 100644
--- a/mojo/public/js/bindings.js
+++ b/mojo/public/js/bindings.js
@@ -4,10 +4,12 @@
define("mojo/public/js/bindings", [
"mojo/public/js/core",
- "mojo/public/js/lib/control_message_proxy",
"mojo/public/js/interface_types",
+ "mojo/public/js/lib/interface_endpoint_client",
"mojo/public/js/router",
-], function(core, controlMessageProxy, types, router) {
+], function(core, types, interfaceEndpointClient, router) {
+
+ var InterfaceEndpointClient = interfaceEndpointClient.InterfaceEndpointClient;
// ---------------------------------------------------------------------------
@@ -67,15 +69,26 @@ define("mojo/public/js/bindings", [
core.close(this.handle_);
this.handle_ = null;
}
+ if (this.interfaceEndpointClient_) {
yzshen1 2017/03/24 21:20:12 It seems nice to move this block above line 62. Al
wangjimmy 2017/03/27 16:51:27 Done.
+ this.interfaceEndpointClient_.passHandle();
yzshen1 2017/03/24 21:20:12 Here we need to close the handle. You could use cl
wangjimmy 2017/03/27 16:51:27 Done.
+ this.interfaceEndpointClient_ = null;
+ }
};
- InterfacePtrController.prototype.setConnectionErrorHandler
- = function(callback) {
+ InterfacePtrController.prototype.resetWithReason = function(reason) {
+ this.configureProxyIfNecessary_();
+ this.interfaceEndpointClient_.closeWithReason(reason);
+ this.interfaceEndpointClient_ = null;
+ this.reset();
+ };
+
+ InterfacePtrController.prototype.setConnectionErrorHandler = function(
+ callback) {
if (!this.isBound())
throw new Error("Cannot set connection error handler if not bound.");
this.configureProxyIfNecessary_();
- this.router_.setErrorHandler(callback);
+ this.interfaceEndpointClient_.setConnectionErrorHandler(callback);
};
InterfacePtrController.prototype.passInterface = function() {
@@ -100,9 +113,9 @@ define("mojo/public/js/bindings", [
return this.proxy_;
};
- InterfacePtrController.prototype.enableTestingMode = function() {
+ InterfacePtrController.prototype.waitForNextMessageForTesting = function() {
this.configureProxyIfNecessary_();
- return this.router_.enableTestingMode();
+ this.router_.waitForNextMessageForTesting();
};
InterfacePtrController.prototype.configureProxyIfNecessary_ = function() {
@@ -111,12 +124,15 @@ define("mojo/public/js/bindings", [
this.router_ = new router.Router(this.handle_);
this.handle_ = null;
- this.router_ .setPayloadValidators([this.interfaceType_.validateResponse]);
- this.controlMessageProxy_ = new
- controlMessageProxy.ControlMessageProxy(this.router_);
+ this.interfaceEndpointClient_ = new InterfaceEndpointClient(
+ this.router_.createLocalEndpointHandle(types.kMasterInterfaceId),
+ this.router_);
- this.proxy_ = new this.interfaceType_.proxyClass(this.router_);
+ this.interfaceEndpointClient_ .setPayloadValidators([
+ this.interfaceType_.validateResponse]);
+ this.proxy_ = new this.interfaceType_.proxyClass(
+ this.interfaceEndpointClient_);
};
InterfacePtrController.prototype.queryVersion = function() {
@@ -126,7 +142,7 @@ define("mojo/public/js/bindings", [
}
this.configureProxyIfNecessary_();
- return this.controlMessageProxy_.queryVersion().then(
+ return this.interfaceEndpointClient_.queryVersion().then(
onQueryVersion.bind(this));
};
@@ -137,7 +153,7 @@ define("mojo/public/js/bindings", [
return;
}
this.version = version;
- this.controlMessageProxy_.requireVersion(version);
+ this.interfaceEndpointClient_.requireVersion(version);
};
// ---------------------------------------------------------------------------
@@ -174,7 +190,7 @@ define("mojo/public/js/bindings", [
// TODO(yzshen): Set the version of the interface pointer.
this.bind(makeRequest(ptr));
return ptr;
- }
+ };
Binding.prototype.bind = function(requestOrHandle) {
this.close();
@@ -184,26 +200,45 @@ define("mojo/public/js/bindings", [
if (!core.isHandle(handle))
return;
+ this.router_ = new router.Router(handle);
+
this.stub_ = new this.interfaceType_.stubClass(this.impl_);
- this.router_ = new router.Router(handle, this.interfaceType_.kVersion);
- this.router_.setIncomingReceiver(this.stub_);
- this.router_ .setPayloadValidators([this.interfaceType_.validateRequest]);
+ this.interfaceEndpointClient_ = new InterfaceEndpointClient(
+ this.router_.createLocalEndpointHandle(types.kMasterInterfaceId),
+ this.router_, this.interfaceType_.kVersion);
+ this.interfaceEndpointClient_.setIncomingReceiver(this.stub_);
+ this.interfaceEndpointClient_ .setPayloadValidators([
+ this.interfaceType_.validateRequest]);
};
Binding.prototype.close = function() {
if (!this.isBound())
return;
+ if (this.interfaceEndpointClient_) {
+ this.interfaceEndpointClient_.passHandle();
yzshen1 2017/03/24 21:20:12 The handle needs to be closed. Please see my comme
wangjimmy 2017/03/27 16:51:27 Done.
+ this.interfaceEndpointClient_ = null;
+ }
+
this.router_.close();
this.router_ = null;
this.stub_ = null;
};
+ Binding.prototype.closeWithReason = function(reason) {
+ if (this.interfaceEndpointClient_) {
+ this.interfaceEndpointClient_.closeWithReason(reason);
+ this.interfaceEndpointClient_ = null;
+ }
+ this.close();
+ };
+
Binding.prototype.setConnectionErrorHandler
= function(callback) {
- if (!this.isBound())
+ if (!this.isBound()) {
throw new Error("Cannot set connection error handler if not bound.");
- this.router_.setErrorHandler(callback);
+ }
+ this.interfaceEndpointClient_.setConnectionErrorHandler(callback);
};
Binding.prototype.unbind = function() {
@@ -216,8 +251,8 @@ define("mojo/public/js/bindings", [
return result;
};
- Binding.prototype.enableTestingMode = function() {
- return this.router_.enableTestingMode();
+ Binding.prototype.waitForNextMessageForTesting = function() {
+ this.router_.waitForNextMessageForTesting();
};
// ---------------------------------------------------------------------------

Powered by Google App Engine
This is Rietveld 408576698