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

Unified Diff: Source/devtools/front_end/profiler/HeapSnapshotProxy.js

Issue 685203003: DevTools: Get rid of synchronous XHRs in the frontend code (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: Source/devtools/front_end/profiler/HeapSnapshotProxy.js
diff --git a/Source/devtools/front_end/profiler/HeapSnapshotProxy.js b/Source/devtools/front_end/profiler/HeapSnapshotProxy.js
index 5f0324eb7e9091febe46a339f13a2dc9d72f2662..425491954acf03295923a4adddbbb67716fd5bd4 100644
--- a/Source/devtools/front_end/profiler/HeapSnapshotProxy.js
+++ b/Source/devtools/front_end/profiler/HeapSnapshotProxy.js
@@ -40,12 +40,34 @@ WebInspector.HeapSnapshotWorkerProxy = function(eventHandler)
this._nextCallId = 1;
this._callbacks = [];
this._previousCallbacks = [];
- this._worker = Runtime.startWorker("heap_snapshot_worker");
- this._worker.onmessage = this._messageReceived.bind(this);
+ this._pendingMessages = [];
+ Runtime.startWorker("heap_snapshot_worker").then(this._init.bind(this)).done();
}
WebInspector.HeapSnapshotWorkerProxy.prototype = {
/**
+ * @param {!Worker} worker
+ */
+ _init: function(worker)
+ {
+ this._worker = worker;
+ if (this._disposed) {
+ this.dispose();
+ return;
+ }
+ this._worker.onmessage = this._messageReceived.bind(this);
+ this._handlePendingMessages();
+ },
+
+ _handlePendingMessages: function()
+ {
+ for (var i = 0; i < this._pendingMessages.length; ++i)
+ this._worker.postMessage(this._pendingMessages[i]);
+
+ delete this._pendingMessages;
+ },
+
+ /**
* @param {number} profileUid
* @param {function(!WebInspector.HeapSnapshotProxy)} snapshotReceivedCallback
* @return {!WebInspector.HeapSnapshotLoaderProxy}
@@ -60,7 +82,10 @@ WebInspector.HeapSnapshotWorkerProxy.prototype = {
dispose: function()
{
- this._worker.terminate();
+ if (this._worker)
+ this._worker.terminate();
+ else
+ this._disposed = true;
if (this._interval)
clearInterval(this._interval);
},
@@ -171,9 +196,15 @@ WebInspector.HeapSnapshotWorkerProxy.prototype = {
callback(data.result);
},
+ /**
+ * @param {!Object} message
+ */
_postMessage: function(message)
{
- this._worker.postMessage(message);
+ if (this._worker)
+ this._worker.postMessage(message);
+ else
+ this._pendingMessages.push(message);
pfeldman 2014/11/07 14:51:17 You should chain it to the _pendingWorkerPromise i
apavlov 2014/11/10 07:44:11 Done.
},
__proto__: WebInspector.Object.prototype
@@ -445,7 +476,7 @@ WebInspector.HeapSnapshotProxy.prototype = {
},
/**
- * @param {!function(!WebInspector.HeapSnapshotCommon.Statistics):void} callback
+ * @param {function(!WebInspector.HeapSnapshotCommon.Statistics):void} callback
*/
getStatistics: function(callback)
{

Powered by Google App Engine
This is Rietveld 408576698