Reland "[Lighthouse] Rename Audits panel to Lighthouse"
This reverts commit 065146856295c7ebf01d538820d3f2e60c383335.
Reason for revert: Cause of failure has been remedied. See: https://chromium-review.googlesource.com/c/chromium/src/+/2055398
Original change's description:
> Revert "[Lighthouse] Rename Audits panel to Lighthouse"
>
> This reverts commit 2ae53ef04d84c4201836eb63238e97bc180ea54d.
>
> Reason for revert: This CL breaks CI: https://ci.chromium.org/p/devtools-frontend/builders/ci/DevTools%20Linux/453. It looks like the layout test expects audits not lighthouse in the name, so it's probably in need of a 3-way merge.
>
> Original change's description:
> > [Lighthouse] Rename Audits panel to Lighthouse
> >
> > Change-Id: Ia2ab175d2a3b6c8ded73aff8ff0f5582f5a8fa0c
> > Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2044605
> > Commit-Queue: Connor Clark <cjamcl@chromium.org>
> > Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
> > Reviewed-by: Paul Irish <paulirish@chromium.org>
>
> TBR=paulirish@chromium.org,aerotwist@chromium.org,tvanderlippe@chromium.org,cjamcl@chromium.org
>
> Change-Id: Ia6d5f42a0e6ece4352696c51bf0de5754774cb0a
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2051983
> Reviewed-by: Paul Lewis <aerotwist@chromium.org>
> Commit-Queue: Paul Lewis <aerotwist@chromium.org>
TBR=paulirish@chromium.org,aerotwist@chromium.org,tvanderlippe@chromium.org,cjamcl@chromium.org
# Not skipping CQ checks because original CL landed > 1 day ago.
Bug: 1052111
Change-Id: I638ca9bd5cd94e02fb7318f2a7d7c66fca40e6c8
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2056866
Reviewed-by: Connor Clark <cjamcl@chromium.org>
Reviewed-by: Paul Irish <paulirish@chromium.org>
Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
Commit-Queue: Connor Clark <cjamcl@chromium.org>
diff --git a/front_end/lighthouse/LighthouseProtocolService.js b/front_end/lighthouse/LighthouseProtocolService.js
new file mode 100644
index 0000000..4290ede
--- /dev/null
+++ b/front_end/lighthouse/LighthouseProtocolService.js
@@ -0,0 +1,94 @@
+// Copyright 2018 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.
+
+export class ProtocolService extends Common.Object {
+ constructor() {
+ super();
+ /** @type {?Protocol.Connection} */
+ this._rawConnection = null;
+ /** @type {?Services.ServiceManager.Service} */
+ this._backend = null;
+ /** @type {?Promise} */
+ this._backendPromise = null;
+ /** @type {?function(string)} */
+ this._status = null;
+ }
+
+ /**
+ * @return {!Promise<undefined>}
+ */
+ async attach() {
+ await self.SDK.targetManager.suspendAllTargets();
+ const childTargetManager = self.SDK.targetManager.mainTarget().model(SDK.ChildTargetManager);
+ this._rawConnection = await childTargetManager.createParallelConnection(this._dispatchProtocolMessage.bind(this));
+ }
+
+ /**
+ * @param {string} auditURL
+ * @param {!Array<string>} categoryIDs
+ * @param {!Object} flags
+ * @return {!Promise<!ReportRenderer.RunnerResult>}
+ */
+ startLighthouse(auditURL, categoryIDs, flags) {
+ return this._send('start', {url: auditURL, categoryIDs, flags});
+ }
+
+ /**
+ * @return {!Promise<undefined>}
+ */
+ async detach() {
+ await this._send('stop');
+ await this._backend.dispose();
+ delete this._backend;
+ delete this._backendPromise;
+ await this._rawConnection.disconnect();
+ await self.SDK.targetManager.resumeAllTargets();
+ }
+
+ /**
+ * @param {function (string): undefined} callback
+ */
+ registerStatusCallback(callback) {
+ this._status = callback;
+ }
+
+ /**
+ * @param {(!Object|string)} message
+ */
+ _dispatchProtocolMessage(message) {
+ this._send('dispatchProtocolMessage', {message: JSON.stringify(message)});
+ }
+
+ _initWorker() {
+ this._backendPromise =
+ Services.serviceManager.createAppService('lighthouse_worker', 'LighthouseService').then(backend => {
+ if (this._backend) {
+ return;
+ }
+ this._backend = backend;
+ this._backend.on('statusUpdate', result => this._status(result.message));
+ this._backend.on('sendProtocolMessage', result => this._sendProtocolMessage(result.message));
+ });
+ }
+
+ /**
+ * @param {string} message
+ */
+ _sendProtocolMessage(message) {
+ this._rawConnection.sendRawMessage(message);
+ }
+
+ /**
+ * @param {string} method
+ * @param {!Object=} params
+ * @return {!Promise<!ReportRenderer.RunnerResult>}
+ */
+ _send(method, params) {
+ if (!this._backendPromise) {
+ this._initWorker();
+ }
+
+ return this._backendPromise.then(_ => this._backend.send(method, params));
+ }
+}