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

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

Issue 2676443005: Add interface versioning. Methods queryVersion and requireVersion. (Closed)
Patch Set: Add interface_control_messages.mojom.js to build resources 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
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/interface_types", 7 "mojo/public/js/interface_types",
8 "mojo/public/js/router", 8 "mojo/public/js/router",
9 ], function(core, types, router) { 9 "mojo/public/js/lib/control_message_proxy",
yzshen1 2017/02/11 01:11:28 alphabetically, please.
wangjimmy 2017/02/13 20:43:06 Done.
10 ], function(core, types, router, controlMessageProxy) {
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_ = new controlMessageProxy.ControlMessageProxy();
yzshen1 2017/02/11 01:11:28 Please consider setting the value to null and movi
wangjimmy 2017/02/13 20:43:06 Done.
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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 return this.router_.enableTestingMode(); 105 return this.router_.enableTestingMode();
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]);
115 this.controlMessageProxy_.receiver = this.router_;
113 116
114 this.proxy_ = new this.interfaceType_.proxyClass(this.router_); 117 this.proxy_ = new this.interfaceType_.proxyClass(this.router_);
115 }; 118 };
116 119
117 // TODO(yzshen): Implement the following methods. 120 InterfacePtrController.prototype.queryVersion = function() {
118 // InterfacePtrController.prototype.queryVersion 121 function onQueryVersion(version) {
119 // InterfacePtrController.prototype.requireVersion 122 this.version = version;
123 return version;
124 }
125
126 this.configureProxyIfNecessary_();
127 return this.controlMessageProxy_.queryVersion().then(
128 onQueryVersion.bind(this));
129 };
130
131 InterfacePtrController.prototype.requireVersion = function(version) {
132 this.configureProxyIfNecessary_();
133
134 if (this.version >= version) {
yzshen1 2017/02/11 01:11:28 Whether to have {} around single-line body is not
wangjimmy 2017/02/13 20:43:06 Done.
135 return;
136 }
137 this.version = version;
138 this.controlMessageProxy_.requireVersion(version);
139 };
120 140
121 // --------------------------------------------------------------------------- 141 // ---------------------------------------------------------------------------
122 142
123 // |request| could be omitted and passed into bind() later. 143 // |request| could be omitted and passed into bind() later.
124 // 144 //
125 // Example: 145 // Example:
126 // 146 //
127 // // FooImpl implements mojom.Foo. 147 // // FooImpl implements mojom.Foo.
128 // function FooImpl() { ... } 148 // function FooImpl() { ... }
129 // FooImpl.prototype.fooMethod1 = function() { ... } 149 // FooImpl.prototype.fooMethod1 = function() { ... }
(...skipping 26 matching lines...) Expand all
156 176
157 Binding.prototype.bind = function(requestOrHandle) { 177 Binding.prototype.bind = function(requestOrHandle) {
158 this.close(); 178 this.close();
159 179
160 var handle = requestOrHandle instanceof types.InterfaceRequest ? 180 var handle = requestOrHandle instanceof types.InterfaceRequest ?
161 requestOrHandle.handle : requestOrHandle; 181 requestOrHandle.handle : requestOrHandle;
162 if (!core.isHandle(handle)) 182 if (!core.isHandle(handle))
163 return; 183 return;
164 184
165 this.stub_ = new this.interfaceType_.stubClass(this.impl_); 185 this.stub_ = new this.interfaceType_.stubClass(this.impl_);
166 this.router_ = new router.Router(handle); 186 this.router_ = new router.Router(handle, this.interfaceType_.version);
yzshen1 2017/02/11 01:11:28 |version| should be named kVersion since it is a c
wangjimmy 2017/02/13 20:43:06 Done.
167 this.router_.setIncomingReceiver(this.stub_); 187 this.router_.setIncomingReceiver(this.stub_);
168 this.router_ .setPayloadValidators([this.interfaceType_.validateRequest]); 188 this.router_ .setPayloadValidators([this.interfaceType_.validateRequest]);
169 }; 189 };
170 190
171 Binding.prototype.close = function() { 191 Binding.prototype.close = function() {
172 if (!this.isBound()) 192 if (!this.isBound())
173 return; 193 return;
174 194
175 this.router_.close(); 195 this.router_.close();
176 this.router_ = null; 196 this.router_ = null;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 var exports = {}; 274 var exports = {};
255 exports.InterfacePtrInfo = types.InterfacePtrInfo; 275 exports.InterfacePtrInfo = types.InterfacePtrInfo;
256 exports.InterfaceRequest = types.InterfaceRequest; 276 exports.InterfaceRequest = types.InterfaceRequest;
257 exports.makeRequest = makeRequest; 277 exports.makeRequest = makeRequest;
258 exports.InterfacePtrController = InterfacePtrController; 278 exports.InterfacePtrController = InterfacePtrController;
259 exports.Binding = Binding; 279 exports.Binding = Binding;
260 exports.BindingSet = BindingSet; 280 exports.BindingSet = BindingSet;
261 281
262 return exports; 282 return exports;
263 }); 283 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698