Chromium Code Reviews| Index: Source/devtools/front_end/profiler/CPUProfileView.js |
| diff --git a/Source/devtools/front_end/profiler/CPUProfileView.js b/Source/devtools/front_end/profiler/CPUProfileView.js |
| index 448328e5d46a11383abe14d72201a4cf8a0ea9d6..240633ea42705e9b3638fec1c16d59cd4316bedd 100644 |
| --- a/Source/devtools/front_end/profiler/CPUProfileView.js |
| +++ b/Source/devtools/front_end/profiler/CPUProfileView.js |
| @@ -73,7 +73,7 @@ WebInspector.CPUProfileView = function(profileHeader) |
| this.resetButton.addEventListener("click", this._resetClicked, this); |
| this._statusBarButtonsElement.appendChild(this.resetButton.element); |
| - this._profileHeader = profileHeader; |
| + this._target = profileHeader.target(); |
| this._linkifier = new WebInspector.Linkifier(new WebInspector.Linkifier.DefaultFormatter(30)); |
| this.profile = new WebInspector.CPUProfileDataModel(profileHeader._profile || profileHeader.protocolProfile()); |
| @@ -352,7 +352,7 @@ WebInspector.CPUProfileView.prototype = { |
| { |
| if (this._flameChart) |
| return; |
| - this._dataProvider = new WebInspector.CPUFlameChartDataProvider(this.profile, this._profileHeader.target()); |
| + this._dataProvider = new WebInspector.CPUFlameChartDataProvider(this.profile, this._target); |
| this._flameChart = new WebInspector.CPUProfileFlameChart(this._dataProvider); |
| this._flameChart.addEventListener(WebInspector.FlameChart.Events.EntrySelected, this._onEntrySelected.bind(this)); |
| }, |
| @@ -364,9 +364,9 @@ WebInspector.CPUProfileView.prototype = { |
| { |
| var entryIndex = event.data; |
| var node = this._dataProvider._entryNodes[entryIndex]; |
| - if (!node || !node.scriptId) |
| + if (!node || !node.scriptId || !this._target) |
| return; |
| - var script = WebInspector.debuggerModel.scriptForId(node.scriptId) |
| + var script = this._target.debuggerModel.scriptForId(node.scriptId) |
| if (!script) |
| return; |
| WebInspector.Revealer.reveal(script.rawLocationToUILocation(node.lineNumber)); |
| @@ -482,6 +482,7 @@ WebInspector.CPUProfileView.prototype = { |
| * @constructor |
| * @extends {WebInspector.ProfileType} |
| * @implements {WebInspector.CPUProfilerModel.Delegate} |
| + * @implements {WebInspector.TargetManager.Observer} |
| */ |
| WebInspector.CPUProfileType = function() |
| { |
| @@ -492,13 +493,29 @@ WebInspector.CPUProfileType = function() |
| this._anonymousConsoleProfileIdToTitle = {}; |
| WebInspector.CPUProfileType.instance = this; |
| - WebInspector.cpuProfilerModel.setDelegate(this); |
| + WebInspector.targetManager.observeTargets(this); |
| } |
| WebInspector.CPUProfileType.TypeId = "CPU"; |
| WebInspector.CPUProfileType.prototype = { |
| /** |
| + * @param {!WebInspector.Target} target |
| + */ |
| + targetAdded: function(target) |
| + { |
| + target.cpuProfilerModel.setDelegate(this); |
|
vsevik
2014/07/01 08:48:54
Let's use event listeners instead of delegate.
sergeyv
2014/07/01 12:22:56
Done.
|
| + }, |
| + |
| + /** |
| + * @param {!WebInspector.Target} target |
| + */ |
| + targetRemoved: function(target) |
| + { |
| + target.cpuProfilerModel.setDelegate(null); |
| + }, |
| + |
| + /** |
| * @override |
| * @return {string} |
| */ |
| @@ -566,8 +583,7 @@ WebInspector.CPUProfileType.prototype = { |
| delete this._anonymousConsoleProfileIdToTitle[protocolId]; |
| } |
| - var target = /** @type {!WebInspector.Target} */ (WebInspector.targetManager.activeTarget()); |
| - var profile = new WebInspector.CPUProfileHeader(target, this, resolvedTitle); |
| + var profile = new WebInspector.CPUProfileHeader(scriptLocation.target(), this, resolvedTitle); |
| profile.setProtocolProfile(cpuProfile); |
| this.addProfile(profile); |
| this._addMessageToConsole(WebInspector.ConsoleMessage.MessageType.ProfileEnd, scriptLocation, WebInspector.UIString("Profile '%s' finished.", resolvedTitle)); |
| @@ -581,8 +597,9 @@ WebInspector.CPUProfileType.prototype = { |
| _addMessageToConsole: function(type, scriptLocation, messageText) |
| { |
| var script = scriptLocation.script(); |
| + var target = scriptLocation.target(); |
| var message = new WebInspector.ConsoleMessage( |
| - WebInspector.console.target(), |
| + target, |
| WebInspector.ConsoleMessage.MessageSource.ConsoleAPI, |
| WebInspector.ConsoleMessage.MessageLevel.Debug, |
| messageText, |
| @@ -600,7 +617,7 @@ WebInspector.CPUProfileType.prototype = { |
| columnNumber: scriptLocation.columnNumber || 0 |
| }]); |
| - WebInspector.console.addMessage(message); |
| + target.consoleModel.addMessage(message); |
| }, |
| /** |
| @@ -613,23 +630,22 @@ WebInspector.CPUProfileType.prototype = { |
| startRecordingProfile: function() |
| { |
| - if (this._profileBeingRecorded) |
| + var target = WebInspector.context.flavor(WebInspector.Target); |
| + if (this._profileBeingRecorded || !target) |
| return; |
| - var target = /** @type {!WebInspector.Target} */ (WebInspector.targetManager.activeTarget()); |
| var profile = new WebInspector.CPUProfileHeader(target, this); |
| this.setProfileBeingRecorded(profile); |
| this.addProfile(profile); |
| profile.updateStatus(WebInspector.UIString("Recording\u2026")); |
| this._recording = true; |
| - WebInspector.cpuProfilerModel.setRecording(true); |
| - WebInspector.userMetrics.ProfilesCPUProfileTaken.record(); |
| - ProfilerAgent.start(); |
| + target.cpuProfilerModel.startRecording(); |
| }, |
| stopRecordingProfile: function() |
| { |
| this._recording = false; |
| - WebInspector.cpuProfilerModel.setRecording(false); |
| + if (!this._profileBeingRecorded || !this._profileBeingRecorded.target()) |
|
vsevik
2014/07/01 08:48:54
What will happen if the worker closes while we are
sergeyv
2014/07/01 12:22:56
In current behavior - nothing will happen, lets ha
|
| + return; |
| /** |
| * @param {?string} error |
| @@ -646,7 +662,7 @@ WebInspector.CPUProfileType.prototype = { |
| this.setProfileBeingRecorded(null); |
| this.dispatchEventToListeners(WebInspector.ProfileType.Events.ProfileComplete, recordedProfile); |
| } |
| - ProfilerAgent.stop(didStopProfiling.bind(this)); |
| + this._profileBeingRecorded.target().cpuProfilerModel.stopRecording(didStopProfiling.bind(this)); |
| }, |
| /** |