Index: Source/devtools/front_end/timeline/TimelineModelImpl.js |
diff --git a/Source/devtools/front_end/timeline/TimelineModelImpl.js b/Source/devtools/front_end/timeline/TimelineModelImpl.js |
index 2525bd0c4e7cb9360efb62186ee0842c73f2298e..da9ecccef5ffcf2b43949003deb33c9255e5e08d 100644 |
--- a/Source/devtools/front_end/timeline/TimelineModelImpl.js |
+++ b/Source/devtools/front_end/timeline/TimelineModelImpl.js |
@@ -5,33 +5,40 @@ |
/** |
* @constructor |
* @extends {WebInspector.TimelineModel} |
- * @param {!WebInspector.TimelineManager} timelineManager |
+ * @implements {WebInspector.TargetManager.Observer} |
*/ |
-WebInspector.TimelineModelImpl = function(timelineManager) |
+WebInspector.TimelineModelImpl = function() |
{ |
WebInspector.TimelineModel.call(this); |
- this._target = timelineManager.target(); |
- this._timelineManager = timelineManager; |
+ /** @type {?WebInspector.Target} */ |
+ this._currentTarget = null; |
this._filters = []; |
this._bindings = new WebInspector.TimelineModelImpl.InterRecordBindings(); |
this.reset(); |
- this._timelineManager.addEventListener(WebInspector.TimelineManager.EventTypes.TimelineEventRecorded, this._onRecordAdded, this); |
- this._timelineManager.addEventListener(WebInspector.TimelineManager.EventTypes.TimelineStarted, this._onStarted, this); |
- this._timelineManager.addEventListener(WebInspector.TimelineManager.EventTypes.TimelineStopped, this._onStopped, this); |
- this._timelineManager.addEventListener(WebInspector.TimelineManager.EventTypes.TimelineProgress, this._onProgress, this); |
+ WebInspector.targetManager.addModelListener(WebInspector.TimelineManager, WebInspector.TimelineManager.EventTypes.TimelineEventRecorded, this._onRecordAdded, this); |
+ WebInspector.targetManager.addModelListener(WebInspector.TimelineManager, WebInspector.TimelineManager.EventTypes.TimelineStarted, this._onStarted, this); |
+ WebInspector.targetManager.addModelListener(WebInspector.TimelineManager, WebInspector.TimelineManager.EventTypes.TimelineStopped, this._onStopped, this); |
+ WebInspector.targetManager.addModelListener(WebInspector.TimelineManager, WebInspector.TimelineManager.EventTypes.TimelineProgress, this._onProgress, this); |
+ WebInspector.targetManager.observeTargets(this); |
} |
WebInspector.TimelineModelImpl.TransferChunkLengthBytes = 5000000; |
WebInspector.TimelineModelImpl.prototype = { |
/** |
- * @return {boolean} |
+ * @param {!WebInspector.Target} target |
*/ |
- loadedFromFile: function() |
+ targetAdded: function(target) { }, |
+ |
+ /** |
+ * @param {!WebInspector.Target} target |
+ */ |
+ targetRemoved: function(target) |
{ |
- return this._loadedFromFile; |
+ if (this._currentTarget === target) |
+ this._currentTarget = null; |
}, |
/** |
@@ -42,21 +49,28 @@ WebInspector.TimelineModelImpl.prototype = { |
startRecording: function(captureStacks, captureMemory, capturePictures) |
{ |
console.assert(!capturePictures, "Legacy timeline does not support capturing pictures"); |
- this._clientInitiatedRecording = true; |
this.reset(); |
+ this._currentTarget = WebInspector.context.flavor(WebInspector.Target); |
+ if (!this._currentTarget) |
yurys
2014/07/21 09:55:20
How can this happen? Shouldn't we fail in this cas
|
+ return; |
+ |
+ this._clientInitiatedRecording = true; |
var maxStackFrames = captureStacks ? 30 : 0; |
var includeGPUEvents = WebInspector.experimentsSettings.gpuTimeline.isEnabled(); |
var liveEvents = [ WebInspector.TimelineModel.RecordType.BeginFrame, |
WebInspector.TimelineModel.RecordType.DrawFrame, |
WebInspector.TimelineModel.RecordType.RequestMainThreadFrame, |
WebInspector.TimelineModel.RecordType.ActivateLayerTree ]; |
- this._timelineManager.start(maxStackFrames, WebInspector.experimentsSettings.timelineNoLiveUpdate.isEnabled(), liveEvents.join(","), captureMemory, includeGPUEvents, this._fireRecordingStarted.bind(this)); |
+ this._currentTarget.timelineManager.start(maxStackFrames, WebInspector.experimentsSettings.timelineNoLiveUpdate.isEnabled(), liveEvents.join(","), captureMemory, includeGPUEvents, this._fireRecordingStarted.bind(this)); |
}, |
stopRecording: function() |
{ |
+ if (!this._currentTarget) |
+ return; |
+ |
if (!this._clientInitiatedRecording) { |
- this._timelineManager.start(undefined, undefined, undefined, undefined, undefined, stopTimeline.bind(this)); |
+ this._currentTarget.timelineManager.start(undefined, undefined, undefined, undefined, undefined, stopTimeline.bind(this)); |
return; |
} |
@@ -67,11 +81,11 @@ WebInspector.TimelineModelImpl.prototype = { |
*/ |
function stopTimeline() |
{ |
- this._timelineManager.stop(this._fireRecordingStopped.bind(this)); |
+ this._currentTarget.timelineManager.stop(this._fireRecordingStopped.bind(this)); |
} |
this._clientInitiatedRecording = false; |
- this._timelineManager.stop(this._fireRecordingStopped.bind(this)); |
+ this._currentTarget.timelineManager.stop(this._fireRecordingStopped.bind(this)); |
}, |
/** |
@@ -87,7 +101,8 @@ WebInspector.TimelineModelImpl.prototype = { |
*/ |
_onRecordAdded: function(event) |
{ |
- if (this._collectionEnabled) |
+ var timelineManager = /** @type {!WebInspector.TimelineManager} */ (event.target); |
+ if (this._collectionEnabled && timelineManager.target() === this._currentTarget) |
this._addRecord(/** @type {!TimelineAgent.TimelineEvent} */(event.data)); |
}, |
@@ -96,10 +111,15 @@ WebInspector.TimelineModelImpl.prototype = { |
*/ |
_onStarted: function(event) |
{ |
- if (event.data) { |
- // Started from console. |
- this._fireRecordingStarted(); |
+ if (!event.data || this._collectionEnabled) |
yurys
2014/07/21 09:55:20
Why do we need to also check this._collectionEnabl
sergeyv
2014/07/21 12:39:11
we need it to prevent situation, when timeline was
|
+ return; |
+ // Started from console. |
+ var timelineManager = /** @type {!WebInspector.TimelineManager} */ (event.target); |
+ if (this._currentTarget !== timelineManager.target()) { |
+ this.reset(); |
+ this._currentTarget = timelineManager.target(); |
} |
+ this._fireRecordingStarted(); |
}, |
/** |
@@ -107,9 +127,14 @@ WebInspector.TimelineModelImpl.prototype = { |
*/ |
_onStopped: function(event) |
{ |
+ var timelineManager = /** @type {!WebInspector.TimelineManager} */ (event.target); |
+ if (timelineManager.target() !== this._currentTarget) |
+ return; |
// If we were buffering events, discard those that got through, the real ones are coming! |
- if (WebInspector.experimentsSettings.timelineNoLiveUpdate.isEnabled()) |
+ if (WebInspector.experimentsSettings.timelineNoLiveUpdate.isEnabled()) { |
this.reset(); |
+ this._currentTarget = timelineManager.target(); |
+ } |
if (event.data) { |
// Stopped from console. |
this._fireRecordingStopped(null, null); |
@@ -121,7 +146,9 @@ WebInspector.TimelineModelImpl.prototype = { |
*/ |
_onProgress: function(event) |
{ |
- this.dispatchEventToListeners(WebInspector.TimelineModel.Events.RecordingProgress, event.data); |
+ var timelineManager = /** @type {!WebInspector.TimelineManager} */ (event.target); |
+ if (timelineManager.target() === this._currentTarget) |
+ this.dispatchEventToListeners(WebInspector.TimelineModel.Events.RecordingProgress, event.data); |
}, |
_fireRecordingStarted: function() |
@@ -236,7 +263,7 @@ WebInspector.TimelineModelImpl.prototype = { |
reset: function() |
{ |
- this._loadedFromFile = false; |
+ this._currentTarget = null; |
this._payloads = []; |
this._stringPool = {}; |
this._bindings._reset(); |
@@ -396,7 +423,7 @@ WebInspector.TimelineModel.RecordImpl.prototype = { |
*/ |
target: function() |
{ |
- return this._model._target; |
+ return this._model._currentTarget; |
}, |
/** |
@@ -586,7 +613,6 @@ WebInspector.TimelineModelLoader.prototype = { |
close: function() |
{ |
- this._model._loadedFromFile = true; |
} |
} |