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

Side by Side Diff: mojo/public/js/bindings.js

Issue 2676443005: Add interface versioning. Methods queryVersion and requireVersion. (Closed)
Patch Set: Expect the result inside the error handler for test. Code formatting and address codereview comment… Created 3 years, 10 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 unified diff | Download patch
« no previous file with comments | « mojo/public/js/BUILD.gn ('k') | mojo/public/js/constants.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 define("mojo/public/js/bindings", [ 5 define("mojo/public/js/bindings", [
6 "mojo/public/js/core", 6 "mojo/public/js/core",
7 "mojo/public/js/lib/control_message_proxy",
7 "mojo/public/js/interface_types", 8 "mojo/public/js/interface_types",
8 "mojo/public/js/router", 9 "mojo/public/js/router",
9 ], function(core, types, router) { 10 ], function(core, controlMessageProxy, types, router) {
10 11
11 // --------------------------------------------------------------------------- 12 // ---------------------------------------------------------------------------
12 13
13 function makeRequest(interfacePtr) { 14 function makeRequest(interfacePtr) {
14 var pipe = core.createMessagePipe(); 15 var pipe = core.createMessagePipe();
15 interfacePtr.ptr.bind(new types.InterfacePtrInfo(pipe.handle0, 0)); 16 interfacePtr.ptr.bind(new types.InterfacePtrInfo(pipe.handle0, 0));
16 return new types.InterfaceRequest(pipe.handle1); 17 return new types.InterfaceRequest(pipe.handle1);
17 } 18 }
18 19
19 // --------------------------------------------------------------------------- 20 // ---------------------------------------------------------------------------
20 21
21 // Operations used to setup/configure an interface pointer. Exposed as the 22 // Operations used to setup/configure an interface pointer. Exposed as the
22 // |ptr| field of generated interface pointer classes. 23 // |ptr| field of generated interface pointer classes.
23 // |ptrInfoOrHandle| could be omitted and passed into bind() later. 24 // |ptrInfoOrHandle| could be omitted and passed into bind() later.
24 function InterfacePtrController(interfaceType, ptrInfoOrHandle) { 25 function InterfacePtrController(interfaceType, ptrInfoOrHandle) {
25 this.version = 0; 26 this.version = 0;
26 27
27 this.interfaceType_ = interfaceType; 28 this.interfaceType_ = interfaceType;
28 this.router_ = null; 29 this.router_ = null;
29 this.proxy_ = null; 30 this.proxy_ = null;
30 31
31 // |router_| is lazily initialized. |handle_| is valid between bind() and 32 // |router_| is lazily initialized. |handle_| is valid between bind() and
32 // the initialization of |router_|. 33 // the initialization of |router_|.
33 this.handle_ = null; 34 this.handle_ = null;
35 this.controlMessageProxy_ = null;
34 36
35 if (ptrInfoOrHandle) 37 if (ptrInfoOrHandle)
36 this.bind(ptrInfoOrHandle); 38 this.bind(ptrInfoOrHandle);
37 } 39 }
38 40
39 InterfacePtrController.prototype.bind = function(ptrInfoOrHandle) { 41 InterfacePtrController.prototype.bind = function(ptrInfoOrHandle) {
40 this.reset(); 42 this.reset();
41 43
42 if (ptrInfoOrHandle instanceof types.InterfacePtrInfo) { 44 if (ptrInfoOrHandle instanceof types.InterfacePtrInfo) {
43 this.version = ptrInfoOrHandle.version; 45 this.version = ptrInfoOrHandle.version;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 }; 106 };
105 107
106 InterfacePtrController.prototype.configureProxyIfNecessary_ = function() { 108 InterfacePtrController.prototype.configureProxyIfNecessary_ = function() {
107 if (!this.handle_) 109 if (!this.handle_)
108 return; 110 return;
109 111
110 this.router_ = new router.Router(this.handle_); 112 this.router_ = new router.Router(this.handle_);
111 this.handle_ = null; 113 this.handle_ = null;
112 this.router_ .setPayloadValidators([this.interfaceType_.validateResponse]); 114 this.router_ .setPayloadValidators([this.interfaceType_.validateResponse]);
113 115
116 this.controlMessageProxy_ = new
117 controlMessageProxy.ControlMessageProxy(this.router_);
118
114 this.proxy_ = new this.interfaceType_.proxyClass(this.router_); 119 this.proxy_ = new this.interfaceType_.proxyClass(this.router_);
115 }; 120 };
116 121
117 // TODO(yzshen): Implement the following methods. 122 InterfacePtrController.prototype.queryVersion = function() {
118 // InterfacePtrController.prototype.queryVersion 123 function onQueryVersion(version) {
119 // InterfacePtrController.prototype.requireVersion 124 this.version = version;
125 return version;
126 }
127
128 this.configureProxyIfNecessary_();
129 return this.controlMessageProxy_.queryVersion().then(
130 onQueryVersion.bind(this));
131 };
132
133 InterfacePtrController.prototype.requireVersion = function(version) {
134 this.configureProxyIfNecessary_();
135
136 if (this.version >= version) {
137 return;
138 }
139 this.version = version;
140 this.controlMessageProxy_.requireVersion(version);
141 };
120 142
121 // --------------------------------------------------------------------------- 143 // ---------------------------------------------------------------------------
122 144
123 // |request| could be omitted and passed into bind() later. 145 // |request| could be omitted and passed into bind() later.
124 // 146 //
125 // Example: 147 // Example:
126 // 148 //
127 // // FooImpl implements mojom.Foo. 149 // // FooImpl implements mojom.Foo.
128 // function FooImpl() { ... } 150 // function FooImpl() { ... }
129 // FooImpl.prototype.fooMethod1 = function() { ... } 151 // FooImpl.prototype.fooMethod1 = function() { ... }
(...skipping 26 matching lines...) Expand all
156 178
157 Binding.prototype.bind = function(requestOrHandle) { 179 Binding.prototype.bind = function(requestOrHandle) {
158 this.close(); 180 this.close();
159 181
160 var handle = requestOrHandle instanceof types.InterfaceRequest ? 182 var handle = requestOrHandle instanceof types.InterfaceRequest ?
161 requestOrHandle.handle : requestOrHandle; 183 requestOrHandle.handle : requestOrHandle;
162 if (!core.isHandle(handle)) 184 if (!core.isHandle(handle))
163 return; 185 return;
164 186
165 this.stub_ = new this.interfaceType_.stubClass(this.impl_); 187 this.stub_ = new this.interfaceType_.stubClass(this.impl_);
166 this.router_ = new router.Router(handle); 188 this.router_ = new router.Router(handle, this.interfaceType_.kVersion);
167 this.router_.setIncomingReceiver(this.stub_); 189 this.router_.setIncomingReceiver(this.stub_);
168 this.router_ .setPayloadValidators([this.interfaceType_.validateRequest]); 190 this.router_ .setPayloadValidators([this.interfaceType_.validateRequest]);
169 }; 191 };
170 192
171 Binding.prototype.close = function() { 193 Binding.prototype.close = function() {
172 if (!this.isBound()) 194 if (!this.isBound())
173 return; 195 return;
174 196
175 this.router_.close(); 197 this.router_.close();
176 this.router_ = null; 198 this.router_ = null;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 var exports = {}; 276 var exports = {};
255 exports.InterfacePtrInfo = types.InterfacePtrInfo; 277 exports.InterfacePtrInfo = types.InterfacePtrInfo;
256 exports.InterfaceRequest = types.InterfaceRequest; 278 exports.InterfaceRequest = types.InterfaceRequest;
257 exports.makeRequest = makeRequest; 279 exports.makeRequest = makeRequest;
258 exports.InterfacePtrController = InterfacePtrController; 280 exports.InterfacePtrController = InterfacePtrController;
259 exports.Binding = Binding; 281 exports.Binding = Binding;
260 exports.BindingSet = BindingSet; 282 exports.BindingSet = BindingSet;
261 283
262 return exports; 284 return exports;
263 }); 285 });
OLDNEW
« no previous file with comments | « mojo/public/js/BUILD.gn ('k') | mojo/public/js/constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698