OLD | NEW |
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 Loading... |
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._pendingWorkerPromise = WorkerRuntime.startWorker("heap_snapshot_worker
").then(this._init.bind(this)); |
44 this._worker.onmessage = this._messageReceived.bind(this); | |
45 } | 44 } |
46 | 45 |
47 WebInspector.HeapSnapshotWorkerProxy.prototype = { | 46 WebInspector.HeapSnapshotWorkerProxy.prototype = { |
48 /** | 47 /** |
| 48 * @param {!Worker} worker |
| 49 */ |
| 50 _init: function(worker) |
| 51 { |
| 52 this._worker = worker; |
| 53 if (this._disposed) { |
| 54 this.dispose(); |
| 55 return; |
| 56 } |
| 57 this._worker.onmessage = this._messageReceived.bind(this); |
| 58 }, |
| 59 |
| 60 /** |
49 * @param {number} profileUid | 61 * @param {number} profileUid |
50 * @param {function(!WebInspector.HeapSnapshotProxy)} snapshotReceivedCallba
ck | 62 * @param {function(!WebInspector.HeapSnapshotProxy)} snapshotReceivedCallba
ck |
51 * @return {!WebInspector.HeapSnapshotLoaderProxy} | 63 * @return {!WebInspector.HeapSnapshotLoaderProxy} |
52 */ | 64 */ |
53 createLoader: function(profileUid, snapshotReceivedCallback) | 65 createLoader: function(profileUid, snapshotReceivedCallback) |
54 { | 66 { |
55 var objectId = this._nextObjectId++; | 67 var objectId = this._nextObjectId++; |
56 var proxy = new WebInspector.HeapSnapshotLoaderProxy(this, objectId, pro
fileUid, snapshotReceivedCallback); | 68 var proxy = new WebInspector.HeapSnapshotLoaderProxy(this, objectId, pro
fileUid, snapshotReceivedCallback); |
57 this._postMessage({callId: this._nextCallId++, disposition: "create", ob
jectId: objectId, methodName: "WebInspector.HeapSnapshotLoader"}); | 69 this._postMessage({callId: this._nextCallId++, disposition: "create", ob
jectId: objectId, methodName: "WebInspector.HeapSnapshotLoader"}); |
58 return proxy; | 70 return proxy; |
59 }, | 71 }, |
60 | 72 |
61 dispose: function() | 73 dispose: function() |
62 { | 74 { |
63 this._worker.terminate(); | 75 this._disposed = true; |
| 76 if (this._worker) |
| 77 this._worker.terminate(); |
64 if (this._interval) | 78 if (this._interval) |
65 clearInterval(this._interval); | 79 clearInterval(this._interval); |
66 }, | 80 }, |
67 | 81 |
68 disposeObject: function(objectId) | 82 disposeObject: function(objectId) |
69 { | 83 { |
70 this._postMessage({callId: this._nextCallId++, disposition: "dispose", o
bjectId: objectId}); | 84 this._postMessage({callId: this._nextCallId++, disposition: "dispose", o
bjectId: objectId}); |
71 }, | 85 }, |
72 | 86 |
73 evaluateForTest: function(script, callback) | 87 evaluateForTest: function(script, callback) |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 delete this._callbacks[data.callId]; | 178 delete this._callbacks[data.callId]; |
165 return; | 179 return; |
166 } | 180 } |
167 if (!this._callbacks[data.callId]) | 181 if (!this._callbacks[data.callId]) |
168 return; | 182 return; |
169 var callback = this._callbacks[data.callId]; | 183 var callback = this._callbacks[data.callId]; |
170 delete this._callbacks[data.callId]; | 184 delete this._callbacks[data.callId]; |
171 callback(data.result); | 185 callback(data.result); |
172 }, | 186 }, |
173 | 187 |
| 188 /** |
| 189 * @param {!Object} message |
| 190 */ |
174 _postMessage: function(message) | 191 _postMessage: function(message) |
175 { | 192 { |
176 this._worker.postMessage(message); | 193 this._pendingWorkerPromise.then(postMessage.bind(this)); |
| 194 |
| 195 /** |
| 196 * @this {WebInspector.HeapSnapshotWorkerProxy} |
| 197 */ |
| 198 function postMessage() |
| 199 { |
| 200 if (this._disposed) |
| 201 return; |
| 202 this._worker.postMessage(message); |
| 203 } |
177 }, | 204 }, |
178 | 205 |
179 __proto__: WebInspector.Object.prototype | 206 __proto__: WebInspector.Object.prototype |
180 } | 207 } |
181 | 208 |
182 | 209 |
183 /** | 210 /** |
184 * @constructor | 211 * @constructor |
185 * @param {!WebInspector.HeapSnapshotWorkerProxy} worker | 212 * @param {!WebInspector.HeapSnapshotWorkerProxy} worker |
186 * @param {number} objectId | 213 * @param {number} objectId |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 */ | 465 */ |
439 function dataReceived(staticData) | 466 function dataReceived(staticData) |
440 { | 467 { |
441 this._staticData = staticData; | 468 this._staticData = staticData; |
442 callback(this); | 469 callback(this); |
443 } | 470 } |
444 this.callMethod(dataReceived.bind(this), "updateStaticData"); | 471 this.callMethod(dataReceived.bind(this), "updateStaticData"); |
445 }, | 472 }, |
446 | 473 |
447 /** | 474 /** |
448 * @param {!function(!WebInspector.HeapSnapshotCommon.Statistics):void} call
back | 475 * @param {function(!WebInspector.HeapSnapshotCommon.Statistics):void} callb
ack |
449 */ | 476 */ |
450 getStatistics: function(callback) | 477 getStatistics: function(callback) |
451 { | 478 { |
452 this.callMethod(callback, "getStatistics"); | 479 this.callMethod(callback, "getStatistics"); |
453 }, | 480 }, |
454 | 481 |
455 get totalSize() | 482 get totalSize() |
456 { | 483 { |
457 return this._staticData.totalSize; | 484 return this._staticData.totalSize; |
458 }, | 485 }, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 * @param {!WebInspector.HeapSnapshotCommon.ComparatorConfig} comparator | 554 * @param {!WebInspector.HeapSnapshotCommon.ComparatorConfig} comparator |
528 * @param {function()} callback | 555 * @param {function()} callback |
529 */ | 556 */ |
530 sortAndRewind: function(comparator, callback) | 557 sortAndRewind: function(comparator, callback) |
531 { | 558 { |
532 this.callMethod(callback, "sortAndRewind", comparator); | 559 this.callMethod(callback, "sortAndRewind", comparator); |
533 }, | 560 }, |
534 | 561 |
535 __proto__: WebInspector.HeapSnapshotProxyObject.prototype | 562 __proto__: WebInspector.HeapSnapshotProxyObject.prototype |
536 } | 563 } |
OLD | NEW |