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

Side by Side Diff: Source/devtools/front_end/sdk/WorkerTargetManager.js

Issue 724013003: DevTools: Connect worker cpu profiles to worker tracing threads. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Addressing comments. Created 6 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 /** 6 /**
7 * @constructor 7 * @constructor
8 * @param {!WebInspector.Target} mainTarget 8 * @param {!WebInspector.Target} mainTarget
9 * @param {!WebInspector.TargetManager} targetManager 9 * @param {!WebInspector.TargetManager} targetManager
10 */ 10 */
11 WebInspector.WorkerTargetManager = function(mainTarget, targetManager) 11 WebInspector.WorkerTargetManager = function(mainTarget, targetManager)
12 { 12 {
13 this._mainTarget = mainTarget; 13 this._mainTarget = mainTarget;
14 this._targetManager = targetManager; 14 this._targetManager = targetManager;
15 this._targetsByWorkerId = new Map();
15 mainTarget.workerManager.addEventListener(WebInspector.WorkerManager.Events. WorkerAdded, this._onWorkerAdded, this); 16 mainTarget.workerManager.addEventListener(WebInspector.WorkerManager.Events. WorkerAdded, this._onWorkerAdded, this);
yurys 2014/11/17 12:51:36 Please make sure there is 1-1 relationship between
alph 2014/11/17 13:36:12 Acknowledged.
17 mainTarget.workerManager.addEventListener(WebInspector.WorkerManager.Events. WorkerRemoved, this._onWorkerRemoved, this);
16 mainTarget.workerManager.addEventListener(WebInspector.WorkerManager.Events. WorkersCleared, this._onWorkersCleared, this); 18 mainTarget.workerManager.addEventListener(WebInspector.WorkerManager.Events. WorkersCleared, this._onWorkersCleared, this);
17 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.Event s.SuspendStateChanged, this._onSuspendStateChanged, this); 19 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.Event s.SuspendStateChanged, this._onSuspendStateChanged, this);
18 this._onSuspendStateChanged(); 20 this._onSuspendStateChanged();
19 this._lastAnonymousTargetId = 0; 21 this._lastAnonymousTargetId = 0;
20 this._shouldPauseWorkerOnStart = WebInspector.isWorkerFrontend(); 22 this._shouldPauseWorkerOnStart = WebInspector.isWorkerFrontend();
21 } 23 }
22 24
23 WebInspector.WorkerTargetManager.prototype = { 25 WebInspector.WorkerTargetManager.prototype = {
24 _onSuspendStateChanged: function() 26 _onSuspendStateChanged: function()
25 { 27 {
26 // FIXME: the logic needs to be extended and cover the case when a worke r was started after disabling autoconnect 28 // FIXME: the logic needs to be extended and cover the case when a worke r was started after disabling autoconnect
27 // and still alive after enabling autoconnect. 29 // and still alive after enabling autoconnect.
28 var suspended = WebInspector.targetManager.allTargetsSuspended(); 30 var suspended = WebInspector.targetManager.allTargetsSuspended();
29 this._mainTarget.workerAgent().setAutoconnectToWorkers(!suspended); 31 this._mainTarget.workerAgent().setAutoconnectToWorkers(!suspended);
30 }, 32 },
31 33
32 /** 34 /**
33 * @param {!WebInspector.Event} event 35 * @param {!WebInspector.Event} event
34 */ 36 */
35 _onWorkerAdded: function(event) 37 _onWorkerAdded: function(event)
36 { 38 {
37 var data = /** @type {{workerId: number, url: string, inspectorConnected : boolean}} */ (event.data); 39 var data = /** @type {{workerId: number, url: string, inspectorConnected : boolean}} */ (event.data);
38 new WebInspector.WorkerConnection(this._mainTarget, data.workerId, data. inspectorConnected, onConnectionReady.bind(this)); 40 new WebInspector.WorkerConnection(this._mainTarget, data.workerId, data. inspectorConnected, onConnectionReady.bind(this, data.workerId));
39 41
40 /** 42 /**
41 * @this {WebInspector.WorkerTargetManager} 43 * @this {WebInspector.WorkerTargetManager}
44 * @param {number} workerId
42 * @param {!InspectorBackendClass.Connection} connection 45 * @param {!InspectorBackendClass.Connection} connection
43 */ 46 */
44 function onConnectionReady(connection) 47 function onConnectionReady(workerId, connection)
45 { 48 {
46 var parsedURL = data.url.asParsedURL(); 49 var parsedURL = data.url.asParsedURL();
47 var workerId = parsedURL ? parsedURL.lastPathComponent : "#" + (++th is._lastAnonymousTargetId); 50 var workerName = parsedURL ? parsedURL.lastPathComponent : "#" + (++ this._lastAnonymousTargetId);
48 this._targetManager.createTarget(WebInspector.UIString("Worker %s", workerId), connection, targetCreated.bind(this)); 51 this._targetManager.createTarget(WebInspector.UIString("Worker %s", workerName), connection, targetCreated.bind(this, workerId));
49 } 52 }
50 53
51 /** 54 /**
52 * @this {WebInspector.WorkerTargetManager} 55 * @this {WebInspector.WorkerTargetManager}
56 * @param {number} workerId
53 * @param {?WebInspector.Target} target 57 * @param {?WebInspector.Target} target
54 */ 58 */
55 function targetCreated(target) 59 function targetCreated(workerId, target)
56 { 60 {
57 if (!target) 61 if (!target)
58 return; 62 return;
63 if (workerId)
64 this._targetsByWorkerId.set(workerId, target);
59 if (data.inspectorConnected) { 65 if (data.inspectorConnected) {
60 if (this._shouldPauseWorkerOnStart) 66 if (this._shouldPauseWorkerOnStart)
61 target.debuggerAgent().pause(); 67 target.debuggerAgent().pause();
62 target.runtimeAgent().run(calculateTitle.bind(this, target)); 68 target.runtimeAgent().run(calculateTitle.bind(this, target));
63 } else { 69 } else {
64 calculateTitle.call(this, target); 70 calculateTitle.call(this, target);
65 } 71 }
66 this._shouldPauseWorkerOnStart = false; 72 this._shouldPauseWorkerOnStart = false;
67 } 73 }
68 74
(...skipping 29 matching lines...) Expand all
98 console.error(error); 104 console.error(error);
99 return; 105 return;
100 } 106 }
101 InspectorFrontendHost.inspectedURLChanged(String(result.value)); 107 InspectorFrontendHost.inspectedURLChanged(String(result.value));
102 } 108 }
103 }, 109 },
104 110
105 _onWorkersCleared: function() 111 _onWorkersCleared: function()
106 { 112 {
107 this._lastAnonymousTargetId = 0; 113 this._lastAnonymousTargetId = 0;
114 this._targetsByWorkerId.clear();
115 },
116
117 /**
118 * @param {!WebInspector.Event} event
119 */
120 _onWorkerRemoved: function(event)
121 {
122 var workerId = /** @type {number} */ (event.data);
123 this._targetsByWorkerId.delete(workerId);
124 },
125
126 /**
127 * @param {number} workerId
128 * @return {?WebInspector.Target}
129 */
130 targetByWorkerId: function(workerId)
131 {
132 return this._targetsByWorkerId.get(workerId) || null;
108 } 133 }
109 } 134 }
110 135
111 /** 136 /**
112 * @constructor 137 * @constructor
113 * @extends {InspectorBackendClass.Connection} 138 * @extends {InspectorBackendClass.Connection}
114 * @param {!WebInspector.Target} target 139 * @param {!WebInspector.Target} target
115 * @param {number} workerId 140 * @param {number} workerId
116 * @param {boolean} inspectorConnected 141 * @param {boolean} inspectorConnected
117 * @param {!function(!InspectorBackendClass.Connection)} onConnectionReady 142 * @param {!function(!InspectorBackendClass.Connection)} onConnectionReady
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 _close: function() 191 _close: function()
167 { 192 {
168 this._target.workerManager.removeEventListener(WebInspector.WorkerManage r.Events.MessageFromWorker, this._dispatchMessageFromWorker, this); 193 this._target.workerManager.removeEventListener(WebInspector.WorkerManage r.Events.MessageFromWorker, this._dispatchMessageFromWorker, this);
169 this._target.workerManager.removeEventListener(WebInspector.WorkerManage r.Events.WorkerRemoved, this._onWorkerRemoved, this); 194 this._target.workerManager.removeEventListener(WebInspector.WorkerManage r.Events.WorkerRemoved, this._onWorkerRemoved, this);
170 this._target.workerManager.removeEventListener(WebInspector.WorkerManage r.Events.WorkersCleared, this._close, this); 195 this._target.workerManager.removeEventListener(WebInspector.WorkerManage r.Events.WorkersCleared, this._close, this);
171 this.connectionClosed("worker_terminated"); 196 this.connectionClosed("worker_terminated");
172 }, 197 },
173 198
174 __proto__: InspectorBackendClass.Connection.prototype 199 __proto__: InspectorBackendClass.Connection.prototype
175 } 200 }
201
202 /**
203 * @type {?WebInspector.WorkerTargetManager}
204 */
205 WebInspector.workerTargetManager;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698