Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 * @extends {WebInspector.Panel} | 7 * @extends {WebInspector.Panel} |
| 8 */ | 8 */ |
| 9 WebInspector.Audits2Panel = function() | 9 WebInspector.Audits2Panel = function() |
| 10 { | 10 { |
| 11 WebInspector.Panel.call(this, "audits2"); | 11 WebInspector.Panel.call(this, "audits2"); |
| 12 this.contentElement.classList.add("vbox"); | 12 this.contentElement.classList.add("vbox"); |
| 13 this.contentElement.appendChild(createTextButton(WebInspector.UIString("Star t"), this._start.bind(this))); | 13 this.contentElement.appendChild(createTextButton(WebInspector.UIString("Star t"), this._start.bind(this))); |
| 14 this.contentElement.appendChild(createTextButton(WebInspector.UIString("Stop "), this._stop.bind(this))); | 14 this.contentElement.appendChild(createTextButton(WebInspector.UIString("Stop "), this._stop.bind(this))); |
| 15 } | 15 } |
| 16 | 16 |
| 17 WebInspector.Audits2Panel.prototype = { | 17 WebInspector.Audits2Panel.prototype = { |
| 18 _start: function() | 18 _start: function() |
| 19 { | 19 { |
| 20 this._backend().then(backend => backend ? backend.send("start") : undefi ned).then(console.error.bind(console, "STARTED")); | 20 WebInspector.targetManager.interceptMainConnection(this._dispatchProtoco lMessage.bind(this)).then(rawConnection => { |
| 21 this._rawConnection = rawConnection; | |
| 22 }); | |
| 23 this._send("start"); | |
|
dgozman
2016/10/15 00:26:26
Let's chain this.
| |
| 24 }, | |
| 25 | |
| 26 /** | |
| 27 * @param {string} message | |
| 28 */ | |
| 29 _dispatchProtocolMessage: function(message) | |
| 30 { | |
| 31 this._send("dispatchProtocolMessage", {message: message}); | |
| 21 }, | 32 }, |
| 22 | 33 |
| 23 _stop: function() | 34 _stop: function() |
| 24 { | 35 { |
| 25 this._backend().then(backend => backend ? backend.send("stop") : undefin ed).then(console.error.bind(console, "STOPPED")); | 36 this._send("stop").then(() => this._rawConnection.yield()); |
| 26 }, | 37 }, |
| 27 | 38 |
| 28 /** | 39 /** |
| 29 * @return {!Promise<?WebInspector.ServiceManager.Service>} | 40 * @param {string} method |
| 41 * @param {!Object=} params | |
| 42 * @return {!Promise<!Object|undefined>} | |
| 30 */ | 43 */ |
| 31 _backend: function() | 44 _send: function(method, params) |
| 32 { | 45 { |
| 33 if (!this._backendPromise) | 46 if (!this._backendPromise) { |
| 34 this._backendPromise = WebInspector.serviceManager.createAppService( "audits2_worker", "Audits2Service", false); | 47 this._backendPromise = WebInspector.serviceManager.createAppService( "audits2_worker", "Audits2Service", false).then(backend => { |
| 35 return this._backendPromise; | 48 this._backend = backend; |
|
dgozman
2016/10/15 00:26:26
Let's clear this._backend at some point.
| |
| 49 this._backend.on("sendProtocolMessage", result => this._rawConne ction.send(result.message)); | |
| 50 }); | |
| 51 } | |
| 52 return this._backendPromise.then(() => this._backend ? this._backend.sen d(method, params) : undefined); | |
| 36 }, | 53 }, |
| 37 | 54 |
| 38 __proto__: WebInspector.Panel.prototype | 55 __proto__: WebInspector.Panel.prototype |
| 39 } | 56 } |
| OLD | NEW |