| 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 * @constructor | 6 * @constructor |
| 7 */ | 7 */ |
| 8 WebInspector.ServiceManager = function() | 8 WebInspector.ServiceManager = function() |
| 9 { | 9 { |
| 10 } | 10 }; |
| 11 | 11 |
| 12 WebInspector.ServiceManager.prototype = { | 12 WebInspector.ServiceManager.prototype = { |
| 13 /** | 13 /** |
| 14 * @param {string} serviceName | 14 * @param {string} serviceName |
| 15 * @return {!Promise<?WebInspector.ServiceManager.Service>} | 15 * @return {!Promise<?WebInspector.ServiceManager.Service>} |
| 16 */ | 16 */ |
| 17 createRemoteService: function(serviceName) | 17 createRemoteService: function(serviceName) |
| 18 { | 18 { |
| 19 if (!this._remoteConnection) { | 19 if (!this._remoteConnection) { |
| 20 var url = Runtime.queryParam("service-backend"); | 20 var url = Runtime.queryParam("service-backend"); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 37 { | 37 { |
| 38 var url = appName + ".js"; | 38 var url = appName + ".js"; |
| 39 var remoteBase = Runtime.queryParam("remoteBase"); | 39 var remoteBase = Runtime.queryParam("remoteBase"); |
| 40 if (remoteBase) | 40 if (remoteBase) |
| 41 url += "?remoteBase=" + remoteBase; | 41 url += "?remoteBase=" + remoteBase; |
| 42 | 42 |
| 43 var worker = isSharedWorker ? new SharedWorker(url, appName) : new Worke
r(url); | 43 var worker = isSharedWorker ? new SharedWorker(url, appName) : new Worke
r(url); |
| 44 var connection = new WebInspector.ServiceManager.Connection(new WebInspe
ctor.ServiceManager.WorkerServicePort(worker)); | 44 var connection = new WebInspector.ServiceManager.Connection(new WebInspe
ctor.ServiceManager.WorkerServicePort(worker)); |
| 45 return connection._createService(serviceName); | 45 return connection._createService(serviceName); |
| 46 } | 46 } |
| 47 } | 47 }; |
| 48 | 48 |
| 49 /** | 49 /** |
| 50 * @constructor | 50 * @constructor |
| 51 * @param {!ServicePort} port | 51 * @param {!ServicePort} port |
| 52 */ | 52 */ |
| 53 WebInspector.ServiceManager.Connection = function(port) | 53 WebInspector.ServiceManager.Connection = function(port) |
| 54 { | 54 { |
| 55 this._port = port; | 55 this._port = port; |
| 56 this._port.setHandlers(this._onMessage.bind(this), this._connectionClosed.bi
nd(this)); | 56 this._port.setHandlers(this._onMessage.bind(this), this._connectionClosed.bi
nd(this)); |
| 57 | 57 |
| 58 this._lastId = 1; | 58 this._lastId = 1; |
| 59 /** @type {!Map<number, function(?Object)>}*/ | 59 /** @type {!Map<number, function(?Object)>}*/ |
| 60 this._callbacks = new Map(); | 60 this._callbacks = new Map(); |
| 61 /** @type {!Map<string, !WebInspector.ServiceManager.Service>}*/ | 61 /** @type {!Map<string, !WebInspector.ServiceManager.Service>}*/ |
| 62 this._services = new Map(); | 62 this._services = new Map(); |
| 63 } | 63 }; |
| 64 | 64 |
| 65 WebInspector.ServiceManager.Connection.prototype = { | 65 WebInspector.ServiceManager.Connection.prototype = { |
| 66 /** | 66 /** |
| 67 * @param {string} serviceName | 67 * @param {string} serviceName |
| 68 * @return {!Promise<?WebInspector.ServiceManager.Service>} | 68 * @return {!Promise<?WebInspector.ServiceManager.Service>} |
| 69 */ | 69 */ |
| 70 _createService: function(serviceName) | 70 _createService: function(serviceName) |
| 71 { | 71 { |
| 72 return this._sendCommand(serviceName + ".create").then(result => { | 72 return this._sendCommand(serviceName + ".create").then(result => { |
| 73 if (!result) { | 73 if (!result) { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 | 141 |
| 142 _connectionClosed: function() | 142 _connectionClosed: function() |
| 143 { | 143 { |
| 144 for (var callback of this._callbacks.values()) | 144 for (var callback of this._callbacks.values()) |
| 145 callback(null); | 145 callback(null); |
| 146 this._callbacks.clear(); | 146 this._callbacks.clear(); |
| 147 for (var service of this._services.values()) | 147 for (var service of this._services.values()) |
| 148 service._dispatchNotification("disposed"); | 148 service._dispatchNotification("disposed"); |
| 149 this._services.clear(); | 149 this._services.clear(); |
| 150 } | 150 } |
| 151 } | 151 }; |
| 152 | 152 |
| 153 /** | 153 /** |
| 154 * @constructor | 154 * @constructor |
| 155 * @param {!WebInspector.ServiceManager.Connection} connection | 155 * @param {!WebInspector.ServiceManager.Connection} connection |
| 156 * @param {string} serviceName | 156 * @param {string} serviceName |
| 157 * @param {string} objectId | 157 * @param {string} objectId |
| 158 */ | 158 */ |
| 159 WebInspector.ServiceManager.Service = function(connection, serviceName, objectId
) | 159 WebInspector.ServiceManager.Service = function(connection, serviceName, objectId
) |
| 160 { | 160 { |
| 161 this._connection = connection; | 161 this._connection = connection; |
| 162 this._serviceName = serviceName; | 162 this._serviceName = serviceName; |
| 163 this._objectId = objectId; | 163 this._objectId = objectId; |
| 164 /** @type {!Map<string, function(!Object=)>}*/ | 164 /** @type {!Map<string, function(!Object=)>}*/ |
| 165 this._notificationHandlers = new Map(); | 165 this._notificationHandlers = new Map(); |
| 166 } | 166 }; |
| 167 | 167 |
| 168 WebInspector.ServiceManager.Service.prototype = { | 168 WebInspector.ServiceManager.Service.prototype = { |
| 169 /** | 169 /** |
| 170 * @return {!Promise} | 170 * @return {!Promise} |
| 171 */ | 171 */ |
| 172 dispose: function() | 172 dispose: function() |
| 173 { | 173 { |
| 174 var params = { id: this._objectId }; | 174 var params = { id: this._objectId }; |
| 175 return this._connection._sendCommand(this._serviceName + ".dispose", par
ams).then(() => { | 175 return this._connection._sendCommand(this._serviceName + ".dispose", par
ams).then(() => { |
| 176 this._connection._serviceDisposed(this); | 176 this._connection._serviceDisposed(this); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 204 */ | 204 */ |
| 205 _dispatchNotification: function(methodName, params) | 205 _dispatchNotification: function(methodName, params) |
| 206 { | 206 { |
| 207 var handler = this._notificationHandlers.get(methodName); | 207 var handler = this._notificationHandlers.get(methodName); |
| 208 if (!handler) { | 208 if (!handler) { |
| 209 console.error("Could not report notification '" + methodName + "' on
'" + this._objectId + "'"); | 209 console.error("Could not report notification '" + methodName + "' on
'" + this._objectId + "'"); |
| 210 return; | 210 return; |
| 211 } | 211 } |
| 212 handler(params); | 212 handler(params); |
| 213 } | 213 } |
| 214 } | 214 }; |
| 215 | 215 |
| 216 /** | 216 /** |
| 217 * @constructor | 217 * @constructor |
| 218 * @implements {ServicePort} | 218 * @implements {ServicePort} |
| 219 * @param {string} url | 219 * @param {string} url |
| 220 */ | 220 */ |
| 221 WebInspector.ServiceManager.RemoteServicePort = function(url) | 221 WebInspector.ServiceManager.RemoteServicePort = function(url) |
| 222 { | 222 { |
| 223 this._url = url; | 223 this._url = url; |
| 224 } | 224 }; |
| 225 | 225 |
| 226 WebInspector.ServiceManager.RemoteServicePort.prototype = { | 226 WebInspector.ServiceManager.RemoteServicePort.prototype = { |
| 227 /** | 227 /** |
| 228 * @override | 228 * @override |
| 229 * @param {function(string)} messageHandler | 229 * @param {function(string)} messageHandler |
| 230 * @param {function(string)} closeHandler | 230 * @param {function(string)} closeHandler |
| 231 */ | 231 */ |
| 232 setHandlers: function(messageHandler, closeHandler) | 232 setHandlers: function(messageHandler, closeHandler) |
| 233 { | 233 { |
| 234 this._messageHandler = messageHandler; | 234 this._messageHandler = messageHandler; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 { | 304 { |
| 305 return this._open().then(() => { | 305 return this._open().then(() => { |
| 306 if (this._socket) { | 306 if (this._socket) { |
| 307 this._socket.close(); | 307 this._socket.close(); |
| 308 this._socket = null; | 308 this._socket = null; |
| 309 delete this._connectionPromise; | 309 delete this._connectionPromise; |
| 310 } | 310 } |
| 311 return true; | 311 return true; |
| 312 }); | 312 }); |
| 313 }, | 313 }, |
| 314 } | 314 }; |
| 315 | 315 |
| 316 /** | 316 /** |
| 317 * @constructor | 317 * @constructor |
| 318 * @implements {ServicePort} | 318 * @implements {ServicePort} |
| 319 * @param {!Worker|!SharedWorker} worker | 319 * @param {!Worker|!SharedWorker} worker |
| 320 */ | 320 */ |
| 321 WebInspector.ServiceManager.WorkerServicePort = function(worker) | 321 WebInspector.ServiceManager.WorkerServicePort = function(worker) |
| 322 { | 322 { |
| 323 this._worker = worker; | 323 this._worker = worker; |
| 324 | 324 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 339 * @this {WebInspector.ServiceManager.WorkerServicePort} | 339 * @this {WebInspector.ServiceManager.WorkerServicePort} |
| 340 */ | 340 */ |
| 341 function onMessage(event) | 341 function onMessage(event) |
| 342 { | 342 { |
| 343 if (event.data === "workerReady") { | 343 if (event.data === "workerReady") { |
| 344 fulfill(true); | 344 fulfill(true); |
| 345 return; | 345 return; |
| 346 } | 346 } |
| 347 this._messageHandler(event.data); | 347 this._messageHandler(event.data); |
| 348 } | 348 } |
| 349 } | 349 }; |
| 350 | 350 |
| 351 WebInspector.ServiceManager.WorkerServicePort.prototype = { | 351 WebInspector.ServiceManager.WorkerServicePort.prototype = { |
| 352 /** | 352 /** |
| 353 * @override | 353 * @override |
| 354 * @param {function(string)} messageHandler | 354 * @param {function(string)} messageHandler |
| 355 * @param {function(string)} closeHandler | 355 * @param {function(string)} closeHandler |
| 356 */ | 356 */ |
| 357 setHandlers: function(messageHandler, closeHandler) | 357 setHandlers: function(messageHandler, closeHandler) |
| 358 { | 358 { |
| 359 this._messageHandler = messageHandler; | 359 this._messageHandler = messageHandler; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 385 * @return {!Promise} | 385 * @return {!Promise} |
| 386 */ | 386 */ |
| 387 close: function() | 387 close: function() |
| 388 { | 388 { |
| 389 return this._workerPromise.then(() => { | 389 return this._workerPromise.then(() => { |
| 390 if (this._worker) | 390 if (this._worker) |
| 391 this._worker.terminate(); | 391 this._worker.terminate(); |
| 392 return false; | 392 return false; |
| 393 }); | 393 }); |
| 394 } | 394 } |
| 395 } | 395 }; |
| 396 | 396 |
| 397 WebInspector.serviceManager = new WebInspector.ServiceManager(); | 397 WebInspector.serviceManager = new WebInspector.ServiceManager(); |
| OLD | NEW |