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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/bindings/NetworkMapping.js

Issue 2290323003: DevTools: use eventListener arrays to avoid memory leaks in dispose methods (Closed)
Patch Set: Created 4 years, 3 months 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @constructor 6 * @constructor
7 * @param {!WebInspector.TargetManager} targetManager 7 * @param {!WebInspector.TargetManager} targetManager
8 * @param {!WebInspector.Workspace} workspace 8 * @param {!WebInspector.Workspace} workspace
9 * @param {!WebInspector.FileSystemWorkspaceBinding} fileSystemWorkspaceBinding 9 * @param {!WebInspector.FileSystemWorkspaceBinding} fileSystemWorkspaceBinding
10 * @param {!WebInspector.FileSystemMapping} fileSystemMapping 10 * @param {!WebInspector.FileSystemMapping} fileSystemMapping
11 */ 11 */
12 WebInspector.NetworkMapping = function(targetManager, workspace, fileSystemWorks paceBinding, fileSystemMapping) 12 WebInspector.NetworkMapping = function(targetManager, workspace, fileSystemWorks paceBinding, fileSystemMapping)
13 { 13 {
14 this._targetManager = targetManager; 14 this._targetManager = targetManager;
15 this._workspace = workspace; 15 this._workspace = workspace;
16 this._fileSystemWorkspaceBinding = fileSystemWorkspaceBinding; 16 this._fileSystemWorkspaceBinding = fileSystemWorkspaceBinding;
17 this._fileSystemMapping = fileSystemMapping; 17 this._fileSystemMapping = fileSystemMapping;
18 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event s.RevealSourceLine, this._revealSourceLine, this); 18 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event s.RevealSourceLine, this._revealSourceLine, this);
19 19
20 // For now, following block is here primarily for testing since in the real life, network manager is created early enough to capture those events. 20 // For now, following block is here primarily for testing since in the real life, network manager is created early enough to capture those events.
21 var fileSystemManager = fileSystemWorkspaceBinding.fileSystemManager(); 21 var fileSystemManager = fileSystemWorkspaceBinding.fileSystemManager();
22 for (var path of fileSystemManager.fileSystemPaths()) { 22 for (var path of fileSystemManager.fileSystemPaths()) {
23 var fileSystem = fileSystemManager.fileSystem(path); 23 var fileSystem = fileSystemManager.fileSystem(path);
24 this._fileSystemAdded(new WebInspector.Event(fileSystemManager, WebInspe ctor.IsolatedFileSystemManager.Events.FileSystemAdded, fileSystem)); 24 this._fileSystemAdded(new WebInspector.Event(fileSystemManager, WebInspe ctor.IsolatedFileSystemManager.Events.FileSystemAdded, fileSystem));
25 } 25 }
26 if (fileSystemManager.fileSystemsLoaded()) 26 if (fileSystemManager.fileSystemsLoaded())
27 this._fileSystemsLoaded(); 27 this._fileSystemsLoaded();
28 28
29 fileSystemManager.addEventListener(WebInspector.IsolatedFileSystemManager.Ev ents.FileSystemAdded, this._fileSystemAdded, this); 29 this._eventListeners = [
30 fileSystemManager.addEventListener(WebInspector.IsolatedFileSystemManager.Ev ents.FileSystemRemoved, this._fileSystemRemoved, this); 30 fileSystemManager.addEventListener(WebInspector.IsolatedFileSystemManage r.Events.FileSystemAdded, this._fileSystemAdded, this),
31 fileSystemManager.addEventListener(WebInspector.IsolatedFileSystemManager.Ev ents.FileSystemsLoaded, this._fileSystemsLoaded, this); 31 fileSystemManager.addEventListener(WebInspector.IsolatedFileSystemManage r.Events.FileSystemRemoved, this._fileSystemRemoved, this),
32 32 fileSystemManager.addEventListener(WebInspector.IsolatedFileSystemManage r.Events.FileSystemsLoaded, this._fileSystemsLoaded, this),
33 this._fileSystemMapping.addEventListener(WebInspector.FileSystemMapping.Even ts.FileMappingAdded, this._fileSystemMappingChanged, this); 33 this._fileSystemMapping.addEventListener(WebInspector.FileSystemMapping. Events.FileMappingAdded, this._fileSystemMappingChanged, this),
34 this._fileSystemMapping.addEventListener(WebInspector.FileSystemMapping.Even ts.FileMappingRemoved, this._fileSystemMappingChanged, this); 34 this._fileSystemMapping.addEventListener(WebInspector.FileSystemMapping. Events.FileMappingRemoved, this._fileSystemMappingChanged, this)
35 ];
35 } 36 }
36 37
37 WebInspector.NetworkMapping.prototype = { 38 WebInspector.NetworkMapping.prototype = {
38 /** 39 /**
39 * @param {!WebInspector.Event} event 40 * @param {!WebInspector.Event} event
40 */ 41 */
41 _fileSystemAdded: function(event) 42 _fileSystemAdded: function(event)
42 { 43 {
43 this._addingFileSystem = true; 44 this._addingFileSystem = true;
44 var fileSystem = /** @type {!WebInspector.IsolatedFileSystem} */ (event. data); 45 var fileSystem = /** @type {!WebInspector.IsolatedFileSystem} */ (event. data);
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 239
239 _fileSystemMappingChanged: function() 240 _fileSystemMappingChanged: function()
240 { 241 {
241 if (!this._fileSystemsReady || this._addingFileSystem) 242 if (!this._fileSystemsReady || this._addingFileSystem)
242 return; 243 return;
243 this._targetManager.suspendAndResumeAllTargets(); 244 this._targetManager.suspendAndResumeAllTargets();
244 }, 245 },
245 246
246 dispose: function() 247 dispose: function()
247 { 248 {
248 this._fileSystemWorkspaceBinding.fileSystemManager().removeEventListener (WebInspector.IsolatedFileSystemManager.Events.FileSystemAdded, this._fileSystem Added, this); 249 WebInspector.EventTarget.removeEventListeners(this._eventListeners);
249 this._fileSystemWorkspaceBinding.fileSystemManager().removeEventListener (WebInspector.IsolatedFileSystemManager.Events.FileSystemRemoved, this._fileSyst emRemoved, this);
250 this._fileSystemMapping.removeEventListener(WebInspector.FileSystemMappi ng.Events.FileMappingAdded, this._fileSystemMappingChanged, this);
251 this._fileSystemMapping.removeEventListener(WebInspector.FileSystemMappi ng.Events.FileMappingRemoved, this._fileSystemMappingChanged, this);
252 } 250 }
253 } 251 }
254 252
255 /** 253 /**
256 * @type {!WebInspector.NetworkMapping} 254 * @type {!WebInspector.NetworkMapping}
257 */ 255 */
258 WebInspector.networkMapping; 256 WebInspector.networkMapping;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698