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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyrightdd 8 * * Redistributions of source code must retain the above copyrightdd
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 22 matching lines...) Expand all
33 * @param {function(string, *)} eventHandler 33 * @param {function(string, *)} eventHandler
34 * @extends {WebInspector.Object} 34 * @extends {WebInspector.Object}
35 */ 35 */
36 WebInspector.HeapSnapshotWorkerProxy = function(eventHandler) 36 WebInspector.HeapSnapshotWorkerProxy = function(eventHandler)
37 { 37 {
38 this._eventHandler = eventHandler; 38 this._eventHandler = eventHandler;
39 this._nextObjectId = 1; 39 this._nextObjectId = 1;
40 this._nextCallId = 1; 40 this._nextCallId = 1;
41 this._callbacks = []; 41 this._callbacks = [];
42 this._previousCallbacks = []; 42 this._previousCallbacks = [];
43 this._worker = Runtime.startWorker("heap_snapshot_worker"); 43 this._pendingMessages = [];
44 this._worker.onmessage = this._messageReceived.bind(this); 44 Runtime.startWorker("heap_snapshot_worker").then(this._init.bind(this)).done ();
45 } 45 }
46 46
47 WebInspector.HeapSnapshotWorkerProxy.prototype = { 47 WebInspector.HeapSnapshotWorkerProxy.prototype = {
48 /** 48 /**
49 * @param {!Worker} worker
50 */
51 _init: function(worker)
52 {
53 this._worker = worker;
54 if (this._disposed) {
55 this.dispose();
56 return;
57 }
58 this._worker.onmessage = this._messageReceived.bind(this);
59 this._handlePendingMessages();
60 },
61
62 _handlePendingMessages: function()
63 {
64 for (var i = 0; i < this._pendingMessages.length; ++i)
65 this._worker.postMessage(this._pendingMessages[i]);
66
67 delete this._pendingMessages;
68 },
69
70 /**
49 * @param {number} profileUid 71 * @param {number} profileUid
50 * @param {function(!WebInspector.HeapSnapshotProxy)} snapshotReceivedCallba ck 72 * @param {function(!WebInspector.HeapSnapshotProxy)} snapshotReceivedCallba ck
51 * @return {!WebInspector.HeapSnapshotLoaderProxy} 73 * @return {!WebInspector.HeapSnapshotLoaderProxy}
52 */ 74 */
53 createLoader: function(profileUid, snapshotReceivedCallback) 75 createLoader: function(profileUid, snapshotReceivedCallback)
54 { 76 {
55 var objectId = this._nextObjectId++; 77 var objectId = this._nextObjectId++;
56 var proxy = new WebInspector.HeapSnapshotLoaderProxy(this, objectId, pro fileUid, snapshotReceivedCallback); 78 var proxy = new WebInspector.HeapSnapshotLoaderProxy(this, objectId, pro fileUid, snapshotReceivedCallback);
57 this._postMessage({callId: this._nextCallId++, disposition: "create", ob jectId: objectId, methodName: "WebInspector.HeapSnapshotLoader"}); 79 this._postMessage({callId: this._nextCallId++, disposition: "create", ob jectId: objectId, methodName: "WebInspector.HeapSnapshotLoader"});
58 return proxy; 80 return proxy;
59 }, 81 },
60 82
61 dispose: function() 83 dispose: function()
62 { 84 {
63 this._worker.terminate(); 85 if (this._worker)
86 this._worker.terminate();
87 else
88 this._disposed = true;
64 if (this._interval) 89 if (this._interval)
65 clearInterval(this._interval); 90 clearInterval(this._interval);
66 }, 91 },
67 92
68 disposeObject: function(objectId) 93 disposeObject: function(objectId)
69 { 94 {
70 this._postMessage({callId: this._nextCallId++, disposition: "dispose", o bjectId: objectId}); 95 this._postMessage({callId: this._nextCallId++, disposition: "dispose", o bjectId: objectId});
71 }, 96 },
72 97
73 evaluateForTest: function(script, callback) 98 evaluateForTest: function(script, callback)
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 delete this._callbacks[data.callId]; 189 delete this._callbacks[data.callId];
165 return; 190 return;
166 } 191 }
167 if (!this._callbacks[data.callId]) 192 if (!this._callbacks[data.callId])
168 return; 193 return;
169 var callback = this._callbacks[data.callId]; 194 var callback = this._callbacks[data.callId];
170 delete this._callbacks[data.callId]; 195 delete this._callbacks[data.callId];
171 callback(data.result); 196 callback(data.result);
172 }, 197 },
173 198
199 /**
200 * @param {!Object} message
201 */
174 _postMessage: function(message) 202 _postMessage: function(message)
175 { 203 {
176 this._worker.postMessage(message); 204 if (this._worker)
205 this._worker.postMessage(message);
206 else
207 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.
177 }, 208 },
178 209
179 __proto__: WebInspector.Object.prototype 210 __proto__: WebInspector.Object.prototype
180 } 211 }
181 212
182 213
183 /** 214 /**
184 * @constructor 215 * @constructor
185 * @param {!WebInspector.HeapSnapshotWorkerProxy} worker 216 * @param {!WebInspector.HeapSnapshotWorkerProxy} worker
186 * @param {number} objectId 217 * @param {number} objectId
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 */ 469 */
439 function dataReceived(staticData) 470 function dataReceived(staticData)
440 { 471 {
441 this._staticData = staticData; 472 this._staticData = staticData;
442 callback(this); 473 callback(this);
443 } 474 }
444 this.callMethod(dataReceived.bind(this), "updateStaticData"); 475 this.callMethod(dataReceived.bind(this), "updateStaticData");
445 }, 476 },
446 477
447 /** 478 /**
448 * @param {!function(!WebInspector.HeapSnapshotCommon.Statistics):void} call back 479 * @param {function(!WebInspector.HeapSnapshotCommon.Statistics):void} callb ack
449 */ 480 */
450 getStatistics: function(callback) 481 getStatistics: function(callback)
451 { 482 {
452 this.callMethod(callback, "getStatistics"); 483 this.callMethod(callback, "getStatistics");
453 }, 484 },
454 485
455 get totalSize() 486 get totalSize()
456 { 487 {
457 return this._staticData.totalSize; 488 return this._staticData.totalSize;
458 }, 489 },
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 * @param {!WebInspector.HeapSnapshotCommon.ComparatorConfig} comparator 558 * @param {!WebInspector.HeapSnapshotCommon.ComparatorConfig} comparator
528 * @param {function()} callback 559 * @param {function()} callback
529 */ 560 */
530 sortAndRewind: function(comparator, callback) 561 sortAndRewind: function(comparator, callback)
531 { 562 {
532 this.callMethod(callback, "sortAndRewind", comparator); 563 this.callMethod(callback, "sortAndRewind", comparator);
533 }, 564 },
534 565
535 __proto__: WebInspector.HeapSnapshotProxyObject.prototype 566 __proto__: WebInspector.HeapSnapshotProxyObject.prototype
536 } 567 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698