OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 * @extends {WebInspector.Object} | 7 * @extends {WebInspector.Object} |
8 * @param {!WebInspector.Workspace} workspace | 8 * @param {!WebInspector.Workspace} workspace |
9 * @param {!WebInspector.BreakpointManager} breakpointManager | 9 * @param {!WebInspector.BreakpointManager} breakpointManager |
10 * @param {!WebInspector.FileSystemMapping} fileSystemMapping | 10 * @param {!WebInspector.FileSystemMapping} fileSystemMapping |
11 */ | 11 */ |
12 WebInspector.Persistence = function(workspace, breakpointManager, fileSystemMapp
ing) | 12 WebInspector.Persistence = function(workspace, breakpointManager, fileSystemMapp
ing) |
13 { | 13 { |
14 WebInspector.Object.call(this); | 14 WebInspector.Object.call(this); |
15 this._workspace = workspace; | 15 this._workspace = workspace; |
16 this._breakpointManager = breakpointManager; | 16 this._breakpointManager = breakpointManager; |
17 this._fileSystemMapping = fileSystemMapping; | 17 this._fileSystemMapping = fileSystemMapping; |
18 /** @type {!Set<!WebInspector.PersistenceBinding>} */ | 18 /** @type {!Set<!WebInspector.PersistenceBinding>} */ |
19 this._bindings = new Set(); | 19 this._bindings = new Set(); |
| 20 |
| 21 /** @type {!Map<string, number>} */ |
| 22 this._filePathPrefixesToBindingCount = new Map(); |
| 23 |
20 this._eventListeners = [ | 24 this._eventListeners = [ |
21 workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeAdd
ed, this._onUISourceCodeAdded, this), | 25 workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeAdd
ed, this._onUISourceCodeAdded, this), |
22 workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeRem
oved, this._onUISourceCodeRemoved, this), | 26 workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeRem
oved, this._onUISourceCodeRemoved, this), |
23 workspace.addEventListener(WebInspector.Workspace.Events.ProjectRemoved,
this._onProjectRemoved, this), | 27 workspace.addEventListener(WebInspector.Workspace.Events.ProjectRemoved,
this._onProjectRemoved, this), |
24 this._fileSystemMapping.addEventListener(WebInspector.FileSystemMapping.
Events.FileMappingAdded, this._remap, this), | 28 this._fileSystemMapping.addEventListener(WebInspector.FileSystemMapping.
Events.FileMappingAdded, this._remap, this), |
25 this._fileSystemMapping.addEventListener(WebInspector.FileSystemMapping.
Events.FileMappingRemoved, this._remap, this) | 29 this._fileSystemMapping.addEventListener(WebInspector.FileSystemMapping.
Events.FileMappingRemoved, this._remap, this) |
26 ]; | 30 ]; |
27 this._remap(); | 31 this._remap(); |
28 } | 32 } |
29 | 33 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 this._bindings.add(binding); | 120 this._bindings.add(binding); |
117 binding.network[WebInspector.Persistence._binding] = binding; | 121 binding.network[WebInspector.Persistence._binding] = binding; |
118 binding.fileSystem[WebInspector.Persistence._binding] = binding; | 122 binding.fileSystem[WebInspector.Persistence._binding] = binding; |
119 | 123 |
120 binding.fileSystem.forceLoadOnCheckContent(); | 124 binding.fileSystem.forceLoadOnCheckContent(); |
121 | 125 |
122 binding.network.addEventListener(WebInspector.UISourceCode.Events.Workin
gCopyCommitted, this._onWorkingCopyCommitted, this); | 126 binding.network.addEventListener(WebInspector.UISourceCode.Events.Workin
gCopyCommitted, this._onWorkingCopyCommitted, this); |
123 binding.fileSystem.addEventListener(WebInspector.UISourceCode.Events.Wor
kingCopyCommitted, this._onWorkingCopyCommitted, this); | 127 binding.fileSystem.addEventListener(WebInspector.UISourceCode.Events.Wor
kingCopyCommitted, this._onWorkingCopyCommitted, this); |
124 binding.fileSystem.addEventListener(WebInspector.UISourceCode.Events.Tit
leChanged, this._onFileSystemUISourceCodeRenamed, this); | 128 binding.fileSystem.addEventListener(WebInspector.UISourceCode.Events.Tit
leChanged, this._onFileSystemUISourceCodeRenamed, this); |
125 | 129 |
| 130 this._addFilePathBindingPrefixes(binding.fileSystem.url()); |
| 131 |
126 this._moveBreakpoints(binding.fileSystem, binding.network); | 132 this._moveBreakpoints(binding.fileSystem, binding.network); |
127 this.dispatchEventToListeners(WebInspector.Persistence.Events.BindingCre
ated, binding); | 133 this.dispatchEventToListeners(WebInspector.Persistence.Events.BindingCre
ated, binding); |
128 }, | 134 }, |
129 | 135 |
130 /** | 136 /** |
131 * @param {!WebInspector.UISourceCode} uiSourceCode | 137 * @param {!WebInspector.UISourceCode} uiSourceCode |
132 */ | 138 */ |
133 _unbind: function(uiSourceCode) | 139 _unbind: function(uiSourceCode) |
134 { | 140 { |
135 var binding = uiSourceCode[WebInspector.Persistence._binding]; | 141 var binding = uiSourceCode[WebInspector.Persistence._binding]; |
136 if (!binding) | 142 if (!binding) |
137 return; | 143 return; |
138 this._bindings.delete(binding); | 144 this._bindings.delete(binding); |
139 binding.network[WebInspector.Persistence._binding] = null; | 145 binding.network[WebInspector.Persistence._binding] = null; |
140 binding.fileSystem[WebInspector.Persistence._binding] = null; | 146 binding.fileSystem[WebInspector.Persistence._binding] = null; |
141 | 147 |
142 binding.network.removeEventListener(WebInspector.UISourceCode.Events.Wor
kingCopyCommitted, this._onWorkingCopyCommitted, this); | 148 binding.network.removeEventListener(WebInspector.UISourceCode.Events.Wor
kingCopyCommitted, this._onWorkingCopyCommitted, this); |
143 binding.fileSystem.removeEventListener(WebInspector.UISourceCode.Events.
WorkingCopyCommitted, this._onWorkingCopyCommitted, this); | 149 binding.fileSystem.removeEventListener(WebInspector.UISourceCode.Events.
WorkingCopyCommitted, this._onWorkingCopyCommitted, this); |
144 binding.fileSystem.removeEventListener(WebInspector.UISourceCode.Events.
TitleChanged, this._onFileSystemUISourceCodeRenamed, this); | 150 binding.fileSystem.removeEventListener(WebInspector.UISourceCode.Events.
TitleChanged, this._onFileSystemUISourceCodeRenamed, this); |
145 | 151 |
| 152 this._removeFilePathBindingPrefixes(binding.fileSystem.url()); |
| 153 |
146 this._copyBreakpoints(binding.network, binding.fileSystem); | 154 this._copyBreakpoints(binding.network, binding.fileSystem); |
147 this.dispatchEventToListeners(WebInspector.Persistence.Events.BindingRem
oved, binding); | 155 this.dispatchEventToListeners(WebInspector.Persistence.Events.BindingRem
oved, binding); |
148 }, | 156 }, |
149 | 157 |
150 /** | 158 /** |
151 * @param {!WebInspector.Event} event | 159 * @param {!WebInspector.Event} event |
152 */ | 160 */ |
153 _onFileSystemUISourceCodeRenamed: function(event) | 161 _onFileSystemUISourceCodeRenamed: function(event) |
154 { | 162 { |
155 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */(event.targe
t); | 163 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */(event.targe
t); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 | 257 |
250 /** | 258 /** |
251 * @param {!WebInspector.UISourceCode} uiSourceCode | 259 * @param {!WebInspector.UISourceCode} uiSourceCode |
252 * @return {?WebInspector.PersistenceBinding} | 260 * @return {?WebInspector.PersistenceBinding} |
253 */ | 261 */ |
254 binding: function(uiSourceCode) | 262 binding: function(uiSourceCode) |
255 { | 263 { |
256 return uiSourceCode[WebInspector.Persistence._binding] || null; | 264 return uiSourceCode[WebInspector.Persistence._binding] || null; |
257 }, | 265 }, |
258 | 266 |
| 267 /** |
| 268 * @param {string} filePath |
| 269 */ |
| 270 _addFilePathBindingPrefixes: function(filePath) |
| 271 { |
| 272 var relative = ""; |
| 273 for (var token of filePath.split("/")) { |
| 274 relative += token + "/"; |
| 275 var count = this._filePathPrefixesToBindingCount.get(relative) || 0; |
| 276 this._filePathPrefixesToBindingCount.set(relative, count + 1); |
| 277 } |
| 278 }, |
| 279 |
| 280 /** |
| 281 * @param {string} filePath |
| 282 */ |
| 283 _removeFilePathBindingPrefixes: function(filePath) |
| 284 { |
| 285 var relative = ""; |
| 286 for (var token of filePath.split("/")) { |
| 287 relative += token + "/"; |
| 288 var count = this._filePathPrefixesToBindingCount.get(relative); |
| 289 if (count === 1) |
| 290 this._filePathPrefixesToBindingCount.delete(relative); |
| 291 else |
| 292 this._filePathPrefixesToBindingCount.set(relative, count - 1); |
| 293 } |
| 294 }, |
| 295 |
| 296 /** |
| 297 * @param {string} filePath |
| 298 * @return {boolean} |
| 299 */ |
| 300 filePathHasBindings: function(filePath) |
| 301 { |
| 302 if (!filePath.endsWith("/")) |
| 303 filePath += "/"; |
| 304 return this._filePathPrefixesToBindingCount.has(filePath); |
| 305 }, |
| 306 |
259 dispose: function() | 307 dispose: function() |
260 { | 308 { |
261 WebInspector.EventTarget.removeEventListeners(this._eventListeners); | 309 WebInspector.EventTarget.removeEventListeners(this._eventListeners); |
262 }, | 310 }, |
263 | 311 |
264 __proto__: WebInspector.Object.prototype | 312 __proto__: WebInspector.Object.prototype |
265 } | 313 } |
266 | 314 |
267 /** | 315 /** |
268 * @constructor | 316 * @constructor |
269 * @param {!WebInspector.UISourceCode} network | 317 * @param {!WebInspector.UISourceCode} network |
270 * @param {!WebInspector.UISourceCode} fileSystem | 318 * @param {!WebInspector.UISourceCode} fileSystem |
271 */ | 319 */ |
272 WebInspector.PersistenceBinding = function(network, fileSystem) | 320 WebInspector.PersistenceBinding = function(network, fileSystem) |
273 { | 321 { |
274 this.network = network; | 322 this.network = network; |
275 this.fileSystem = fileSystem; | 323 this.fileSystem = fileSystem; |
276 } | 324 } |
277 | 325 |
278 /** @type {!WebInspector.Persistence} */ | 326 /** @type {!WebInspector.Persistence} */ |
279 WebInspector.persistence; | 327 WebInspector.persistence; |
OLD | NEW |