Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/audits2/Audits2Panel.js

Issue 2441933002: [DevTools] Refactor connection-related classes. (Closed)
Patch Set: test fixes Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 WebInspector.targetManager.interceptMainConnection(this._dispatchProtoco lMessage.bind(this)).then(rawConnection => { 20 WebInspector.targetManager.mainChannelInterceptor().takeMainChannel().th en(channel => {
21 this._rawConnection = rawConnection; 21 this._channel = channel;
22 this._channel.addEventListener(InspectorBackendClass.Channel.Events. MessageReceived, this._dispatchProtocolMessage, this);
pfeldman 2016/10/21 21:04:34 design: You don't want to expose the MessageReceiv
22 this._send("start"); 23 this._send("start");
23 }); 24 });
24 }, 25 },
25 26
26 /** 27 /**
27 * @param {string} message 28 * @param {!WebInspector.Event} event
28 */ 29 */
29 _dispatchProtocolMessage: function(message) 30 _dispatchProtocolMessage: function(event)
30 { 31 {
32 var message = /** @type {!Object|string} */ (event.data);
31 this._send("dispatchProtocolMessage", {message: message}); 33 this._send("dispatchProtocolMessage", {message: message});
32 }, 34 },
33 35
34 _stop: function() 36 _stop: function()
35 { 37 {
36 this._send("stop").then(() => { 38 this._send("stop").then(() => {
37 this._rawConnection.yieldConnection(); 39 this._channel.removeEventListener(InspectorBackendClass.Channel.Even ts.MessageReceived, this._dispatchProtocolMessage, this);
38 this._backend.dispose(); 40 this._backend.dispose();
41 delete this._channel;
39 delete this._backend; 42 delete this._backend;
40 delete this._backendPromise; 43 delete this._backendPromise;
44 WebInspector.targetManager.mainChannelInterceptor().yieldMainChannel ();
pfeldman 2016/10/21 21:04:33 design: only the one how has connection should be
41 }); 45 });
42 }, 46 },
43 47
44 /** 48 /**
45 * @param {string} method 49 * @param {string} method
46 * @param {!Object=} params 50 * @param {!Object=} params
47 * @return {!Promise<!Object|undefined>} 51 * @return {!Promise<!Object|undefined>}
48 */ 52 */
49 _send: function(method, params) 53 _send: function(method, params)
50 { 54 {
51 if (!this._backendPromise) { 55 if (!this._backendPromise) {
52 this._backendPromise = WebInspector.serviceManager.createAppService( "audits2_worker", "Audits2Service", false).then(backend => { 56 this._backendPromise = WebInspector.serviceManager.createAppService( "audits2_worker", "Audits2Service", false).then(backend => {
53 this._backend = backend; 57 this._backend = backend;
54 this._backend.on("sendProtocolMessage", result => this._rawConne ction.send(result.message)); 58 this._backend.on("sendProtocolMessage", result => this._channel. sendMessage(result.message));
55 }); 59 });
56 } 60 }
57 return this._backendPromise.then(() => this._backend ? this._backend.sen d(method, params) : undefined); 61 return this._backendPromise.then(() => this._backend ? this._backend.sen d(method, params) : undefined);
58 }, 62 },
59 63
60 __proto__: WebInspector.Panel.prototype 64 __proto__: WebInspector.Panel.prototype
61 } 65 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698