| 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 * @unrestricted | 5 * @unrestricted |
| 6 */ | 6 */ |
| 7 WebInspector.Automapping = class { | 7 Persistence.Automapping = class { |
| 8 /** | 8 /** |
| 9 * @param {!WebInspector.Workspace} workspace | 9 * @param {!Workspace.Workspace} workspace |
| 10 * @param {function(!WebInspector.PersistenceBinding)} onBindingCreated | 10 * @param {function(!Persistence.PersistenceBinding)} onBindingCreated |
| 11 * @param {function(!WebInspector.PersistenceBinding)} onBindingRemoved | 11 * @param {function(!Persistence.PersistenceBinding)} onBindingRemoved |
| 12 */ | 12 */ |
| 13 constructor(workspace, onBindingCreated, onBindingRemoved) { | 13 constructor(workspace, onBindingCreated, onBindingRemoved) { |
| 14 this._workspace = workspace; | 14 this._workspace = workspace; |
| 15 | 15 |
| 16 this._onBindingCreated = onBindingCreated; | 16 this._onBindingCreated = onBindingCreated; |
| 17 this._onBindingRemoved = onBindingRemoved; | 17 this._onBindingRemoved = onBindingRemoved; |
| 18 /** @type {!Set<!WebInspector.PersistenceBinding>} */ | 18 /** @type {!Set<!Persistence.PersistenceBinding>} */ |
| 19 this._bindings = new Set(); | 19 this._bindings = new Set(); |
| 20 | 20 |
| 21 /** @type {!Map<string, !WebInspector.UISourceCode>} */ | 21 /** @type {!Map<string, !Workspace.UISourceCode>} */ |
| 22 this._fileSystemUISourceCodes = new Map(); | 22 this._fileSystemUISourceCodes = new Map(); |
| 23 this._sweepThrottler = new WebInspector.Throttler(100); | 23 this._sweepThrottler = new Common.Throttler(100); |
| 24 | 24 |
| 25 var pathEncoder = new WebInspector.Automapping.PathEncoder(); | 25 var pathEncoder = new Persistence.Automapping.PathEncoder(); |
| 26 this._filesIndex = new WebInspector.Automapping.FilePathIndex(pathEncoder); | 26 this._filesIndex = new Persistence.Automapping.FilePathIndex(pathEncoder); |
| 27 this._projectFoldersIndex = new WebInspector.Automapping.FolderIndex(pathEnc
oder); | 27 this._projectFoldersIndex = new Persistence.Automapping.FolderIndex(pathEnco
der); |
| 28 this._activeFoldersIndex = new WebInspector.Automapping.FolderIndex(pathEnco
der); | 28 this._activeFoldersIndex = new Persistence.Automapping.FolderIndex(pathEncod
er); |
| 29 | 29 |
| 30 this._eventListeners = [ | 30 this._eventListeners = [ |
| 31 this._workspace.addEventListener( | 31 this._workspace.addEventListener( |
| 32 WebInspector.Workspace.Events.UISourceCodeAdded, | 32 Workspace.Workspace.Events.UISourceCodeAdded, |
| 33 event => this._onUISourceCodeAdded(/** @type {!WebInspector.UISourceCo
de} */ (event.data))), | 33 event => this._onUISourceCodeAdded(/** @type {!Workspace.UISourceCode}
*/ (event.data))), |
| 34 this._workspace.addEventListener( | 34 this._workspace.addEventListener( |
| 35 WebInspector.Workspace.Events.UISourceCodeRemoved, | 35 Workspace.Workspace.Events.UISourceCodeRemoved, |
| 36 event => this._onUISourceCodeRemoved(/** @type {!WebInspector.UISource
Code} */ (event.data))), | 36 event => this._onUISourceCodeRemoved(/** @type {!Workspace.UISourceCod
e} */ (event.data))), |
| 37 this._workspace.addEventListener( | 37 this._workspace.addEventListener( |
| 38 WebInspector.Workspace.Events.ProjectAdded, | 38 Workspace.Workspace.Events.ProjectAdded, |
| 39 event => this._onProjectAdded(/** @type {!WebInspector.Project} */ (ev
ent.data)), this), | 39 event => this._onProjectAdded(/** @type {!Workspace.Project} */ (event
.data)), this), |
| 40 this._workspace.addEventListener( | 40 this._workspace.addEventListener( |
| 41 WebInspector.Workspace.Events.ProjectRemoved, | 41 Workspace.Workspace.Events.ProjectRemoved, |
| 42 event => this._onProjectRemoved(/** @type {!WebInspector.Project} */ (
event.data)), this), | 42 event => this._onProjectRemoved(/** @type {!Workspace.Project} */ (eve
nt.data)), this), |
| 43 ]; | 43 ]; |
| 44 | 44 |
| 45 for (var fileSystem of workspace.projects()) | 45 for (var fileSystem of workspace.projects()) |
| 46 this._onProjectAdded(fileSystem); | 46 this._onProjectAdded(fileSystem); |
| 47 for (var uiSourceCode of workspace.uiSourceCodes()) | 47 for (var uiSourceCode of workspace.uiSourceCodes()) |
| 48 this._onUISourceCodeAdded(uiSourceCode); | 48 this._onUISourceCodeAdded(uiSourceCode); |
| 49 } | 49 } |
| 50 | 50 |
| 51 _scheduleRemap() { | 51 _scheduleRemap() { |
| 52 for (var binding of this._bindings.valuesArray()) | 52 for (var binding of this._bindings.valuesArray()) |
| 53 this._unbindNetwork(binding.network); | 53 this._unbindNetwork(binding.network); |
| 54 this._scheduleSweep(); | 54 this._scheduleSweep(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 _scheduleSweep() { | 57 _scheduleSweep() { |
| 58 this._sweepThrottler.schedule(sweepUnmapped.bind(this)); | 58 this._sweepThrottler.schedule(sweepUnmapped.bind(this)); |
| 59 | 59 |
| 60 /** | 60 /** |
| 61 * @this {WebInspector.Automapping} | 61 * @this {Persistence.Automapping} |
| 62 * @return {!Promise} | 62 * @return {!Promise} |
| 63 */ | 63 */ |
| 64 function sweepUnmapped() { | 64 function sweepUnmapped() { |
| 65 var networkProjects = this._workspace.projectsForType(WebInspector.project
Types.Network); | 65 var networkProjects = this._workspace.projectsForType(Workspace.projectTyp
es.Network); |
| 66 for (var networkProject of networkProjects) { | 66 for (var networkProject of networkProjects) { |
| 67 for (var uiSourceCode of networkProject.uiSourceCodes()) | 67 for (var uiSourceCode of networkProject.uiSourceCodes()) |
| 68 this._bindNetwork(uiSourceCode); | 68 this._bindNetwork(uiSourceCode); |
| 69 } | 69 } |
| 70 this._onSweepHappenedForTest(); | 70 this._onSweepHappenedForTest(); |
| 71 return Promise.resolve(); | 71 return Promise.resolve(); |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 | 74 |
| 75 _onSweepHappenedForTest() { | 75 _onSweepHappenedForTest() { |
| 76 } | 76 } |
| 77 | 77 |
| 78 /** | 78 /** |
| 79 * @param {!WebInspector.Project} project | 79 * @param {!Workspace.Project} project |
| 80 */ | 80 */ |
| 81 _onProjectRemoved(project) { | 81 _onProjectRemoved(project) { |
| 82 for (var uiSourceCode of project.uiSourceCodes()) | 82 for (var uiSourceCode of project.uiSourceCodes()) |
| 83 this._onUISourceCodeRemoved(uiSourceCode); | 83 this._onUISourceCodeRemoved(uiSourceCode); |
| 84 if (project.type() !== WebInspector.projectTypes.FileSystem) | 84 if (project.type() !== Workspace.projectTypes.FileSystem) |
| 85 return; | 85 return; |
| 86 var fileSystem = /** @type {!WebInspector.FileSystemWorkspaceBinding.FileSys
tem} */ (project); | 86 var fileSystem = /** @type {!Bindings.FileSystemWorkspaceBinding.FileSystem}
*/ (project); |
| 87 for (var gitFolder of fileSystem.gitFolders()) | 87 for (var gitFolder of fileSystem.gitFolders()) |
| 88 this._projectFoldersIndex.removeFolder(gitFolder); | 88 this._projectFoldersIndex.removeFolder(gitFolder); |
| 89 this._projectFoldersIndex.removeFolder(fileSystem.fileSystemPath()); | 89 this._projectFoldersIndex.removeFolder(fileSystem.fileSystemPath()); |
| 90 this._scheduleRemap(); | 90 this._scheduleRemap(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 /** | 93 /** |
| 94 * @param {!WebInspector.Project} project | 94 * @param {!Workspace.Project} project |
| 95 */ | 95 */ |
| 96 _onProjectAdded(project) { | 96 _onProjectAdded(project) { |
| 97 if (project.type() !== WebInspector.projectTypes.FileSystem) | 97 if (project.type() !== Workspace.projectTypes.FileSystem) |
| 98 return; | 98 return; |
| 99 var fileSystem = /** @type {!WebInspector.FileSystemWorkspaceBinding.FileSys
tem} */ (project); | 99 var fileSystem = /** @type {!Bindings.FileSystemWorkspaceBinding.FileSystem}
*/ (project); |
| 100 for (var gitFolder of fileSystem.gitFolders()) | 100 for (var gitFolder of fileSystem.gitFolders()) |
| 101 this._projectFoldersIndex.addFolder(gitFolder); | 101 this._projectFoldersIndex.addFolder(gitFolder); |
| 102 this._projectFoldersIndex.addFolder(fileSystem.fileSystemPath()); | 102 this._projectFoldersIndex.addFolder(fileSystem.fileSystemPath()); |
| 103 this._scheduleRemap(); | 103 this._scheduleRemap(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 /** | 106 /** |
| 107 * @param {!WebInspector.UISourceCode} uiSourceCode | 107 * @param {!Workspace.UISourceCode} uiSourceCode |
| 108 */ | 108 */ |
| 109 _onUISourceCodeAdded(uiSourceCode) { | 109 _onUISourceCodeAdded(uiSourceCode) { |
| 110 if (uiSourceCode.project().type() === WebInspector.projectTypes.FileSystem)
{ | 110 if (uiSourceCode.project().type() === Workspace.projectTypes.FileSystem) { |
| 111 this._filesIndex.addPath(uiSourceCode.url()); | 111 this._filesIndex.addPath(uiSourceCode.url()); |
| 112 this._fileSystemUISourceCodes.set(uiSourceCode.url(), uiSourceCode); | 112 this._fileSystemUISourceCodes.set(uiSourceCode.url(), uiSourceCode); |
| 113 this._scheduleSweep(); | 113 this._scheduleSweep(); |
| 114 } else if (uiSourceCode.project().type() === WebInspector.projectTypes.Netwo
rk) { | 114 } else if (uiSourceCode.project().type() === Workspace.projectTypes.Network)
{ |
| 115 this._bindNetwork(uiSourceCode); | 115 this._bindNetwork(uiSourceCode); |
| 116 } | 116 } |
| 117 } | 117 } |
| 118 | 118 |
| 119 /** | 119 /** |
| 120 * @param {!WebInspector.UISourceCode} uiSourceCode | 120 * @param {!Workspace.UISourceCode} uiSourceCode |
| 121 */ | 121 */ |
| 122 _onUISourceCodeRemoved(uiSourceCode) { | 122 _onUISourceCodeRemoved(uiSourceCode) { |
| 123 if (uiSourceCode.project().type() === WebInspector.projectTypes.FileSystem)
{ | 123 if (uiSourceCode.project().type() === Workspace.projectTypes.FileSystem) { |
| 124 this._filesIndex.removePath(uiSourceCode.url()); | 124 this._filesIndex.removePath(uiSourceCode.url()); |
| 125 this._fileSystemUISourceCodes.delete(uiSourceCode.url()); | 125 this._fileSystemUISourceCodes.delete(uiSourceCode.url()); |
| 126 var binding = uiSourceCode[WebInspector.Automapping._binding]; | 126 var binding = uiSourceCode[Persistence.Automapping._binding]; |
| 127 if (binding) | 127 if (binding) |
| 128 this._unbindNetwork(binding.network); | 128 this._unbindNetwork(binding.network); |
| 129 } else if (uiSourceCode.project().type() === WebInspector.projectTypes.Netwo
rk) { | 129 } else if (uiSourceCode.project().type() === Workspace.projectTypes.Network)
{ |
| 130 this._unbindNetwork(uiSourceCode); | 130 this._unbindNetwork(uiSourceCode); |
| 131 } | 131 } |
| 132 } | 132 } |
| 133 | 133 |
| 134 /** | 134 /** |
| 135 * @param {!WebInspector.UISourceCode} networkSourceCode | 135 * @param {!Workspace.UISourceCode} networkSourceCode |
| 136 */ | 136 */ |
| 137 _bindNetwork(networkSourceCode) { | 137 _bindNetwork(networkSourceCode) { |
| 138 if (networkSourceCode[WebInspector.Automapping._processingPromise] || | 138 if (networkSourceCode[Persistence.Automapping._processingPromise] || |
| 139 networkSourceCode[WebInspector.Automapping._binding]) | 139 networkSourceCode[Persistence.Automapping._binding]) |
| 140 return; | 140 return; |
| 141 var createBindingPromise = this._createBinding(networkSourceCode).then(onBin
ding.bind(this)); | 141 var createBindingPromise = this._createBinding(networkSourceCode).then(onBin
ding.bind(this)); |
| 142 networkSourceCode[WebInspector.Automapping._processingPromise] = createBindi
ngPromise; | 142 networkSourceCode[Persistence.Automapping._processingPromise] = createBindin
gPromise; |
| 143 | 143 |
| 144 /** | 144 /** |
| 145 * @param {?WebInspector.PersistenceBinding} binding | 145 * @param {?Persistence.PersistenceBinding} binding |
| 146 * @this {WebInspector.Automapping} | 146 * @this {Persistence.Automapping} |
| 147 */ | 147 */ |
| 148 function onBinding(binding) { | 148 function onBinding(binding) { |
| 149 if (networkSourceCode[WebInspector.Automapping._processingPromise] !== cre
ateBindingPromise) | 149 if (networkSourceCode[Persistence.Automapping._processingPromise] !== crea
teBindingPromise) |
| 150 return; | 150 return; |
| 151 networkSourceCode[WebInspector.Automapping._processingPromise] = null; | 151 networkSourceCode[Persistence.Automapping._processingPromise] = null; |
| 152 if (!binding) { | 152 if (!binding) { |
| 153 this._onBindingFailedForTest(); | 153 this._onBindingFailedForTest(); |
| 154 return; | 154 return; |
| 155 } | 155 } |
| 156 | 156 |
| 157 this._bindings.add(binding); | 157 this._bindings.add(binding); |
| 158 binding.network[WebInspector.Automapping._binding] = binding; | 158 binding.network[Persistence.Automapping._binding] = binding; |
| 159 binding.fileSystem[WebInspector.Automapping._binding] = binding; | 159 binding.fileSystem[Persistence.Automapping._binding] = binding; |
| 160 if (binding.exactMatch) { | 160 if (binding.exactMatch) { |
| 161 var projectFolder = this._projectFoldersIndex.closestParentFolder(bindin
g.fileSystem.url()); | 161 var projectFolder = this._projectFoldersIndex.closestParentFolder(bindin
g.fileSystem.url()); |
| 162 var newFolderAdded = projectFolder ? this._activeFoldersIndex.addFolder(
projectFolder) : false; | 162 var newFolderAdded = projectFolder ? this._activeFoldersIndex.addFolder(
projectFolder) : false; |
| 163 if (newFolderAdded) | 163 if (newFolderAdded) |
| 164 this._scheduleSweep(); | 164 this._scheduleSweep(); |
| 165 } | 165 } |
| 166 this._onBindingCreated.call(null, binding); | 166 this._onBindingCreated.call(null, binding); |
| 167 } | 167 } |
| 168 } | 168 } |
| 169 | 169 |
| 170 _onBindingFailedForTest() { | 170 _onBindingFailedForTest() { |
| 171 } | 171 } |
| 172 | 172 |
| 173 /** | 173 /** |
| 174 * @param {!WebInspector.UISourceCode} networkSourceCode | 174 * @param {!Workspace.UISourceCode} networkSourceCode |
| 175 */ | 175 */ |
| 176 _unbindNetwork(networkSourceCode) { | 176 _unbindNetwork(networkSourceCode) { |
| 177 if (networkSourceCode[WebInspector.Automapping._processingPromise]) { | 177 if (networkSourceCode[Persistence.Automapping._processingPromise]) { |
| 178 networkSourceCode[WebInspector.Automapping._processingPromise] = null; | 178 networkSourceCode[Persistence.Automapping._processingPromise] = null; |
| 179 return; | 179 return; |
| 180 } | 180 } |
| 181 var binding = networkSourceCode[WebInspector.Automapping._binding]; | 181 var binding = networkSourceCode[Persistence.Automapping._binding]; |
| 182 if (!binding) | 182 if (!binding) |
| 183 return; | 183 return; |
| 184 | 184 |
| 185 this._bindings.delete(binding); | 185 this._bindings.delete(binding); |
| 186 binding.network[WebInspector.Automapping._binding] = null; | 186 binding.network[Persistence.Automapping._binding] = null; |
| 187 binding.fileSystem[WebInspector.Automapping._binding] = null; | 187 binding.fileSystem[Persistence.Automapping._binding] = null; |
| 188 if (binding.exactMatch) { | 188 if (binding.exactMatch) { |
| 189 var projectFolder = this._projectFoldersIndex.closestParentFolder(binding.
fileSystem.url()); | 189 var projectFolder = this._projectFoldersIndex.closestParentFolder(binding.
fileSystem.url()); |
| 190 if (projectFolder) | 190 if (projectFolder) |
| 191 this._activeFoldersIndex.removeFolder(projectFolder); | 191 this._activeFoldersIndex.removeFolder(projectFolder); |
| 192 } | 192 } |
| 193 this._onBindingRemoved.call(null, binding); | 193 this._onBindingRemoved.call(null, binding); |
| 194 } | 194 } |
| 195 | 195 |
| 196 /** | 196 /** |
| 197 * @param {!WebInspector.UISourceCode} networkSourceCode | 197 * @param {!Workspace.UISourceCode} networkSourceCode |
| 198 * @return {!Promise<?WebInspector.PersistenceBinding>} | 198 * @return {!Promise<?Persistence.PersistenceBinding>} |
| 199 */ | 199 */ |
| 200 _createBinding(networkSourceCode) { | 200 _createBinding(networkSourceCode) { |
| 201 if (networkSourceCode.url().startsWith('file://')) { | 201 if (networkSourceCode.url().startsWith('file://')) { |
| 202 var fileSourceCode = this._fileSystemUISourceCodes.get(networkSourceCode.u
rl()); | 202 var fileSourceCode = this._fileSystemUISourceCodes.get(networkSourceCode.u
rl()); |
| 203 var binding = fileSourceCode ? new WebInspector.PersistenceBinding(network
SourceCode, fileSourceCode, false) : null; | 203 var binding = fileSourceCode ? new Persistence.PersistenceBinding(networkS
ourceCode, fileSourceCode, false) : null; |
| 204 return Promise.resolve(binding); | 204 return Promise.resolve(binding); |
| 205 } | 205 } |
| 206 | 206 |
| 207 var networkPath = WebInspector.ParsedURL.extractPath(networkSourceCode.url()
); | 207 var networkPath = Common.ParsedURL.extractPath(networkSourceCode.url()); |
| 208 if (networkPath === null) | 208 if (networkPath === null) |
| 209 return Promise.resolve(/** @type {?WebInspector.PersistenceBinding} */ (nu
ll)); | 209 return Promise.resolve(/** @type {?Persistence.PersistenceBinding} */ (nul
l)); |
| 210 | 210 |
| 211 if (networkPath.endsWith('/')) | 211 if (networkPath.endsWith('/')) |
| 212 networkPath += 'index.html'; | 212 networkPath += 'index.html'; |
| 213 var similarFiles = this._filesIndex.similarFiles(networkPath).map(path => th
is._fileSystemUISourceCodes.get(path)); | 213 var similarFiles = this._filesIndex.similarFiles(networkPath).map(path => th
is._fileSystemUISourceCodes.get(path)); |
| 214 if (!similarFiles.length) | 214 if (!similarFiles.length) |
| 215 return Promise.resolve(/** @type {?WebInspector.PersistenceBinding} */ (nu
ll)); | 215 return Promise.resolve(/** @type {?Persistence.PersistenceBinding} */ (nul
l)); |
| 216 | 216 |
| 217 return this._pullMetadatas(similarFiles.concat(networkSourceCode)).then(onMe
tadatas.bind(this)); | 217 return this._pullMetadatas(similarFiles.concat(networkSourceCode)).then(onMe
tadatas.bind(this)); |
| 218 | 218 |
| 219 /** | 219 /** |
| 220 * @this {WebInspector.Automapping} | 220 * @this {Persistence.Automapping} |
| 221 */ | 221 */ |
| 222 function onMetadatas() { | 222 function onMetadatas() { |
| 223 var activeFiles = similarFiles.filter(file => !!this._activeFoldersIndex.c
losestParentFolder(file.url())); | 223 var activeFiles = similarFiles.filter(file => !!this._activeFoldersIndex.c
losestParentFolder(file.url())); |
| 224 var networkMetadata = networkSourceCode[WebInspector.Automapping._metadata
]; | 224 var networkMetadata = networkSourceCode[Persistence.Automapping._metadata]
; |
| 225 if (!networkMetadata || (!networkMetadata.modificationTime && typeof netwo
rkMetadata.contentSize !== 'number')) { | 225 if (!networkMetadata || (!networkMetadata.modificationTime && typeof netwo
rkMetadata.contentSize !== 'number')) { |
| 226 // If networkSourceCode does not have metadata, try to match against act
ive folders. | 226 // If networkSourceCode does not have metadata, try to match against act
ive folders. |
| 227 if (activeFiles.length !== 1) | 227 if (activeFiles.length !== 1) |
| 228 return null; | 228 return null; |
| 229 return new WebInspector.PersistenceBinding(networkSourceCode, activeFile
s[0], false); | 229 return new Persistence.PersistenceBinding(networkSourceCode, activeFiles
[0], false); |
| 230 } | 230 } |
| 231 | 231 |
| 232 // Try to find exact matches, prioritizing active folders. | 232 // Try to find exact matches, prioritizing active folders. |
| 233 var exactMatches = this._filterWithMetadata(activeFiles, networkMetadata); | 233 var exactMatches = this._filterWithMetadata(activeFiles, networkMetadata); |
| 234 if (!exactMatches.length) | 234 if (!exactMatches.length) |
| 235 exactMatches = this._filterWithMetadata(similarFiles, networkMetadata); | 235 exactMatches = this._filterWithMetadata(similarFiles, networkMetadata); |
| 236 if (exactMatches.length !== 1) | 236 if (exactMatches.length !== 1) |
| 237 return null; | 237 return null; |
| 238 return new WebInspector.PersistenceBinding(networkSourceCode, exactMatches
[0], true); | 238 return new Persistence.PersistenceBinding(networkSourceCode, exactMatches[
0], true); |
| 239 } | 239 } |
| 240 } | 240 } |
| 241 | 241 |
| 242 /** | 242 /** |
| 243 * @param {!Array<!WebInspector.UISourceCode>} uiSourceCodes | 243 * @param {!Array<!Workspace.UISourceCode>} uiSourceCodes |
| 244 * @return {!Promise} | 244 * @return {!Promise} |
| 245 */ | 245 */ |
| 246 _pullMetadatas(uiSourceCodes) { | 246 _pullMetadatas(uiSourceCodes) { |
| 247 var promises = uiSourceCodes.map(file => fetchMetadata(file)); | 247 var promises = uiSourceCodes.map(file => fetchMetadata(file)); |
| 248 return Promise.all(promises); | 248 return Promise.all(promises); |
| 249 | 249 |
| 250 /** | 250 /** |
| 251 * @param {!WebInspector.UISourceCode} file | 251 * @param {!Workspace.UISourceCode} file |
| 252 * @return {!Promise} | 252 * @return {!Promise} |
| 253 */ | 253 */ |
| 254 function fetchMetadata(file) { | 254 function fetchMetadata(file) { |
| 255 return file.requestMetadata().then(metadata => file[WebInspector.Automappi
ng._metadata] = metadata); | 255 return file.requestMetadata().then(metadata => file[Persistence.Automappin
g._metadata] = metadata); |
| 256 } | 256 } |
| 257 } | 257 } |
| 258 | 258 |
| 259 /** | 259 /** |
| 260 * @param {!Array<!WebInspector.UISourceCode>} files | 260 * @param {!Array<!Workspace.UISourceCode>} files |
| 261 * @param {!WebInspector.UISourceCodeMetadata} networkMetadata | 261 * @param {!Workspace.UISourceCodeMetadata} networkMetadata |
| 262 * @return {!Array<!WebInspector.UISourceCode>} | 262 * @return {!Array<!Workspace.UISourceCode>} |
| 263 */ | 263 */ |
| 264 _filterWithMetadata(files, networkMetadata) { | 264 _filterWithMetadata(files, networkMetadata) { |
| 265 return files.filter(file => { | 265 return files.filter(file => { |
| 266 var fileMetadata = file[WebInspector.Automapping._metadata]; | 266 var fileMetadata = file[Persistence.Automapping._metadata]; |
| 267 if (!fileMetadata) | 267 if (!fileMetadata) |
| 268 return false; | 268 return false; |
| 269 // Allow a second of difference due to network timestamps lack of precisio
n. | 269 // Allow a second of difference due to network timestamps lack of precisio
n. |
| 270 var timeMatches = !networkMetadata.modificationTime || | 270 var timeMatches = !networkMetadata.modificationTime || |
| 271 Math.abs(networkMetadata.modificationTime - fileMetadata.modificationT
ime) < 1000; | 271 Math.abs(networkMetadata.modificationTime - fileMetadata.modificationT
ime) < 1000; |
| 272 var contentMatches = !networkMetadata.contentSize || fileMetadata.contentS
ize === networkMetadata.contentSize; | 272 var contentMatches = !networkMetadata.contentSize || fileMetadata.contentS
ize === networkMetadata.contentSize; |
| 273 return timeMatches && contentMatches; | 273 return timeMatches && contentMatches; |
| 274 }); | 274 }); |
| 275 } | 275 } |
| 276 }; | 276 }; |
| 277 | 277 |
| 278 WebInspector.Automapping._binding = Symbol('Automapping.Binding'); | 278 Persistence.Automapping._binding = Symbol('Automapping.Binding'); |
| 279 WebInspector.Automapping._processingPromise = Symbol('Automapping.ProcessingProm
ise'); | 279 Persistence.Automapping._processingPromise = Symbol('Automapping.ProcessingPromi
se'); |
| 280 WebInspector.Automapping._metadata = Symbol('Automapping.Metadata'); | 280 Persistence.Automapping._metadata = Symbol('Automapping.Metadata'); |
| 281 | 281 |
| 282 /** | 282 /** |
| 283 * @unrestricted | 283 * @unrestricted |
| 284 */ | 284 */ |
| 285 WebInspector.Automapping.PathEncoder = class { | 285 Persistence.Automapping.PathEncoder = class { |
| 286 constructor() { | 286 constructor() { |
| 287 /** @type {!WebInspector.CharacterIdMap<string>} */ | 287 /** @type {!Common.CharacterIdMap<string>} */ |
| 288 this._encoder = new WebInspector.CharacterIdMap(); | 288 this._encoder = new Common.CharacterIdMap(); |
| 289 } | 289 } |
| 290 | 290 |
| 291 /** | 291 /** |
| 292 * @param {string} path | 292 * @param {string} path |
| 293 * @return {string} | 293 * @return {string} |
| 294 */ | 294 */ |
| 295 encode(path) { | 295 encode(path) { |
| 296 return path.split('/').map(token => this._encoder.toChar(token)).join(''); | 296 return path.split('/').map(token => this._encoder.toChar(token)).join(''); |
| 297 } | 297 } |
| 298 | 298 |
| 299 /** | 299 /** |
| 300 * @param {string} path | 300 * @param {string} path |
| 301 * @return {string} | 301 * @return {string} |
| 302 */ | 302 */ |
| 303 decode(path) { | 303 decode(path) { |
| 304 return path.split('').map(token => this._encoder.fromChar(token)).join('/'); | 304 return path.split('').map(token => this._encoder.fromChar(token)).join('/'); |
| 305 } | 305 } |
| 306 }; | 306 }; |
| 307 | 307 |
| 308 /** | 308 /** |
| 309 * @unrestricted | 309 * @unrestricted |
| 310 */ | 310 */ |
| 311 WebInspector.Automapping.FilePathIndex = class { | 311 Persistence.Automapping.FilePathIndex = class { |
| 312 /** | 312 /** |
| 313 * @param {!WebInspector.Automapping.PathEncoder} encoder | 313 * @param {!Persistence.Automapping.PathEncoder} encoder |
| 314 */ | 314 */ |
| 315 constructor(encoder) { | 315 constructor(encoder) { |
| 316 this._encoder = encoder; | 316 this._encoder = encoder; |
| 317 this._reversedIndex = new WebInspector.Trie(); | 317 this._reversedIndex = new Common.Trie(); |
| 318 } | 318 } |
| 319 | 319 |
| 320 /** | 320 /** |
| 321 * @param {string} path | 321 * @param {string} path |
| 322 */ | 322 */ |
| 323 addPath(path) { | 323 addPath(path) { |
| 324 var encodedPath = this._encoder.encode(path); | 324 var encodedPath = this._encoder.encode(path); |
| 325 this._reversedIndex.add(encodedPath.reverse()); | 325 this._reversedIndex.add(encodedPath.reverse()); |
| 326 } | 326 } |
| 327 | 327 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 343 if (!longestCommonPrefix) | 343 if (!longestCommonPrefix) |
| 344 return []; | 344 return []; |
| 345 return this._reversedIndex.words(longestCommonPrefix) | 345 return this._reversedIndex.words(longestCommonPrefix) |
| 346 .map(encodedPath => this._encoder.decode(encodedPath.reverse())); | 346 .map(encodedPath => this._encoder.decode(encodedPath.reverse())); |
| 347 } | 347 } |
| 348 }; | 348 }; |
| 349 | 349 |
| 350 /** | 350 /** |
| 351 * @unrestricted | 351 * @unrestricted |
| 352 */ | 352 */ |
| 353 WebInspector.Automapping.FolderIndex = class { | 353 Persistence.Automapping.FolderIndex = class { |
| 354 /** | 354 /** |
| 355 * @param {!WebInspector.Automapping.PathEncoder} encoder | 355 * @param {!Persistence.Automapping.PathEncoder} encoder |
| 356 */ | 356 */ |
| 357 constructor(encoder) { | 357 constructor(encoder) { |
| 358 this._encoder = encoder; | 358 this._encoder = encoder; |
| 359 this._index = new WebInspector.Trie(); | 359 this._index = new Common.Trie(); |
| 360 /** @type {!Map<string, number>} */ | 360 /** @type {!Map<string, number>} */ |
| 361 this._folderCount = new Map(); | 361 this._folderCount = new Map(); |
| 362 } | 362 } |
| 363 | 363 |
| 364 /** | 364 /** |
| 365 * @param {string} path | 365 * @param {string} path |
| 366 * @return {boolean} | 366 * @return {boolean} |
| 367 */ | 367 */ |
| 368 addFolder(path) { | 368 addFolder(path) { |
| 369 if (path.endsWith('/')) | 369 if (path.endsWith('/')) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 398 /** | 398 /** |
| 399 * @param {string} path | 399 * @param {string} path |
| 400 * @return {string} | 400 * @return {string} |
| 401 */ | 401 */ |
| 402 closestParentFolder(path) { | 402 closestParentFolder(path) { |
| 403 var encodedPath = this._encoder.encode(path); | 403 var encodedPath = this._encoder.encode(path); |
| 404 var commonPrefix = this._index.longestPrefix(encodedPath, true); | 404 var commonPrefix = this._index.longestPrefix(encodedPath, true); |
| 405 return this._encoder.decode(commonPrefix); | 405 return this._encoder.decode(commonPrefix); |
| 406 } | 406 } |
| 407 }; | 407 }; |
| OLD | NEW |