| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 /** | 5 /** |
| 6 * @interface | 6 * @interface |
| 7 */ | 7 */ |
| 8 function Service() { } | 8 function Service() { } |
| 9 | 9 |
| 10 Service.prototype = { | 10 Service.prototype = { |
| 11 /** |
| 12 * @return {!Promise} |
| 13 */ |
| 11 dispose: function() { } | 14 dispose: function() { } |
| 12 } | 15 } |
| 13 | 16 |
| 14 /** | 17 /** |
| 15 * @constructor | 18 * @constructor |
| 16 * @param {!ServicePort} port | 19 * @param {!ServicePort} port |
| 17 */ | 20 */ |
| 18 function ServiceDispatcher(port) | 21 function ServiceDispatcher(port) |
| 19 { | 22 { |
| 20 this._constructors = new Map(); | 23 this._constructors = new Map(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 39 */ | 42 */ |
| 40 _dispatchMessageWrapped: function(data) | 43 _dispatchMessageWrapped: function(data) |
| 41 { | 44 { |
| 42 try { | 45 try { |
| 43 var message = JSON.parse(data); | 46 var message = JSON.parse(data); |
| 44 if (!(message instanceof Object)) { | 47 if (!(message instanceof Object)) { |
| 45 this._sendErrorResponse(message["id"], "Malformed message"); | 48 this._sendErrorResponse(message["id"], "Malformed message"); |
| 46 return; | 49 return; |
| 47 } | 50 } |
| 48 this._dispatchMessage(message); | 51 this._dispatchMessage(message); |
| 49 } catch(e) { | 52 } catch (e) { |
| 50 this._sendErrorResponse(message["id"], e.toString()); | 53 this._sendErrorResponse(message["id"], e.toString()); |
| 51 } | 54 } |
| 52 }, | 55 }, |
| 53 | 56 |
| 54 /** | 57 /** |
| 55 * @param {!Object} message | 58 * @param {!Object} message |
| 56 */ | 59 */ |
| 57 _dispatchMessage: function(message) | 60 _dispatchMessage: function(message) |
| 58 { | 61 { |
| 59 var domainAndMethod = message["method"].split("."); | 62 var domainAndMethod = message["method"].split("."); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 | 233 |
| 231 function onNewPort(port) | 234 function onNewPort(port) |
| 232 { | 235 { |
| 233 var servicePort = new WorkerServicePort(port); | 236 var servicePort = new WorkerServicePort(port); |
| 234 var dispatcher = new ServiceDispatcher(servicePort); | 237 var dispatcher = new ServiceDispatcher(servicePort); |
| 235 dispatchers.push(dispatcher); | 238 dispatchers.push(dispatcher); |
| 236 for (var name of services.keys()) | 239 for (var name of services.keys()) |
| 237 dispatcher.registerObject(name, services.get(name)); | 240 dispatcher.registerObject(name, services.get(name)); |
| 238 } | 241 } |
| 239 } | 242 } |
| OLD | NEW |