| 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 Persistence.Automapping = class { | 7 Persistence.Automapping = class { |
| 8 /** | 8 /** |
| 9 * @param {!Workspace.Workspace} workspace | 9 * @param {!Workspace.Workspace} workspace |
| 10 * @param {function(!Persistence.PersistenceBinding)} onBindingCreated | 10 * @param {function(!Persistence.PersistenceBinding)} onBindingCreated |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 {Persistence.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(Workspace.projectTyp
es.Network); | 65 for (var uiSourceCode of Bindings.NetworkProject.uiSourceCodes(this._works
pace)) |
| 66 for (var networkProject of networkProjects) { | 66 this._bindNetwork(uiSourceCode); |
| 67 for (var uiSourceCode of networkProject.uiSourceCodes()) | |
| 68 this._bindNetwork(uiSourceCode); | |
| 69 } | |
| 70 this._onSweepHappenedForTest(); | 67 this._onSweepHappenedForTest(); |
| 71 return Promise.resolve(); | 68 return Promise.resolve(); |
| 72 } | 69 } |
| 73 } | 70 } |
| 74 | 71 |
| 75 _onSweepHappenedForTest() { | 72 _onSweepHappenedForTest() { |
| 76 } | 73 } |
| 77 | 74 |
| 78 /** | 75 /** |
| 79 * @param {!Workspace.Project} project | 76 * @param {!Workspace.Project} project |
| 80 */ | 77 */ |
| 81 _onProjectRemoved(project) { | 78 _onProjectRemoved(project) { |
| 82 for (var uiSourceCode of project.uiSourceCodes()) | 79 for (var uiSourceCode of project.uiSourceCodes()) |
| 83 this._onUISourceCodeRemoved(uiSourceCode); | 80 this._onUISourceCodeRemoved(uiSourceCode); |
| 84 if (project.type() !== Workspace.projectTypes.FileSystem) | 81 if (!Persistence.FileSystemWorkspaceBinding.isFileSystemProject(project)) |
| 85 return; | 82 return; |
| 86 var fileSystem = /** @type {!Persistence.FileSystemWorkspaceBinding.FileSyst
em} */ (project); | 83 var fileSystem = /** @type {!Persistence.FileSystemWorkspaceBinding.FileSyst
em} */ (project); |
| 87 for (var gitFolder of fileSystem.gitFolders()) | 84 for (var gitFolder of fileSystem.gitFolders()) |
| 88 this._projectFoldersIndex.removeFolder(gitFolder); | 85 this._projectFoldersIndex.removeFolder(gitFolder); |
| 89 this._projectFoldersIndex.removeFolder(fileSystem.fileSystemPath()); | 86 this._projectFoldersIndex.removeFolder(fileSystem.fileSystemPath()); |
| 90 this._scheduleRemap(); | 87 this._scheduleRemap(); |
| 91 } | 88 } |
| 92 | 89 |
| 93 /** | 90 /** |
| 94 * @param {!Workspace.Project} project | 91 * @param {!Workspace.Project} project |
| 95 */ | 92 */ |
| 96 _onProjectAdded(project) { | 93 _onProjectAdded(project) { |
| 97 if (project.type() !== Workspace.projectTypes.FileSystem) | 94 if (!Persistence.FileSystemWorkspaceBinding.isFileSystemProject(project)) |
| 98 return; | 95 return; |
| 99 var fileSystem = /** @type {!Persistence.FileSystemWorkspaceBinding.FileSyst
em} */ (project); | 96 var fileSystem = /** @type {!Persistence.FileSystemWorkspaceBinding.FileSyst
em} */ (project); |
| 100 for (var gitFolder of fileSystem.gitFolders()) | 97 for (var gitFolder of fileSystem.gitFolders()) |
| 101 this._projectFoldersIndex.addFolder(gitFolder); | 98 this._projectFoldersIndex.addFolder(gitFolder); |
| 102 this._projectFoldersIndex.addFolder(fileSystem.fileSystemPath()); | 99 this._projectFoldersIndex.addFolder(fileSystem.fileSystemPath()); |
| 103 this._scheduleRemap(); | 100 this._scheduleRemap(); |
| 104 } | 101 } |
| 105 | 102 |
| 106 /** | 103 /** |
| 107 * @param {!Workspace.UISourceCode} uiSourceCode | 104 * @param {!Workspace.UISourceCode} uiSourceCode |
| 108 */ | 105 */ |
| 109 _onUISourceCodeAdded(uiSourceCode) { | 106 _onUISourceCodeAdded(uiSourceCode) { |
| 110 if (uiSourceCode.project().type() === Workspace.projectTypes.FileSystem) { | 107 if (Persistence.FileSystemWorkspaceBinding.isFileSystemUISourceCode(uiSource
Code)) { |
| 111 this._filesIndex.addPath(uiSourceCode.url()); | 108 this._filesIndex.addPath(uiSourceCode.url()); |
| 112 this._fileSystemUISourceCodes.set(uiSourceCode.url(), uiSourceCode); | 109 this._fileSystemUISourceCodes.set(uiSourceCode.url(), uiSourceCode); |
| 113 this._scheduleSweep(); | 110 this._scheduleSweep(); |
| 114 } else if (uiSourceCode.project().type() === Workspace.projectTypes.Network)
{ | 111 } else if (Bindings.NetworkProject.isNetworkUISourceCode(uiSourceCode)) { |
| 115 this._bindNetwork(uiSourceCode); | 112 this._bindNetwork(uiSourceCode); |
| 116 } | 113 } |
| 117 } | 114 } |
| 118 | 115 |
| 119 /** | 116 /** |
| 120 * @param {!Workspace.UISourceCode} uiSourceCode | 117 * @param {!Workspace.UISourceCode} uiSourceCode |
| 121 */ | 118 */ |
| 122 _onUISourceCodeRemoved(uiSourceCode) { | 119 _onUISourceCodeRemoved(uiSourceCode) { |
| 123 if (uiSourceCode.project().type() === Workspace.projectTypes.FileSystem) { | 120 if (Persistence.FileSystemWorkspaceBinding.isFileSystemUISourceCode(uiSource
Code)) { |
| 124 this._filesIndex.removePath(uiSourceCode.url()); | 121 this._filesIndex.removePath(uiSourceCode.url()); |
| 125 this._fileSystemUISourceCodes.delete(uiSourceCode.url()); | 122 this._fileSystemUISourceCodes.delete(uiSourceCode.url()); |
| 126 var binding = uiSourceCode[Persistence.Automapping._binding]; | 123 var binding = uiSourceCode[Persistence.Automapping._binding]; |
| 127 if (binding) | 124 if (binding) |
| 128 this._unbindNetwork(binding.network); | 125 this._unbindNetwork(binding.network); |
| 129 } else if (uiSourceCode.project().type() === Workspace.projectTypes.Network)
{ | 126 } else if (Bindings.NetworkProject.isNetworkUISourceCode(uiSourceCode)) { |
| 130 this._unbindNetwork(uiSourceCode); | 127 this._unbindNetwork(uiSourceCode); |
| 131 } | 128 } |
| 132 } | 129 } |
| 133 | 130 |
| 134 /** | 131 /** |
| 135 * @param {!Workspace.UISourceCode} networkSourceCode | 132 * @param {!Workspace.UISourceCode} networkSourceCode |
| 136 */ | 133 */ |
| 137 _bindNetwork(networkSourceCode) { | 134 _bindNetwork(networkSourceCode) { |
| 138 if (networkSourceCode[Persistence.Automapping._processingPromise] || | 135 if (networkSourceCode[Persistence.Automapping._processingPromise] || |
| 139 networkSourceCode[Persistence.Automapping._binding]) | 136 networkSourceCode[Persistence.Automapping._binding]) |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 /** | 396 /** |
| 400 * @param {string} path | 397 * @param {string} path |
| 401 * @return {string} | 398 * @return {string} |
| 402 */ | 399 */ |
| 403 closestParentFolder(path) { | 400 closestParentFolder(path) { |
| 404 var encodedPath = this._encoder.encode(path); | 401 var encodedPath = this._encoder.encode(path); |
| 405 var commonPrefix = this._index.longestPrefix(encodedPath, true); | 402 var commonPrefix = this._index.longestPrefix(encodedPath, true); |
| 406 return this._encoder.decode(commonPrefix); | 403 return this._encoder.decode(commonPrefix); |
| 407 } | 404 } |
| 408 }; | 405 }; |
| OLD | NEW |