Title: [107373] trunk/Source/WebCore
Revision
107373
Author
[email protected]
Date
2012-02-10 00:05:49 -0800 (Fri, 10 Feb 2012)

Log Message

Web Inspector: [refactoring] TimelineModel should not depend on TimelinePanel
https://bugs.webkit.org/show_bug.cgi?id=78254

Reviewed by Yury Semikhatsky.

* inspector/front-end/TimelinePanel.js:
(WebInspector.TimelinePanel):
(WebInspector.TimelinePanel.prototype._loadFromFile):
(WebInspector.TimelinePanel.prototype._toggleTimelineButtonClicked):
(WebInspector.TimelinePanel.prototype._onTimelineEventRecorded):
(WebInspector.TimelinePanel.prototype._clearPanel):
(WebInspector.TimelinePanel.prototype._onRecordsCleared):
(WebInspector.TimelineModel):
(WebInspector.TimelineModel.prototype.startRecord):
(WebInspector.TimelineModel.prototype.stopRecord):
(WebInspector.TimelineModel.prototype._onRecordAdded):
(WebInspector.TimelineModel.prototype._addRecord):
(WebInspector.TimelineModel.prototype._loadNextChunk):
(WebInspector.TimelineModel.prototype._loadFromFile):
(WebInspector.TimelineModel.prototype._reset):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (107372 => 107373)


--- trunk/Source/WebCore/ChangeLog	2012-02-10 07:58:54 UTC (rev 107372)
+++ trunk/Source/WebCore/ChangeLog	2012-02-10 08:05:49 UTC (rev 107373)
@@ -1,3 +1,26 @@
+2012-02-09  Andrey Kosyakov  <[email protected]>
+
+        Web Inspector: [refactoring] TimelineModel should not depend on TimelinePanel
+        https://bugs.webkit.org/show_bug.cgi?id=78254
+
+        Reviewed by Yury Semikhatsky.
+
+        * inspector/front-end/TimelinePanel.js:
+        (WebInspector.TimelinePanel):
+        (WebInspector.TimelinePanel.prototype._loadFromFile):
+        (WebInspector.TimelinePanel.prototype._toggleTimelineButtonClicked):
+        (WebInspector.TimelinePanel.prototype._onTimelineEventRecorded):
+        (WebInspector.TimelinePanel.prototype._clearPanel):
+        (WebInspector.TimelinePanel.prototype._onRecordsCleared):
+        (WebInspector.TimelineModel):
+        (WebInspector.TimelineModel.prototype.startRecord):
+        (WebInspector.TimelineModel.prototype.stopRecord):
+        (WebInspector.TimelineModel.prototype._onRecordAdded):
+        (WebInspector.TimelineModel.prototype._addRecord):
+        (WebInspector.TimelineModel.prototype._loadNextChunk):
+        (WebInspector.TimelineModel.prototype._loadFromFile):
+        (WebInspector.TimelineModel.prototype._reset):
+
 2012-02-09  Kentaro Hara  <[email protected]>
 
         Unreviewed, rolling out r107368.

Modified: trunk/Source/WebCore/inspector/front-end/TimelinePanel.js (107372 => 107373)


--- trunk/Source/WebCore/inspector/front-end/TimelinePanel.js	2012-02-10 07:58:54 UTC (rev 107372)
+++ trunk/Source/WebCore/inspector/front-end/TimelinePanel.js	2012-02-10 08:05:49 UTC (rev 107373)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 Google Inc. All rights reserved.
+ * Copyright (C) 2012 Google Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -114,10 +114,11 @@
     this._expandOffset = 15;
 
     this._createFileSelector();
-    this._model = new WebInspector.TimelineModel(this);
+    this._model = new WebInspector.TimelineModel();
+    this._model.addEventListener(WebInspector.TimelineModel.Events.RecordAdded, this._onTimelineEventRecorded, this);
+    this._model.addEventListener(WebInspector.TimelineModel.Events.RecordsCleared, this._onRecordsCleared, this);
 
     this._registerShortcuts();
-    WebInspector.timelineManager.addEventListener(WebInspector.TimelineManager.EventTypes.TimelineEventRecorded, this._onTimelineEventRecorded, this);
     this._linkifier = WebInspector.debuggerPresentationModel.createLinkifier();
 }
 
@@ -354,11 +355,10 @@
 
     _loadFromFile: function()
     {
-        if (this.toggleTimelineButton.toggled)
-            WebInspector.timelineManager.stop();
-
-        this._clearPanel();
-
+        if (this.toggleTimelineButton.toggled) {
+            this.toggleTimelineButton.toggled = false;
+            this._model.stopRecord();
+        }
         this._model._loadFromFile(this._fileSelectorElement.files[0]);
         this._createFileSelector();
     },
@@ -422,10 +422,9 @@
     _toggleTimelineButtonClicked: function()
     {
         if (this.toggleTimelineButton.toggled)
-            WebInspector.timelineManager.stop();
+            this._model.stopRecord();
         else {
-            this._clearPanel();
-            WebInspector.timelineManager.start(30);
+            this._model.startRecord();
             WebInspector.userMetrics.TimelineStarted.record();
         }
         this.toggleTimelineButton.toggled = !this.toggleTimelineButton.toggled;
@@ -462,21 +461,13 @@
 
     _onTimelineEventRecorded: function(event)
     {
-        if (this.toggleTimelineButton.toggled) {
-            this._addRecordToTimeline(event.data);
+        this._innerAddRecordToTimeline(event.data, this._rootRecord);
+        this._scheduleRefresh(false);
 
-            if (this._memoryStatistics && event.data["domGroups"])
-                this._memoryStatistics.addTimlineEvent(event);
-        }
+        if (this._memoryStatistics && event.data["domGroups"])
+            this._memoryStatistics.addTimlineEvent(event);
     },
 
-    _addRecordToTimeline: function(record)
-    {
-        this._model._addRecord(record);
-        this._innerAddRecordToTimeline(record, this._rootRecord);
-        this._scheduleRefresh(false);
-    },
-
     _findParentRecord: function(record)
     {
         var recordTypes = WebInspector.TimelineAgent.RecordType;
@@ -600,6 +591,11 @@
 
     _clearPanel: function()
     {
+        this._model._reset();
+    },
+
+    _onRecordsCleared: function()
+    {
         this._timeStampRecords = [];
         this._sendRequestRecords = {};
         this._scheduledResourceRequests = {};
@@ -611,7 +607,6 @@
         this._adjustScrollPosition(0);
         this._refresh();
         this._closeRecordDetails();
-        this._model._reset();
         this._linkifier.reset();
     },
 
@@ -1426,23 +1421,55 @@
 
 /**
  * @constructor
+ * @extends {WebInspector.Object}
  */
-WebInspector.TimelineModel = function(timelinePanel)
+WebInspector.TimelineModel = function()
 {
-    this._panel = timelinePanel;
     this._records = [];
+    this._collectionEnabled = false;
+
+    WebInspector.timelineManager.addEventListener(WebInspector.TimelineManager.EventTypes.TimelineEventRecorded, this._onRecordAdded, this);
 }
 
+WebInspector.TimelineModel.Events = {
+    RecordAdded: "RecordAdded",
+    RecordsCleared: "RecordsCleared"
+}
+
 WebInspector.TimelineModel.prototype = {
+    startRecord: function()
+    {
+        if (this._collectionEnabled)
+            return;
+        this._reset();
+        WebInspector.timelineManager.start(30);
+        this._collectionEnabled = true;
+    },
+
+    stopRecord: function()
+    {
+        if (!this._collectionEnabled)
+            return;
+        WebInspector.timelineManager.stop();
+        this._collectionEnabled = false;
+    },
+
+    _onRecordAdded: function(event)
+    {
+        if (this._collectionEnabled)
+            this._addRecord(event.data);
+    },
+
     _addRecord: function(record)
     {
         this._records.push(record);
+        this.dispatchEventToListeners(WebInspector.TimelineModel.Events.RecordAdded, record);
     },
 
     _loadNextChunk: function(data, index)
     {
         for (var i = 0; i < 20 && index < data.length; ++i, ++index)
-            this._panel._addRecordToTimeline(data[index]);
+            this._addRecord(data[index]);
 
         if (index !== data.length)
             setTimeout(this._loadNextChunk.bind(this, data, index), 0);
@@ -1453,7 +1480,7 @@
         function onLoad(e)
         {
             var data = ""
-            var version = data[0];
+            this._reset();
             this._loadNextChunk(data, 1);
         }
 
@@ -1494,6 +1521,10 @@
 
     _reset: function()
     {
+        this.stopRecord();
         this._records = [];
+        this.dispatchEventToListeners(WebInspector.TimelineModel.Events.RecordsCleared);
     }
 }
+
+WebInspector.TimelineModel.prototype.__proto__ = WebInspector.Object.prototype;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to