Title: [118742] trunk
Revision
118742
Author
[email protected]
Date
2012-05-29 02:17:36 -0700 (Tue, 29 May 2012)

Log Message

Web Inspector: REGRESSION: load heap snapshot doesn't work.
https://bugs.webkit.org/show_bug.cgi?id=87642

Source/WebCore:

HeapSnapshotReceiver interface was introduced.
It declares the API for HeapSnapshotLoader, HeapSnapshotLoaderProxy and HeapSnapshotSaveToFileReceiver.
The HeapProfileHeader was refactored and tests were added.

Reviewed by Yury Semikhatsky.

* inspector/front-end/HeapSnapshotLoader.js:
(WebInspector.HeapSnapshotLoader):
(WebInspector.HeapSnapshotLoader.prototype.startLoading):
(WebInspector.HeapSnapshotLoader.prototype.dispose):
(WebInspector.HeapSnapshotLoader.prototype._reset):
(WebInspector.HeapSnapshotLoader.prototype.finishLoading):
* inspector/front-end/HeapSnapshotProxy.js:
(WebInspector.HeapSnapshotWorker.prototype.startCheckingForLongRunningCalls):
(WebInspector.HeapSnapshotLoaderProxy.prototype.startLoading):
(WebInspector.HeapSnapshotLoaderProxy.prototype.pushJSONChunk):
(WebInspector.HeapSnapshotLoaderProxy.prototype.finishLoading):
* inspector/front-end/HeapSnapshotView.js:
(WebInspector.HeapSnapshotReceiver):
(WebInspector.HeapSnapshotReceiver.prototype.startLoading):
(WebInspector.HeapSnapshotReceiver.prototype.pushJSONChunk):
(WebInspector.HeapSnapshotReceiver.prototype.finishLoading):
(WebInspector.HeapSnapshotReceiver.prototype.dispose):
(WebInspector.HeapProfileHeader):
(WebInspector.HeapProfileHeader.prototype.load):
(WebInspector.HeapProfileHeader.prototype._setupWorker):
(WebInspector.HeapProfileHeader.prototype.dispose):
(WebInspector.HeapProfileHeader.prototype._saveStatusUpdate):
(WebInspector.HeapProfileHeader.prototype.pushJSONChunk):
(WebInspector.HeapProfileHeader.prototype._parsed):
(WebInspector.HeapProfileHeader.prototype.finishHeapSnapshot):
(WebInspector.HeapProfileHeader.prototype.saveToFile):
(WebInspector.HeapProfileHeader.prototype.loadFromFile.onLoad):
(WebInspector.HeapProfileHeader.prototype.loadFromFile):
(WebInspector.HeapProfileHeader.prototype._loadNextChunk):
(WebInspector.HeapProfileHeader.prototype._nextChunkLoaded):
(WebInspector.HeapProfileHeader.prototype._createFileReader):
(WebInspector.HeapSnapshotSaveToFileReceiver):
(WebInspector.HeapSnapshotSaveToFileReceiver.prototype.startLoading):
(WebInspector.HeapSnapshotSaveToFileReceiver.prototype.pushJSONChunk):
(WebInspector.HeapSnapshotSaveToFileReceiver.prototype.finishLoading):
(WebInspector.HeapSnapshotSaveToFileReceiver.prototype.dispose):
(WebInspector.HeapSnapshotSaveToFileReceiver.prototype._startSavingSnapshot):
(WebInspector.HeapSnapshotSaveToFileReceiver.prototype._saveStatusUpdate):
* inspector/front-end/ProfilesPanel.js:
(WebInspector.ProfilesPanel.prototype._createFileSelectorElement.onChange):
(WebInspector.ProfilesPanel.prototype._createFileSelectorElement):
(WebInspector.ProfilesPanel.prototype._loadFromFile):

LayoutTests:

HeapSnapshotReceiver interface was introduced.
It declares the API for HSLoader, HSLoaderProxy and HSSaveToFileReceiver.
The HeapProfileHeader was refactored and tests were added.

Reviewed by Yury Semikhatsky.

* inspector/profiler/heap-snapshot-loader-expected.txt:
* inspector/profiler/heap-snapshot-loader.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (118741 => 118742)


--- trunk/LayoutTests/ChangeLog	2012-05-29 09:12:11 UTC (rev 118741)
+++ trunk/LayoutTests/ChangeLog	2012-05-29 09:17:36 UTC (rev 118742)
@@ -1,3 +1,17 @@
+2012-05-29  Ilya Tikhonovsky  <[email protected]>
+
+        Web Inspector: REGRESSION: load heap snapshot doesn't work.
+        https://bugs.webkit.org/show_bug.cgi?id=87642
+
+        HeapSnapshotReceiver interface was introduced.
+        It declares the API for HSLoader, HSLoaderProxy and HSSaveToFileReceiver.
+        The HeapProfileHeader was refactored and tests were added.
+
+        Reviewed by Yury Semikhatsky.
+
+        * inspector/profiler/heap-snapshot-loader-expected.txt:
+        * inspector/profiler/heap-snapshot-loader.html:
+
 2012-05-29  Marcus Bulach  <[email protected]>
 
         Test expectation pngs missing checksums are treated as MISSING by bots
@@ -12,6 +26,20 @@
 
         * platform/chromium/test_expectations.txt:
 
+2012-05-29  Marcus Bulach  <[email protected]>
+
+        Test expectation pngs missing checksums are treated as MISSING by bots
+        https://bugs.webkit.org/show_bug.cgi?id=87552
+
+        Unreviewed gardening.
+
+        This test was already failing for IMAGE and TEXT reasons prior to r118566.
+        On r118566, new images were added, probably without an embedded checksum.
+        It looks like our test infrastructure thinks that these images are MISSING.
+        Temporarily add MISSING expectations, so that we can proceed with this (failing) test.
+
+        * platform/chromium/test_expectations.txt:
+
 2012-05-29  Thiago Marcos P. Santos  <[email protected]>
 
         [EFL] MathML tests needs rebaseline after r118713

Modified: trunk/LayoutTests/inspector/profiler/heap-snapshot-loader-expected.txt (118741 => 118742)


--- trunk/LayoutTests/inspector/profiler/heap-snapshot-loader-expected.txt	2012-05-29 09:12:11 UTC (rev 118741)
+++ trunk/LayoutTests/inspector/profiler/heap-snapshot-loader-expected.txt	2012-05-29 09:17:36 UTC (rev 118742)
@@ -3,3 +3,7 @@
 
 Running: heapSnapshotLoaderTest
 
+Running: heapSnapshotSaveToFileTest
+
+Running: heapSnapshotLoadFromFileTest
+

Modified: trunk/LayoutTests/inspector/profiler/heap-snapshot-loader.html (118741 => 118742)


--- trunk/LayoutTests/inspector/profiler/heap-snapshot-loader.html	2012-05-29 09:12:11 UTC (rev 118741)
+++ trunk/LayoutTests/inspector/profiler/heap-snapshot-loader.html	2012-05-29 09:17:36 UTC (rev 118742)
@@ -11,12 +11,13 @@
         InspectorTest.assertEquals(JSON.stringify(reference), JSON.stringify(actual));
     }
 
+    var source = InspectorTest.createHeapSnapshotMockRaw();
+    var sourceStringified = JSON.stringify(source);
+    var partSize = sourceStringified.length >> 3;
+
     InspectorTest.runTestSuite([
         function heapSnapshotLoaderTest(next)
         {
-            var source = InspectorTest.createHeapSnapshotMockRaw();
-            var sourceStringified = JSON.stringify(source);
-            var partSize = sourceStringified.length >> 3;
             var loader = new WebInspector.HeapSnapshotLoader();
             for (var i = 0, l = sourceStringified.length; i < l; i += partSize)
                 loader.pushJSONChunk(sourceStringified.slice(i, i + partSize));
@@ -25,6 +26,83 @@
             result._containmentEdges = new Uint32Array(result._containmentEdges);
             InspectorTest.assertSnapshotEquals(new WebInspector.HeapSnapshot(InspectorTest.createHeapSnapshotMock()), result);
             next();
+        },
+
+        function heapSnapshotSaveToFileTest(next)
+        {
+            var profileUID = 42;
+
+            var dispatcher = InspectorBackend._domainDispatchers["Profiler"];
+            var panel = WebInspector.panels.profiles;
+
+            dispatcher.addProfileHeader({
+                typeId: WebInspector.HeapSnapshotProfileType.TypeId,
+                title: "heapSnapshotSaveToFileTest",
+                uid: profileUID,
+                maxJSObjectId: 6
+            });
+
+            var profileHeader = panel._profiles[0];
+
+            var oldGetProfile = ProfilerAgent.getProfile;
+            ProfilerAgent.getProfile = function getProfileMock(profileTypeName, uid) {
+                for (var i = 0, l = sourceStringified.length; i < l; i += partSize)
+                    dispatcher.addHeapSnapshotChunk(uid, sourceStringified.slice(i, i + partSize));
+                dispatcher.finishHeapSnapshot(uid);
+            };
+
+            var savedSnapshotData;
+            var oldSave = InspectorFrontendHost.save;
+            InspectorFrontendHost.save = function saveMock(url, data)
+            {
+                savedSnapshotData = data;
+                WebInspector.fileManager.savedURL(url);
+            }
+
+            var oldAppend = InspectorFrontendHost.append;
+            InspectorFrontendHost.append = function appendMock(url, data)
+            {
+                savedSnapshotData += data;
+                WebInspector.fileManager.appendedToURL(url);
+            }
+
+            function parsed()
+            {
+                profileHeader.saveToFile();
+                InspectorTest.assertEquals(sourceStringified, savedSnapshotData, "Saved snapshot data");
+
+                InspectorFrontendHost.save = oldSave;
+                InspectorFrontendHost.append = oldAppend;
+                ProfilerAgent.getProfile = oldGetProfile;
+                next();
+            }
+            InspectorTest.addSniffer(profileHeader, "_parsed", parsed);
+
+            panel.showProfile(profileHeader);
+        },
+
+        function heapSnapshotLoadFromFileTest(next)
+        {
+            var panel = WebInspector.panels.profiles;
+
+            var fileMock = {
+                name: "mock.heapsnapshot",
+                size: sourceStringified.length,
+                webkitSlice: function(begin, end) {
+                    return this;
+                }
+            };
+
+            WebInspector.HeapProfileHeader.prototype._createFileReader = function() {
+                return {
+                    readAsText: function(filePart) {
+                        var profileHeader = panel._profiles[panel._profiles.length - 1];
+                        InspectorTest.addSniffer(profileHeader, "_parsed", function parsed() { next(); });
+                        profileHeader._nextChunkLoaded(sourceStringified);
+                    }
+                };
+            }
+            panel._loadFromFile(fileMock);
         }
     ]);
 }

Modified: trunk/Source/WebCore/ChangeLog (118741 => 118742)


--- trunk/Source/WebCore/ChangeLog	2012-05-29 09:12:11 UTC (rev 118741)
+++ trunk/Source/WebCore/ChangeLog	2012-05-29 09:17:36 UTC (rev 118742)
@@ -1,3 +1,57 @@
+2012-05-29  Ilya Tikhonovsky  <[email protected]>
+
+        Web Inspector: REGRESSION: load heap snapshot doesn't work.
+        https://bugs.webkit.org/show_bug.cgi?id=87642
+
+        HeapSnapshotReceiver interface was introduced.
+        It declares the API for HeapSnapshotLoader, HeapSnapshotLoaderProxy and HeapSnapshotSaveToFileReceiver.
+        The HeapProfileHeader was refactored and tests were added.
+
+        Reviewed by Yury Semikhatsky.
+
+        * inspector/front-end/HeapSnapshotLoader.js:
+        (WebInspector.HeapSnapshotLoader):
+        (WebInspector.HeapSnapshotLoader.prototype.startLoading):
+        (WebInspector.HeapSnapshotLoader.prototype.dispose):
+        (WebInspector.HeapSnapshotLoader.prototype._reset):
+        (WebInspector.HeapSnapshotLoader.prototype.finishLoading):
+        * inspector/front-end/HeapSnapshotProxy.js:
+        (WebInspector.HeapSnapshotWorker.prototype.startCheckingForLongRunningCalls):
+        (WebInspector.HeapSnapshotLoaderProxy.prototype.startLoading):
+        (WebInspector.HeapSnapshotLoaderProxy.prototype.pushJSONChunk):
+        (WebInspector.HeapSnapshotLoaderProxy.prototype.finishLoading):
+        * inspector/front-end/HeapSnapshotView.js:
+        (WebInspector.HeapSnapshotReceiver):
+        (WebInspector.HeapSnapshotReceiver.prototype.startLoading):
+        (WebInspector.HeapSnapshotReceiver.prototype.pushJSONChunk):
+        (WebInspector.HeapSnapshotReceiver.prototype.finishLoading):
+        (WebInspector.HeapSnapshotReceiver.prototype.dispose):
+        (WebInspector.HeapProfileHeader):
+        (WebInspector.HeapProfileHeader.prototype.load):
+        (WebInspector.HeapProfileHeader.prototype._setupWorker):
+        (WebInspector.HeapProfileHeader.prototype.dispose):
+        (WebInspector.HeapProfileHeader.prototype._saveStatusUpdate):
+        (WebInspector.HeapProfileHeader.prototype.pushJSONChunk):
+        (WebInspector.HeapProfileHeader.prototype._parsed):
+        (WebInspector.HeapProfileHeader.prototype.finishHeapSnapshot):
+        (WebInspector.HeapProfileHeader.prototype.saveToFile):
+        (WebInspector.HeapProfileHeader.prototype.loadFromFile.onLoad):
+        (WebInspector.HeapProfileHeader.prototype.loadFromFile):
+        (WebInspector.HeapProfileHeader.prototype._loadNextChunk):
+        (WebInspector.HeapProfileHeader.prototype._nextChunkLoaded):
+        (WebInspector.HeapProfileHeader.prototype._createFileReader):
+        (WebInspector.HeapSnapshotSaveToFileReceiver):
+        (WebInspector.HeapSnapshotSaveToFileReceiver.prototype.startLoading):
+        (WebInspector.HeapSnapshotSaveToFileReceiver.prototype.pushJSONChunk):
+        (WebInspector.HeapSnapshotSaveToFileReceiver.prototype.finishLoading):
+        (WebInspector.HeapSnapshotSaveToFileReceiver.prototype.dispose):
+        (WebInspector.HeapSnapshotSaveToFileReceiver.prototype._startSavingSnapshot):
+        (WebInspector.HeapSnapshotSaveToFileReceiver.prototype._saveStatusUpdate):
+        * inspector/front-end/ProfilesPanel.js:
+        (WebInspector.ProfilesPanel.prototype._createFileSelectorElement.onChange):
+        (WebInspector.ProfilesPanel.prototype._createFileSelectorElement):
+        (WebInspector.ProfilesPanel.prototype._loadFromFile):
+
 2012-05-29  Eric Seidel  <[email protected]>
 
         Add HTMLIFrameElement.seamless property accessor now that seamless is enabled and works

Modified: trunk/Source/WebCore/inspector/front-end/HeapSnapshotLoader.js (118741 => 118742)


--- trunk/Source/WebCore/inspector/front-end/HeapSnapshotLoader.js	2012-05-29 09:12:11 UTC (rev 118741)
+++ trunk/Source/WebCore/inspector/front-end/HeapSnapshotLoader.js	2012-05-29 09:17:36 UTC (rev 118742)
@@ -30,15 +30,35 @@
 
 /**
  * @constructor
+ * @implements {WebInspector.HeapSnapshotReceiver}
  */
 WebInspector.HeapSnapshotLoader = function()
 {
-    this._json = "";
-    this._state = "find-snapshot-info";
-    this._snapshot = {};
+    this._reset();
 }
 
 WebInspector.HeapSnapshotLoader.prototype = {
+    /**
+     * @param {function(WebInspector.HeapSnapshotProxy)} callback
+     * @return {boolean}
+     */
+    startLoading: function(callback)
+    {
+        return true;
+    },
+
+    dispose: function()
+    {
+        this._reset();
+    },
+
+    _reset: function()
+    {
+        this._json = "";
+        this._state = "find-snapshot-info";
+        this._snapshot = {};
+    },
+
     _findBalancedCurlyBrackets: function()
     {
         var counter = 0;
@@ -60,10 +80,8 @@
         if (!this._json)
             return null;
         this._parseStringsArray();
-        this._json = "";
         var result = new WebInspector.HeapSnapshot(this._snapshot);
-        this._json = "";
-        this._snapshot = {};
+        this._reset();
         return result;
     },
 
@@ -114,6 +132,9 @@
         this._snapshot.strings = JSON.parse(this._json);
     },
 
+    /**
+     * @param {string} chunk
+     */
     pushJSONChunk: function(chunk)
     {
         this._json += chunk;

Modified: trunk/Source/WebCore/inspector/front-end/HeapSnapshotProxy.js (118741 => 118742)


--- trunk/Source/WebCore/inspector/front-end/HeapSnapshotProxy.js	2012-05-29 09:12:11 UTC (rev 118741)
+++ trunk/Source/WebCore/inspector/front-end/HeapSnapshotProxy.js	2012-05-29 09:17:36 UTC (rev 118742)
@@ -245,6 +245,8 @@
 
     startCheckingForLongRunningCalls: function()
     {
+        if (this._interval)
+            return;
         this._checkLongRunningCalls();
         this._interval = setInterval(this._checkLongRunningCalls.bind(this), 300);
     },
@@ -353,6 +355,7 @@
 /**
  * @constructor
  * @extends {WebInspector.HeapSnapshotProxyObject}
+ * @implements {WebInspector.HeapSnapshotReceiver}
  */
 WebInspector.HeapSnapshotLoaderProxy = function(worker, objectId)
 {
@@ -363,7 +366,26 @@
 WebInspector.HeapSnapshotLoaderProxy.prototype = {
     /**
      * @param {function(WebInspector.HeapSnapshotProxy)} callback
+     * @return {boolean}
      */
+    startLoading: function(callback)
+    {
+        var loadingHasJustStarted = !this._onLoadCallbacks.length;
+        this._onLoadCallbacks.push(callback);
+        return loadingHasJustStarted;
+    },
+
+    /**
+     * @param {string} chunk
+     */
+    pushJSONChunk: function(chunk)
+    {
+        this.callMethod(null, "pushJSONChunk", chunk);
+    },
+
+    /**
+     * @param {function(WebInspector.HeapSnapshotProxy)} callback
+     */
     finishLoading: function(callback)
     {
         this._onLoadCallbacks.unshift(callback);
@@ -380,22 +402,6 @@
             this._onLoadCallbacks = null;
         }
         this.callFactoryMethod(updateStaticData.bind(this), "finishLoading", "WebInspector.HeapSnapshotProxy");
-    },
-
-    /**
-     * @param {function(WebInspector.HeapSnapshotProxy)} callback
-     * @return {boolean}
-     */
-    startLoading: function(callback)
-    {
-        var loadingHasJustStarted = !this._onLoadCallbacks.length;
-        this._onLoadCallbacks.push(callback);
-        return loadingHasJustStarted;
-    },
-
-    pushJSONChunk: function(chunk)
-    {
-        this.callMethod(null, "pushJSONChunk", chunk);
     }
 };
 

Modified: trunk/Source/WebCore/inspector/front-end/HeapSnapshotView.js (118741 => 118742)


--- trunk/Source/WebCore/inspector/front-end/HeapSnapshotView.js	2012-05-29 09:12:11 UTC (rev 118741)
+++ trunk/Source/WebCore/inspector/front-end/HeapSnapshotView.js	2012-05-29 09:17:36 UTC (rev 118742)
@@ -785,7 +785,43 @@
 
 WebInspector.HeapSnapshotProfileType.prototype.__proto__ = WebInspector.ProfileType.prototype;
 
+
 /**
+ * @interface
+ */
+WebInspector.HeapSnapshotReceiver = function()
+{
+}
+
+WebInspector.HeapSnapshotReceiver.prototype = {
+    /**
+     * @param {function(WebInspector.HeapSnapshotProxy)} callback
+     * @return {boolean}
+     */
+    startLoading: function(callback)
+    {
+    },
+
+    /**
+     * @param {string} chunk
+     */
+    pushJSONChunk: function(chunk)
+    {
+    },
+
+    /**
+     * @param {function(WebInspector.HeapSnapshotProxy)} callback
+     */
+    finishLoading: function(callback)
+    {
+    },
+
+    dispose: function()
+    {
+    }
+};
+
+/**
  * @constructor
  * @extends {WebInspector.ProfileHeader}
  * @param {WebInspector.HeapSnapshotProfileType} type
@@ -798,9 +834,9 @@
     WebInspector.ProfileHeader.call(this, type, title, uid);
     this.maxJSObjectId = maxJSObjectId;
     /**
-     * @type {WebInspector.HeapSnapshotLoaderProxy}
+     * @type {WebInspector.HeapSnapshotReceiver}
      */
-    this._loaderProxy = null;
+    this._receiver = null;
     /**
      * @type {WebInspector.HeapSnapshotProxy}
      */
@@ -841,10 +877,11 @@
             return;
         }
 
-        if (!this._loaderProxy)
+        if (!this._receiver)
             this._setupWorker();
 
-        if (this._loaderProxy.startLoading(callback)) {
+        this._numberOfChunks = 0;
+        if (this._receiver.startLoading(callback)) {
             this.sidebarElement.subtitle = WebInspector.UIString("Loading\u2026");
             this.sidebarElement.wait = true;
             ProfilerAgent.getProfile(this.profileType().id, this.uid);
@@ -858,31 +895,28 @@
         }
         var worker = new WebInspector.HeapSnapshotWorker();
         worker.addEventListener("wait", setProfileWait, this);
-        this._loaderProxy = worker.createObject("WebInspector.HeapSnapshotLoader");
+        this._receiver = worker.createObject("WebInspector.HeapSnapshotLoader");
     },
 
     dispose: function()
     {
-        if (this._loaderProxy)
-            this._loaderProxy.dispose();
+        if (this._receiver)
+            this._receiver.dispose();
         else if (this._snapshotProxy)
             this._snapshotProxy.dispose();
     },
 
     /**
-     * @param {WebInspector.Event} event
+     * @param {number} savedChunksCount
      */
-    _saveStatusUpdate: function(event)
+    _saveStatusUpdate: function(savedChunksCount)
     {
-        if (event.data !== this._fileName)
-            return;
-        if (++this._savedChunksCount === this._totalNumberOfChunks) {
+        if (savedChunksCount === this._totalNumberOfChunks) {
             this.sidebarElement.subtitle = Number.bytesToString(this._snapshotProxy.totalSize);
             this.sidebarElement.wait = false;
             this._savedChunksCount = 0;
-            WebInspector.fileManager.removeEventListener(WebInspector.FileManager.EventTypes.AppendedToURL, this._saveStatusUpdate, this);
         } else
-            this.sidebarElement.subtitle = WebInspector.UIString("Saving\u2026 %d\%", (this._savedChunksCount * 100 / this._totalNumberOfChunks).toFixed(2));
+            this.sidebarElement.subtitle = WebInspector.UIString("Saving\u2026 %d\%", (savedChunksCount * 100 / this._totalNumberOfChunks).toFixed(2));
     },
 
     /**
@@ -890,28 +924,26 @@
      */
     pushJSONChunk: function(chunk)
     {
-        if (this._loaderProxy) {
-            ++this._totalNumberOfChunks;
-            this._loaderProxy.pushJSONChunk(chunk);
-        } else {
-            this.sidebarElement.wait = true;
-            WebInspector.fileManager.append(this._fileName, chunk);
-        }
+        ++this._numberOfChunks;
+        this._receiver.pushJSONChunk(chunk);
     },
 
+    _parsed: function(snapshotProxy)
+    {
+        this._receiver = null;
+        if (snapshotProxy)
+            this._snapshotProxy = snapshotProxy;
+        this.sidebarElement.subtitle = Number.bytesToString(this._snapshotProxy.totalSize);
+        this.sidebarElement.wait = false;
+        var worker = /** @type {WebInspector.HeapSnapshotWorker} */ this._snapshotProxy.worker;
+        this.isTemporary = false;
+        worker.startCheckingForLongRunningCalls();
+    },
+
     finishHeapSnapshot: function()
     {
-        function parsed(snapshotProxy)
-        {
-            this._loaderProxy = null;
-            this._snapshotProxy = snapshotProxy;
-            this.sidebarElement.subtitle = Number.bytesToString(snapshotProxy.totalSize);
-            this.sidebarElement.wait = false;
-            var worker = /** @type {WebInspector.HeapSnapshotWorker} */ snapshotProxy.worker;
-            this.isTemporary = false;
-            worker.startCheckingForLongRunningCalls();
-        }
-        if (this._loaderProxy.finishLoading(parsed.bind(this)))
+        this._totalNumberOfChunks = this._numberOfChunks;
+        if (this._receiver.finishLoading(this._parsed.bind(this)))
             this.sidebarElement.subtitle = WebInspector.UIString("Parsing\u2026");
     },
 
@@ -929,24 +961,9 @@
      */
     saveToFile: function()
     {
-        /**
-         * @param {WebInspector.Event} event
-         */
-        function startSavingSnapshot(event)
-        {
-            if (event.data !== this._fileName)
-                return;
-            this.sidebarElement.wait = true;
-            this.sidebarElement.subtitle = WebInspector.UIString("Saving\u2026 %d\%", 0);
-            this._savedChunksCount = 0;
-            WebInspector.fileManager.removeEventListener(WebInspector.FileManager.EventTypes.SavedURL, startSavingSnapshot, this);
-            WebInspector.fileManager.addEventListener(WebInspector.FileManager.EventTypes.AppendedToURL, this._saveStatusUpdate, this);
-            ProfilerAgent.getProfile(this.profileType().id, this.uid);
-        }
-
         this._fileName = this._fileName || "Heap-" + new Date().toISO8601Compact() + ".heapsnapshot";
-        WebInspector.fileManager.addEventListener(WebInspector.FileManager.EventTypes.SavedURL, startSavingSnapshot, this);
-        WebInspector.fileManager.save(this._fileName, "", true);
+        this._receiver = new WebInspector.HeapSnapshotSaveToFileReceiver(this._fileName, this);
+        this._receiver.startLoading(function(snapshot) { });
     },
 
     /**
@@ -983,16 +1000,9 @@
         this.sidebarElement.subtitle = WebInspector.UIString("Loading\u2026");
         this.sidebarElement.wait = true;
         this._setupWorker();
-        this._loaderProxy.startLoading(function(ignoredSnapshotProxy) { });
+        this._numberOfChunks = 0;
+        this._receiver.startLoading(function(ignoredSnapshotProxy) { });
 
-        function loadNextChunk(file, reader, loadedSize)
-        {
-            var chunkSize = 10000000;
-            var size = file.size < loadedSize + chunkSize ? file.size - loadedSize : chunkSize;
-            var nextPart = file.webkitSlice(loadedSize, loadedSize + size);
-            reader.readAsText(nextPart);
-        }
-
         /**
          * @param {Event} event
          */
@@ -1000,25 +1010,122 @@
         {
             if (event.target.readyState !== FileReader.DONE)
                 return;
+            this._nextChunkLoaded(event.target.result);
+        }
 
-            this._loadedSize += event.target.result.length;
-            this._loaderProxy.pushJSONChunk(event.target.result);
-            this.sidebarElement.subtitle = WebInspector.UIString("Loading\u2026 %d%", (this._loadedSize * 100 / file.size).toFixed(2));
+        this._file = file;
+        this._expectedSize = file.size;
+        this._loadedSize = 0;
+        this._reader = this._createFileReader();
+        this._reader._onload_ = onLoad.bind(this);
+        this._reader._onerror_ = onError;
+        this._loadNextChunk();
+    },
 
-            if (this._loadedSize === file.size) {
-                this.finishHeapSnapshot();
-                return;
-            }
+    _loadNextChunk: function()
+    {
+        var loadedSize = this._loadedSize;
+        var chunkSize = 10000000;
+        var size = this._expectedSize < loadedSize + chunkSize ? this._expectedSize - loadedSize : chunkSize;
+        var nextPart = this._file.webkitSlice(loadedSize, loadedSize + size);
+        this._reader.readAsText(nextPart);
+    },
 
-            loadNextChunk(file, reader, this._loadedSize);
+    _nextChunkLoaded: function(data)
+    {
+        this._loadedSize += data.length;
+        this._receiver.pushJSONChunk(data);
+        this.sidebarElement.subtitle = WebInspector.UIString("Loading\u2026 %d%", (this._loadedSize * 100 / this._expectedSize).toFixed(2));
+
+        if (this._loadedSize === this._expectedSize) {
+            this._file = null;
+            this._reader = null;
+            this.finishHeapSnapshot();
+            return;
         }
+        this._loadNextChunk();
+    },
 
-        var reader = new FileReader();
-        reader._onload_ = onLoad.bind(this);
-        reader._onerror_ = onError;
-        this._loadedSize = 0;
-        loadNextChunk(file, reader, this._loadedSize);
+    _createFileReader: function()
+    {
+        return new FileReader();
     }
 }
 
 WebInspector.HeapProfileHeader.prototype.__proto__ = WebInspector.ProfileHeader.prototype;
+
+
+/**
+ * @constructor
+ * @implements {WebInspector.HeapSnapshotReceiver}
+ */
+WebInspector.HeapSnapshotSaveToFileReceiver = function(fileName, snapshotHeader)
+{
+    this._fileName = fileName;
+    this._snapshotHeader = snapshotHeader;
+    this._savedChunks = 0;
+    this._finishLoadingCallbacks = [];
+}
+
+WebInspector.HeapSnapshotSaveToFileReceiver.prototype = {
+    /**
+     * @param {function(WebInspector.HeapSnapshotProxy)} callback
+     * @return {boolean}
+     */
+    startLoading: function(callback)
+    {
+        WebInspector.fileManager.addEventListener(WebInspector.FileManager.EventTypes.SavedURL, this._startSavingSnapshot, this);
+        WebInspector.fileManager.save(this._fileName, "", true);
+        if (callback)
+            this._finishLoadingCallbacks.push(callback);
+        return true;
+    },
+
+    /**
+     * @param {string} chunk
+     */
+    pushJSONChunk: function(chunk)
+    {
+        WebInspector.fileManager.append(this._fileName, chunk);
+    },
+
+    /**
+     * @param {function(WebInspector.HeapSnapshotProxy)} callback
+     */
+    finishLoading: function(callback)
+    {
+        this._finishLoadingCallbacks.push(callback);
+        for (var i = 0; i < this._finishLoadingCallbacks.length; ++i)
+            this._finishLoadingCallbacks[i](null);
+    },
+
+    dispose: function()
+    {
+    },
+
+    /**
+     * @param {WebInspector.Event} event
+     */
+    _startSavingSnapshot: function(event)
+    {
+        if (event.data !== this._fileName)
+            return;
+        this._snapshotHeader._saveStatusUpdate(0);
+        WebInspector.fileManager.removeEventListener(WebInspector.FileManager.EventTypes.SavedURL, this._startSavingSnapshot, this);
+        WebInspector.fileManager.addEventListener(WebInspector.FileManager.EventTypes.AppendedToURL, this._saveStatusUpdate, this);
+        ProfilerAgent.getProfile(this._snapshotHeader.profileType().id, this._snapshotHeader.uid);
+    },
+
+    /**
+     * @param {WebInspector.Event} event
+     */
+    _saveStatusUpdate: function(event)
+    {
+        if (event.data !== this._fileName)
+            return;
+        this._snapshotHeader._saveStatusUpdate(++this._savedChunks);
+        if (this._savedChunks === this._snapshotHeader._totalNumberOfChunks)
+            WebInspector.fileManager.removeEventListener(WebInspector.FileManager.EventTypes.AppendedToURL, this._saveStatusUpdate, this);
+    }
+};
+

Modified: trunk/Source/WebCore/inspector/front-end/ProfilesPanel.js (118741 => 118742)


--- trunk/Source/WebCore/inspector/front-end/ProfilesPanel.js	2012-05-29 09:12:11 UTC (rev 118741)
+++ trunk/Source/WebCore/inspector/front-end/ProfilesPanel.js	2012-05-29 09:17:36 UTC (rev 118742)
@@ -264,14 +264,16 @@
         fileSelectorElement.type = "file";
         fileSelectorElement.style.zIndex = -1;
         fileSelectorElement.style.position = "absolute";
-        fileSelectorElement._onchange_ = this._loadFromFile.bind(this);
+        function onChange(event) {
+            this._loadFromFile(this._fileSelectorElement.files[0]);
+        }
+        fileSelectorElement._onchange_ = onChange.bind(this);
         this.element.appendChild(fileSelectorElement);
         this._fileSelectorElement = fileSelectorElement;
     },
 
-    _loadFromFile: function(event)
+    _loadFromFile: function(file)
     {
-        var file = this._fileSelectorElement.files[0];
         if (!file.name.endsWith(".heapsnapshot")) {
             WebInspector.log(WebInspector.UIString("Only heap snapshots from files with extension '.heapsnapshot' can be loaded."));
             return;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to