Commit e9224910 authored by Tim van der Lippe's avatar Tim van der Lippe Committed by Commit Bot

Migrate services/ to ESM

Bug: 1006759
Change-Id: I17818dd46ad42882388a145cdd49400f2f2e5a7b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1845711Reviewed-by: default avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Tim Van der Lippe <tvanderlippe@chromium.org>
Cr-Commit-Position: refs/heads/master@{#703691}
parent c2a7a56e
...@@ -590,7 +590,6 @@ all_devtools_files = [ ...@@ -590,7 +590,6 @@ all_devtools_files = [
"front_end/security_test_runner/module.json", "front_end/security_test_runner/module.json",
"front_end/security_test_runner/SecurityTestRunner.js", "front_end/security_test_runner/SecurityTestRunner.js",
"front_end/services/module.json", "front_end/services/module.json",
"front_end/services/ServiceManager.js",
"front_end/settings/frameworkBlackboxSettingsTab.css", "front_end/settings/frameworkBlackboxSettingsTab.css",
"front_end/settings/FrameworkBlackboxSettingsTab.js", "front_end/settings/FrameworkBlackboxSettingsTab.js",
"front_end/settings/module.json", "front_end/settings/module.json",
...@@ -848,6 +847,8 @@ lighthouse_locale_files = [ ...@@ -848,6 +847,8 @@ lighthouse_locale_files = [
all_devtools_files += lighthouse_locale_files all_devtools_files += lighthouse_locale_files
all_devtools_modules = [ all_devtools_modules = [
"front_end/services/services.js",
"front_end/services/ServiceManager.js",
"front_end/sdk/sdk.js", "front_end/sdk/sdk.js",
"front_end/sdk/TracingModel.js", "front_end/sdk/TracingModel.js",
"front_end/sdk/TracingManager.js", "front_end/sdk/TracingManager.js",
...@@ -1193,6 +1194,8 @@ application_templates = [ ...@@ -1193,6 +1194,8 @@ application_templates = [
] ]
copied_devtools_modules = [ copied_devtools_modules = [
"$resources_out_dir/services/services.js",
"$resources_out_dir/services/ServiceManager.js",
"$resources_out_dir/sdk/sdk.js", "$resources_out_dir/sdk/sdk.js",
"$resources_out_dir/sdk/TracingModel.js", "$resources_out_dir/sdk/TracingModel.js",
"$resources_out_dir/sdk/TracingManager.js", "$resources_out_dir/sdk/TracingManager.js",
......
...@@ -10,3 +10,5 @@ import './host/host.js'; ...@@ -10,3 +10,5 @@ import './host/host.js';
import './protocol/protocol.js'; import './protocol/protocol.js';
import './sdk/sdk.js'; import './sdk/sdk.js';
import './ui/ui.js'; import './ui/ui.js';
import './services/services.js';
...@@ -4,20 +4,19 @@ ...@@ -4,20 +4,19 @@
/** /**
* @unrestricted * @unrestricted
*/ */
Services.ServiceManager = class { export default class ServiceManager {
/** /**
* @param {string} serviceName * @param {string} serviceName
* @return {!Promise<?Services.ServiceManager.Service>} * @return {!Promise<?Service>}
*/ */
createRemoteService(serviceName) { createRemoteService(serviceName) {
if (!this._remoteConnection) { if (!this._remoteConnection) {
const url = Root.Runtime.queryParam('service-backend'); const url = Root.Runtime.queryParam('service-backend');
if (!url) { if (!url) {
console.error('No endpoint address specified'); console.error('No endpoint address specified');
return /** @type {!Promise<?Services.ServiceManager.Service>} */ (Promise.resolve(null)); return /** @type {!Promise<?Service>} */ (Promise.resolve(null));
} }
this._remoteConnection = this._remoteConnection = new Connection(new RemoteServicePort(url));
new Services.ServiceManager.Connection(new Services.ServiceManager.RemoteServicePort(url));
} }
return this._remoteConnection._createService(serviceName); return this._remoteConnection._createService(serviceName);
} }
...@@ -25,7 +24,7 @@ Services.ServiceManager = class { ...@@ -25,7 +24,7 @@ Services.ServiceManager = class {
/** /**
* @param {string} appName * @param {string} appName
* @param {string} serviceName * @param {string} serviceName
* @return {!Promise<?Services.ServiceManager.Service>} * @return {!Promise<?Service>}
*/ */
createAppService(appName, serviceName) { createAppService(appName, serviceName) {
let url = appName + '.js'; let url = appName + '.js';
...@@ -49,15 +48,15 @@ Services.ServiceManager = class { ...@@ -49,15 +48,15 @@ Services.ServiceManager = class {
} }
const worker = new Worker(url); const worker = new Worker(url);
const connection = new Services.ServiceManager.Connection(new Services.ServiceManager.WorkerServicePort(worker)); const connection = new Connection(new WorkerServicePort(worker));
return connection._createService(serviceName); return connection._createService(serviceName);
} }
}; }
/** /**
* @unrestricted * @unrestricted
*/ */
Services.ServiceManager.Connection = class { export class Connection {
/** /**
* @param {!ServicePort} port * @param {!ServicePort} port
*/ */
...@@ -68,13 +67,13 @@ Services.ServiceManager.Connection = class { ...@@ -68,13 +67,13 @@ Services.ServiceManager.Connection = class {
this._lastId = 1; this._lastId = 1;
/** @type {!Map<number, function(?Object)>}*/ /** @type {!Map<number, function(?Object)>}*/
this._callbacks = new Map(); this._callbacks = new Map();
/** @type {!Map<string, !Services.ServiceManager.Service>}*/ /** @type {!Map<string, !Service>}*/
this._services = new Map(); this._services = new Map();
} }
/** /**
* @param {string} serviceName * @param {string} serviceName
* @return {!Promise<?Services.ServiceManager.Service>} * @return {!Promise<?Service>}
*/ */
_createService(serviceName) { _createService(serviceName) {
return this._sendCommand(serviceName + '.create').then(result => { return this._sendCommand(serviceName + '.create').then(result => {
...@@ -82,14 +81,14 @@ Services.ServiceManager.Connection = class { ...@@ -82,14 +81,14 @@ Services.ServiceManager.Connection = class {
console.error('Could not initialize service: ' + serviceName); console.error('Could not initialize service: ' + serviceName);
return null; return null;
} }
const service = new Services.ServiceManager.Service(this, serviceName, result.id); const service = new Service(this, serviceName, result.id);
this._services.set(serviceName + ':' + result.id, service); this._services.set(serviceName + ':' + result.id, service);
return service; return service;
}); });
} }
/** /**
* @param {!Services.ServiceManager.Service} service * @param {!Service} service
*/ */
_serviceDisposed(service) { _serviceDisposed(service) {
this._services.delete(service._serviceName + ':' + service._objectId); this._services.delete(service._serviceName + ':' + service._objectId);
...@@ -156,14 +155,14 @@ Services.ServiceManager.Connection = class { ...@@ -156,14 +155,14 @@ Services.ServiceManager.Connection = class {
} }
this._services.clear(); this._services.clear();
} }
}; }
/** /**
* @unrestricted * @unrestricted
*/ */
Services.ServiceManager.Service = class { export class Service {
/** /**
* @param {!Services.ServiceManager.Connection} connection * @param {!Connection} connection
* @param {string} serviceName * @param {string} serviceName
* @param {string} objectId * @param {string} objectId
*/ */
...@@ -216,13 +215,13 @@ Services.ServiceManager.Service = class { ...@@ -216,13 +215,13 @@ Services.ServiceManager.Service = class {
} }
handler(params); handler(params);
} }
}; }
/** /**
* @implements {ServicePort} * @implements {ServicePort}
* @unrestricted * @unrestricted
*/ */
Services.ServiceManager.RemoteServicePort = class { export class RemoteServicePort {
/** /**
* @param {string} url * @param {string} url
*/ */
...@@ -251,7 +250,7 @@ Services.ServiceManager.RemoteServicePort = class { ...@@ -251,7 +250,7 @@ Services.ServiceManager.RemoteServicePort = class {
/** /**
* @param {function(boolean)} fulfill * @param {function(boolean)} fulfill
* @this {Services.ServiceManager.RemoteServicePort} * @this {RemoteServicePort}
*/ */
function promiseBody(fulfill) { function promiseBody(fulfill) {
let socket; let socket;
...@@ -265,7 +264,7 @@ Services.ServiceManager.RemoteServicePort = class { ...@@ -265,7 +264,7 @@ Services.ServiceManager.RemoteServicePort = class {
} }
/** /**
* @this {Services.ServiceManager.RemoteServicePort} * @this {RemoteServicePort}
*/ */
function onConnect() { function onConnect() {
this._socket = socket; this._socket = socket;
...@@ -274,14 +273,14 @@ Services.ServiceManager.RemoteServicePort = class { ...@@ -274,14 +273,14 @@ Services.ServiceManager.RemoteServicePort = class {
/** /**
* @param {!Event} event * @param {!Event} event
* @this {Services.ServiceManager.RemoteServicePort} * @this {RemoteServicePort}
*/ */
function onMessage(event) { function onMessage(event) {
this._messageHandler(event.data); this._messageHandler(event.data);
} }
/** /**
* @this {Services.ServiceManager.RemoteServicePort} * @this {RemoteServicePort}
*/ */
function onClose() { function onClose() {
if (!this._socket) { if (!this._socket) {
...@@ -331,13 +330,13 @@ Services.ServiceManager.RemoteServicePort = class { ...@@ -331,13 +330,13 @@ Services.ServiceManager.RemoteServicePort = class {
this._closeHandler(); this._closeHandler();
} }
} }
}; }
/** /**
* @implements {ServicePort} * @implements {ServicePort}
* @unrestricted * @unrestricted
*/ */
Services.ServiceManager.WorkerServicePort = class { export class WorkerServicePort {
/** /**
* @param {!Worker} worker * @param {!Worker} worker
*/ */
...@@ -352,7 +351,7 @@ Services.ServiceManager.WorkerServicePort = class { ...@@ -352,7 +351,7 @@ Services.ServiceManager.WorkerServicePort = class {
/** /**
* @param {!Event} event * @param {!Event} event
* @this {Services.ServiceManager.WorkerServicePort} * @this {WorkerServicePort}
*/ */
function onMessage(event) { function onMessage(event) {
if (event.data === 'workerReady') { if (event.data === 'workerReady') {
...@@ -401,6 +400,27 @@ Services.ServiceManager.WorkerServicePort = class { ...@@ -401,6 +400,27 @@ Services.ServiceManager.WorkerServicePort = class {
return false; return false;
}); });
} }
}; }
Services.serviceManager = new Services.ServiceManager(); /* Legacy exported object */
self.Services = self.Services || {};
/* Legacy exported object */
Services = Services || {};
/** @constructor */
Services.ServiceManager = ServiceManager;
/** @constructor */
Services.ServiceManager.Connection = Connection;
/** @constructor */
Services.ServiceManager.Service = Service;
/** @constructor */
Services.ServiceManager.RemoteServicePort = RemoteServicePort;
/** @constructor */
Services.ServiceManager.WorkerServicePort = WorkerServicePort;
Services.serviceManager = new ServiceManager();
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
"common", "common",
"host" "host"
], ],
"scripts": [ "scripts": [],
"modules": [
"services.js",
"ServiceManager.js" "ServiceManager.js"
] ]
} }
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import * as ServiceManager from './ServiceManager.js';
export {
ServiceManager,
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment